我用MSP430f2618发PWM脉冲,timer-B时钟选择ACLK 可以产生波形,为什么把时钟该为SMCLK就没波形了???smclk选择的是高速晶体振荡器。
程序如下
#include <msp430x26x.h style="word-wrap: break-word; line-height: normal; ">
void InitSys()
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
InitSys();
P4DIR |= 0x7e; // P4.1 - P4.6 output
P4SEL |= 0x7e; // P4.1 - P4.6 TBx options
TBCCR0 = 512-1; // PWM Period
TBCCTL1 = OUTMOD_7; // CCR1 reset/set
TBCCR1 = 384; // CCR1 PWM duty cycle
TBCCTL2 = OUTMOD_7;
TBCCR2 = 128;
TBCCTL3 = OUTMOD_7;
TBCCR3 = 64;
TBCCTL4 = OUTMOD_7;
TBCCR4 = 32;
TBCCTL5 = OUTMOD_7;
TBCCR5 = 16;
TBCCTL6 = OUTMOD_7;
TBCCR6 = 8;
TBCTL = TBSSEL_1 + MC_1; // ACLK, up mode
_BIS_SR(LPM3_bits); // Enter LPM3
}
void InitSys()
{
unsigned int iq0;
//使用XT2振荡器
BCSCTL1&=~XT2OFF; //打开XT2振荡器
do
{
IFG1 &= ~OFIFG; // 清除振荡器失效标志
for (iq0 = 0xFF; iq0 > 0; iq0--); // 延时,等待XT2起振
}
while ((IFG1 & OFIFG) != 0); // 判断XT2是否起振
BCSCTL2 =SELM_2+SELS; //选择MCLK、SMCLK为XT2
}
上面这个可以产生6列波,但改成下面的就完全没有了,哪位大神可看看什么问题???
#include <msp430x26x.h style="word-wrap: break-word; line-height: normal; ">
void InitSys()
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
InitSys();
P4DIR |= 0x7e; // P4.1 - P4.6 output
P4SEL |= 0x7e; // P4.1 - P4.6 TBx options
TBCCR0 = 512-1; // PWM Period
TBCCTL1 = OUTMOD_7; // CCR1 reset/set
TBCCR1 = 384; // CCR1 PWM duty cycle
TBCCTL2 = OUTMOD_7;
TBCCR2 = 128;
TBCCTL3 = OUTMOD_7;
TBCCR3 = 64;
TBCCTL4 = OUTMOD_7;
TBCCR4 = 32;
TBCCTL5 = OUTMOD_7;
TBCCR5 = 16;
TBCCTL6 = OUTMOD_7;
TBCCR6 = 8;
TBCTL = TBSSEL_2 + MC_1; // SMCLK, up mode,就这边改了一下把时钟换为SMCLK
_BIS_SR(LPM3_bits); // Enter LPM3
}
void InitSys()
{
unsigned int iq0;
//使用XT2振荡器
BCSCTL1&=~XT2OFF; //打开XT2振荡器
do
{
IFG1 &= ~OFIFG; // 清除振荡器失效标志
for (iq0 = 0xFF; iq0 > 0; iq0--); // 延时,等待XT2起振
}
while ((IFG1 & OFIFG) != 0); // 判断XT2是否起振
BCSCTL2 =SELM_2+SELS; //选择MCLK、SMCLK为XT2
} |