SPRUHJ1I January 2013 – October 2021 TMS320F2802-Q1 , TMS320F28026-Q1 , TMS320F28026F , TMS320F28027-Q1 , TMS320F28027F , TMS320F28027F-Q1 , TMS320F28052-Q1 , TMS320F28052F , TMS320F28052F-Q1 , TMS320F28052M , TMS320F28052M-Q1 , TMS320F28054-Q1 , TMS320F28054F , TMS320F28054F-Q1 , TMS320F28054M , TMS320F28054M-Q1 , TMS320F2806-Q1 , TMS320F28062-Q1 , TMS320F28062F , TMS320F28062F-Q1 , TMS320F28068F , TMS320F28068M , TMS320F28069-Q1 , TMS320F28069F , TMS320F28069F-Q1 , TMS320F28069M , TMS320F28069M-Q1
In this hardware configuration, the negative pin of the shunt resistor, which is connected to ground, is also connected to the inverting pin of the operational amplifier. Figure 6-5 shows a positive polarity in hardware and its configuration in software. The highlighted sign is required to be configured in order to have correct polarity for the current feedback in software. The code is shown, a variable "current_sf" is negative in HAL_readAdcData( ) for inverting operation. For positive feedback, the current offsets are negative in user.h to correct the polarity mismatch. The lines of code shown illustrate offset negation done in user.h. Functions HAL_readAdcData( ) is located in hal.h file. No change is needed in these functions.
static inline void HAL_readAdcData(HAL_Handle handle,HAL_AdcData_t *pAdcData)
{
HAL_Obj *obj = (HAL_Obj *)handle;
_iq value;
_iq current_sf = -HAL_getCurrentScaleFactor(handle);
_iq voltage_sf = HAL_getVoltageScaleFactor(handle);
// convert current A
// sample the first sample twice due to errata sprz342f, ignore the first sample
value = (_iq)ADC_readResult(obj->adcHandle,ADC_ResultNumber_1);
value = _IQ12mpy(value,current_sf) - obj->adcBias.I.value[0]; // divide by 2^numAdcBits = 2^12
pAdcData->I.value[0] = value;
// convert current B
value = (_iq)ADC_readResult(obj->adcHandle,ADC_ResultNumber_2);
value = _IQ12mpy(value,current_sf) - obj->adcBias.I.value[1]; // divide by 2^numAdcBits = 2^12
pAdcData->I.value[1] = value;
#define I_A_offset (-0.8641905189)
#define I_B_offset (-0.8677659631)
#define I_C_offset (-0.8685645461)