//预存A相和B相的正弦值列表,C相的可以根据A相和B相的值计算出来
float sina[30]={ 0.000000, 0.104528, 0.207911, 0.309016, 0.406737,
0.500000, 0.587785, 0.669131, 0.743145, 0.809017,
0.866025, 0.913545, 0.951057, 0.978148, 0.994522,
1.000000, 0.994522, 0.978148, 0.951057, 0.913545,
0.866025, 0.809017, 0.743145, 0.669131, 0.587785,
0.500000, 0.406737, 0.309016, 0.207911, 0.104528};
float sinb[30]={ 0.866025, 0.809017, 0.743145, 0.669131, 0.587785,
0.500000, 0.406737, 0.309016, 0.207911, 0.104528,
0.000000, -0.104528, -0.207911, -0.309016, -0.406737,
-0.500000, -0.587785, -0.669131, -0.743145, -0.809017,
-0.866025, -0.913545, -0.951057, -0.978148, -0.994522,
-1.000000, -0.994522, -0.978148, -0.951057, -0.913545};
interrupt void T1PINT_ISR(void) // 通用定时器T1的周期中断
{
if((i>0)&&(i<N/2)) //前半周期
{
EvaRegs.CMPR1=EvaRegs.T1PR*((1.0+M*sina[i])/2.0); //A相
EvaRegs.CMPR2=EvaRegs.T1PR*((1.0+M*sinb[i])/2.0); //B相
EvaRegs.CMPR3=EvaRegs.T1PR*((1.0-M*(sina[i]+sinb[i]))/2.0); //C相
}
if((i>=N/2)&&(i<N)) //后半周期
{
EvaRegs.CMPR1=EvaRegs.T1PR*((1.0-M*sina[i-30])/2.0); //A相
EvaRegs.CMPR2=EvaRegs.T1PR*((1.0-M*sinb[i-30])/2.0); //B相
EvaRegs.CMPR3=EvaRegs.T1PR*((1.0+M*(sina[i]+sinb[i]))/2.0); //C相
}
i++;
{
if(i>=N)
{
i=0;
}
}
PieCtrl.PIEACK.bit.ACK2=1; //响应同组中断
EvaRegs.EVAIFRA.bit.T1PINT=1;//清除中断标志位
EINT; //开全局中断
}
请问这里的通用定时器1程序中后半周期是怎么算的CMPR1,CMPR2,CMPR3 |