各位老师好,这个BLDC3-1例程中,PWM模块这占空比是怎么算的呢?求指导
void F281X_EV1_BDC_PWM_Update(PWMGEN *p)
{
int32 Tmp;
int16 Period, GPR0_BDC_PWM;
// PWM1&4 are enabled (PWM4's forced ON) and PWM2&3 are disabled
if (p->Rotation==0)
EvaRegs.ACTRA.all = 0x00C2;
// PWM2&3 are enabled (PWM2's forced ON) and PWM1&4 are disabled
else if (p->Rotation==1)
EvaRegs.ACTRA.all = 0x002C;
// Otherwise, PWM1-4 are disabled
else
EvaRegs.ACTRA.all = 0x0000;
// Convert "Period" (Q15) modulation function to Q0
Tmp = (int32)p->PeriodMax*(int32)p->MfuncPeriod; // Q15 = Q0*Q15
Period = (int16)(Tmp>>15); // Q15 -> Q0 (period)
// Check pwm_active setting
if (p->PwmActive==1) // PWM active high
GPR0_BDC_PWM = 0x7FFF - p->DutyFunc;
else if (p->PwmActive==0) // PWM active low
GPR0_BDC_PWM = p->DutyFunc;
// Convert "DutyFunc" or "GPR0_BDC_PWM" (Q15) duty modulation function to Q0
Tmp = (int32)Period*(int32)GPR0_BDC_PWM; // Q15 = Q0*Q15
EvaRegs.CMPR1 = (int16)(Tmp>>15); // Q15 -> Q0
EvaRegs.CMPR2 = (int16)(Tmp>>15); // Q15 -> Q0
}
为什么总是对Tmp进行右移呢?这个0x7FFF是干啥的?速度计算那块就有0x7FFF,解释是周期寄存器的值,但是也找不到哪个周期寄存器的值是0x7FFF.
麻烦老师指导一下。谢谢