2964 views|0 replies

6366

Posts

4929

Resources
The OP
 

MSP430 MCU simulation example 16 based on Proteus - timer timing 1 second [Copy link]




This content is originally created by EEWORLD forum user tiankai001. If you need to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source. 1. Task requirements
Use the timer TA of the MSP30F247 microcontroller to generate a set time interval interrupt, and switch the LED light on and off in the interrupt service program, turning on for 1S and off for 1S.
2. Analysis and explanation
The clock source of timer A can be selected as SMCLK, ACLK and external pin input clock source (TACLK, INCLK), generally SMCLK and ACLK are selected. ACLK is an external low-frequency crystal oscillator, usually 32768Hz, or 1/2/4/8 division of ACLK. Timer A can divide ACLK by 1/2/4/8 again. The minimum unit of the time base of Timer A is 1/32768 seconds (about 30 microseconds), and the maximum is 1.95 milliseconds after 64 division. Therefore, the timing range of Timer A is 2S (corresponding to the time base of 30 microseconds) and 128S (corresponding to the time base of 1.95ms). SMCLK can choose XT2 and internal DCO as the clock source. If SMCLK chooses XT2 (for example, 8MHz), the time base of Timer A is 0.125 microseconds, and the maximum is 8 microseconds after 64 division. Therefore, the timing range of Timer A is 8.19ms (corresponding to the time base of 0.125 microseconds) and 524mS (corresponding to the time base of 8us).
In short, when the timer time interval is required to be less than a few hundred milliseconds, the clock source of timer A uses SMCLK, and SMCLK generally uses XT2 as the clock source; when the timing time interval is from a few hundred milliseconds to tens of seconds, ACLK (or appropriate frequency division) should be used as the clock source of timer A.
III. Hardware Circuit
The hardware circuit is shown in the figure below.
Select P4.1 of MSP430F247 microcontroller to connect an LED light, and use a 32768Hz low-frequency crystal oscillator to obtain a stable ACLK clock. XT2 is connected to an 8MHz crystal oscillator (the frequency range of XT2 is 400kHz~16MHz), and two 22pF matching capacitors are used to supply MCLK and SMCLK clocks. The tube voltage drop of a general light-emitting diode is about 1.8~2.2V, and the current is 5~10mA. In this example, the current limiting resistor is selected as 300 ohms. .
Fourth, Program Design
In the interrupt service program, the P1.0 port is inverted to get a signal with a period of 2S, in which the high level is 1S and the low level is 1S.
#include "msp430f247.h"
#include "stdlib.h"
#include "string.h"
/*********************************************Software delay, main frequency 1M*******************/
#define CPU_F1 ((double)1000000)
#define delay_us1M(x) __delay_cycles((long)(CPU_F1*(double)x/1000000.0))
#define delay_ms1M(x) __delay_cycles((long)(CPU_F1*(double)x/1000.0))/************************************************************************//******************************************************** Function name: main function Function function: timer A timing function Entry parameters: none Exit parameters: none Description: Author: Lao Ma Shi Tu MCU Date: January 7, 2018 **********************************************************/main(){ WDTCTL = WDTPW + WDTHOLD; //Turn off the watchdog
P4DIR = 0x01; //P1.0 output _EINT(); CCTL0 = CCIE; //CCR0 interrupt enabled CCR0 = 32768; //Timing time interval 1S TACTL = TASSEL_1 + MC_1; //Timer A clock source is ACLK, up counting mode //BCSCTL1 |= 0; while(1) { _BIS_SR(SCG1+SCG0+CPUOFF+GIE); //Enter LPM0 low power mode, total interrupt enabled _NOP(); } } #pragma vector = TIMERA0_VECTOR __interrupt void Timer_A(void) // Timer A0 interrupt service program { P4OUT ^= 0x01; // P1.0 output inverted } V. Program Description The default main clock MCLK=DCO=1.1MHz after the program store of MSP430F247 microcontroller runs. Timer A adopts the up-counting mode, and the clock source of timer A is ACLK=32768Hz. The time base unit is 1/32768S. Set CCR0=32768, and the timing time interval is 1S. Note that the frequency of the ACLK clock in the properties of the microcontroller is set. As shown in the figure below
VI. Simulation Results and Analysis
After drawing the circuit diagram in proteus, double-click the microcontroller to load the executable file into the microcontroller, click Run, and observe the display of the digital tube. As shown in the figure below. Although the program is short, it contains the basic usage of the timer. Before using the timer, set the control register TACTL, clock source selection, counting mode selection, interrupt enable and the value of the timing time interval CCR0. In the up-counting mode, when the count value of timer A reaches CCR0, the TACCR0_CCIFG interrupt flag is established. CCR0 is a single-source interrupt. The CPU responds to the interrupt and automatically clears the interrupt flag TACCR-_CCIFG after entering the timer A0 interrupt service routine.

This post is from Microcontroller MCU
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

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