This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

各位老师好,请教一下BLDC3-1的程序中PWM—Update模块中计算通过计算占空比得到比较寄存器CMPR1,2,3的值时,怎么能那样计算呢?实在看不懂,还请老师赐教。

void F281X_EV1_BLDC_PWM_Update(PWMGEN *p)
{

int32 Tmp;
int16 Period, GPR0_BLDC_PWM;

// State s1: current flows to motor windings from phase A->B, de-energized phase = C
if (p->CmtnPointer==0)
EvaRegs.ACTRA.all = 0x00C2;

// State s2: current flows to motor windings from phase A->C, de-energized phase = B
else if (p->CmtnPointer==1)
EvaRegs.ACTRA.all = 0x0C02;

// State s3: current flows to motor windings from phase B->C, de-energized phase = A
else if (p->CmtnPointer==2)
EvaRegs.ACTRA.all = 0x0C20;

// State s4: current flows to motor windings from phase B->A, de-energized phase = C
else if (p->CmtnPointer==3)
EvaRegs.ACTRA.all = 0x002C;

// State s5: current flows to motor windings from phase C->A, de-energized phase = B
else if (p->CmtnPointer==4)
EvaRegs.ACTRA.all = 0x020C;

// State s6: current flows to motor windings from phase C->B, de-energized phase = A
else if (p->CmtnPointer==5)
EvaRegs.ACTRA.all = 0x02C0;

// 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 PwmActive setting
if (p->PwmActive==1) // PWM active high,如果PWM调制在ACTRA设置为高电平有效时,则占空比需要进行下一步运算。
GPR0_BLDC_PWM = 0x7FFF - p->DutyFunc;

else if (p->PwmActive==0) // PWM active low
GPR0_BLDC_PWM = p->DutyFunc;

// Convert "DutyFunc" or "GPR0_BLDC_PWM" (Q15) duty modulation function to Q0
Tmp = (int32)Period*(int32)GPR0_BLDC_PWM; // Q15 = Q0*Q15
EvaRegs.CMPR1 = (int16)(Tmp>>15); // Q15 -> Q0
EvaRegs.CMPR2 = (int16)(Tmp>>15); // Q15 -> Q0
EvaRegs.CMPR3 = (int16)(Tmp>>15); // Q15 -> Q0

}