# MCWDT (Multi-Counter Watchdog)¶

group group_mcwdt

A MCWDT has two 16-bit counters and one 32-bit counter.

The functions and other declarations used in this driver are in cy_mcwdt.h. You can include cy_pdl.h to get access to all functions and declarations in the PDL.

You can use this driver to create a free-running timer or generate periodic interrupts. The driver also includes support for the watchdog function to recover from CPU or firmware failures.

There are two primary use cases for MCWDT: generating periodic CPU interrupts; and implementing a free-running timer. Both have many applications in embedded systems:

• Measuring time between events

• Generating periodic events

• Synchronizing actions

• Real-time clocking

• Polling

An additional use case is to implement a watchdog used for recovering from a CPU or firmware failure.

Configuration Considerations

Each MCWDT may be configured for a particular product. One MCWDT block can be associated with only one CPU during runtime. A single MCWDT is not intended to be used by multiple CPUs simultaneously. Each block contains three sub-counters, each of which can be configured for various system utility functions - free running counter, periodic interrupts, watchdog reset, or three interrupts followed by a watchdog reset. All counters are clocked by either LFCLK (nominal 32 kHz) or by a cascaded counter. A simplified diagram of the MCWDT hardware is shown below:

The frequency of the periodic interrupts can be configured using the Match value with combining Clear on match option, which can be set individually for each counter using

Cy_MCWDT_SetClearOnMatch(). When the Clear on match option is not set, the periodic interrupts of the C0 and C1 16-bit sub-counters occur after 65535 counts and the match value defines the shift between interrupts (see the figure below). The enabled Clear on match option resets the counter when the interrupt occurs.

32-bit sub-counter C2 does not have Clear on match option. The interrupt of counter C2 occurs when the counts equal 2

Toggle bit value.

To set up an MCWDT, provide the configuration parameters in the

cy_stc_mcwdt_config_t structure. Then call Cy_MCWDT_Init() to initialize the driver. Call Cy_MCWDT_Enable() to enable all specified counters.

You can also set the mode of operation for any counter. If you choose interrupt mode, use Cy_MCWDT_SetInterruptMask() with the parameter for the masks described in Macro Section. All counter interrupts are OR’d together to from a single combined MCWDT interrupt. Additionally, enable the Global interrupts and initialize the referenced interrupt by setting the priority and the interrupt vector using Cy_SysInt_Init() of the sysint driver.

The values of the MCWDT counters can be monitored using Cy_MCWDT_GetCount().

note

In addition to the MCWDTs, each device has a separate watchdog timer (WDT) that can also be used to generate a watchdog reset or periodic interrupts. For more information on the WDT, see the appropriate section of the PDL.