This example demonstrates how watchdog timer works with the interrupt mode and the reset mode.
The device used in this code example (CE) is:
The board used for testing is:
- PSoC™ 4 HVMS Lite Kit (KIT_PSoC4-HVMS-128K_LITE)
- PSoC™ 4 HVMS Lite Kit (KIT_PSoC4-HVMS-64K_LITE)
This code example deals with the watchdog timer (WDT) of PSoC™ 4. The WDT operates in two modes: the interrupt mode and the reset mode. In the interrupt mode, the LED toggles every second. If it's configured as the reset mode, the LED blinks thrice with an interval of 200 milliseconds each time the watchdog reset occurs.
The WDTs are used to automatically reset the device in the event of an unexpected firmware execution path. They are also used as a wakeup source to periodically generate interrupts as a wakeup source in low-power modes. There are several WDT functionalities in PSoC™ 4 HVMS devices. These are:
- Basic WDT
- Challenge-response WDT (CRWDT)
- Lifetime counter with wakeup capability.
The basic WDT is a free-running up-counter with programmable limit values and a maximum resolution of 32 bits, as featured in this code example.
- 32-bit counter and compares, clocked by LFCLK
- Lower, Warn, and Upper limits with programmable actions for each
- Implemented in VCCD logic domain
More details can be found in:
- PSoC™ 4 HVMS Series
This Code Example has been developed for:
Figure 1. KIT_PSoC4-HVMS-128K_LITE (Top View)
The firmware is implemented in main.c and performs the following functions:
- Enable WDT interrupt
- Initialize and start WDT
- LED6 toggles every second if it's the interrupt mode
- LED6 blinks thrice each time the reset occurs if it's the reset mode
You can change the interrupt mode/the reset mode by changing the macro
Figure 2. The macro to change the mode
ModusToolbox™ Device configurator
This code example project can be created or imported using ModusToolbox™ IDE. To configure the project in the Quick Panel, click on Device Configurator. You can configure peripheral and clock settings on Device Configurator. You can see Watchdog Timer (WDT) clock is from LFCLK on Clock System.
Figure 3. Select Device Configurator
PDL functions
- Cy_SysLib_GetResetReason() is used to get the reset reason to check if the reset caused by WDT reset.
- Cy_SysLib_ClearResetReason() is used to clear reset cause register.
- Cy_SysLib_Delay() is used to make an interval between LED ON/LED OFF.
- Cy_SysInt_Init() is used to set interrupt source and interrupt handler.
- Cy_GPIO_Write() is used to change LED state.
- Cy_GPIO_Inv() is used to invert the LED state.
- Cy_WDT_Unlock() is used to unlock WDT register.
- Cy_WDT_Lock() is used to lock WDT register.
- Cy_WDT_SetLowerLimit() is used to set lower limit.
- Cy_WDT_SetUpperLimit() is used to set upper limit.
- Cy_WDT_SetWarnLimit() is used to set warn limit.
- Cy_WDT_SetLowerAction() is used to set the action that occurs if the service is set before the count is lower limit.
- Cy_WDT_SetUpperAction() is used to set the action that occurs if the service isn't set although the count is over upper limit.
- Cy_WDT_SetWarnAction() is used to set the action that occurs if the service isn't set although the count is over warn limit.
- Cy_WDT_SetAutoService() is used to set auto service that occurs if the count reaches to the warn limit.
- Cy_WDT_SetDeepSleepPause() is used to set whether the WDT counter runs/pauses when the system is in DEEPSLEEP.
- Cy_WDT_SetDebugRun() is used to set whether the WDT counter runs/pauses when the system is in debug mode.
- Cy_WDT_Disable() is used to disable WDT.
- Cy_WDT_Enable() is used to enable WDT.
- Cy_WDT_IsEnabled() is used to check if WDT is enabled.
- Cy_WDT_SetService() is used to service WDT then the count is cleared.
- Cy_WDT_ClearInterrupt() is used to clear WDT interrupt flag.
- Cy_WDT_MaskInterrupt() is used to prevent from WDT interrupt passes to the CPU.
- Cy_WDT_UnmaskInterrupt() is used to unmask WDT interrupt and make WDT interrupt pass to the CPU.
Before testing this code example:
- Power the board through the dedicated power connector
- Connect the board to the PC through the USB interface
- Build the project using the dedicated Build button
Figure 6. Build Project
or by right-clicking the project name and selecting "Build Project"
- To program the board, in the Quick Panel, scroll down, and click [Project Name] Program (KitProg3_MiniProg4)
-
After programming, the code example will start automatically and you can see
-
The LED6 toggles every second in the interrupt mode
-
The LED6 blinks thrice with an interval of 200 milliseconds each time the watchdog reset occurs in the reset mode
-
You can debug the example to step through the code. In the IDE, use the [Project Name] Debug (KitProg3_MiniProg4) configuration in the Quick Panel. For details, see the "Program and debug" section in the Eclipse IDE for Toolbox™ software user guide.
Note: (Only while debugging) On the CM7 CPU, some code in main() may execute before the debugger halts at the beginning of main(). This means that some code executes twice: once before the debugger stops execution, and again after the debugger resets the program counter to the beginning of main(). See KBA231071 to learn about this and for the workaround.
Relevant Application notes are:
- AN0034 - Getting started with PSOC™ 4 HV MS MCUs in ModusToolbox™
ModusToolbox™ is available online:
Associated PSoC™ 4 HVMS MCUs can be found on:
More code examples can be found on the GIT repository:
For additional trainings, visit our webpage:
For questions and support, use the PSoC™ 4 HVMS Forum: