cancel
Showing results for 
Search instead for 
Did you mean: 

Enabling ADC Offset

Hazardy
Associate

Hi,

I'm trying to apply an Offset on the ADC, I'm using a H743. I'm pretty sure I have the ADC working correctly, because measuring temperatures (MCU internal and one external) as well as measuring some voltages on my board result in plausible values.

Now I have to read some currents, but I there is an offset of about -0.2A when the line is in idle. I have:

  • Calibrated the ADC.
  • Set the ADC to 12 bit.
  • Left shift the result by 4 bit, back to an uint16.
  • Wait until the reading is stable, this means that only the two LSB change for 100 ms.

Then I get the value from the JDR1 (I'm using injected conversions) and subtract 2^15-1 from that, since the expected value would be 1.25V and VDDA is 2.5V. I set the difference (which is negative) as the offset and apply that to the channel. But then my reading is too high. I've experimented a bit, and for now I right shift the difference by 2 bit and now I get a better reading, so that I at least can continue to work.

Has anyone a hint what I'm doing wrong?

Here my offset calculation (through a self made wrapper around the registers):

    const auto rawValue = adc.injectedData1();

    AdcOffset offset;
    offset.Channel  = Channel::Adc1::MotorPhaseA;
    offset.Offset   = rawValue - onePointTwoFiveInRaw;
    offset.Offset >>= 2;
    offset.Offset  &= ~0b1111;
    adc.setOffset(offset, /*number=*/0);
0 REPLIES 0