Oh, that explains a lot. Thank you.
I went ahead to use the same logic in my program. So, I now want to use a watchdog timer, give a timer value and refresh it before the watchdog expires so that my program will continue to work without resetting the MCU.
The following is the program that I am using. I am using an interrupt to generate a 20ms flag. Every 20ms I refresh the watchdog so as to not to reset MCU. Timeout value is 0x28 in hex for 40ms considering LPO = 1KHz. (Is that the right way to calculate??)
To make sure that my program is running smoothly, I have a running pwm pulse and I'm monitoring it. But on the oscilloscope, I notice that there is a glitch every 20ms which halts the pulsing.
WDOG_GetDefaultConfig(&config);
config.timeoutValue = 0x28U;
WDOG_Init(wdog_base, &config);
while (1)
{
if(flag_20ms == 1)
{
flag_20ms = 0;
GPIO_PortToggle(GPIOD, 1u << 1u);
WDOG_Refresh(wdog_base);
}
}
Where am I going wrong? For my application, is there a need for interrupt to be used? Is this the right way to initialize WDOG?
If I remove the interrupts and only run the program with watchdog, then ate every 20ms, the console gets refreshed and the MCU is reset. How can I avoid this?
WDOG_GetDefaultConfig(&config);
config.timeoutValue = 0x28U;
WDOG_Init(wdog_base, &config);
for(int i = 0; i < 10; i ++)
{
PRINTF("--- Refresh wdog %d time ---\r\n", i + 1);
}
while (1)
{
// if(flag_20ms == 1)
{
// flag_20ms = 0;
// GPIO_PortToggle(GPIOD, 1u << 1u);
WDOG_Refresh(wdog_base);
}
}
the console reading is as follows
Capture.PNG
Help me figure this out.
thank you in advance