1462 views|0 replies

2015

Posts

0

Resources
The OP
 

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

1- Introduction

Brief introduction to the MSP430 microcontroller timer A structure and its application examples.

2-Timer module

The MSP430 series of microcontrollers have 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. In order to enhance beginners' understanding and application of timer A.

In the 430 series, different sub-series have different timer resources; F11X and F11X1 do not have timer B resources. The 430 timer is mainly divided into three modules: watchdog timer, timer A, and timer B. The main resource features of timer A are 16-bit timer counter with 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 a program error occurs. 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: It is used as a basic timer and is basically the same as Timer A, but some of its functions are more enhanced than Timer A. For details, please see the application examples of Timer B.

3-Timer A module structure

4-Timer A--Basic Application Example (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 enable the CCR0 capture/compare function interrupt.

CCR0 = 50000; //The initial value of capture/compare control register CCR0 is 5000.

TACTL = TASSEL_2 + MC_2; //Set the timer A control register TACTL to select the SMCLK auxiliary clock as the clock source.

_BIS_SR(LPM0_bits + GIE); //Enter low power mode LPM0 and enable interrupt

}

//Timer A interrupt service program 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 examples (2)

//Routine description: Use the timer timing function to achieve P1.0 square wave output.

// It should be noted that the timer interrupt program uses a 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, and disconnect the timer

_BIS_SR(LPM0_bits + GIE); //Enter low power mode LPM0 and enable 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
Find a datasheet?

EEWorld Datasheet Technical Support

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