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.

question about HAL_updateAdcBias in lab02a

Hello:

The following code is copied from lab02a during motor identification process in Main Run Forerver Loop. Why does it call HAL_updateAdcBias() here?

I know HAL_updateAdcBias() is used for Current Feedback Polarity, and ADC bias value is calculated in the controller offline state. After the bias calculation is completed, the state changes to CTRL_State_OnLine.

Why does it modify the ADC bias value at the beginning of CTRL_State_OnLine? Does it mean the bias value calculated in the previous offline state is not correct?

Thank you in advance.

if(flag_ctrlStateChanged)
{
   .
   .
   .
   else if(ctrlState == CTRL_State_OnLine)
   {
       if((estState < EST_State_LockRotor) || (estState > EST_State_MotorIdentified))
          // update the ADC bias values
          HAL_updateAdcBias(halHandle);
       .
       .
       .
   }
   .
   .
   .
}

  • HAL_updateAdcBias(halHandle);

    is NOT running the offset calibration, it is simply using that calculated 

      // update the current bias
      for(cnt=0;cnt<HAL_getNumCurrentSensors(handle);cnt++)
        {
          bias = HAL_getBias(handle,HAL_SensorType_Current,cnt);
         
          bias += OFFSET_getOffset(obj->offsetHandle_I[cnt]);

          HAL_setBias(handle,HAL_SensorType_Current,cnt,bias);
        }


      // update the voltage bias
      for(cnt=0;cnt<HAL_getNumVoltageSensors(handle);cnt++)
        {
          bias = HAL_getBias(handle,HAL_SensorType_Voltage,cnt);

          bias += OFFSET_getOffset(obj->offsetHandle_V[cnt]);

          HAL_setBias(handle,HAL_SensorType_Voltage,cnt,bias);
        }

      return;
    } // end of HAL_updateAdcBias() function

    static inline void HAL_setBias(HAL_Handle handle,
                                   const HAL_SensorType_e sensorType,
                                   uint_least8_t sensorNumber,
                                   const _iq bias)
    {
      HAL_Obj *obj = (HAL_Obj *)handle;


      if(sensorType == HAL_SensorType_Current)
        {
          obj->adcBias.I.value[sensorNumber] = bias;
        }
      else if(sensorType == HAL_SensorType_Voltage)
        {
          obj->adcBias.V.value[sensorNumber] = bias;
        }

      return;
    } // end of HAL_setBias() function