This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hello everyone,
Greetings!!!
My task is to reset the microcontroller if it's halted, for that, I am using a watchdog timer,
I am setting the watchdog time period as 1sec and am clearing WTD every 200ms for that I am using a timer so that the WTD won't reset every 1sec,
I wrote code, I wish to check the program so I added while(1);, the program halted here, the WDT is not resetting the microcontroller,
my program holds on while(1);, what's the problem, am I doing anything wrong? please guide me on how to solve it. I have mentioned my code below for your reference.
#include "msp430g2553.h" unsigned int Timer1ms=0; unsigned int count=0; void Timer_Init(); void main(void) { WDTCTL = WDTPW + WDTHOLD;// Stop the WDT to prevent reset // Count value for delay Timer_Init(); WDTCTL = WDT_ARST_1000; // 1 sec watchdog interval while(1) { // WDTCTL = WDT_ARST_1000; count++; if(count>5000) { while(1); count=0; } } } void Timer_Init() { DCOCTL = CALDCO_8MHZ; BCSCTL1 = CALBC1_8MHZ; TA0CCTL0=CCIE; TA0CTL=TASSEL_2+MC_1+ID_3;//SMCLK, Up mode, Divider -->1 TA0CCR0=999;//from above calculation _BIS_SR(GIE);//off CPU until interrupt occurs } #pragma vector=TIMER0_A0_VECTOR __interrupt void TIMER0_A0_ISR(void) { Timer1ms++; if(Timer1ms>=200) { WDTCTL = WDTPW + WDTHOLD + WDTCNTCL;// Stop WDT WDTCTL = WDT_ARST_1000; //again 1sec reload Timer1ms=0; } }
Thanks in advance!!
Regards,
Aravinth K.
Hi,
You do not need to add the while(1) to check your code. You can add breakpoints in the timer ISR like line 36 or line 39 to check the status.
Best regards,
Cash Hao
Hello, cash Hao11,
Thanks for your reply, I just added a breakpoint at timer line 39 it's working, but how do I manually halt the controller and check WTD is resetting the controller?
Thanks & Regards,
Aravinth K
Hi,
If you want to check the watchdog is resetting the controller. You need to block the feed dog code.
You can refer to this example code for some ideas.
https://dev.ti.com/tirex/explore/node?node=AEBlR0c40D8-.JOaN5u6sQ__IOGqZri__LATEST
Best regards,
Cash Hao
Hi, cash Hao11,
Thanks for your reply,
The above-mentioned code works by some modifications, Every 200ms I am clearing the WDT counter, am setting a flag after 5000 counts so that timer can't able to reset the WDT counter so WDT expires and starts reset controller. I have mentioned the code below
Thanks for your guidance
#include "msp430g2553.h" unsigned int Timer1ms=0; unsigned int count=0; unsigned int temp=0; void Timer_Init(); void main(void) { WDTCTL = WDTPW + WDTHOLD;// Stop the WDT to prevent reset // Count value for delay Timer_Init(); // Initialize timer WDTCTL = WDT_ARST_1000; // 1 sec watchdog interval count=0; temp=0;//flag while(1) { count++; if(count>5000) { temp=1;// after 5000 count temp will set count=0;//clearing count } } } void Timer_Init() { DCOCTL = CALDCO_8MHZ; BCSCTL1 = CALBC1_8MHZ; TA0CCTL0=CCIE; TA0CTL=TASSEL_2+MC_1+ID_3;//SMCLK, Up mode, Divider -->1 TA0CCR0=999;//from above calculation _BIS_SR(GIE);//off CPU until interrupt occurs } #pragma vector=TIMER0_A0_VECTOR __interrupt void TIMER0_A0_ISR(void) { if(temp==0)// the WDT count clears every 200ms if temp is 0 else WDT won't clear itself, so WDT resets the controller { Timer1ms++; if(Timer1ms>=200) { WDTCTL = WDTPW + WDTCNTCL;// Clear WDT counter WDTCTL = WDT_ARST_1000; //again 1sec Timer1ms=0; } } }
Thanks & regards,
Aravinth K.
**Attention** This is a public forum