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.

MSP430G2553: Blink onboad LED for one second using TAR compare interrupt

Part Number: MSP430G2553
Other Parts Discussed in Thread: MSP-EXP430G2ET

Hello,

I am trying to blink the onboard LED every one second via a Timer A interrupt, but am failing to understand the logic of specifying the exact interval of the blinking. From what I understand from the users guide, the ACLK is driven directly by the crystal, which oscillates at 32768 Hz. It also says that the TAR increments on every rising edge of the clock signal. So, my immediate thought is that the TAR should overflow after exactly one second if I set the value of the compare register to be 32768, since there is one rising edge per cycle and 32768 cycles in one second. But, with the code I have pasted below, the interrupt triggers roughly every 20 seconds or so. This leads me to believe that the number that should be in TACCR0 is *much* lower than 32768, but I don't know how to calculate it. I'm wondering where my logic is breaking down. I am pretty new to microcontroller development so please forgive me ignorance of electrical engineering related concepts. Please have a look at my code below if you don't mind. Thanks.

#include<msp430g2553.h>

void main(void) {
        // DISABLE WATCHDOG TIMER
        WDTCTL = WDTPW | WDTHOLD;

        // SET TIMER_A CONTROL REGISTER USING ACLK AS CLOCK SRC AND IN UP MODE WITH NO CLOCK DIVISION
        TACTL = TASSEL_1 | MC_1 | ID_0;

        // SET CAPTURE/COMPARE REGISTER TO SPECIFIC VALUE
        TACCR0 |= 0x8000; // 32768 hz, which is the oscillation frequency of aclk

        // SET CAPTURE/COMPARE CONTROL REGISTER TO DICTATE BEHAVIOR OF CAPTURE/COMPARE REGISTER
        // THIS LINE BASICALLY JUST ENABLES INTERRUPTS
        TACCTL0 |= CCIE;

        // MAKE P1.0 AN OUTPUT PIN AND HAVE IT TURNED OFF INITIALLY
        P1DIR |= 0x01;
        P1OUT &= 0x00;

        // ENTER LOW POWER MODE 
        // INFORM STATUS REGISTER THAT CPU IS OFF AND GLOBAL INTERRUPTS ARE ENABLED
        _BIS_SR(CPUOFF + GIE);
}

// INTERRUPT SERVICE ROUTINE... TOGGLE LED1 WHENEVER INTERRUPT OCCURS
// I SUSPECT THAT THE MSP430 PLACES THIS ISR IN THE INTERRUPT VECTOR ADDRESS FOR THIS PARTICULAR INTERRUPT
#pragma vector = TIMER0_A0_VECTOR
__interrupt void TIMER0_A0_ISR (void) {
        P1OUT ^= 0x01;
}
  • Hi Michael,

    What hardware are you using?

    If you are using MSP-EXP430G2ET, you have to change the crystal selection sesistors default setting.

    Regards,

    Ling

  • Sorry for leaving that information out. I actually didn't know there was a different name for the development board itself. I have a MSP-EXP430G2 model. I am starting to think I'm an idiot.. I don't think there is a crystal oscillator even on here. I for some reason thought it was much smaller in embedded in the board.
  • The G2 Launchpad used to come with a 32kHz crystal in the box. You have to solder it on yourself (the capacitors are in the MCU) but the pads are pretty big and have reflow (built-in solder) already.

    [Edit: Another way:]

    If you don't have a soldering iron handy, use TASSEL_2 (SMCLK), ID_3 (/8) and CCR0=1000000/8/2=62500 then count to 2 in the ISR.

  • Thank you. I got this development board a while back in college and have just recently been getting back into using it, so if a crystal oscillator did come with it, I obviously forgot about that component. It may be laying around somewhere, so I will solder it on if I find it otherwise use your other proposed method.

    My final question... if I do find the crystal and get it placed on the board, will my code succeed in blinking every second? I'm really just wondering if my logic and assumptions are correct.

**Attention** This is a public forum