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.

UCD3138: Questions about the int handle_iout_temp_comp(int iout_adc_count, int temperature) function in UCD3138 full-bridge hard-switch development board firmware

Part Number: UCD3138

Hello,
I was recently learning UCD3138 full-bridge hard switch development board firmware
I met a problem.
Is the int handle_iout_temp_comp(int iout_adc_count, int temperature) function a temperature compensation algorithm? If so, is there an application note describing the algorithm? I do not understand the meaning of the function.What are the meanings of these constants like  R0_23C、ADC_COUNT_23C and FACTOR,and how do they get their values?

int handle_iout_temp_comp(int iout_adc_count, int temperature) 
{
instant_resistance_negative = R0_23C - (temperature - ADC_COUNT_23C) * FACTOR; //multipled by 100000
adc_count_factor_negative = (instant_resistance_negative << 10) / R0_23C;

instant_resistance_positive = R0_23C + (temperature - ADC_COUNT_23C) * FACTOR; //multipled by 100000
adc_count_factor_positive = (instant_resistance_positive << 10) / R0_23C;
// instant_resistance = 2720 + (temperature - 1041) * 1.22; //multipled by 100000

return ((iout_adc_count * adc_count_factor_negative) >>10);
// We can switch to a multi segment linearization later on
}

  • The comment isn’t exactly correct, but it’s a technique for dealing with fractional values in integer math. Apparently if the divide was done without shifting the numerator left, the result would be too small for good representation as an integer. So we effectively multiply the value by 2 to the 10th, which would be 1000000000 in binary.

    Apparently after the multiply at the end, we have a big enough integer, so we take the multiplier back out.

    This a common way to handle this situation. The c compiler does support floating point math, but it takes longer.
  • Got it,Thank you!