MSP430 Microcontroller Timer A Structure and Application Example

MSP430 Microcontroller Timer A Structure and Application Example

1 Introduction

Introduction MSP430 microcontroller timer A structure and its application examples.

2-timer module

In MSP430 series one-chip computer with powerful timer resource, this timer plays an important role in the one-chip computer application system. Using the MSP430 (hereinafter referred to as 430) microcontroller timer can be used to achieve timing, delay, signal frequency measurement, signal trigger detection, pulse width signal measurement, PWM signal generation. In addition, it can be used as a baud rate generator for serial port. Later we will use Timer A as a baud rate generator to write a serial port routine for beginners. To enhance beginners' understanding and application of Timer A.

In the 430 series of products, the timer resources of different sub-series products are different; in the F11X and F11X1, there is no timer B resource. 430 timers are mainly divided into three parts: watchdog timer, timer A, timer B. Timer A main resource features 16-bit timer counter, there are four count modes. Various count clock signals are available for selection. Three configurable input capture/compare function registers and three configurable output ones for eight output modes. The above blocks of timer resources can be used in various combinations to achieve powerful functions.

MSP430

Timer resource function description

(1) Watchdog Timer (WDT): This is mainly used to reset the system reset 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 a capture/compare function module to achieve timing control and output of a programmable waveform signal. Can be used as a serial baud rate generator.

(3) Timer B: Used as a basic timer, which is basically the same as Timer A, but some functions have more functions than A. See the timer B application example for details.

3-Timer A module structure

4-Timer A--Basic Application Routines (1)

/ / Routine Description: Use timer timer 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 port P1.0 as output.

CCTL0 = CCIE; // Set the CCIE bit in the capture/compare control register to 1 and the CCR0 capture/comparison function interrupt is enabled.

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 open 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

}

// Routine 1 ends -------------------------------------------- ------------------------------

Basic Application Routines (2)

/ / Routine Description: Use timer timer function to achieve P1.0 square wave output.

// It is important to note that timer interrupt routines use vector queries.

#include

Void main(void)

{

WDTCTL = WDTPW + WDTHOLD; // Stop watchdog WDT

P1DIR |= 0x01; // Set P1.0 direction as output.

TACTL = TASSEL_2 + MC_2 + TAIE; // Select SMCLK as the clock source, select the count mode, and 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;

}

}

Absolute Encoder

Rotary encoders are used as sensors for angle,position,speed and acceleration. We can offer incremental encoders and absolute encoders.

A-LEC-1

Absolute Encoder,Custom Encoder On Motor,Custom Optical Encoders,High Resolution Encoder

Yuheng Optics Co., Ltd.(Changchun) , https://www.yhenoptics.com

Posted on