用的是MSP430G2553 管脚上没有TA0.2,不像TA1那样。但是貌似论坛上有人说每路TA都能产生两路PWM波,好奇之余试试···结果没成功。以下是程序:
#include <msp430g2553.h>
void main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
//时钟设置为1MHz mclk=smclk=dco
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
BCSCTL3 |= LFXT1S_2;
BCSCTL2 |=SELM_1 + DIVM_0;
//初始化TA0为两通道pwm,smclk
P1DIR |= (BIT1+BIT2);
P1SEL |= (BIT1+BIT2);
TA0CCR2 = 2000;
TA0CCTL0 = OUTMOD_7;
TA0CCTL1 = OUTMOD_7;
TA0CCR0 = 200;
TA0CCR1 = 1000;
TA0CTL = TASSEL_2 + MC_1;
_BIS_SR(LPM0_bits); //进入LPM0低功耗模式
}
额··没出波形···是不是PWM波周期设置只认CCR0??对哦 没看到哪里可以设置说周期可以设置为CCR1或者CCR2·····那怎么过TA0输出两路PWM呢??膜拜高手解答·······阿弥陀佛····
此帖出自
小平头技术问答
void main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
//时钟设置为1MHz mclk=smclk=dco
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
BCSCTL3 |= LFXT1S_2;
BCSCTL2 |=SELM_1 + DIVM_0;
//初始化TA0为两通道pwm,smclk,由P2.1和P2.4输出
P2DIR |= (BIT1+BIT4);
P2SEL |= (BIT1+BIT4);
TA1CCR0 = 2000; //周期为2000个时钟周期
TA1CCTL1 = OUTMOD_7;
TA1CCTL2 = OUTMOD_7;
TA1CCR1 = 500; //占空比500/2000=0.25
TA1CCR2 = 1000; //占空比1000/2000=0.5
TA1CTL = TASSEL_2 + MC_1;
_BIS_SR(LPM0_bits); //进入LPM3低功耗模式
}
一周热门 更多>