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.

CCS/MSP430F5529: WDT interrupt interval

Part Number: MSP430F5529

Tool/software: Code Composer Studio

I am wanting to raise a WDT interrupt every 0.5ms.  I know that to set the interval time, I just have to add a line in main like this:  WDTCTL = WDT_MDLY_32  this would set the time interval to 32ms.  There is no command like this to make it 0.5ms, so I am curious how this can be done.  Thank you for your time in advance.

  • The WDT is not a general-purpose timer, but it does offer 8x dividers for 2x clocks. 

    If you right-click->Go To Definition you'll see the settings for the pre-defined WDT times. Of interest are the WDTIS bits, which refer to User Guide (SLAU208Q) Table 16-2, which shows the available divisors. The predefines use only 4x of the available divisors.

    2^19 is about 524k, so if SMCLK is running at 1MHz (which it probably is) WDTSSEL=SMCLK and WDTIS=3 should give you 0.524 seconds.

  • So, if I wanted to implement this in C, I could do the following?

    WDTIS = 6;

    WDTSSEL = SMCLK;

    This would make 2^9 = 512/1MHz = about 0.5 milliseconds.  I can't find very many examples of using this in C, so I just want to double check the syntax.

  • Actually it looks like I can use the ones defined in the header file like this:

    WDTCTL = WDT_MRST_0_5;  // Set interval to 0.5ms

  • It would be "WDTCTL = WDTPW | WDTSSEL__SMCLK | WDTIS__512".

    Check the header file for appropriate symbols to use. Do not forget the password or you get an instant reset.

  • Oh, thank you, I see it now.  I am getting close to being done with it, I think.  For some reason my interrupt flag isn't being thrown, though.

    #include <msp430.h>
    
    volatile unsigned int i = 0;
    
    int main(void)
    {
        WDTCTL = WDTPW | WDTSSEL__SMCLK | WDTIS__512;  // WDT interval 0.5ms
        _EINT();                // enable interrupts
        SFRIE1 |= WDTIE;        // Enable WDT interrupt
    
        P4DIR |= BIT7;      // LED2 to output
        P4OUT &= ~BIT7;     // LED2 initially OFF
    
        P2DIR &= ~BIT1;     // set P2.1 as input (SW1)
        P2REN |= BIT1;      // enable pull-up resistor
        P2OUT |= BIT1;      // required for proper IO
        P2IE |= BIT1;       // enable interrupt at P2.1
        P2IES |= BIT1;      // enable hi->lo edge for interrupt
        P2IFG &= ~BIT1;     // clear any erroneous interrupt flag
    
        volatile unsigned int i = 0;
    
        while(1)    // Sit here and wait for interrupt
        {
            if(i >= 1000)
            {
                P2IFG |= BIT1;
                i = 0;
            }
        }
    }
    
    #pragma vector = WDT_VECTOR             //WDT ISR
    __interrupt void watchdog_timer(void)
    {
            i++;
    }
    
    #pragma vector = PORT2_VECTOR       //SW1 ISR
    __interrupt void PORT2_ISR(void)
    {
        P2IFG &= ~BIT1; // Clear the flag
    
        P4OUT ^= BIT7;  // Toggle LED2
    }
    

  • The WDT ISR never happens, and i never increments.

  • The watchdog generates a reset unless you put it in timer mode.

**Attention** This is a public forum