MSP430F5438 Study Notes 1-Timer

Publisher:静逸闲云Latest update time:2015-10-15 Source: eefocusKeywords:MSP430F5438 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Comparison Mode:

    This is the default mode of the timer. When in comparison mode, the hardware related to the capture mode stops working. If the timer interrupt is enabled at this time, then the timer final value is set (write the final value into TACCRx), and the timer is enabled, when the value of TAR increases to TACCRx, the interrupt flag CCIFGx is set to 1, and an interrupt is generated. If the interrupt is not enabled, only the interrupt flag CCIFGx is set to 1.

Example: The comparison mode is like the 51 MCU. It is necessary to be able to set the time interval by software to generate interrupts to handle some things, such as keyboard scanning. It can also be combined with signal output to generate timing pulse generators and PWM signal generators. For example: continuously load TACCRx, start the timer, and compare TAR with TACCRx to generate interrupt processing.

Capture Mode:

    Use the rising edge, falling edge, or rising and falling edge trigger of the external signal to measure external or internal events, and can also be stopped by software. The capture source can be selected by CCISx CCIxA, CCIxB, GND, VCC. After the capture is completed, the corresponding capture flag CCIFGx is set

Application of capture mode:

    Use the capture source to trigger the capture of the TAR value, and save each captured value to TACCRx. You can read the value of TACCRx at any time. TACCRx is a 16-bit register. The capture mode is used for precise positioning of events, such as measuring time, frequency, speed, etc.

Example: Use the values ​​of two captures to measure the pulse width. Or capture any edge, CCISx = "11" (input selects VCC), so that the capture condition is generated when VCC and GND switch.

Combined use: Asynchronous communication

The comparison mode and capture mode are used at the same time to realize UART asynchronous communication. That is, the comparison mode of the timer is used to simulate the baud rate of the communication sequence to send data, and the capture mode is used to receive data, and the comparison mode is switched in time to select and adjust the receiving baud rate of the communication, so as to achieve the purpose of several byte

-------------------------------------------------- --------------------------------------------------

The pulse width is measured by combining the MSP430 single-chip microcomputer timer A with the capture/compare function module.

     This example uses the CCI1A port of timer A (such as the P1.2 pin of MSP430F14X) to capture the pulse level jump of the external input, and combines it with a simple software algorithm to achieve the measurement of pulse width. In actual applications, the pulse width can be calculated based on the three variables start, end, and overflow in the example. This functional module has a high application value in actual product applications.

2- Routine

#include

unsigned int start,end;

unsigned char overflow;

void main (void)

{

WDTCTL  = WDTPW+WDTHOLD;                  // Turn off the watchdog timer

P1DIR = BIT0+BIT4;                       //Set P1.0 direction to output

P1SEL = BIT2;                            //Set P1.2 port to be used as a functional module

TACTL = TASSEL0+TACLR+TAIE+MC1;          //Select ACLK as the clock signal of timer A, and set the counting mode of timer A to continuous increment mode

CCTL1 = MC0+SCS+CAP+CCIE;                // Input rising edge capture, CCI0A is the capture signal source

_EINT();                                 //Interrupt enable

while(1);                                //LOOP

}

#pragma vector=TIMERA1_VECTOR             //Timer A interrupt processing

__interrupt void timer_a(void)

{

switch(TAIV)                             //vector query

case  2:                               //Capture interrupt

if(CCTL1&CM0)                     // rising edge

{

CCTL1=(CCTL1&(~CM0))|CM1;      //Change to falling edge trigger

start=TAR;                     //Record initial time

overflow=0;                    //Reset overflow count variable

}

else if (CCTL1&CM1)               // falling edge

{

CCTL1=(CCTL1&(~CM1))|CM0;     //Change to rising edge trigger

end=TAR;                     // Use start, end, overflow to calculate pulse width

}

break;

case 10:                            //Timer overflow interrupt

overflow++;

break;                           // Overflow count plus 1

default:break;

}

}

// End of routine

Keywords:MSP430F5438 Reference address:MSP430F5438 Study Notes 1-Timer

Previous article:MSP430 System Clock Overview
Next article:111 instructions of the microcontroller

Recommended ReadingLatest update time:2024-11-16 15:42

Microcontroller MSP430 - Timer_A timer interrupt program
1. Use the timer timing function to realize the timer single overflow interrupt and realize P3.0 square wave output #include "cc430x613x.h"      void main()   {       WDTCTL = WDTPW + WDTHOLD; // Stop the watchdog timer       P3DIR |= 0x04; // Initialize P3 port and set it to output mode              TA0CCR0 = 32768
[Microcontroller]
STM8L timer2 generates PWM
Introduction This article introduces how to use timer2 in the STM8L series to generate 38K frequency PWM. Among them, this article uses the first channel (PB0) of timer2. experiment platform Compiler software: IAR for STM8 1.42.2 Hardware platform: stm8l101f3p6 development board Emulator: ST-LINK Library version: ST
[Microcontroller]
STM8L timer2 generates PWM
Use of STM32 TIMER2
The configuration of the timing 100us is as follows: TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;   RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);   TIM_DeInit(TIM2);   TIM_TimeBaseStructure.TIM_Period = 1;//59999;//1199;//9999;   TIM_TimeBaseStructure.TIM_CounterMode =  TIM_CounterMode_Up;   TIM_TimeB
[Microcontroller]
Design of wireless environment detection system based on MSP430F5438 microcontroller
Environmental monitoring refers to determining the environmental quality (or degree of pollution) and its changing trend by measuring the representative values ​​of factors that affect environmental quality. With the continuous advancement of science and technology, especially the continuous development of computer
[Microcontroller]
Design of wireless environment detection system based on MSP430F5438 microcontroller
S3C6410 WATCHDOG TIMER (watchdog timer) driver under Linux (1)
Let's talk about the overall structure first. We have to talk about the platform device that everyone is familiar with. The watchdog timer also exists as a platform device, but the difference from the previous one is that the watchdog timer is a hybrid device. Let's introduce the hybrid device first. 1. Mixed equipm
[Microcontroller]
System tick Timer (SYSTICK Timer) of STM32F10xxx
background When studying the STM32F10xxx timer, I accidentally saw the System tick Timer, so I took a deeper look at it and made a record here. text System tick timer is a 24-bit system timer of Cotex-M core. Its auto-reload value can be configured and changed at any time, and if the system timer is configured, its in
[Microcontroller]
stm8s development (V) Use of TIMER: timing!
STM8S provides three types of TIM timers: advanced control type (TIM1), general type (TIM2/TIM3/TIM5) and basic timer (TIM4/TIM6). Although they have different functions, they are all based on a common architecture. This common architecture makes it very easy and convenient to design applications using various timers
[Microcontroller]
stm8s development (V) Use of TIMER: timing!
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号