concept

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

If timer_ The counter of a operates in the count up mode, and the output adopts output mode 7 (reset / set mode)

Register taxccr0 is used to control the cycle of PWM waveform, and another register taxccrx is used to control the duty cycle (t high level / T cycle)

subject

Set aclk = taclk = lfxt1 = 32768Hz, MCLK = smclk = dcoclk = 32 * aclk = 1.048576mhz, and use timer_ A PWM torque waveform with output cycle 512 / 32768 = 15.625ms and duty cycle 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 cycle

CCTL1 = OUTMOD_ 7; // The capture / compare control register sets the output mode 7

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

CCTL2 = OUTMOD_ 7; // The capture / compare control register sets the 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 increment count mode

for (;;)

{

_ BIS_ SR(LPM3_bits); // Enter low power mode 3

_ NOP();

}

}

Display output:

How to realize PWM signal with MSP430 Single Chip Microcomputer

75% duty cycle, as shown in yellow waveform

How to realize PWM signal with MSP430 Single Chip Microcomputer

 

25% duty cycle, as shown in blue waveform

25% waveform is obviously wrong!! But I don’t know why! The chip used in the simulation is f249, and the code is msp430x44x. H

Leave a Reply

Your email address will not be published. Required fields are marked *