1138 views|0 replies

3836

Posts

19

Resources
The OP
 

MSP430 MCU Timer A Structure and Application Examples [Copy link]

MSP430 MCU Timer A Structure and Application Examples 1-Introduction Introduction MSP430 MCU Timer A Structure and Application Examples. 2-Timer module The MSP430 series MCU has powerful timer resources, which play an important role in the MCU application system. The timer of MSP430 (hereinafter referred to as 430) MCU 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 counter, 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 for resetting 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 the CCIE bit in the capture/compare control register to 1, and the 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 the 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; } }

This post is from Microcontroller MCU
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list