MSP430 MCU Timer A Structure and Application Examples[Copy link]
1-IntroductionIntroduction to the structure of MSP430 microcontroller timer A and its application examples. 2-Timer moduleThe MSP430 series microcontroller has powerful timer resources, which play an important role in the microcontroller application system. The timer of the MSP430 (hereinafter referred to as 430) microcontroller can be used to realize timing, delay, signal frequency measurement, signal trigger detection, pulse width signal measurement, and PWM signal generation. In addition, it can be used as a baud rate generator for the serial port through software writing. Later, we will use timer A as a baud rate generator to write a serial port routine for beginners to refer to. To enhance beginners' understanding and application of timer A. In the large series of 430 products, different sub-series products have different timer resources; in F11X and F11X1, there is no timer B resource. The timer of 430 is mainly divided into 3 modules: watchdog timer, timer A, and timer B. The main resource features of timer A are 16-bit timer counters, and there are 4 counting modes. A variety of counting clock signals are available. 3 configurable input capture/compare function registers and 3 configurable output single chips with 8 output modes. The above timer resources can be used in various combinations to achieve powerful functions. MSP430 timer resource function description (1) Watchdog timer (WDT): Mainly used to reset the microcontroller system when an error occurs in the program. In addition, it can also be used as a basic timer. (2) Timer A: Used as a basic timer, combined with the capture/compare function module to achieve timing control, programmable waveform signal generation and output. Can be used as a serial port baud rate generator. (3) Timer B: Used as a basic timer, it is basically the same as timer A, but some functions are more enhanced than A. For details, please see the application example of timer B. 3-Timer A module structure 4-Timer A--Basic application routine (1) //Routine description: Use the timer timing function to achieve P1.0 square wave output. #include { WDTCTL = WDTPW + WDTHOLD; //Stop the watchdog WDT and do not use the internal watchdog timer. P1DIR |= 0x01; //Set the direction of P1.0 port to output. CCTL0 = CCIE; //Set CCIE bit in the capture/compare control register to 1, and CCR0 capture/compare function interrupt to enable. CCR0 = 50000; //The initial value of the capture/compare control register CCR0 is 5000. TACTL = TASSEL_2 + MC_2; //Set the timer A control register TACTL to select the clock source as SMCLK auxiliary clock. _BIS_SR(LPM0_bits + GIE); //Enter low power mode LPM0 and enable interrupt} //Timer A interrupt service routine area #pragma vector=TIMERA0_VECTOR __interrupt void TImer_A (void) { P1OUT ^= 0x01; //P1.0 inverted output CCR0 += 50000; //Reload CCR0 capture/compare data register data} //End of routine 1------------------------------------------------------------------------------------------ Basic application routine (2) //Routine description: Use the timer timing function to realize P1.0 square wave output. //It should be noted that the timer interrupt program uses vector query method. #include void main(void) { WDTCTL = WDTPW + WDTHOLD; //Stop watchdog WDT P1DIR |= 0x01; //Set the direction of P1.0 port to output. TACTL = TASSEL_2 + MC_2 + TAIE; // Select SMCLK as the clock source, select counting mode, disconnect the timer_BIS_SR(LPM0_bits + GIE); // Enter low power mode LPM0 and open interrupt } // TImer_A3 interrupt vector (TAIV) processing #pragma vector=TIMERA1_VECTOR __interrupt void Timer_A(void) { switch( TAIV ) { case 2: break; //CCR1 is not used case 4: break; //CCR2 is not used case 10: P1OUT ^= 0x01; //Overflow break; } }