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 timer code

Other Parts Discussed in Thread: MSP430G2553

Hi I am new to MSP430 and wrote a timer capture code, which I want to ask members of this forum if it is correct. Thanks for review.

#include <msp430g2553.h>

unsigned int counter = 0;

/*
* Timer capture example that captures the timer value and then
* turn off LED based on the timer value.
*/
void main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer

// Sets the DCO to 1 MHZ.
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;

// Sets up LED 0 and LED 1.
P1DIR |= BIT0 + BIT6;
// Turn off the LEDs.
P1OUT &= ~(BIT0 + BIT6);

// Sets up TimerA0 control registers.
// SMCLK + /8 + Continous Up + Clear the flags.
TA0CTL = TASSEL_2 + ID_3 + MC_2 + TACLR;
// Set up the timer.
// Positive edge + Toggle ground + Capture mode + Interrupt enabled.
TA0CCTL0 = CM_1 + CCIS_2 + CAP + CCIE;

// Enables global interrupts.
__enable_interrupt();
__bis_SR_register(GIE);

// Trigger the capture.
for (;;) {
TA0CCTL0 |= CCIS_3;
TA0CCTL0 &= ~CCIS_3;
}
}

/**
* ISR for handling the timer capture interrupt.
*/
#pragma vector=TIMER0_A0_VECTOR
__interrupt void handleTimer0Overflow() {
counter = TA0R;
if (counter > 32767) {
P1OUT |= BIT0;
P1OUT &= ~BIT6;
} else {
P1OUT |= BIT6;
P1OUT &= ~BIT0;
}
}

  • Amaltas Bohra said:
    which I want to ask members of this forum if it is correct

    I purpose Flash it into the chip and test it. If it is not working as expected tell us what is out of your expectation.

    Next time when you want to insert code use the   button which makes it more readable.

**Attention** This is a public forum