Electronic – Timer overflow on MSP430

cinterruptsmsp430

I'm using an interrupt to wake the microcontroller once the value has been reached. I see that in the Capture/Compare Control Register there is a Capture Overflow bit. I can't seem to find an example of checking for this bit once the value has been reached. One example interrupt looked like:

#pragma vector = TIMERA0_VECTOR
__interrupt void CCR0_ISR(void) {
    if (++i == 120) {
        P1OUT ^= RLY1;
        i=0;
    }
} // CCR0_ISR

But this doesn't check the value of the bit. So how do i check to see if the timer has overflowed?

Best Answer

Not sure exactly which series MSP you're using so you'll have to look up the specifics. But the basic premise should apply across the board I think.

The following example is from the file msp430g2xx1_ta_03.c in the code snippets that can be downloaded from the TI Wiki:

#include <msp430.h>

int main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  P1DIR |= 0x01;                            // P1.0 output
  TACTL = TASSEL_2 + MC_2 + TAIE;           // SMCLK, contmode, interrupt

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

// Timer_A3 Interrupt Vector (TAIV) handler
#pragma vector=TIMERA1_VECTOR
__interrupt void Timer_A(void)
{
 switch( TAIV )
 {
   case  2: break;                          // CCR1 not used
   case  4: break;                          // CCR2 not used
   case 10: P1OUT ^= 0x01;                  // overflow
            break;
 }
}

The key is checking the TAIV register to see what caused the interrupt. Take a look at page 416 of the CC430 Family User's Guide:

TAIV Register Description

Now the code example is looking for a value of 10 in the TAIV register and the User Guide indicates that 0x0E is the overflow. So, again, check your specific chip's documentation. But the TAIV register is what will tell you what the cause of the interrupt is.