WDT (Watchdog Timer) sample program2 for PSoC4

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Kenshow
Level 8
Level 8
Distributor - Marubun (Japan)
50 solutions authored 25 solutions authored 10 solutions authored

Goal: Cascade the two WDTs so that they can represent a little longer time.

Hi,

I have to take medicine every morning because I had been over weight for years. However, as I get used to taking medicine every day, I sometime forget to take it. In order to prevent this, I am thinking of programming to make it known by lighting the LED at a certain fixed time. I studied the Deep Sleep function to make it battery-powered and have a long life. I will introduce the program created at that time.

 

The environment used is as follows:

・PSoC Creator 4.4

・CY8CKIT-042-BLE-A

 

Program behavior:

 The CPU wakes up at regular intervals and toggles the LED. After the initial setting (WDT setting), the CPU goes into Deep Sleep. The WDT interrupt wakes up the CPU and processes the LED, goes in Deep Sleep. The purpose is to significantly reduce CPU consumption.

 The WDT has three timers and is supplied by LFCLK. The aim of this time is to connect WDT in a cascade and use two timers so that it can be expressed in a slightly longer time. WDT0 and WDT1 are connected in cascade, and WDT_INT1 is used for WakeUp and interrupt operations.

1.png

 

The circuit is simply the setting of the LED part as shown below.

2.png

 

Pin map for CY8CKIT-042-BLE-A is as below.

3.png

 

WDT is set by the configure System clocks in PSoC Creator, Check WDT0 and WDT1 to enable them and set Divider respectively.

 4.png

 

The program is simple. When the time comes in the WDT, an interrupt is input to the CPU and Wakup is performed, the LED is toggled by interrupt processing, and Deep Sleep in the for loop is executed when the interrupt processing is completed.

#include "project.h"

 

#define LED_ON                  (0u)

#define LED_OFF                 (1u)

 

#include "project.h"

 

void wdtCallback()

{

    LED_Write(~LED_Read()); //LED Toggle

}

 

int main(void)

{

    CyGlobalIntEnable; /* Enable global interrupts. */

    CySysWdtSetInterruptCallback(CY_SYS_WDT_COUNTER1,wdtCallback);

    CySysWdtSetCascade(CY_SYS_WDT_CASCADE_01);

   

    CySysWdtSetMode(CY_SYS_WDT_COUNTER0,CY_SYS_WDT_MODE_NONE);

    CySysWdtSetMode(CY_SYS_WDT_COUNTER1,CY_SYS_WDT_MODE_INT);

   

    LED_Write(LED_OFF); //LED OFF

     

    for(;;)

    {

        CySysPmDeepSleep();

    }

}

 

Thanks,
Kenshow

0 Likes
0 Replies