- #include "msp430.h"
-
- #define NUMBER_TIMER_CAPTURES 20
- volatile unsigned int timerAcaptureValues[NUMBER_TIMER_CAPTURES];
- unsigned int timerAcapturePointer = 0;
-
- int main(void)
- {
- WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
-
- // Configure GPIO
- P1OUT &= ~0x01; // Clear P1.0 output
- P1DIR |= 0x01; // Set P1.0 to output direction
-
- // Disable the GPIO power-on default high-impedance mode to activate
- // previously configured port settings
- PM5CTL0 &= ~LOCKLPM5;
-
- // Clock System Setup
- CSCTL0_H = CSKEY >> 8; // Unlock CS registers
- CSCTL2 &= ~SELA_7;
- CSCTL2 |= SELA__VLOCLK; // Select ACLK=VLOCLK
- CSCTL0_H = 0x00; // Lock CS module (use byte mode to upper byte)
-
- __delay_cycles(1000); // Allow clock system to settle
-
- // Timer0_A3 Setup
- TA0CCTL2 = CM_1 | CCIS_1 | SCS | CAP | CCIE;
- // Capture rising edge,
- // Use CCI2B=ACLK,
- // Synchronous capture,
- // Enable capture mode,
- // Enable capture interrupt
- TA0CTL = TASSEL__SMCLK | MC__CONTINUOUS; // Use SMCLK as clock source,
- // Start timer in continuous mode
-
- __bis_SR_register(LPM0_bits | GIE);
- __no_operation();
- }
-
- // Timer0_A3 CC1-4, TA Interrupt Handler
- #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
- #pragma vector = TIMER0_A1_VECTOR
- __interrupt void Timer0_A1_ISR(void)
- #elif defined(__GNUC__)
- void __attribute__ ((interrupt(TIMER0_A1_VECTOR))) Timer0_A1_ISR (void)
- #else
- #error Compiler not supported!
- #endif
- {
- switch (__even_in_range(TA0IV, TA0IV_TAIFG)) {
- case TA0IV_TA0CCR1:
- break;
- case TA0IV_TA0CCR2:
- timerAcaptureValues[timerAcapturePointer++] = TA0CCR2;
- if (timerAcapturePointer >= 20) {
- while (1) {
- P1OUT ^= 0x01; // Toggle P1.0 (LED)
- __delay_cycles(100000);
- }
- }
- break;
- case TA0IV_TA0IFG:
- break;
- default:
- break;
- }
- }
-
|