Near Field Notes

Note 45SensingRev 1Watch the video · 3:07

Current sense errors

How far off can a motor driver’s current reading be with every part in spec?

By the datasheets, moteus-c1’s current sensor can read 2.0 A with the motor stopped, and a true 10 A can read anywhere from 8 to 12 A. Zeroing at startup, which moteus’s firmware does every time the driver turns on, narrows that to 9.5 to 10.5 A. A one-point gain calibration takes it to 9.7 to 10.3 A. What’s left is the amp’s drift as the board warms.

The amp is allowed 4 mV of offset. Across a 2 mΩ shunt, that reads as 2 A.

Below is every error in the chain, two ways to add them up, and what each calibration takes out.

A true 10 A

What the driver can read

78910111213What the driver reads, ANo calibration8 to 12 ANo calibration8 to 12 AStartup zero9.5 to 10.5 ANo calibration8 to 12 AStartup zero9.5 to 10.5 AFactory calibration9.7 to 10.3 A78910111213What the driver reads, ANo calibration8 to 12 ANo calibration8 to 12 AStartup zero9.5 to 10.5 ANo calibration8 to 12 AStartup zero9.5 to 10.5 AFactory calibration9.7 to 10.3 A78910111213What the driver reads, ANo calibration8 to 12 ANo calibration8 to 12 AStartup zero9.5 to 10.5 ANo calibration8 to 12 AStartup zero9.5 to 10.5 AFactory calibration9.7 to 10.3 A
Worked from the datasheet limits of moteus-c1’s parts, added by root sum square, with the board 50 °C warmer than at its zero. The dashed line is the true current.
The numbers
StateA true 10 A reads asError either way
No calibration8 to 12 A2.05 A
Startup zero9.5 to 10.5 A0.46 A
Factory calibration9.7 to 10.3 A0.26 A

One phase, four parts

moteus-c1, phase A

moteus-c1 is a 38 mm square motor controller from mjbots. Its schematics and firmware are open, so its current sensor can be followed part by part.

It senses low side. Each phase’s current returns to ground through a 2 mΩ shunt under the bottom FET. An amp inside the DRV8323 gate driver multiplies the shunt’s few millivolts by 20.

The amp’s output passes a 22 Ω resistor and a 1 nF capacitor on its way to the microcontroller’s 12-bit ADC. One 3.3 V rail is the reference for both the amp and the ADC.

The sense chain of one phase
Fig. 45aBottom FETR62 mΩAmp, ×2022 Ω1 nFADC12 bits3.3 V railFig. 45aBottom FETR62 mΩAmp, ×2022 Ω1 nFADC12 bits3.3 V railFig. 45aBottom FETR62 mΩAmp, ×2022 Ω1 nFADC12 bits3.3 V rail

Phase A of three. R6 is a Stackpole CSSH0805, the amp is one of three inside the DRV8323, the ADC is the STM32G474’s, and the rail comes from a TLV702 regulator.

The firmware turns ADC counts into amps with one fixed number, built from the nominal value of every part:

k=Vref4096 · Rs · G

=3.3 V4096 × 2 mΩ × 20=20.1 mA

A real board’s parts are never exactly nominal. Every error below is one part sitting somewhere else inside its datasheet limits. Note 19 covers where a drive’s shunt can sit, and Note 5 covers the error from where the sense traces tap it.

An offset adds the same amps to every reading

4 mV on 2 mΩ

The DRV8323’s datasheet lets its amp’s input sit up to 4 mV off. The amp can’t tell that from current in the shunt:

Ios=VosRs

=4 mV2 mΩ=2.0 A

The ADC adds an offset of its own, up to 4 counts. At 20.1 mA a count that is 0.08 A. Its nonlinearity is worth up to 0.07 A more.

Added by root sum square, a stopped motor can read 2.02 A. Nearly all of it is the amp.

Each offset, as amps
Fig. 45bReads as, with no current flowingAmp offset, 4 mV2.00 AAmp drift over 50 °C0.25 AADC offset, 4 counts0.08 AADC nonlinearity, 3.4 counts0.07 ARoot sum square2.02 AFig. 45bReads as, with no current flowingAmp offset, 4 mV2.00 AAmp drift over 50 °C0.25 AADC offset, 4 counts0.08 AADC nonlinearity, 3.4 counts0.07 ARoot sum square2.02 AFig. 45bReads as, with no current flowingAmp offset, 4 mV2.00 AAmp drift over 50 °C0.25 AADC offset, 4 counts0.08 AADC nonlinearity, 3.4 counts0.07 ARoot sum square2.02 A

Each bar is one datasheet limit on a 2 mΩ shunt at a gain of 20. The drift is TI’s typical figure over a 50 °C rise.

The numbers
OffsetReads as
Amp offset, 4 mV2.00 A
Amp drift over 50 °C0.25 A
ADC offset, 4 counts0.08 A
ADC nonlinearity, 3.4 counts0.07 A
Root sum square2.02 A

A gain error is a share of the reading

Three parts and a rail

A gain error tilts the whole line. It adds nothing at zero current and the most at full current.

The shunt is a 1% part. The amp’s gain of 20 can be anywhere from 19.4 to 20.6, which is 3%.

The 3.3 V rail is in the measurement too. The ADC counts against it, and the firmware assumes it is exactly 3.3 V. The TLV702 regulator that makes it is a 2% part.

So the 1% shunt is the smallest of the three. The ADC’s own gain error is 0.16%.

Each gain error, and two totals
Fig. 45cShare of the readingAmp gain, 19.4 to 20.63%3.3 V rail2%Shunt1%ADC gain, 6.6 counts0.16%Straight sum6.2%Root sum square3.7%Fig. 45cShare of the readingAmp gain, 19.4 to 20.63%3.3 V rail2%Shunt1%ADC gain, 6.6 counts0.16%Straight sum6.2%Root sum square3.7%Fig. 45cShare of the readingAmp gain, 19.4 to 20.63%3.3 V rail2%Shunt1%ADC gain, 6.6 counts0.16%Straight sum6.2%Root sum square3.7%

Each filled bar is one datasheet limit. The two open bars are the same four limits added two ways.

The numbers
Gain errorShare of the reading
Amp gain, 19.4 to 20.63.00%
3.3 V rail2.00%
Shunt1.00%
ADC gain, 6.6 counts0.16%
Straight sum6.16%
Root sum square3.745%

Resistance in front of the ADC matters as well. The ADC’s sample capacitor, about 5 pF, charges through whatever sits in front of its pin, and it only has the sample time to do it.

ST publishes the most resistance the source may have. For 12 bits on a fast channel at the shortest sample time, it is 100 Ω. moteus-c1 has 22 Ω in front of each current pin, with 1 nF at the pin. Which channel type and sample time the board uses isn’t confirmed here, so the 100 Ω is ST’s limit and not a verdict on this board.

Worst case, or root sum square

100,000 boards

Stack the four gain limits end to end and the total is 6.2%. That is the worst case: every part at its limit, all leaning the same way.

3% + 2% + 1% + 0.16%=6.16%

These four errors are independent, so they rarely all lean the same way. Root sum square adds them at right angles, the way the sides of a triangle add:

3² + 2² + 1² + 0.16²%=3.745%

To see which total holds, I simulated 100,000 boards, each with every part drawn from somewhere inside its limit.

If each datasheet limit is 3 sigma of a bell curve, 99.74% of the boards land inside the root sum square.

If parts are spread evenly across their tolerance, 91.96% do. About 8 boards in 100 land outside, and the worst channel in the run was 6.2% off.

Root sum square is where most boards land, and the straight sum is the edge. A trip limit should use the edge.

Root sum square only works for independent errors. Two errors that share a cause add in a straight line.

The gain error of 100,000 boards
Fig. 45dBoards in each 0.1% stepLimits at 3 sigma of a bell curve99.74% inside the root sum square1,5003,0000Spread evenly inside the limits91.96% inside the root sum square1,5003,0000−6.2%−3.7%03.7%6.2%Gain error of one phaseFig. 45dBoards in each 0.1% stepLimits at 3 sigma of a bell curve99.74% inside the root sum square1,5003,0000Spread evenly inside the limits91.96% inside the root sum square1,5003,0000−6.2%−3.7%03.7%6.2%Gain error of one phaseFig. 45dBoards in each 0.1% stepLimits at 3 sigma of a bell curve99.74% inside the root sum square1,5003,0000Spread evenly inside the limits91.96% inside the root sum square1,5003,0000−6.2%−3.7%03.7%6.2%Gain error of one phase

One phase from each simulated board. The solid lines mark the root sum square, 3.7%, and the dashed lines the straight sum, 6.2%.

The numbers
How parts are spreadInside the root sum squareLargest of all three phases
Limits at 3 sigma of a bell curve99.74%5.9%
Spread evenly inside the limits91.96%6.2%

Two calibrations

A zero, then a gain

An offset hurts most at low current. With no calibration, a true 1 A can read anywhere from −1 to 3 A.

So zero it. With the motor off, moteus’s firmware averages 256 samples per phase and calls the result zero, every time the driver turns on. A board whose amp sits at its 4 mV limit zeros at 2,147 counts instead of 2,048. Those 99 counts are the whole 2 A.

With the offset gone, the gain error is the big one, and it grows with current. A true 10 A reads 9.5 to 10.5 A.

The second calibration is done once, at the factory. Run a known current through each phase and store the ratio. The first board in my run read 10.09 A at a true 10 A, so it stores 0.991. That one number absorbs the shunt, the amp and the rail, and 10 A now reads 9.7 to 10.3 A.

The error left in each state
Fig. 45eError either way, A0.511.52005101520 ATrue currentNo calibrationStartup zeroFactory calibrationFig. 45eError either way, A0.511.52005101520 ATrue currentNo calibrationStartup zeroFactory calibrationFig. 45eError either way, A0.511.52005101520 ATrue currentNo calibrationStartup zeroFactory calibration

Root sum square of the limits left in each state, with the board 50 °C warmer than at its zero. The factory calibration is one point at 10 A against an exact reference.

The numbers
StateAdded up by0 A1 A5 A10 A20 A
No calibrationRoot sum square2.02 A2.02 A2.03 A2.05 A2.15 A
No calibrationStraight sum2.40 A2.46 A2.73 A3.05 A3.71 A
Startup zeroRoot sum square0.26 A0.26 A0.32 A0.46 A0.80 A
Startup zeroStraight sum0.32 A0.38 A0.65 A0.97 A1.63 A
Factory calibrationRoot sum square0.26 A0.26 A0.26 A0.26 A0.27 A
Factory calibrationStraight sum0.32 A0.32 A0.34 A0.36 A0.39 A

After the zero, what the zero leaves behind and the gain error are equal at 6.9 A. Below that current the leftover offset sets the accuracy. Above it the gain does.

What calibration can’t fix

Drift

A zero is only good at the temperature it was taken at. TI gives the DRV8323’s amp a typical offset drift of 10 µV per °C. On a 2 mΩ shunt that is

10 µV per °C2 mΩ=5 mA per °C

If the board warms 50 °C after its zero, the offset can move 0.25 A, and a zero taken at startup can’t see it. That is nearly all of the 0.26 A left at the bottom of Fig. 45e.

A zero-drift amp like the INA240 is held to 0.25 µV per °C, 40 times less. On the same shunt that is 0.125 mA per °C.

What the motor feels

10 A of torque current at 171 rpm

A current loop trusts its readings. I simulated a closed loop holding 10 A of torque current, then put each kind of error into what it reads.

An offset on one phase makes the torque ripple once per electrical turn. With 0.25 A of offset, the ripple is 3.2% peak to peak.

A gain mismatch between phases ripples twice per turn. With one phase reading 1% high, it is 0.6% peak to peak, and the torque is 0.33% low.

If all three phases read 3.75% high, there is no ripple. The torque is just 3.6% low.

Torque over one electrical turn
Fig. 45fTorque, share of what was asked for0.25 A offset on one phase3.2% peak to peak, once a turn100%95%+1% gain on one phase0.6% peak to peak, twice a turn100%95%+3.75% gain on all threeNo ripple, 3.6% low100%95%00.51Electrical turnsFig. 45fTorque, share of what was asked for0.25 A offset on one phase3.2% peak to peak, once a turn100%95%+1% gain on one phase0.6% peak to peak, twice a turn100%95%+3.75% gain on all threeNo ripple, 3.6% low100%95%00.51Electrical turnsFig. 45fTorque, share of what was asked for0.25 A offset on one phase3.2% peak to peak, once a turn100%95%+1% gain on one phase0.6% peak to peak, twice a turn100%95%+3.75% gain on all threeNo ripple, 3.6% low100%95%00.51Electrical turns

Simulated at 171 rpm with the current loop at moteus’s 100 Hz default. The dashed line is the torque asked for. The offset’s ripple is 3.3% at 43 rpm and 2.1% at 857 rpm.

The numbers
Error in the readingsPeak to peakOnce a turnTwice a turnMean torque
0.25 A offset on one phase3.23%1.61%0.00%−0.00%
+1% gain on one phase0.60%0.00%0.30%−0.33%
+3.75% gain on all three0.00%0.00%0.00%−3.61%

Which error to chase

A key

Key to a current sense error

What is wrong with the reading?

  1. 1aIt reads current with the motor stoppedOffset. Zero at startup
  2. 1bIt is right at a standstillGo to 2
  3. 2aIt moves as the board warmsAmp drift. A zero-drift amp
  4. 2bIt is off by the same share at any temperatureGain. Calibrate once at a known current

moteus’s firmware does 1a every time the driver turns on.

Conditions

Board
One phase of mjbots moteus-c1, read from its KiCad files and firmware: a 2 mΩ shunt (Stackpole CSSH0805FT2L00), the DRV8323S’s built-in amp at a gain of 20, 22 Ω and 1 nF at the pin, the STM32G474’s 12-bit ADC, and one 3.3 V rail from a TLV70233 for the amp’s reference and the ADC’s
Limits
Datasheet maximums: shunt ±1% and ±75 ppm per °C, amp gain 19.4 to 20.6, amp input offset ±4 mV, rail ±2%, ADC offset 4 counts, gain 6.6 counts and nonlinearity 3.4 counts. The amp’s offset drift of 10 µV per °C is TI’s typical figure. TI gives no maximum, so it is used here as a limit
Our picks
The board is 50 °C warmer at the reading than at its zero. The factory calibration is one point at 10 A against an exact reference
Adding
Root sum square of the limits left in each state, unless a figure says straight sum
Boards
100,000 boards of three phases, every part drawn from inside its limit, through the chain and the firmware’s own zero of 256 averaged samples. Run twice: each limit as 3 sigma of a bell curve, and parts spread evenly across their tolerance. ADC noise is 0.76 counts rms, from ST’s 10.6 effective bits
Motor
A closed current loop holding 10 A of torque current with moteus’s PI rule at its 100 Hz default. The motor’s 50 mΩ, 30 µH and 7 pole pairs are our picks. Its Kv of 330 is mjbots’ figure for the mj5208
Video
The video’s board is built from mjbots’ KiCad board file: the outline, every copper shape on both faces, every pad, the silkscreen text, and each part’s place, turn and side. The package bodies, connectors, colors, silkscreen typeface, solder and phase wires are stand-ins matched by eye to mjbots’ product photos. The motor is a stand-in the size of the mj5208, 63 mm across and 25 mm tall, with 12 coils, a six-spoke bell and no markings. The lit path in the shunt close-up follows phase A’s copper from the motor pad through the low-side FET and R6 to ground, 13.7 mm. The turning motor is slowed: two electrical turns at 171 rpm take 0.1 s, and the video shows them in 4 s. Nothing in it is a photograph or a clip of a real board

These are datasheet limits and model runs. Nothing on this page has been measured on a board.

Limits

  • Whether the DRV8323’s ±4 mV is before or after the chip’s own offset trim isn’t confirmed. moteus’s firmware runs that trim at every enable too.
  • The amp’s offset drift is a typical figure with no maximum, so the quarter amp over 50 °C isn’t a guaranteed limit either way.
  • Whether moteus-c1’s current pins are fast or slow ADC channels, and its ADC clock, aren’t confirmed.
  • Factory gain calibration is shown as a general step. moteus’s firmware has no per-board gain value.
  • The motor in the torque run is our pick, and its trace is at 171 rpm. The ripple shrinks above the current loop’s bandwidth.
  • Using the straight sum for a trip limit is our advice, not a quoted rule.
  • The ripple at once and twice per electrical turn is our run. Chung and Sul’s 1998 paper reports the same, and was read as an abstract only.

Files

  • sim/boards.py100,000 boards through the chain and the firmware’s zero
  • sim/foc.pyThe current loop, with errors put into its readings

Sources

Like this note?

Rev 1 ·
  1. Rev 1First published

Each fix gets a line here, with the reader's name if they want credit.

Did it answer your question?

Want more on this?

Report a problem

What should the next note be? Ask for one