MSP430F149 Timer

Publisher:疯狂小马Latest update time:2015-04-13 Source: eechinaKeywords:MSP430F149 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
(1) Timing data implemented using timer A mode 2 (continuous) The

timing data implemented using timer A mode 2 (continuous) controls TACTL in the program. When TACTL is assigned the following value:

TACTL = TASSEL_2 + MC_2 + TAIE; // SMCLK, contmode, interrupt

TASSEL_X can be changed to achieve different timings.

When it is TASSEL_1, ACLK is selected as the timing clock, which can achieve the shortest timing of 2S, followed by timing of multiples of 2S. When

it is TASSEL_2, SMCLK is selected as the timing clock. The timing depends on the clock source of SMCLK.

1. SMCLK selects DCO = 800KHZ as the clock source. The shortest timing time is 0.08S, followed by its multiples.
2. SMCLK selects XT2, which is an external high-frequency crystal oscillator. At this time, the timing depends on the crystal oscillator frequency and its frequency division setting. The main thing is to set BCSCTL1 and BCSCTS2.

   BCSCTL1 &= ~XT2OFF;
  BCSCTL2 |= SELS + DIVS_3;

Different delays can be achieved by setting the above two sentences differently.

 

/************************************************************************
// MSP-FET430P140 Demo - Timer_A, Toggle P3.4, Overflow ISR, DCO SMCLK
//
// Description: Toggle P3.4 using software and Timer_A overflow ISR.
// In this example an ISR triggers when TA overflows. Inside the TA
// overflow ISR P3.4 is toggled. Toggle rate is approximatlely 12Hz.         // Proper use of the TAIV interrupt vector generator
is demonstrated. // ACLK = n/a, MCLK = SMCLK = TACLK = default DCO ~
800kHz
//
//            MSP430 F149
// --------------- //
/|| IAR Embedded Workbench Version: 3.42A Function: Timer A uses 800KHz DCO to achieve a timing interrupt of nearly one second; calculation method: T = 1/800,000 = 1.25uS so According to the continuous counting mode, when the count reaches 0XFFFF, an overflow interrupt occurs. Therefore, the overflow time is: 65536*1.25 = 0.0819S, so 12 overflows are required to count 1 second. ************************************************************************/ #include  typedef unsigned char uchar; typedef unsigned int uint; uchar flag=0; void main(void) {   WDTCTL = WDTPW + WDTHOLD; // Stop WDT   BCSCTL1 &= ~XT2OFF;   BCSCTL2 |= SELS + DIVS_3; 3D IR  |= BIT4;   TACTL = TASSEL_2 + MC_2 + TAIE; // SMCLK, contmode, interrupt   _BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt } // Timer_A3 Interrupt Vector (TAIV) handler #pragma vector= TI MERA1_VECTOR __interrupt void Timer_A(void) {  switch( TAIV )  {    case 2: break; // CCR1 not used    case 4: break; // CCR2 not used


























 













   case 10: P4OUT ^= BIT5; // overflow
            break;
 }
}

/*

// Timer A0 interrupt service routine
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
  P4OUT ^= BIT5; // Toggle P3.4
}

*/

(2) Timing data using timer A mode 1 (rising)

At this time, TACCTL0 and TACCR0 are used. Different timings can be achieved by setting different TACCR0 and different TASSEL_X.

However, the interrupt program needs to be changed.

Description of timer A interrupt:

1. The interrupt address of TIMERA1_VECTOR is 0XFFEA. This interrupt entry address contains 3 interrupt sources. It is a multi-source interrupt. The value of TAIV can be used to know which source the interrupt is from. When TAIV is 0X02H, the interrupt source is TACCR1 CCR1IFG.

                                      When TAIV is 0X04H, the interrupt source is TACCR2 CCR2IFG

                                      . When TAIV is 0X0AH, the interrupt source is TA OVERFLOW TAIFG.

2. The interrupt address of TIMERA0_VECTOR is 0XFFEC. It is a single-source interrupt. The interrupt source is TACCR0 CCR0IFG.

 [page]

Description of timing time:

When TASSEL_1, select ACLK = 32.768KHZ. At this time, different delays can be achieved by selecting different TACCR0.

When TASSEL_2, select SMCLK = DCO When

                            SMCLK = XT2 is selected,

the key statements are:

TACTL = TASSEL_X + MC_1;

TACCR0 = ~~~~~~~;

TACCTL0 = CCIE;

(3) By using the comparison mode of timer A, output mode 4 and continuous counting mode, four independent timing intervals or four different frequency outputs can be realized at the same time.

In the process of the experiment, the four segments of the digital tube are driven at the same time.  

In the comparison mode, the interrupt vectors and entry addresses of TACCR0 TACCR1 TACCR2 and TAIFG, as well as the output modes (8 in total) are mainly distinguished.

 

The program is as follows:

#include 

typedef unsigned char uchar;
typedef unsigned int uint;
uchar flag=0;
uchar table[] = {0x18,0x7e,0x51,0x52,0x36,0x92,0x90,0x5E,0x10,0x12}; //Corresponding to the common anode code of 0---9
void main(void)
{
  WDTCTL = WDTPW + WDTHOLD; // Stop WDT
  //BCSCTL1 |= XT2OFF;
  //BCSCTL2 |= SELS + DIVS_3;
  TACCTL0 = OUTMOD_4 +CCIE ; //Enable interrupt
  TACCTL1 = OUTMOD_4 +CCIE ;
  TACCTL2 = OUTMOD_4 +CCIE ;

  TACCR1 = 0X8000;
  TACCR2 = 0X2000;
  TACCR0 = 0XF000;
  P3DIR |= BIT6 + BIT7; // P3.4 output
  P3OUT |= BIT6 + BIT7;
  P4DIR = 0XFF;
  P4OUT = 0XFF;
  TACTL = TASSEL_2 + MC_2 + TAIE; // SMCLK, contmode, interrupt
  _BI S_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt

}
/**/
// Timer_A3 Interrupt Vector (TAIV) handler
#pragma vector=TIMERA1_VECTOR
__interrupt void Timer_A(void)
{
 switch( TAIV )
 {
   case 2: P4OUT ^= BIT5; TACCR1 += 0X8000;break; // CCR1 not used
   case 4: P4OUT ^= BIT3;TAACCR2 += 0X2000;break; // CCR2 not used
   case 10: flag++;
   if(flag==12){P4OUT ^= BIT2; flag = 0; } // overflow
            break;//flag++;
 }
}

/**/
// Timer A0 interrupt service routine
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer0_A (void )
{
  P4OUT ^= BIT4; // Toggle P3.4
  TACCR0 += 0XF000;
Keywords:MSP430F149 Reference address:MSP430F149 Timer

Previous article:MSP430 non-simulated IIC bus control program
Next article:My opinion on MSP430 introduction

Recommended ReadingLatest update time:2024-11-15 07:22

MSP430F149 controls the LED light on and off C program
The first program of MSP430 microcontroller controls the on and off of LED light at P1.0 port. The C language program uses IAR 6.0 as programming environment; MCU: MSP430F149; the program has detailed comments and is very suitable for beginners. #include msp430x14x.h typedef unsigned int uint; typedef unsigned cha
[Microcontroller]
PIC Timer (TIMER0)
    For example, if the internal instruction cycle clock is set as the clock source and the frequency division is 1:4 for a 4M crystal oscillator, the timer increment is 1us (but the PIC18F microcontroller is Three-stage pipeline, one instruction cycle = 1/4 clock/crystal cycle. For example: 8M crystal
[Microcontroller]
PIC Timer (TIMER0)
STC MCU timer2 capture mode frequency measurement
The most common method of measuring frequency using an STC microcontroller is to count the number of pulses within a certain period of time. This method generally requires a counter and a timer to work together, and it is not very accurate for low-frequency signals. Next, we can use the capture mode of timer2 to calcu
[Microcontroller]
STC MCU timer2 capture mode frequency measurement
MSP430F149 memory structure and FLASH reading and writing
1 Overview 1.1 FLASH characteristics     The write operation can only rewrite 1 to 0, and cannot rewrite 0 to 1. After the FLASH is erased, all cells become 1, and the erase operation can only be performed on the entire segment. The FLASH cannot be rewritten before being erased. 1.2 MSP430F149 memory addressing me
[Microcontroller]
MSP430 basic timer basic timer interrupt time calculation
I recently worked with 430 and was troubled by the BT timer. The BT timer is different from the ordinary timer of AVR that I have used before. The previous timer counted to FF and then generated an overflow interrupt. But the BT timer is different. The BT timer generates an interrupt when the corresponding selectio
[Microcontroller]
MSP430 basic timer basic timer interrupt time calculation
STM32 TImer several modes_general timer
Input capture mode Library function routine location: STM32F10x_StdPeriph_Lib_V3.3.0\Project\STM32F10x_StdPeriph_Examples\TIM\InputCapture In input capture mode, when the corresponding edge on the ICx signal is detected, the current value of the counter is latched into the capture/compare register (TIMx_CCRx). When
[Microcontroller]
STM32 TImer several modes_general timer
MSP430 MCU 16-bit timer Timer_A operation
/**********(一)Timer A comparison mode*************/  int main( void )  {  WDTCTL=WDTPW+WDTHOLD; //Turn off watchdog  BCSCTL1 =CALBC1_1M Hz ; //Set DCO to 1MHZ  DCOCTL =CALBC1_1MHZ;    P1DIR |= BIT0; //LED enable  TACTL=TASSEL1+TACLR; //Timer A clock source is SMCLK, and clear TAR  CCTL0 |= CCIE; //CCR0 interrupt enabl
[Microcontroller]
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号