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.

Help With a Piece of Code



Guys can someone just please confirm for me what the following two lines of code do?

  WDTCTL = WDT_MDLY_32;                     // WDT Timer interval
  IE1 |= WDTIE;                             // Enable WDT interrupt

My understanding is that the first line sets the watchdog timer (which is set up to act as an interval timer here) interval to be 32ms.

My confusion comes in the second line. I know this enables the watchdog timer interval, but my question now is when does the interrupt kick in?

Does it happen every 32ms or does it wait until the GIE bit is set?

For clarity here is the code in it's entirity:-

#include  <msp430x20x3.h>

int results[100];             // holds ADC temperature result
int i = 0;

void main(void)
{
  BCSCTL2 |= DIVS_3;                        // SMCLK/8
  WDTCTL = WDT_MDLY_32;                     // WDT Timer interval
  IE1 |= WDTIE;                             // Enable WDT interrupt
  P1DIR |= 0x01;                            // P1.0 to output direction - For LED?
  SD16CTL = SD16REFON +SD16SSEL_1;          // 1.2V ref, SMCLK
  SD16INCTL0 = SD16INCH_2;                  // A2 selected as I/P channel
  SD16CCTL0 = SD16SNGL + SD16IE ;           // Single conv, interrupt

  _BIS_SR(LPM0_bits + GIE);                 // Enter LPM0 with interrupt
}

#pragma vector=SD16_VECTOR
__interrupt void SD16ISR(void)
{
  results[ i ] = SD16MEM0;                    // Store value
  i++;
}

// Watchdog Timer interrupt service routine
#pragma vector=WDT_VECTOR
__interrupt void watchdog_timer(void)
{
  SD16CCTL0 |= SD16SC;                      // Start SD16 conversion
}

  • Mike2108 said:

    Guys can someone just please confirm for me what the following two lines of code do?

      WDTCTL = WDT_MDLY_32;                     // WDT Timer interval
      IE1 |= WDTIE;                             // Enable WDT interrupt

    My understanding is that the first line sets the watchdog timer (which is set up to act as an interval timer here) interval to be 32ms.

    My confusion comes in the second line. I know this enables the watchdog timer interval, but my question now is when does the interrupt kick in?

    Does it happen every 32ms or does it wait until the GIE bit is set?

    [/quote]

    The Watchdog timer is configured as an interval timer by the first line.  It begins its counting immediately.  32ms after that instruction is executed, the watchdog timer interval will expire and the WDTIFG should be set.

    The second line simply enables the interrupt to propagate from the Watchdog timer.  When GIE is set, then you will actually take an interrupt vector when the watchdog timer expires.  If GIE is not set, there will not be an interrupt, but the watchdog timer will have expired.

**Attention** This is a public forum