I want to implement a very simple watchdog timer that will reset the controller if not cleared within a specified counter ticks.
My main() function begins as follows:
CyGlobalIntEnable; /* Enable global interrupts. */
However, as soon as the WDT is enabled the CPU stops running.
I am using CySysWdtResetCounters(CY_SYS_WDT_COUNTER0_RESET) function in a continuous main loop to clear the counter.
What am I missing? Please help.
You missed setting up the interrupt handler:
WDT_ISR_StartEx(WDT_Int_Handler);//setup WDT interrupt ISR
Otherwise, the unhandled interrupt will cause the CPU to lock into a NOP loop (default int handler or some other name)
Thanks for the quick response.
I am not using any interrupt handler. And I am not sure why this is required.
My understanding is:
- enabling the WDT in reset on match mode will reset the cpu once counter reaches the match value
- the main function continuously resets the counter to 0
- if main function hangs, the WDT will reset the cpu
I do not see where the interrupt handler is required.
Please could you explain about the purpose of ISR in watch dog timer and also how to implement it.
Hmmmm; If you are using it as a reset on reaching the match value, and are continuously resetting it, then I would agree with you that it should work.
The WDT can also be used as a generic timer, that runs a function/code upon reaching the matching value.
Thus, you need to start the WDT using the WDT_ISR_StartEx(Int_Handler) with the Int_Handler being the address of the function to run upon the timer interrupting. (You would then handle clearing the interrupt flag, and/or doing other code)
I misunderstood that you didn't want to use it as a timer for firing cleanup code or shutdown/restart code
Going back to your use/method: The CySysWdtResetCounters() function requires you to unlock and lock the WDT before and after changing values/resetting the cound. This mitigates program code running WDT reset code by accident from random address jumping without first running the unlock sequence beforehand. The document describing WDT usage and notes: http://www.cypress.com/file/233616/download
Looking at your code, it should be working as is I think.
You could try running the unit with a debugger, and set up an interrupt to see if the WDT is firing an interrupt, or if the program is crashing before it reaches the WDT reset function(s).
I think the issue might be more towards something else than your code;
If you attach an archive of your project, we can all look at your settings and give more information hopefully
I had the same question for the CY8CPROTO-063-BLE.
The CE220060 example code was modified for the 063-BLE but I just could not get it to run like it was supposed to. So, the example was simplified to only do the WDT reset function using the red LED (P6_3) to show when resets happen and the green LED (P7_1) when the watchdog is being "fed". The resulting bundle is attached. (Whoops. I don't see how to attach a bundle. Maybe someone can tell me.)
Again, while in debug mode I could not get it to work. Then pressed the reset button and it was working fine.
Not knowing this behavior wasted a lot of time. Why does the debug loose control after a WDT reset?