WDT (Watchdog Timer) sample program3 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: Clear the state with GPIO interrupt.

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:

Count the blinking of the blue LED, and when it blinks 3 times, change the red color. Clear the counter with SW.

 The WDT has three timers and is supplied by LFCLK. By connecting WDTs in cascade and using two timers, the purpose is to be able to express 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 SW/GPIO and 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 CPU wakes up due to a WDT interrupt at regular intervals and increments the counter. The color of the LED is changed according to the value of the counter. The counter is cleared by the GPIO interrupt of SW.

#include "project.h"

 

#define LED_ON                  (0u)

#define LED_OFF                 (1u)

#define LED_ON_TIME             (100u)

 

#include "project.h"

 

volatile int Cnt = 0;

void wdtCallback()

{

    Cnt++;

}

 

CY_ISR(GPIOIsrHandler)

{

    /* Clear pending Interrupt */

    isr_GPIO_ClearPending();

    /* Clear pin Interrupt */

    Pin_Sw_ClearInterrupt();

    Cnt = 0;

}

 

int main(void)

{

    CySysWdtSetInterruptCallback(CY_SYS_WDT_COUNTER1,wdtCallback);

    isr_GPIO_StartEx(GPIOIsrHandler);

 

    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_B_Write(LED_OFF); //LED OFF

    LED_R_Write(LED_OFF); //LED OFF

 

    CyGlobalIntEnable; /* Enable global interrupts. */

   

    for(;;)

    {

        CySysPmDeepSleep();

       

        if(Cnt<4){

            LED_B_Write(LED_ON); //LED Blue ON

            CyDelay(LED_ON_TIME);        

            LED_B_Write(LED_OFF); //LED OFF

        }else{

            LED_R_Write(LED_ON); //LED Red Toggle

            CyDelay(LED_ON_TIME);       

            LED_R_Write(LED_OFF); //LED OFF

        }

    }

}

Thanks,
Kenshow

0 Likes
0 Replies