1124 views|0 replies

3836

Posts

19

Resources
The OP
 

Using MSP430 to implement PWM signal [Copy link]

PWM signal is a digital signal with a fixed period and variable duty cycle.

If the counter of Timer_A works in up-counting mode, the output adopts output mode 7 (reset/set mode)

Use register TAxCCR0 to control the period of the PWM waveform, and use another register TAxCCRx to control the duty cycle (t high level / T period)

topic

Assume ACLK = TACLK = LFXT1 = 32768Hz, MCLK = SMCLK = DCOCLK = 32 * ACLK = 1.048576MHz, and 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 sets output mode 7

CCR1 = 384; //Duty cycle 384/512=0.75

CCTL2 = OUTMOD_7; //Capture/compare control register sets output mode 7

CCR2 = 128; //Duty cycle 128/512=0.25

P1DIR |= 0x04; //P1.2 output

P1SEL |= 0x04; //P1.2 is the peripheral module TA1

P2DIR |= 0x01; //P2.0 output

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:

75% duty cycle as shown in the yellow waveform

25% duty cycle as shown in the blue waveform

The 25% waveform is obviously wrong!! But I don't know why! The chip used for simulation is F249, and the code is msp430x44x.h

This post is from Microcontroller MCU
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

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