How to Implement Watchdog Timer Function Using Microcontroller I/O

Designers often face two microcontroller I/O problems. The first problem is that the best microcontroller for the application does not have the right combination of I/O capabilities. The second problem is that I/O needs to be added to the product line that has been introduced.

Author: Jacob Beningo

Designers often face two microcontroller I/O problems. The first problem is that the best microcontroller for the application does not have the right combination of I/O capabilities. The second problem is that I/O needs to be added to the product line that has been introduced.

When the first problem arises, developers often have to buy more expensive and more powerful microcontrollers. When faced with the second problem, the cost and time required to switch to a new microcontroller and the accompanying software migration can be prohibitive.

To address both of these issues, one potential solution is to use an external I/O expansion device, which is usually connected to the microcontroller’s SPI or I2C bus. This avoids over-specifying the microcontroller in terms of pin count and possibly performance and packaging. At the same time, this approach allows for forward-looking product design in response to features such as feature creep, target market expansion, customer feature requests, and poor microcontroller selection, which happens from time to time.

This article will discuss typical microcontroller I/O requirements, introduce some suitable external expansion devices, and then show how to use these off-chip resources to add general-purpose inputs and outputs, memory storage, pulse-width modulation (PWM), and even watchdogs Timer function.

Select extension interface

The microcontroller is equipped with several different on-chip peripheral interfaces that can be used to communicate with external devices. Depending on the microcontroller, these interfaces may include (to name a few):

• Serial Peripheral Interface (SPI)
• Inter-Integrated circuit (I2C) bus
• Universal Serial Bus (USB)
• Universal Asynchronous Receiver/Transmitter (UART)
• Controller Area Network (CAN)
Wi-Fi

The most suitable interfaces for communicating with external expansion devices are I2C and SPI.

I2C is a two-wire bus that traditionally runs at 100 kilobits per second (kb/s) or 400 kb/s, but there are some high-speed devices that can support 1 Mb/s or faster. One of the lines is a dedicated clock pin, while the other line is used for bidirectional communication between the master and slave devices. Typically, the microcontroller acts as the master and the external device acts as the slave. Slaves can be addressed using a 7-bit or 10-bit addressing scheme.

SPI is a three-wire bus interface that operates between 1 Mb/s and 12 Mb/s. The SPI bus has dedicated master output data lines, slave output data lines, and a clock. The microcontroller is also configured as a master device and communicates with the slave device using the “slave select” line. Each slave device connected to the microcontroller needs a dedicated output pin to select it for communication. It’s not hard to imagine that if a developer has a lot of external devices they want to connect, they might quickly run out of I/O lines and choose a slave device.

For example, if the developer uses STMicroelectronics’ STM32L011D4P7, a total of 11 I/O lines are available. Three I/O lines are required for the SPI data and clock alone, and the remaining eight lines are required to perform all other functions required by the system in addition to communicating with the slave device. While this is perfectly adequate for many applications, at some point the designer may still need to expand the I/O.

In general, the rule of thumb is very simple: use the I2C bus when adding:

• I/O
• PWM
• EEPROM
• Watchdog Timer
• The SPI bus should be used to add functions such as providing high-speed memory access for SD cards.
• Extended general purpose I/O
• There are quite a few integrated circuits that support expansion of inputs and outputs via the I2C interface. Here are some interesting examples:
• TCA9534PWR from Texas Instruments
• PCA8574 from NXP Semiconductors
• SX1520I087TRT from Semtech CorporaTion

The PCA8574 is a particularly interesting device because it contains only one register for performing input and output. A single register greatly reduces the amount of software required to configure the device and read and write pins (Figure 2). The microcontroller communicates with the PCA8574 via I2C and addresses the device according to how the A0 to A2 pins are configured. This feature increases design flexibility, so developers can choose the slave address for the PCA8574 and can use multiple slave addresses in a design.


Figure 2: NXP’s PCA8574 is a quasi-bidirectional 8-bit I/O I2C expander. The expander has only one I2C register to read and write to perform I/O functions on its pins, making it a very simple, compact device. (Image credit: NXP Semiconductors)

By default, P0 to P7 are configured as inputs at power-up. Reading a single internal register assigns the state of each pin on the device, whether that pin is configured as an input or an output. The PCA8574 allows pins to be used as both input and output, so writes to registers also set the corresponding bit output.

The output drive is pulled up by a weak internal Resistor that is easily overloaded by the input value. If the state of any of the inputs changes, the INT pin will toggle low, letting the microcontroller know that the state of the input has changed. The microcontroller can then call I2C to read the new value.

Extended PWM

The PWM expander is a very useful expansion device. This device is especially useful when driving LEDs. When the microcontroller is not doing anything, it can be put into sleep mode, where the PWM expander is responsible for driving the LED states.

A perfect example of how to use a PWM expander is often found in an RGB button circuit using E-Switch’s PV6F240SSG RGB button or Schurter Electronic components‘ 3-101-399 SPST RGB button (Figure 3).

Schurter’s RGB buttons feature red, green, and blue LEDs around the SPST buttons, allowing developers to create bright-colored patterns. These types of applications are ideal for PWM expansion chips.

Maxim Integrated’s MAX7315 is a PWM expansion chip for the I2C interface. The MAX7315 features 8 PWM ports with LED intensity control, which easily covers the 3 channels required to drive an RGB switch, enabling a single device to drive several switches and some individual LEDs. In addition, the MAX7315 has a ninth port that can be used as a transition-detection interrupt or a general-purpose output.

The MAX7315 I2C interface is slightly more complex than NXP’s PCA8574 because it contains multiple registers. Therefore, the developer must address the slave device, provide the memory address it is interested in reading or writing, and then perform the write or read. The memory map of the MAX7315 is shown in Figure 4.


Figure 4: The MAX7315 PWM controller features eight output ports, including an LED intensity function. The device’s register map is very simple, allowing easy access to advanced PWM functions. (Image credit: Maxim Integrated)

The MAX7315’s register map is very simple, allowing easy access to advanced PWM functions.

Combo Expander with WDT, EEPROM and PWM

As shown, the I2C-bus I/O expander can be very powerful when used as a stand-alone device. That is, the expander only includes specific functions such as I/O or PWM. An example is Cypress semiconductor‘s CY8C9520A multiport I/O expander, which contains multiple peripheral expansions in one IC package. CY8C9520A has three extensions: 20-bit, 40-bit or 60-bit extension. These pins can then be configured as input, output, or PWM (Figure 5).


Figure 5: Cypress Semiconductor’s CY8C9520 is a 20-, 40-, or 60-bit I/O expander with EEPROM. This expander allows the expansion pins to be configured as input, output or PWM. (Image credit: Cypress Semiconductor)

In addition to I/O expansion, the CY8C9520 also features an EEPROM that can be used to store important application settings such as serial numbers, as well as other important configuration parameters.

Looking closely at Figure 5, you can see the WD6 pin on GPort 2. This pin is a watchdog timer output pin and can be used to reset the microcontroller when the microcontroller cannot communicate, and to operate the CY8C9529 watchdog. Watchdog settings are fully configurable and can be used to add additional robustness to application code.

Tips and Tricks for Expanding Microcontroller Capabilities

There are many technologies that help expand the capabilities of microcontrollers. Here are some helpful tips and tricks:

Use I2C to connect external devices. The interface requires only two pins and supports multiple slave devices.

Before designing a part into hardware, buy a development board, or solder a chip to an expansion board, and test if it meets your system needs.

Using I2C bus tools to interface with expansion devices and see how they work can dramatically speed up software development.

During software development, use a bus analyzer to monitor communications with external devices to minimize debugging time.

If possible, choose a device with an external watchdog timer as a tool to add robustness to the system design.

When connecting off-chip memory to obtain data (not configuration data), please use a high-speed interface such as SPI.

If the device returns a negative acknowledge (NAK) signal, or the bus is dragged, make sure that the microcontroller’s I2C driver can handle such issues. It is not uncommon for these drivers to ignore errors and enter an infinite loop when they receive an unexpected response.

in conclusion

When the design progresses to the point where the microcontroller can no longer provide more I/O, developers do not need to tear down the existing design. Instead, they can use peripheral chips to add extra functionality to the system.

Author: Jacob Beningo

Designers often face two microcontroller I/O problems. The first problem is that the best microcontroller for the application does not have the right combination of I/O capabilities. The second problem is that I/O needs to be added to the product line that has been introduced.

When the first problem arises, developers often have to buy more expensive and more powerful microcontrollers. When faced with the second problem, the cost and time required to switch to a new microcontroller and the accompanying software migration can be prohibitive.

To address both of these issues, one potential solution is to use an external I/O expansion device, which is usually connected to the microcontroller’s SPI or I2C bus. This avoids over-specifying the microcontroller in terms of pin count and possibly performance and packaging. At the same time, this approach allows for forward-looking product design in response to features such as feature creep, target market expansion, customer feature requests, and poor microcontroller selection, which happens from time to time.

This article will discuss typical microcontroller I/O requirements, introduce some suitable external expansion devices, and then show how to use these off-chip resources to add general-purpose inputs and outputs, memory storage, pulse-width modulation (PWM), and even watchdogs Timer function.

Select extension interface

The microcontroller is equipped with several different on-chip peripheral interfaces that can be used to communicate with external devices. Depending on the microcontroller, these interfaces may include (to name a few):

• Serial Peripheral Interface (SPI)
• Inter-Integrated Circuit (I2C) bus
• Universal Serial Bus (USB)
• Universal Asynchronous Receiver/Transmitter (UART)
• Controller Area Network (CAN)
• Wi-Fi

The most suitable interfaces for communicating with external expansion devices are I2C and SPI.

I2C is a two-wire bus that traditionally runs at 100 kilobits per second (kb/s) or 400 kb/s, but there are some high-speed devices that can support 1 Mb/s or faster. One of the lines is a dedicated clock pin, while the other line is used for bidirectional communication between the master and slave devices. Typically, the microcontroller acts as the master and the external device acts as the slave. Slaves can be addressed using a 7-bit or 10-bit addressing scheme.

SPI is a three-wire bus interface that operates between 1 Mb/s and 12 Mb/s. The SPI bus has dedicated master output data lines, slave output data lines, and a clock. The microcontroller is also configured as a master device and communicates with the slave device using the “slave select” line. Each slave device connected to the microcontroller needs a dedicated output pin to select it for communication. It’s not hard to imagine that if a developer has a lot of external devices they want to connect, they might quickly run out of I/O lines and choose a slave device.

For example, if the developer uses STMicroelectronics’ STM32L011D4P7, a total of 11 I/O lines are available. Three I/O lines are required for the SPI data and clock alone, and the remaining eight lines are required to perform all other functions required by the system in addition to communicating with the slave device. While this is perfectly adequate for many applications, at some point the designer may still need to expand the I/O.

In general, the rule of thumb is very simple: use the I2C bus when adding:

• I/O
• PWM
• EEPROM
• Watchdog Timer
• The SPI bus should be used to add functions such as providing high-speed memory access for SD cards.
• Extended general purpose I/O
• There are quite a few integrated circuits that support expansion of inputs and outputs via the I2C interface. Here are some interesting examples:
• TCA9534PWR from Texas Instruments
• PCA8574 from NXP Semiconductors
• SX1520I087TRT from Semtech CorporaTion

The PCA8574 is a particularly interesting device because it contains only one register for performing input and output. A single register greatly reduces the amount of software required to configure the device and read and write pins (Figure 2). The microcontroller communicates with the PCA8574 via I2C and addresses the device according to how the A0 to A2 pins are configured. This feature increases design flexibility, so developers can choose the slave address for the PCA8574 and can use multiple slave addresses in a design.


Figure 2: NXP’s PCA8574 is a quasi-bidirectional 8-bit I/O I2C expander. The expander has only one I2C register to read and write to perform I/O functions on its pins, making it a very simple, compact device. (Image credit: NXP Semiconductors)

By default, P0 to P7 are configured as inputs at power-up. Reading a single internal register assigns the state of each pin on the device, whether that pin is configured as an input or an output. The PCA8574 allows pins to be used as both input and output, so writes to registers also set the corresponding bit output.

The output drive is pulled up by a weak internal resistor that is easily overloaded by the input value. If the state of any of the inputs changes, the INT pin will toggle low, letting the microcontroller know that the state of the input has changed. The microcontroller can then call I2C to read the new value.

Extended PWM

The PWM expander is a very useful expansion device. This device is especially useful when driving LEDs. When the microcontroller is not doing anything, it can be put into sleep mode, where the PWM expander is responsible for driving the LED states.

A perfect example of how to use a PWM expander is often found in an RGB button circuit using E-Switch’s PV6F240SSG RGB button or Schurter Electronic Components’ 3-101-399 SPST RGB button (Figure 3).

Schurter’s RGB buttons feature red, green, and blue LEDs around the SPST buttons, allowing developers to create bright-colored patterns. These types of applications are ideal for PWM expansion chips.

Maxim Integrated’s MAX7315 is a PWM expansion chip for the I2C interface. The MAX7315 features 8 PWM ports with LED intensity control, which easily covers the 3 channels required to drive an RGB switch, enabling a single device to drive several switches and some individual LEDs. In addition, the MAX7315 has a ninth port that can be used as a transition-detection interrupt or a general-purpose output.

The MAX7315 I2C interface is slightly more complex than NXP’s PCA8574 because it contains multiple registers. Therefore, the developer must address the slave device, provide the memory address it is interested in reading or writing, and then perform the write or read. The memory map of the MAX7315 is shown in Figure 4.


Figure 4: The MAX7315 PWM controller features eight output ports, including an LED intensity function. The device’s register map is very simple, allowing easy access to advanced PWM functions. (Image credit: Maxim Integrated)

The MAX7315’s register map is very simple, allowing easy access to advanced PWM functions.

Combo Expander with WDT, EEPROM and PWM

As shown, the I2C-bus I/O expander can be very powerful when used as a stand-alone device. That is, the expander only includes specific functions such as I/O or PWM. An example is Cypress Semiconductor’s CY8C9520A multiport I/O expander, which contains multiple peripheral expansions in one IC package. CY8C9520A has three extensions: 20-bit, 40-bit or 60-bit extension. These pins can then be configured as input, output, or PWM (Figure 5).


Figure 5: Cypress Semiconductor’s CY8C9520 is a 20-, 40-, or 60-bit I/O expander with EEPROM. This expander allows the expansion pins to be configured as input, output or PWM. (Image credit: Cypress Semiconductor)

In addition to I/O expansion, the CY8C9520 also features an EEPROM that can be used to store important application settings such as serial numbers, as well as other important configuration parameters.

Looking closely at Figure 5, you can see the WD6 pin on GPort 2. This pin is a watchdog timer output pin and can be used to reset the microcontroller when the microcontroller cannot communicate, and to operate the CY8C9529 watchdog. Watchdog settings are fully configurable and can be used to add additional robustness to application code.

Tips and Tricks for Expanding Microcontroller Capabilities

There are many technologies that help expand the capabilities of microcontrollers. Here are some helpful tips and tricks:

Use I2C to connect external devices. The interface requires only two pins and supports multiple slave devices.

Before designing a part into hardware, buy a development board, or solder a chip to an expansion board, and test if it meets your system needs.

Using I2C bus tools to interface with expansion devices and see how they work can dramatically speed up software development.

During software development, use a bus analyzer to monitor communications with external devices to minimize debugging time.

If possible, choose a device with an external watchdog timer as a tool to add robustness to the system design.

When connecting off-chip memory to obtain data (not configuration data), please use a high-speed interface such as SPI.

If the device returns a negative acknowledge (NAK) signal, or the bus is dragged, make sure that the microcontroller’s I2C driver can handle such issues. It is not uncommon for these drivers to ignore errors and enter an infinite loop when they receive an unexpected response.

in conclusion

When the design progresses to the point where the microcontroller can no longer provide more I/O, developers do not need to tear down the existing design. Instead, they can use peripheral chips to add extra functionality to the system.

View more : IGBT modules | LCD displays | Electronic Components