cancel
Showing results for 
Search instead for 
Did you mean: 

STML431 ADC differential mode

user 143
Associate III

Hey guys,

I'm a bit confused in using the ADC in differential mode.

I've got a shunt resistor and want to measure the voltage as exact as possible. One side of the shunt is connected to GND, but with higher currents, this GND is not anymore GND (it's a few mV higher, because of the resistance of the PCB trace). So measuring the voltage only on the top of the shunt is inaccurate. I thought using the ADC in differential mode to compense that.

I connected the top of the shunt to the ADC channel 5, the bottom of the shunt to channel 6 and configured channel 5 in differential mode. Before reading the values, I called the ADC calibration function in differential mode. Now I getting results, but I don't know how to convert this register value into a voltage.

For single-ended ADC configuration I found this formula in the reference manual:

0693W000001skDrQAI.png

Maybe my ADC_DATA values are wrong, but with this formula I get wrong values.

Is there another formula to calculate the voltage in differential mode?

Thanks

6 REPLIES 6
TDK
Guru

That's the right formula. What are you ADC readings and what do you expect the value to be?

Since you're using GND on one side of the shunt, you'll have to make sure that the GND connected to the chip is never higher than the GND connected to the shunt.

If you feel a post has answered your question, please click "Accept as Solution".
user 143
Associate III

Here was crap

For example: My shunt value is 120 mOhm (+/- 1%) and the current is 2 A. My Reference voltage for the ADC is 1,8 V. With the internal reference voltage and the calibrated value from ST, I get exactly 1795 mV for my reference voltage. 0693W000001slslQAA.pngSo, I'm expecting a voltage at the top of the shunt of 240 mV and the register value should be 546. When I'm working with single ended ADC I get a register value of 560 (=246,2 mV, 30 values ​​measured and averaged). So the value is a bit too high. But when I measure at the bottom of the shunt, I get a register value of 12 (=5,3 mV). The values seem to be plausible (I also verify the voltage with a oscilloscope).

But when I configured the ADC in differential mode, the register value is 2323. Thats much higher.

I was looking for a example in the Cube library and found one with the STM32H7 controller. In the source code, they used this formula:

0693W000001slxbQAA.pngWith this formula (6600 replaced with 3590, 0xFFFF replaced with 4095 and 3300 replaced with 1795) I get a voltage value which I expect. But I do not understand this formula...

Yeah, GND of the Chip is never higher then GND of the shunt (different GND planes, just connected with a small bridge), also verified with the osciloscope.

S.Ma
Principal

The purpose of differential pairs or analog signal (digital stretched limit is... analog!) is to cancel common mode noise, and sometime in sensors wheatstone bridge to magnify or cancel temperature dependency to the first order.

If one of the differential is near supply voltage, it may not work. Check the acceptable common mode voltage range and differential max amplitude in the electrical part of the datasheet.

TDK
Guru

> With this formula (6600 replaced with 3590, 0xFFFF replaced with 4095 and 3300 replaced with 1795) I get a voltage value which I expect. But I do not understand this formula...

If your inputs were the same (no voltage differential), the converted value would be 4095/2. Maybe rewriting it as follows would make more sense conceptually:

swInputVoltage = (uwConvertedValue / 4095 - 0.5) * (2 * VREF+)

The reference manual does say the input should be biased to VREF+/2, but not sure how much this will affect results. Seems to be relatively okay in your example.

When ADC is configured as differential mode, both inputs should be biased at (VREF+) / 2 voltage.

If you feel a post has answered your question, please click "Accept as Solution".
user 143
Associate III

"Check the acceptable common mode voltage range and differential max amplitude in the electrical part of the datasheet."

The common mode voltage should be between (Vref+ - Vref-)/2 - 0,18 and (Vref+ - Vref-)/2 + 0,18. So in my case between 0,72V and 1,08V. But there is no special liimit for the max. amplitude in differential mode. Or I could not find it.

"If your inputs were the same (no voltage differential), the converted value would be 4095/2."

Exact. Now I understand the formula too. Thank you.

At the moment i just connected both shunt pints directly with the two ADC Pins, without any biasing. With the ADC in differential mode I get the best results. Maybe it could get better when they would be biased, but I'm not sure how to do it.