|
用430产生SPWM,输出用逻辑分析仪检测时候会出现有几个脉冲丢失或畸形的现象,请大神帮忙解决一下
波形图:
程序如下:
#include
#include
int y[3]={0,60,30};
//定义正弦表,将正弦波正半周分为9份//
const long SinTable[90]=
{
0x10 , 0x2F , 0x4D , 0x6C , 0x8B , 0xAA , 0xC8 , 0xE6 , 0x104 , 0x121 ,
0x13F , 0x15B , 0x178 , 0x194 , 0x1AF , 0x1CA , 0x1E4 , 0x1FE , 0x217 , 0x22F ,
0x247 , 0x25E , 0x275 , 0x28A , 0x29F , 0x2B3 , 0x2C6 , 0x2D8 , 0x2E9 , 0x2FA ,
0x309 , 0x318 , 0x326 , 0x332 , 0x33E , 0x348 , 0x352 , 0x35B , 0x362 , 0x369 ,
0x36E , 0x372 , 0x375 , 0x378 , 0x379 , 0x379 , 0x378 , 0x375 , 0x372 , 0x36E ,
0x369 , 0x362 , 0x35B , 0x352 , 0x348 , 0x33E , 0x332 , 0x326 , 0x318 , 0x309 ,
0x2FA , 0x2E9 , 0x2D8 , 0x2C6 , 0x2B3 , 0x29F , 0x28A , 0x275 , 0x25E , 0x247 ,
0x22F , 0x217 , 0x1FE , 0x1E4 , 0x1CA , 0x1AF , 0x194 , 0x178 , 0x15B , 0x13F ,
0x121 , 0x104 , 0xE6 , 0xC8 , 0xAA , 0x8B , 0x6C , 0x4D , 0x2F , 0x10
};
//合成正弦波主程序//
void main(void)
{
int i;
WDTCTL = WDTPW+WDTHOLD;// 禁止看门狗定时器
// 设置系统时钟,使用外接晶振 :8MHz,使单片机的时钟源设为 XT2
BCSCTL1 &= ~XT2OFF;
do
{
IFG1 &= ~OFIFG;
for(i=0xFF;i>0;i--);
}
while((IFG1 & OFIFG)!=0);
BCSCTL2 |= SELM_2 + SELS; // MCLK--XT2,SMCLK--XT2
//初始化端口//
P2DIR |= BIT1; // OUTPUT--P2.0
P2OUT = 0x00;
P4SEL |= BIT1 + BIT2 + BIT3 + BIT4 + BIT5 + BIT6;
P4DIR |= BIT1 + BIT2 + BIT3 + BIT4 + BIT5 + BIT6;
//设置Timer_a
TBCTL |= TBSSEL_2 + TBCLR;//选择SMLK为时钟,定时器清除
TBCCTL1 |= OUTMOD_2;
TBCCTL2 |= OUTMOD_2;
TBCCTL3 |= OUTMOD_2;
TBCCTL4 |= OUTMOD_7;
TBCCTL5 |= OUTMOD_7;
TBCCTL6 |= OUTMOD_7;
TBCCTL0=CCIE;
TBCCR0 = 888;
TBCCR1 = SinTable[0];
TBCCR2 = SinTable[60];
TBCCR3 = SinTable[30];
TBCCR4 = SinTable[0];
TBCCR5 = SinTable[60];
TBCCR6 = SinTable[30];
TBCTL |= MC_1;// + TAIE;//选择up,16位模式 ,中断开启
_EINT(); //中断允许
while(1);
}
//调用中断函数//
#pragma vector=TIMERB0_VECTOR
__interrupt void Timer_A(void)
{
y[0]=(y[0]+1)%90;
y[1]=(y[1]+1)%90;
y[2]=(y[2]+1)%90;
/*
if(y==0)
{
TACCR1 = SinTable[0];
}
else
{
TACCR1 = SinTable[y];
}
*/
TBCCR1 = SinTable[y[0]];
TBCCR2 = SinTable[y[1]];
TBCCR3 = SinTable[y[2]];
TBCCR4 = SinTable[y[0]];
TBCCR5 = SinTable[y[1]];
TBCCR6 = SinTable[y[2]];
}
|
|