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.

motor ware 例程 pwm输出函数 怎么理解?



static inline void HAL_writePwmData(HAL_Handle handle,HAL_PwmData_t *pPwmData)
{
  uint_least8_t cnt;
  HAL_Obj *obj = (HAL_Obj *)handle;
  PWM_Obj *pwm;
  _iq period;
  _iq pwmData_neg;
  _iq pwmData_sat;
  _iq pwmData_sat_dc;
  _iq value;
  uint16_t value_sat;

  for(cnt=0;cnt<3;cnt++)
    {
      pwm = (PWM_Obj *)obj->pwmHandle[cnt];
      period = (_iq)pwm->TBPRD;
      pwmData_neg = _IQmpy(pPwmData->Tabc.value[cnt],_IQ(-1.0));
      pwmData_sat = _IQsat(pwmData_neg,_IQ(0.5),_IQ(-0.5));    //_IQsat(A, long P, long N)//IQ数值的限幅函数 把A限制到[N P]之间
      pwmData_sat_dc = pwmData_sat + _IQ(0.5);
      value = _IQmpy(pwmData_sat_dc, period);
      value_sat = (uint16_t)_IQsat(value, period, _IQ(0.0));

      // write the PWM data
      PWM_write_CmpA(obj->pwmHandle[cnt],value_sat);
    }

  return;
} // end of HAL_writePwmData() function

 

 

 

这个函数能不能讲解一下?