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.

CCS/TMS320F28054F: IQ Math is inconsistent in Motorware and seems to be part of our problem getting reasonable values. Why is IQ24 and IQ12 being mixed together?

Part Number: TMS320F28054F
Other Parts Discussed in Thread: MOTORWARE

Tool/software: Code Composer Studio

We are making progress on the flux error in lab2a and have also been working on lab1b.  I just discovered that there is an inconsistency in IQ math mixing IQ24 and IQ that we do not understand.  We are apply 29 volts to the Vdc Bus and expect the calculations in the motorware to realize that value but that is impossible because the preprocessor calculated USER_VOLTAGE_SF in user.h isn't allowed to go below 0.1.  There are other values like resistance which are not correct yet either but we are working through all the values.  In Hal.c HAL_setParams(), it converts the user voltage_sf to IQ24 because of the following in IQMathLib.h:

#ifndef   GLOBAL_Q
#define   GLOBAL_Q       24
#endif

In Hal.c HAL_setParams():

  _iq voltage_sf = _IQ(pUserParams->voltage_sf);
  HAL_setVoltageScaleFactor(handle,voltage_sf);
This puts the IQ24 version of the voltage_sf constant into halHandle->voltage_sf
In Hal.h static inline void HAL_readAdcData(HAL_Handle handle,HAL_AdcData_t *pAdcData):
 
 // read the dcBus voltage value
  value = (_iq)ADC_readResult(obj->adcHandle,ADC_ResultNumber_7);     // divide by 2^numAdcBits = 2^12
  value = _IQ12mpy(value,voltage_sf);
  pAdcData->dcBus = value;
 
This is doing IQ12 fixed point math on an IQ24 fixed point value (voltage_sf).
 
If we use the code composer debugger to display the dcBus value in IQ12 format, the lowest we can get he bus voltage is around 40 volts unless we change GLOBAL_Q to a lower fixed point precision.
 
Note the following prevents the USER_VOLTAGE_SF being less than 0.1 in user.c USER_checkForErrors:
 
  if(USER_VOLTAGE_SF < 0.1)
    {
      USER_setErrorCode(pUserParams, USER_ErrorCode_voltage_sf_Low);
    }
 
So what are we supposed to do in order to get the correct dc voltage scale factor so we can move on to unravel the next problem in getting past the flux error? 
Also how do we get the source code for IQmath.lib. I want to look at the source code for the  IQmpy() function.
  • David,

    Please give me some time to research this issue and come back to you. I will get back to you on Monday.

    Thanks,
    Sira
  • Hi David

    The ADC conversion is captured in an IQ12 variable since the integer portion of the conversion is 12 bits. The multiplication with the scale factor puts the value into a format that can be read as an IQ24 variable. Please read the value as an IQ24 value in the watch window

    The scale factor check is because the estimator uses 1/dcbus in it's calculations. This statement guards against doing an inverse using a very small dc bus which can cause variable overflow

    I'll have to check on the IQmath source library for you, I'm not sure how we handle distributing the library source

    Sean