/**********(一)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 enable
CCR0 =50000; //Count value is 50000 SMCLK cycles
TACTL |= MC1; //Start timer A in continuous counting mode
_BIS_SR(GIE+CPUOFF);
return 0;
}
#pragma vector = TIMERA0_VECTOR //ccr0 interrupt service
__interrupt void ta0_isr(void)
{
P1OUT ^= BIT0; //LED flip
CCR0 +=50000; //Timing compensation
}
/********** (II) Timer A capture mode************/
volatile unsigned int cap_value; //Store the difference between two capture values
int main( void )
{
volatile unsigned int first_value,second_value,n;
WDTCTL=WDTPW+WDTHOLD; //Turn off watchdog
BCSCTL1 =CALBC1_8MHZ; //Set DCO to 1MHZ
DCOCTL =CALBC1_8MHZ;
BCSCTL1 |=DIVA_3; //ACLK input eight-
frequency division do //Wait for crystal oscillator to stabilize
{
IFG1 &=~OFIFG;
for(n=5000;n>0;n--);
} while(OFIFG&IFG1);
TACCTL2=CM1+CCIS_1+CAP; //Capture mode, capture rising edge, capture internal ACLK
TACTL=TASSEL_2+MC_2+TACLR; //Timer clock source is SMCLK, start continuous counting, clear TAR
TACCTL2 &=~CCIFG; //Clear CCR2 flag
while(!(CCIFG&TACCTL2)); //Check CCR2 flag
first_value=TACCR2; //The first captured value is stored in first_value
TACCTL2 &=~CCIFG; //Clear the flag of CCR2
while(!(CCIFG&TACCTL2)); //Check the flag of CCR2
second_value=TACCR2; //Store the second captured value in second_value
TACCTL2 &=~CCIFG; //Clear the flag of CCR2
TACCTL2 &=~MC1; //Turn off timer A
cap_value=(second_value-first_value);
return 0;
}
/************(三)Timer PWM output program********************/
int main( void )
{
WDTCTL=WDTPW+WDTHOLD; //Turn off watchdog
BCSCTL1 =CALBC1_1MHZ; //Set DCO to 1MHZ
DCOCTL =CALBC1_1MHZ;
TACTL=TASSEL1+TAR; //SMCLK is the clock source, clear TAR
CCR0=512; //Set PWM period
CCTL1 |=OUTMOD_7; //CCR1 Output is reset/set mode
CCR1=384; //PWM duty cycle setting of CCR1
CCTL2 |=OUTMOD_7; //CCR2 output is reset/set mode
CCR2=128; //PWM duty cycle setting of CCR2
P1SEL |=BIT2+BIT3; //TA1,TA2 output function
P1DIR |=BIT2+BIT3;
TACTL |=MC0; //Start timer A up-counting mode
_BIS_SR(CPUOFF);
return 0;
}
Previous article:ADC10 measurement single channel single shot mode
Next article:The role of the watchdog in the MSP430 microcontroller
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- 【GD32L233C-START Review】17. Completed work: Indoor environment monitoring equipment
- [Atria AT32WB415 Series Bluetooth BLE 5.0 MCU] Part 3: Lightble Control OLED Display
- Car sunlight sensor, urgent help
- Communication Principles_matlab.pdf
- Flyback power supply saber simulation
- Fundamentals of Spectrum Analysis
- Linux/UNIX System Programming Manual (Volumes 1 and 2)
- TMS320C6000 chip structure diagram and basic characteristics
- [ESK32-360 Review] + Serial communication and applications
- EEWORLD University Hall----Live Replay: TI's new generation of low-power Bluetooth microcontrollers helps you reduce application costs