CE95400 - Watchdog Timer Reset and Interrupt for PSoC® 41xx/42xx Devices

Objective

This example demonstrates how to use the watchdog timer in PSoC 41xx/42xx devices to both reset the system and wake up from the Deep Sleep low power mode.

Overview

There are three examples that can run on the CY8CKIT-042 Pioneer kit; however, these can be ported to other boards that contain LEDs and buttons.

Description of Figure 1: Watchdog Block Diagram for PSoC 4100/4200 Devices. This diagram illustrates the watchdog timer architecture, showing three cascaded watchdog timers (WDT0, WDT1, WDT2) connected to the LFCLK. WDT0 and WDT1 are 16-bit counters, while WDT2 is a 32-bit counter. Each timer has a counter, match value, mode configuration, and generates interrupt or reset signals. Cascade connections between timers are shown, leading to final INTERRUPT and RESET outputs.

Requirements

Design

For PSoC 41xx/42xx devices, the watchdog timer (WDT) counts the 32-kHz internal clock "LFCLK". When the counter value equals the MATCH register value, the WDT generates an interrupt. If the counter is cleared before reaching the match value, the interrupt is prevented. This is known as "clearing the watchdog counter".

Rules for clearing the watchdog counter:

Clearing the watchdog counter may require a short settling time, detailed in the device datasheet or technical reference manual. If clearing halts due to a fault (e.g., an infinite loop), the watchdog generates an interrupt. For PSoC 41xx/42xx devices, a system reset occurs after the third continuous unhandled interrupt. The system reset can be disabled to use the WDT for periodic interrupts, useful for waking the system from deep sleep.

Project #1 - Using Watchdog Timer to Reset the System

The watchdog timer is configured to generate an interrupt every second. The counter is cleared periodically in the main loop. If the SW2 button is pressed (simulating a fault), clearing stops. After three seconds (third unhandled interrupt), the system resets. The first watchdog interrupt stores log data (0-127) in the last row of internal flash for fault analysis via PSoC Programmer.

Three LEDs indicate system status:

Description of Figure 2: Creator Schematic for Project #1. This schematic shows the hardware connections for Project #1, including LEDs (Red, Green, Blue) connected to GPIO pins via resistors, and the SW2 button connected to a GPIO pin. The Watchdog Timer interrupt (WDT INT) is shown connected to an interrupt component.

Description of Figure 3: Firmware Flow for Project #1. This flowchart details the program logic. The main function handles power-up, button scanning (SW2), LED control (Green, Blue, Red based on status), watchdog initialization, clearing the watchdog counter, and enabling interrupts. The Watchdog ISR handles the interrupt, checks for log data storage, and exits. A system reset occurs if the watchdog is not cleared.

Project #2 - Wakeup from Deep Sleep

The watchdog timer is configured to generate an interrupt every 250 milliseconds, waking the system from deep sleep. The system then delays for 500 milliseconds using CyDelay functions before re-entering deep sleep.

Two LEDs indicate system status: The Green LED is ON during deep sleep. After waking by a watchdog interrupt, the Red LED turns ON during the firmware delay, then the Green LED turns ON again as the system enters deep sleep.

Description of Figure 4: Creator Schematic for Project #2. This schematic displays the hardware setup for Project #2, similar to Project #1, showing connections for Red, Green, and Blue LEDs, and the SW2 button to GPIO pins, along with the WDT INT signal.

Description of Figure 5: Firmware Flow for Project #2. This flowchart outlines the program logic for Project #2. The main function manages power-up, turning on the Green LED, initializing the watchdog, enabling interrupts, entering deep sleep, and turning on the Red LED upon wake-up. The Watchdog ISR handles interrupts, clears the flag, and exits.

Project #3 - Wakeup from Sleep with System Reset Enabled

The watchdog timer in PSoC 41xx/42xx devices features three 16-bit counters. Counter 0 and Counter 1 can be cascaded. Counter 0 generates an interrupt (no reset) on a match event. Counter 1 counts Counter 0's match events and generates an interrupt when its value matches its own match value. Three continuous unhandled interrupts trigger a system reset.

This example combines system reset and sleep wake-up. Counter 0 is set for a 250 ms interrupt to wake from deep sleep. Counter 1 is set for a 1-second interrupt. If not handled for three consecutive times, the system resets and logs data. LED indications are similar to Project #1.

Description of Figure 6: Creator Schematic for Project #3. This schematic shows the hardware configuration for Project #3, including connections for LEDs (Red, Green, Blue) and the SW2 button to GPIO pins, and the WDT INT signal.

Description of Figure 7: Firmware Flow for Project #3. This flowchart illustrates the program logic for Project #3. The main function handles power-up, reset checks, LED control, button scanning, clearing watchdog counters (0 and 1), entering deep sleep, and waking up. The Watchdog ISR handles interrupts from Counter 0 and Counter 1, checks for log data storage, and exits. The system's behavior depends on the SW2 button state.

Design Considerations

The pull-up resistor for the SW2 button is integrated within the chip's GPIO block; no external resistor is required. The CY8CKIT-042 uses a three-in-one LED package (Red, Green, Blue), which may be separated or replaced in other kits.

Hardware Setup

For basic kit board setup, refer to the corresponding Kit Guide. For specific kit setups:

Software Setup

No special software setup is required. All supported compilers can be used with any optimization.

Components

Table 1 lists the PSoC Creator Components used in this example and their hardware resources.

Table 1. List of PSoC Creator Components
ComponentHardware Resources
Digital Output PinThree PSoC 4 GPIO configured as digital output without pull-up or pull-down resistors
Digital Input PinOne PSoC 4 GPIO configured as digital input with a pull-up resistor
InterruptOne interrupt service routine with the highest priority
Global SignalConnect the WDT interrupt to the Interrupt Component
PinThree pins for LED indicators; one pin for switch button detection

Parameter Settings

Digital Output Pins:

Clear the "HW Connection" option to prevent build errors.

Description of Figure 8: Uncheck HW Connection. This figure shows a PSoC Creator interface element where the 'HW Connection' option for a digital output pin should be unchecked.

Digital Input Pins:

  1. Clear the "HW Connection" option to prevent build errors.
  2. Set the drive mode as "Resistive Pull Up" in the General Tab.

Description of Figure 9: Set Pull-up Resistor Drive Mode. This figure shows the PSoC Creator interface for setting the drive mode of a digital input pin to 'Resistive Pull Up'.

Design-Wide Resources

Figures 10 and 11 show the pin assignments for each example. No other design-wide resource needs to be changed from its default setting.

Description of Figure 10: Pin Assignment for Project #1 and Project #3. This figure displays a table mapping component names (LED_Blue, LED_Green, LED_Red, SW2) to their respective Port and Pin assignments for Projects #1 and #3.

Description of Figure 11: Pin Assignment for Project #2. This figure displays a table mapping component names (LED_Blue, LED_Green, LED_Red) to their respective Port and Pin assignments for Project #2.

Operation

Project #1 - Using the Watchdog Timer to Reset the System

  1. In the Workspace Explorer, right-click the “Project '1-Reset_System'” and select "Set As Active Project". See Figure 12.
  2. Build the project to generate the hex file.
  3. Connect the PC to CY8CKIT-042 J10 with the USB cable.
  4. Download the hex file to the PSoC 4 chip.
  5. Keep the USB cable connection for power supply.
  6. Observe LED status:
    • Pressing the Reset button: Green LED blinks then turns ON, indicating system reset and normal operation.
    • Pressing SW2: Green LED turns OFF, Blue LED turns ON. Releasing SW2 turns Green ON and Blue OFF. Blue LED indicates SW2 pressed.
    • Holding SW2 for >3 seconds: Blue LED is ON, then Red LED turns ON for ~1 second, then Blue LED turns ON again. Red LED indicates a watchdog reset due to uncleared counter.
    • Releasing SW2: Green LED turns ON.
    • Holding SW2 again: Red LED turns ON periodically, indicating continuous resets.
  7. Launch PSoC Programmer from the Start menu (see Figure 13).
  8. In PSoC Programmer, click the "Read" button to read flash data (Figure 14).
  9. Scroll to the end of flash data to view logged data (Figure 16), which are incremental integers from 0 to 128, stored when a watchdog reset occurred.

Description of Figure 12: Choose Project #1 as Active Project. This figure shows a screenshot of the PSoC Creator Workspace Explorer with a right-click context menu displaying the option to 'Set As Active Project'.

Description of Figure 13: Launch PSoC Programmer. This figure shows the Windows Start menu with 'PSoC Programmer 3.21.1' highlighted.

Description of Figure 14: Read Operation in PSoC Programmer. This figure displays the PSoC Programmer interface, highlighting the 'Read' button and settings for reading flash data.

Description of Figure 15: Data in Beginning Rows of Flash. This figure shows a screenshot of the PSoC Programmer results window displaying hexadecimal data from the flash memory.

Description of Figure 16: Log Data after Watchdog Reset Happens. This figure shows the PSoC Programmer results window displaying logged data in hexadecimal format, typically incremental integers, stored in flash after a watchdog reset.

Project #2 - Wakeup from Deep Sleep

  1. In the Workspace Explorer, right-click “Project '2-Sleep_Wakeup'” and select "Set As Active Project" (see Figure 17).
  2. Build the project to generate the hex file.
  3. Connect the PC to CY8CKIT-042 J10 with the USB cable.
  4. Download the hex file to the PSoC 4 chip.
  5. Keep the USB cable connection for power supply.
  6. Observe LED status:
    • Pressing the Reset button: Green LED blinks then turns ON, indicating system reset and normal operation.
    • Later, Green LED turns OFF, Red LED turns ON. This repeats indefinitely. The Red LED indicates the system has woken from deep sleep via a watchdog interrupt.

Description of Figure 17: Choose Project #2 as Active Project. This figure shows a screenshot of the PSoC Creator Workspace Explorer with a right-click context menu displaying the option to 'Set As Active Project'.

Project #3 - Wakeup from Sleep with System Reset Enabled

  1. In Workspace Explorer, right-click “Project '3-Sleep_Wakeup_and_Reset_System'” and select "Set As Active Project" (see Figure 18).
  2. Build the project to generate the hex file.
  3. Connect the PC to CY8CKIT-042 J10 with the USB cable.
  4. Download the hex file to the PSoC 4 chip.
  5. Keep the USB cable connection for power supply.
  6. Observe LED status:
    • Pressing the Reset button: Green LED blinks then turns ON, indicating system reset and normal operation.
    • If SW2 is not pressed, the system behaves as in Project #2.
    • If SW2 is pressed, the system behaves as in Project #1.

Description of Figure 18: Choose Project #3 as Active Project. This figure shows a screenshot of the PSoC Creator Workspace Explorer with a right-click context menu displaying the option to 'Set As Active Project'.

Upgrade Information

N/A

Related Documents

Table 2 lists relevant application notes, code examples, knowledge base articles, device datasheets, and Component datasheets.

Table 2. Related Documents
DocumentTitleComment
AN79953Getting Started with PSoC® 4Introduces PSoC® 4, an ARM® Cortex™-M0 MCU based programmable system-on-chip. It helps explore the architecture and Creator development tools.
AN86439PSoC® 4 - Using GPIO PinsExplains how to use PSoC® 4 GPIO pins effectively and take full advantage of their features, including basics, configuration options, mixed-signal use, registers, interrupts, and low-power behavior.
AN90114PSoC® 4000 Family Low-Power System Design TechniquesIntroduces the low-power modes of the PSoC® 4000 family and methods for designing low-power systems.
AN90799PSoC® 4 InterruptsExplains the interrupt architecture in PSoC 4 and its configuration in PSoC Creator™ IDE with three example projects.
AN89610PSoC® 4 and PSoC 5LP ARM Cortex Code OptimizationShows how to optimize C and assembler code for ARM Cortex CPUs in PSoC® 4 and PSoC 5LP, supporting Gcc and Keil MDK C compilers.
001-94480System Reference GuideDescribes functions supplied by the PSoC Creator cy_boot component, providing system functionality for projects and access to chip resources.
KBA91373Watchdog Timer in the PSoC® 4000 FamilyExplains the differences between the PSoC® 4000 family WDT and the PSoC 4100/4200 family WDT, and how to generate a periodic ISR using the PSoC 4000 WDT.
PSoC 4 DatasheetsPSoC 4 Technical Reference Manuals
Development Kit (DVK) DocumentationPSoC 4 Kits

Document History

Document Title: CE95400 - Watchdog Timer Reset and Interrupt for PSoC® 41xx/42xx Devices

Document Number: 001-95400

RevisionECNOrig. of ChangeSubmission DateDescription of Change
**4644987BOBH05/12/2015New spec

Worldwide Sales and Design Support

Cypress maintains a worldwide network of offices, solution centers, manufacturer's representatives, and distributors. To find the office closest to you, visit us at Cypress Locations.

Products

PSoC® Solutions

psoc.cypress.com/solutions

PSoC 1 | PSoC 3 | PSoC 4 | PSoC 5LP

Cypress Developer Community

Community | Forums | Blogs | Video | Training

Technical Support

cypress.com/go/support

PSoC is a registered trademark and PSoC Creator is a trademark of Cypress Semiconductor Corp. All other trademarks or registered trademarks referenced herein are the property of their respective owners.

Cypress Semiconductor
198 Champion Court
San Jose, CA 95134-1709

Phone : 408-943-2600
Fax : 408-943-4730
Website : www.cypress.com

Cypress Semiconductor Corporation, 2015. The information contained herein is subject to change without notice. Cypress Semiconductor Corporation assumes no responsibility for the use of any circuitry other than circuitry embodied in a Cypress product. Nor does it convey or imply any license under patent or other rights. Cypress products are not warranted nor intended to be used for medical, life support, life saving, critical control or safety applications, unless pursuant to an express written agreement with Cypress. Furthermore, Cypress does not authorize its products for use as critical components in life-support systems where a malfunction or failure may reasonably be expected to result in significant injury to the user. The inclusion of Cypress products in life-support systems application implies that the manufacturer assumes all risk of such use and in doing so indemnifies Cypress against all charges. This Source Code (software and/or firmware) is owned by Cypress Semiconductor Corporation (Cypress) and is protected by and subject to worldwide patent protection (United States and foreign), United States copyright laws and international treaty provisions. Cypress hereby grants to licensee a personal, non-exclusive, non-transferable license to copy, use, modify, create derivative works of, and compile the Cypress Source Code and derivative works for the sole purpose of creating custom software and or firmware in support of licensee product to be used only in conjunction with a Cypress integrated circuit as specified in the applicable agreement. Any reproduction, modification, translation, compilation, or representation of this Source Code except as specified above is prohibited without the express written permission of Cypress. Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress reserves the right to make changes without further notice to the materials described herein. Cypress does not assume any liability arising out of the application or use of any product or circuit described herein. Cypress does not authorize its products for use as critical components in life-support systems where a malfunction or failure may reasonably be expected to result in significant injury to the user. The inclusion of Cypress' product in a life-support systems application implies that the manufacturer assumes all risk of such use and in doing so indemnifies Cypress against all charges. Use may be limited by and subject to the applicable Cypress software license agreement.

PDF preview unavailable. Download the PDF instead.

CE95400 Watchdog Timer Reset and Interrupt for PSoC 41xx 42xx Devices Microsoft Office Word 2007 Microsoft Office Word 2007

Related Documents

PreviewCypress PSoC 3/PSoC 5LP Trim and Margin Code Example
This document details the CE95387 code example for Cypress PSoC 3 and PSoC 5LP microcontrollers, focusing on the Trim and Margin Component for power converter voltage adjustment and monitoring. It covers hardware setup, software configuration, component parameters, pin assignments, and operational modes, including manual trimming, margining, and rail control.
PreviewGetting Started with PSoC 5LP
This application note introduces the PSoC 5LP, an Arm Cortex-M3-based programmable system-on-chip, detailing its architecture, development environment, and how to create a simple design using PSoC Creator. It guides users to resources for in-depth learning.
PreviewCypress CY8CKIT-002 PSoC MiniProg3 Program and Debug Kit
The Cypress CY8CKIT-002 PSoC MiniProg3 is a development kit for programming and debugging PSoC microcontrollers. It supports SWD, JTAG, ISSP, and USB-I2C protocols and features hardware improvements in revision B, enhancing power cycle programming, ESD protection, and voltage detection.
PreviewCypress PSoC 1 CE58033: Pulse Width Measurement with Timer Capture - Technical Guide
This document details how to implement pulse width measurement using the Timer Capture feature in Cypress PSoC 1 microcontrollers. It covers the principles, hardware connections, user module parameters, and operational aspects of the CE58033 code example.
PreviewCypress ModusToolbox IDE User Guide: Embedded Development Essentials
Explore the Cypress ModusToolbox IDE, a comprehensive Integrated Development Environment for embedded systems. This guide covers application creation, SDK usage, configuration, building, and debugging for Cypress devices.
PreviewCY8CKIT-025 PSoC Precision Analog Temperature Sensor Expansion Board Kit Guide
This guide provides comprehensive information on the Cypress CY8CKIT-025 PSoC Precision Analog Temperature Sensor Expansion Board Kit. It details the kit's components, operation, and hardware, supporting temperature sensing applications with thermocouples, thermistors, RTDs, and diodes. Ideal for engineers developing PSoC-based solutions.
PreviewCypress CY8CKIT-059 PSoC 5LP Prototyping Kit Release Notes
Release notes for the Cypress CY8CKIT-059 PSoC 5LP Prototyping Kit, detailing kit content, software requirements like PSoC Creator and PSoC Programmer, and links to installation guides and technical support.
PreviewPSoC® Arm® Cortex® Code Optimization Guide
Optimize C and assembler code for PSoC 4/5LP Arm Cortex CPUs with gcc/MDK compilers. This Cypress application note covers performance, memory, and power efficiency techniques for embedded development.