1
\$\begingroup\$

This is the code I have for a green LED blinking every 2s with watchdog mode for MSP432.

#include "msp.h"

void main(void)
 {
     volatile uint32_t i;
     WDT_A->CTL = WDT_A_CTL_PW & 0xFF00;
     WDT_A->CTL = WDT_A_CTL_PW | WDT_A_CTL_IS_5;
     P2DIR |= BIT1;
     while (1) // continuous loop
     {
         P2OUT ^=BIT1; // Blink P1.0 LED
         for (i =6000000; i> 0; i--); // Delay with 3Mhz clock.
     }
 }

How to design Watchdog timer that reset the system if Watchdog counter is not cleared at least every 1/4 seconds?

| improve this question | | | | |
\$\endgroup\$
  • \$\begingroup\$ Make an outer loop around your delay loop. Shorten the delay time. Trigger the watchdog inside the outer loop. \$\endgroup\$ – Janka Oct 28 '18 at 18:09
  • \$\begingroup\$ Thanks for your reply. So Something like this, for(j= 30000; j> 0; j--) { WDT_A->CTL = WDT_A_CTL_PW & 0XFF00; for(I=3000000; I>0; I-- ); } I apologize I am very good at programming. \$\endgroup\$ – dhruv Oct 28 '18 at 18:23
  • \$\begingroup\$ if 6000000 means 2s, and your watchdog needs to be triggered each 1/4s, you have to divide number this by eight, and your outer loop has to count to eight to make it the same delay. \$\endgroup\$ – Janka Oct 28 '18 at 18:41
  • 1
    \$\begingroup\$ @Janka Ok, so you answered his question, how will he mark it as accepted? \$\endgroup\$ – pipe Oct 28 '18 at 20:40
  • 1
    \$\begingroup\$ @Mike But he did not. He chose to ignore the information when posting his comment, which states "avoid answering questions in comments." The question will now remain listed as unsolved. \$\endgroup\$ – pipe Oct 30 '18 at 8:48
0
\$\begingroup\$

The purist/best practice solution is that your program should only kick the watchdog once, at the top of the eternal loop in main(). Thus the best practice is this:

void main (void)
{
  ...

  uint32_t count = 0;

  for(;;)
  {
    kick_dog();

    if(count < max)
    {
      blink_led();
      delay(n);
      count++;
    }
  } // for(;;)
}

But of course busy-delay loops is an amateur solution in itself. Professional code would instead utilize on-chip hardware timers. Such as:

void main (void)
{
  ...
  init_timer();
  ...

  uint32_t count = 0;
  timer_busy = false;

  for(;;)
  {
    kick_dog();
    led();
  }
}

static void led (void)
{
  if(!timer_busy)
  {
    blink_led();
    timer_busy = true;          
    start_timer(); // some hw timer that will clear the timer_busy flag from its ISR

    count++;
    if(count == max)
    {
      // do something
    }
  }
}
| improve this answer | | | | |
\$\endgroup\$
0
\$\begingroup\$

I am not really familiar with MSP controller, but the answer should be something like this:

#include "msp.h"

void main(void)
{
    volatile uint32_t i, j;
    WDT_A->CTL = WDT_A_CTL_PW & 0xFF00;
    WDT_A->CTL = WDT_A_CTL_PW | WDT_A_CTL_IS_5;
    P2DIR |= BIT1;
    while (1) // continuous loop
    {
        P2OUT ^=BIT1; // Blink P1.0 LED
        for (j = 8; j > 0; j--)
        {
             WDT_A->CTL = WDT_A_CTL_PW & 0XFF00;
             for (i = 750000; i > 0; i--);      // Delay with 3Mhz clock, 0,26s.
        }
    }
 }
| improve this answer | | | | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.