用430 产生一个spwm,我用的是规则采样,当载波比设置为129的时候波形正常,一旦超过129就会失真,如果设置成500那正弦波直接变为尖峰。不知道为什么,请教各位大神啊!!!!!!!
下面是我的程序:
void Init() { MyClkInit(); ChangeMF (4); Timer_InitPWM (); }
void Cal_i() { uchar k; //p = (uchar*) malloc ((sizeof(uchar))*100); for(k=0;k<_N;k++) { p[k]= (uchar)(k*(129.00/_N)); } }
void Calnum () { T_2 = (uint)(T0/2); //PI_N = (double)(128/_N); } void main () { Init(); P1DIR |= BIT7 + BIT6; P1OUT |= BIT7; P1OUT |= BIT6; Calnum (); Cal_i(); j_f = _N-1; //j_f = GetPos(p); _EINT(); while(1); }
#pragma vector=TIMERB1_VECTOR __interrupt void Timer_B1(void) { // TB0CTL |= MC_0; TB0CTL&=~TBIFG; uchar j=0; j = p[i_f++]; if(i_f == j_f) i_f = 0; ulong di; di = (ulong)(T_2*(offset + sin[j]));//1 di >>= 14; if(j>64) di = T0 - di; //di = T0 - di; TB0CCR6 = di; // TB0CTL |= MC_3; //j_f %= 129; P1OUT ^= BIT7; //TB0CTL&=~TBIFG; }
|