1877 views|2 replies

2015

Posts

0

Resources
The OP
 

MSP430 series MCU-Timer_A realizes PWM [Copy link]

Concept
PWM signal is a digital signal with fixed period and indefinite duty cycle.
If the counter of Timer_A works in up-counting mode, the output adopts output mode 7 (reset/set mode)
and uses register TAxCCR0 to control the period of PWM waveform, and uses another register TAxCCRx to control the duty cycle (t high level / T period)

Question
Assume ACLK = TACLK = LFXT1 = 32768Hz, MCLK = SMCLK = DCOCLK = 32 * ACLK = 1.048576MHz, use Timer_A to output a PWM waveform with a period of 512/32768 = 15.625ms and a duty cycle of 75% and 25% respectively.

The code is as follows:

#include "msp430x44x.h"

void main()
{

WDTCTL = WDTPW + WDTHOLD;
FLL_CTL0 |= XCAP14PF;
TACTL = TASSEL0 + TACLR; //ACLK, clear TAR
CCR0 = 512 - 1; //Set PWM period
CCTL1 = OUTMOD_7; //Capture/compare control register set output mode 7
CCR1 = 384; //Duty cycle 384/512=0.75
CCTL2 = OUTMOD_7; //Capture/compare control register set output mode 7
CCR2 = 128; //Duty cycle 128/512=0.25

P1DIR |= 0x04; //P1.2 outputs
P1SEL |= 0x04; //P1.2 is the peripheral module TA1
P2DIR |= 0x01; //P2.0 outputs
P2SEL |= 0x01; //P2.0 is the peripheral module TA2
TACTL |= MC0; //Timer_A control register is set to up-counting mode

for (;;)
{
_BIS_SR(LPM3_bits); //Enter low power mode 3
_NOP();
}
}

Display output:

This post is from Microcontroller MCU

Latest reply

  Details Published on 2020-2-6 09:29
 

4005

Posts

0

Resources
2
 

This is too simple, I am really good at it

430G2553 Electronic Music

This post is from Microcontroller MCU
 
 

2618

Posts

0

Resources
3
 

This post is from Microcontroller MCU
 
 
 

Guess Your Favourite
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