Configuring delay for WDT2 timer on PSoC 4200

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

cross mob
gpsot_dev
Level 1
Level 1
First solution authored 10 sign-ins First reply posted

The doc cy_lfclk_v1_20.pdf describes a function CySysTimerDelay 

I need to programmatically configure WDT2 but it fails because SySysTimerDelay implementation in CyLFClck.c checks that  the counterNum < CY_SYS_WDT_COUNTER2

The doc cy_lfclk_v1_20,pdf does not say anything about this limitation but in the function comment  it says that the valid range is 0-1

Why? Is there another way to programmatically configure delay for  WDT2?
Thanks

 

0 Likes
1 Solution
gpsot_dev
Level 1
Level 1
First solution authored 10 sign-ins First reply posted

Yes, it works for me. The only change I made was to wait for the timer to be disabled instead of using a hard coded delay value

Here is the updated version

Thanks for help

-------------------------------
void WDT2_SetInterval(uint32_t wdt2_bits)
{
int i;

CySysWdtDisable(CY_SYS_WDT_COUNTER2_MASK);
/* CySysWdtSetToggleBit is skipped if the timer is enabled so wait up to 1 ms
*/
while(CySysWdtGetEnabledStatus(CY_SYS_WDT_COUNTER2))
{
if(i > 4)
{
break;
}
CyDelayUs(250);
i++;
}
CySysWdtSetToggleBit(wdt2_bits);
CySysWdtEnable(CY_SYS_WDT_COUNTER2_MASK);
}

 

View solution in original post

0 Likes
6 Replies
PandaS
Moderator
Moderator
Moderator
100 solutions authored 5 likes given 250 sign-ins

Hi @gpsot_dev ,

If you refer the Architecture TRM of PSoC 4200, you will find the following block diagram:

PandaS_0-1658476431785.png

WDT asserts an interrupt or a hardware reset to the device after a programmable interval, unless it is periodically serviced in firmware. The WDT has two 16-bit counters (WDT0 and WDT1) and one 32-bit counter (WDT2). These counters can be configured to work independently or in cascade.

WDT0 and WDT1 can be configured to generate an interrupt on a match event, that is, when the counter value equals the match value. The WDT0 and WDT1 counters can also be configured to generate a reset on a match event or after three successive match events that are not handled (match event interrupt not cleared).

WDT2 can be configured to generate an interrupt based on the value stored in the WDT_BITS2[4:0] bits in the WDT_CONFIG register. WDT2 cannot generate a system reset or an interrupt with any match value similar to WDT1 or WDT0. WDT2 can generate an interrupt only on a rising edge on one of the 32 bits present in the counter. The WDT_BITS2[4:0] bits in the WDT_CONFIG register control the bit that generates the interrupt. See the WDT_CONFIG register in the PSoC 4100M/4200M Family: PSoC 4 Registers TRM for details.

 

Thanks and Regards

Sobhit

0 Likes

Thank you very much!

0 Likes

Just in case someone else runs into this, here is what I ended up doing

Sobhit, could you please confirm that this is the right approach

void WDT2_SetInterval(uint32_t wdt2_bits)
{
CySysWdtDisable(CY_SYS_WDT_COUNTER2_MASK);
CyDelayUs(500);
CySysWdtSetToggleBit(wdt2_bits);
CySysWdtEnable(CY_SYS_WDT_COUNTER2_MASK);
}

wdt_bits is a value 0 - 31 and corresponds to the interval dropdown menu in the LFCLK window

0 Likes
PandaS
Moderator
Moderator
Moderator
100 solutions authored 5 likes given 250 sign-ins

Hi @gpsot_dev ,

Were you able to workaround with the above function? 

Warm Regards

Sobhit

0 Likes
gpsot_dev
Level 1
Level 1
First solution authored 10 sign-ins First reply posted

Yes, it works for me. The only change I made was to wait for the timer to be disabled instead of using a hard coded delay value

Here is the updated version

Thanks for help

-------------------------------
void WDT2_SetInterval(uint32_t wdt2_bits)
{
int i;

CySysWdtDisable(CY_SYS_WDT_COUNTER2_MASK);
/* CySysWdtSetToggleBit is skipped if the timer is enabled so wait up to 1 ms
*/
while(CySysWdtGetEnabledStatus(CY_SYS_WDT_COUNTER2))
{
if(i > 4)
{
break;
}
CyDelayUs(250);
i++;
}
CySysWdtSetToggleBit(wdt2_bits);
CySysWdtEnable(CY_SYS_WDT_COUNTER2_MASK);
}

 

0 Likes
PandaS
Moderator
Moderator
Moderator
100 solutions authored 5 likes given 250 sign-ins

Hi @gpsot_dev ,

That's great! Glad that you solved the problem.

Warm Regards

Sobhit

0 Likes