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.
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;
}
}
**Attention** This is a public forum