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.

请教一个TI官网的例程 PMSM31_1中PWM_Update的问题



void F281X_EV1_PWM_Update(PWMGEN *p) {         int16 MPeriod;         int32 Tmp;

// Compute the timer period (Q0) from the period modulation input (Q15)        

Tmp = (int32)p->PeriodMax*(int32)p->MfuncPeriod;           // Q15 = Q0*Q15        

MPeriod = (int16)(Tmp>>16) + (int16)(p->PeriodMax>>1);     // Q0 = (Q15->Q0)/2 + (Q0/2)        

EvaRegs.T1PR = MPeriod; 

// Compute the compare 1 (Q0) from the PWM 1&2 duty cycle ratio (Q15)        

Tmp = (int32)MPeriod*(int32)p->MfuncC1;                    // Q15 = Q0*Q15        

EvaRegs.CMPR1 = (int16)(Tmp>>16) + (int16)(MPeriod>>1);    // Q0 = (Q15->Q0)/2 + (Q0/2)

// Compute the compare 2 (Q0) from the PWM 3&4 duty cycle ratio (Q15)        

Tmp = (int32)MPeriod*(int32)p->MfuncC2;                   // Q15 = Q0*Q15        

EvaRegs.CMPR2 = (int16)(Tmp>>16) + (int16)(MPeriod>>1);   // Q0 = (Q15->Q0)/2 + (Q0/2)

// Compute the compare 3 (Q0) from the PWM 5&6 duty cycle ratio (Q15)        

Tmp = (int32)MPeriod*(int32)p->MfuncC3;                   // Q15 = Q0*Q15        

EvaRegs.CMPR3 = (int16)(Tmp>>16) + (int16)(MPeriod>>1);   // Q0 = (Q15->Q0)/2 + (Q0/2)        

 }

 

这个程序的作用是什么?为什么要将PeriodMax的值进行变换,原本不就是Q0格式吗?还有MfuncPeriod的初值是0X7FFF,这个又是什么作用?