求助:spwm波产生怎么有误差??

zhuxiaoying   2009-11-23 16:32 楼主
我的spwm波产生怎么有误差??
#include <msp430x14x.h>
#define uint unsigned int
#define uchar unsigned char
uint j=0;
uint k=0;



uint b[100] = {11.3088,33.9152,56.4882,79.0055,101.4447,123.7839,146.0008,168.0738,189.9808,
211.7003,233.2110,254.4914,275.5207,296.2782,316.7432,336.8956,356.7156,376.1835,
395.2802,413.9868,432.2848,450.1562,467.5834,484.5491,501.0366,517.0297,532.5125,
547.4698,561.8868,575.7493,589.0436,601.7566,613.8757,625.3890,636.2851,646.5533,
656.1834,665.1659,673.4920,681.1534,688.1427,694.4528,700.0776,705.0114,709.2495,
712.7877,715.6225,717.7510,719.1711,719.8816,719.8816,719.1711,717.7510,715.6225,
712.7877,709.2495,705.0114,700.0776,694.4528,688.1427,681.1534,673.4920,665.1659,
656.1834,646.5533,636.2851,625.3890,613.8757,601.7566,589.0436,575.7493,561.8868,
547.4698,532.5125,517.0297,501.0366,484.5491,467.5834,450.1562,432.2848,413.9868,
395.2802,376.1835,356.7156,336.8956,316.7432,296.2782,275.5207,254.4914,233.2110,
211.7003,189.9808,168.0738,146.0008,123.7839,101.4447,79.0055,56.4882,33.9152,
11.3088 };



void int_clk()
{
uchar i;
BCSCTL1 &=~XT2OFF; //打开XT振荡器
BCSCTL2 |=SELM1+SELS; //MCLK 8M

do
{
IFG1 &= ~OFIFG; //清除振荡错误标志
for(i = 0; i <200; i++)
_NOP(); //延时等待
}
while ((IFG1 & OFIFG) != 0); //如果标志为1继续循环等待
IFG1&=~OFIFG;
BCSCTL2 |=SELM1+SELS; //MCLK 8M
}

void main()
{
WDTCTL=WDTPW+WDTHOLD;
int_clk();
TBCCTL0 = CCIE;
TBCCR0=800;
TBCTL=TBSSEL_2+MC0;
_BIS_SR(LPM0_bits + GIE);

}
#pragma vector=TIMERB0_VECTOR
__interrupt void Timer_B(void)
{
TBCCR0=800;
k++;
if(k<101)
{
if (k==1)

{
P4SEL|=BIT3;
P4DIR|=BIT3;
P4SEL &= ~BIT2;
P4DIR &= ~BIT2;
P4OUT &= ~BIT2;
TBCCTL3=OUTMOD_7;
}


TBCCR3=b[j];
j++;
if(j>=100)
{
j=0;
}

}

else if(k>100&&k<201)
{
if (k==101)
{
P4SEL|=BIT2;
P4DIR|=BIT2;
P4SEL &= ~BIT3;
P4DIR &= ~BIT3;
P4OUT &= ~BIT3;
TBCCTL2=OUTMOD_7;

}
TBCCR2 = b[j];
j++;
if(j>=100)
{
j=0;
}
}

else
{
k=0;
// j=0;
}
return;
}



这个是我写的spwm波形,现在出现的一个问题就是等到最后几个波的时候,spwm突然会有一个满占空比的波产生,上下多会有。我用断点仿真查看错误但是还是没有效果,没有看出其中的误差。。。所以我很迷茫,热切盼望大侠的指导。。万分感激。。

回复评论 (4)

TBCCR3=101.4447?
点赞  2009-11-23 16:51
大侠请指点,是不是这句有问题啊?
点赞  2009-11-23 16:55
是不是需要是整数啊,我对这个定时器的输出模式一直很迷茫。
多谢指教
点赞  2009-11-23 17:15
你这个写的就有问题
点赞  2012-7-31 14:41
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复