TI中文支持网
TI专业的中文技术问题搜集分享网站

msp430g2553上用定时器输出两路频率、占空比可调的方波

如何在msp430g2553上用定时器输出两路频率、占空比可调的方波?求源码,如果有已有的例程更好,谢谢!

灰小子:

官网例程里没有两路的。一路pwm输出的好像也没有可调频率、占空比的。不过很简单的,下面例程调节CCR0和CCR1就能调整频率和占空比。一路会了,两路就简单了。 

//******************************************************************************
//MSP430G2xx3 Demo - Timer_A, PWM TA1, Up/Down Mode, 32kHz ACLK
//
//Description: This program generates one PWM output on P1.2 using
//Timer_A configured for up/down mode. The value in CCR0, 128, defines the
//PWM period/2 and the value in CCR1 the PWM duty cycle. Using
//32kHz ACLK as TACLK, the timer period is 7.8ms with a 75% duty cycle on
//P1.2. Normal operating mode is LPM3.
//ACLK = TACLK = LFXT1 = 32768Hz, MCLK = default DCO
////* External watch crystal installed on XIN XOUT is required for ACLK *////
//MSP430G2xx3
//-----------------
///|\|XIN|-
//| || 32kHz
//--|RSTXOUT|-
//||
//|P1.2/TA1|--> CCR1 - 75% PWM
//
//D. Dang
//Texas Instruments, Inc
//December 2010
//Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10
//******************************************************************************#include <msp430.h>int main(void)
{WDTCTL = WDTPW + WDTHOLD;// Stop WDTP1DIR |= 0x0C;// P1.2 and P1.3 outputP1SEL |= 0x0C;// P1.2 and P1.3 TA1/2 otionsCCR0 = 128;// PWM Period/2CCTL1 = OUTMOD_6;// CCR1 toggle/setCCR1 = 32;// CCR1 PWM duty cycleTACTL = TASSEL_1 + MC_3;// ACLK, up-down mode__bis_SR_register(LPM3_bits);// Enter LPM3
}

赞(0)
未经允许不得转载:TI中文支持网 » msp430g2553上用定时器输出两路频率、占空比可调的方波
分享到: 更多 (0)