Voltecx is in beta. The macOS build comes first; Windows and Linux packages are still being tested.Beta. macOS comes first; Windows and Linux are still in testing. What's new

A controller can only regulate what it measures. If the current sensor reads 3 % high, the converter delivers 3 % less current than you asked for, and no amount of loop tuning will notice. If the sensor is slow, the loop sees an old copy of the current and loses phase margin. If the sensor's output does not fit the ADC, the reading clips at the worst possible moment: during a fault.

This post goes through the sensors a power converter actually uses and how to size each one:

  • a resistive divider for voltages, with its anti-alias capacitor;
  • a shunt resistor with a current-sense amplifier;
  • a Hall-effect sensor;
  • an isolated amplifier across an isolation barrier;
  • and the last step every one of them shares: scaling the signal into the ADC range with headroom.

Every number comes from a Voltecx run with sensor models whose values cite their data sheets.

The intuition: every sensor takes something

A perfect sensor would read the true value instantly and change nothing in the circuit. Real sensors all pay for their reading somewhere:

Sensor What it costs What it gives
Divider Current from the measured node, resistor tolerance Cheap, simple, accurate DC
Shunt + amplifier Power I2RI^2 R and a voltage drop Accurate, fast, cheap
Hall sensor Offset, noise, limited bandwidth Built-in isolation, almost no loss
Isolated amplifier A delay of microseconds, a price Accurate reading across a barrier

Choosing a sensor is choosing which of these costs your design can afford. Keep that table in mind; the rest of the post puts numbers on each line.

The signal chain

Whatever the sensor, the path to the controller has the same four parts:

  1. The sensor turns the current or voltage into a small voltage.
  2. The scaling (a gain or a divider) maps the range you care about onto the ADC's input range.
  3. The filter removes what the ADC must not see (switching noise that would alias) at the price of some phase lag.
  4. The ADC samples and rounds it (see the ADC sampling post).

Each stage adds an error and a delay. The design job is to keep the sum inside the regulation band and the phase budget.

Voltage: the divider

A divider of R1R_1 (top) and R2R_2 (bottom) scales the voltage by

k=R2R1+R2k = \frac{R_2}{R_1 + R_2}

It looks trivial, but four numbers decide it.

1. The highest voltage it must read. Not the nominal output: the output at the top of its tolerance, plus start-up overshoot, plus half the ripple. The ratio kk must keep that highest value inside the ADC's full scale, even with the resistors at the worst of their tolerance and temperature drift.

2. The source resistance the ADC accepts. A SAR ADC charges a small sampling capacitor through whatever drives its pin, during a short sampling time. If the source resistance R1∥R2R_1 \parallel R_2 is too high, the capacitor does not finish charging and the reading is low. The microcontroller data sheet gives the limit: for the STM32G474 at 12 bits and a sampling time of 12.5 ADC clocks at 42.5 MHz (294 ns) on a slow channel, ST's DS12288 (Rev 4, Table 67) allows 470 Ω.

3. The power the divider burns. A low source resistance means a low R1R_1, and R1R_1 carries the whole voltage.

4. The error. With a large attenuation, k≈R2/R1k \approx R_2/R_1, so the errors of both resistors add almost in full.

Worked example: a 48 V boost output into a 3.3 V ADC

Take a boost from 12 V to 48 V at 100 kHz, output tolerance ±2 %, 0.5 V of ripple. design.senseNetwork sizes the network into an STM32G474 input:

  • Highest signal: 48×1.02×1.10+0.25=54.148 \times 1.02 \times 1.10 + 0.25 = 54.1 V (10 % start-up overshoot by default).
  • Divider: R1=8.06R_1 = 8.06 kΩ over R2=499R_2 = 499 Ω, both Vishay CRCW E96 values (±1 %, ±100 ppm/K, document 20035). k=0.0583k = 0.0583, so the ADC's full-scale code corresponds to 56.6 V.
  • Source resistance: 8.06 k∥499=4708.06\text{ k} \parallel 499 = 470 Ω, right at the limit.
  • Power: at 54.1 V, R1R_1 takes 0.32 W, which needs a 1210 chip. That is the price of the 470 Ω limit.
  • Error: the ratio alone can be off by 3.15 % at the worst of tolerance and drift; with the ADC's own error the worst case is 3.35 % of full scale.

Two lessons hide in those numbers. First, a 1 % resistor does not give a 1 % divider when the divider attenuates 17 times: both resistors' errors add. For a tight output tolerance use 0.1 % resistors, or calibrate. Second, the 0.32 W is not inevitable: a longer sampling time or a fast channel raises the allowed source resistance (the same table allows 1.8 kΩ at 47.5 cycles), and a buffer amplifier removes the limit altogether.

The anti-alias capacitor

A capacitor from the ADC pin to ground does two jobs. It is a charge reservoir: the sampling capacitor takes its charge from it, not through the resistors. And with R1∥R2R_1 \parallel R_2 it forms a low-pass filter with a pole at

fp=12π (R1∥R2) Cf_p = \frac{1}{2\pi\,(R_1 \parallel R_2)\, C}

Here C=15C = 15 nF puts the pole at 22.6 kHz. The loop's crossover is 10 kHz, so the filter costs arctan⁡(10/22.6)=23.9°\arctan(10/22.6) = 23.9° of phase margin, which must be added to the loop budget.

The boost output in Voltecx scaled by the divider ratio, v(out) × k, and the voltage at the ADC pin, v(adc), behind the 15 nF capacitor: the 29.4 mV sawtooth becomes 4.98 mV.

In the simulation, the 0.505 V output ripple becomes 29.4 mV after the divider and 4.98 mV at the pin: about 6 LSB of a 12-bit, 3.3 V ADC, rounded off and delayed. The average at the pin is exactly kk times the output.

Current: the shunt

A shunt is a small resistor in the current path. Ohm's law does the measuring, V=IRV = I R, and Joule's law sends the bill, P=I2RP = I^2 R.

The choice of RR is a pure trade-off:

  • A larger shunt gives more signal, so offset and noise matter less and one ADC code is a smaller current.
  • A smaller shunt wastes less power and drops less voltage.

The amplifier sits between the two. In the examples below it is the INA240A2 (Texas Instruments, SBOS662C): a gain of 50 V/V, 400 kHz of bandwidth, ±5 µV typical offset, an input common-mode range of −4 V to 80 V, with its reference pins at ground for a unidirectional output.

Worked example: the 5 A buck

Put the shunt and the amplifier in series with the inductor of the 12 V to 3.3 V, 5 A, 200 kHz buck. The inductor current is 4.96 A RMS in the simulation. We want to read up to 10 A (twice the rated current, for the current limit) inside a 3.3 V ADC.

The shunt choice against its value: the loss I²R at the simulated 4.96 A RMS, the amplifier output at 10 A with a gain of 50 (the line marks 3.3 V), and the current of one 12-bit LSB of 3.3 V. The vertical line marks 5 mΩ.

Read the three panels from top to bottom:

  • Loss grows linearly with RR.
  • Signal at 10 A is 50×R×1050 \times R \times 10 A. It must stay below 3.3 V, so R≤6.6R \le 6.6 mΩ.
  • Resolution: one LSB of a 12-bit ADC over 3.3 V is 0.806 mV, so one code is 0.806 mV/(50R)0.806\ \text{mV} / (50 R) of current.

A 5 mΩ shunt gives 0.25 V/A: 2.5 V at 10 A, which leaves 0.8 V of headroom; 3.22 mA per code; and 0.123 W of loss at 4.96 A RMS (0.5 W at 10 A). That loss is about 0.75 % of the 16.5 W output: small, but not free, which is why high-current converters go down to fractions of a milliohm and higher gains.

Kelvin connection

At 5 mΩ, the copper of the board is part of the measurement. Half a milliohm of trace between the shunt and the amplifier's input pins is a 10 % error. The fix is a Kelvin (four-wire) connection: the current flows through the outer pads, and two separate thin traces take the voltage from the inner points of the shunt to the amplifier, routed together as a pair, carrying no current. Many shunts have four terminals for exactly this.

High side or low side?

  • Low side (between the load and ground): the amplifier sees almost 0 V of common mode, so any amplifier works. But the load is no longer at ground, and a short from the load to ground bypasses the shunt and is never seen.
  • High side (between the supply and the load, or in series with an inductor whose node switches): the amplifier must reject a large and possibly fast-moving common-mode voltage. That is what parts like the INA240 are made for, with its −4 V to 80 V input range and its enhanced PWM rejection.
  • In the switch leg of a bridge: the shunt sees the current only while that switch conducts, which is fine if you sample in that window.

How fast is the shunt amplifier?

The INA240A2 is a single pole at 400 kHz in Voltecx, so a 10 A step reaches half its final value after ln⁡2/(2π×400 kHz)=0.28\ln 2 / (2\pi \times 400\,\text{kHz}) = 0.28 µs (the simulation agrees). Against the buck's 200 kHz triangle it is not perfect either:

Three switching periods of the buck in Voltecx: the inductor current i(L1) and what the INA240A2 and the ACS712-05B report, converted back to amperes.

The true ripple is 1.46 A peak to peak; the INA240A2 reports 1.12 A of it, slightly rounded and shifted right. Both sensors report the right average, 4.95 A. Two consequences:

  • For average-current control sampled in the middle of the on-time, the sensor's delay shifts the waveform. Move the ADC trigger later by about the sensor's delay, or the sample is no longer at the midpoint.
  • For peak-current protection, a slow sensor reads the peak low and late. Trip on a fast comparator path, or lower the threshold to allow for it.

Current: the Hall sensor

A Hall sensor measures the magnetic field of the current, so the primary conductor has no electrical connection to the output: isolation comes free, and the loss is only that of the conductor. The ACS712ELC-05B (Allegro MicroSystems, ACS712-DS Rev. 22) has a primary resistance of 1.2 mΩ, a sensitivity of 185 mV/A around a zero-current output of 2.5 V on a 5 V supply, and 80 kHz of bandwidth.

The costs are in the other columns of the table:

  • Bandwidth. 80 kHz is well below the 200 kHz switching frequency. In the figure above the ACS712 reports only 0.43 A of the 1.46 A ripple, a smooth wave delayed by about a fifth of a period. For a loop crossing at a few kHz that is fine; for cycle-by-cycle current limiting it is not.
  • Offset and noise. The zero-current level and the sensitivity are ratiometric to the supply (they follow VCC), so a noisy 5 V supply becomes a noisy reading, and the data sheet gives 21 mV peak to peak of noise (with its filter capacitor set for 2 kHz of bandwidth) at 185 mV/A: about 0.11 A. Calibrate the zero at start-up with no current flowing.
  • The 5 V output. The output is centred at 2.5 V for a bidirectional range. On a 3.3 V ADC, that is the next problem.

Isolated amplifiers across a barrier

When the shunt sits on a high-voltage node (the phase current of a 400 V inverter, a PFC's DC bus) the controller must be isolated from it. An isolated amplifier measures the small shunt voltage on the hot side and sends it across a reinforced barrier.

The AMC1302 (Texas Instruments, SBAS812D) takes a linear input of ±50 mV with a gain of 41, has 280 kHz of output bandwidth, and outputs a differential voltage around a 1.44 V common mode. In the bench below its shunt is 4 mΩ, so 10 A is 40 mV, inside the ±50 mV range.

Its cost is delay: the data sheet gives a signal delay of 1.6 µs (50 % to 50 %), because the signal is modulated, sent across the barrier and demodulated.

A 9.9 A current step down in Voltecx and what three sensors report, in amperes: the INA240A2 crosses half way after 0.28 µs, the ACS712-05B after 1.39 µs and the AMC1302 after 1.61 µs, its data-sheet delay.

The three sensors in series carry the same 9.9 A current, which drops to zero at once:

Sensor Model in Voltecx 50 % time Before the step
INA240A2 400 kHz pole 0.28 µs 9.9 A
ACS712-05B 80 kHz pole 1.39 µs 9.9 A
AMC1302 1.21 µs delay + 280 kHz pole 1.61 µs 9.9 A

The AMC1302 is accurate (all three read the steady current within 0.1 %) but late. For a current loop at 100 kHz sampling, 1.6 µs is 16 % of a period, so move the ADC trigger by that much; for overcurrent protection, use the hot-side comparator or a desaturation detector, which do not wait for the barrier.

Read the output as the difference of its two pins. Each pin sits near 1.44 V, so a single-ended reading of one pin is off by that much.

Scaling into the ADC range, with headroom

The last step is the same for every sensor: map the range you must read onto the ADC's input range, with some room left at the top.

The output voltage against the current in Voltecx for the INA240A2 on 5 mΩ, the ACS712-05B, and the ACS712-05B through a 10 kΩ over 20 kΩ divider. The horizontal lines mark the 0 to 3.3 V range of the ADC.

The figure ramps a test current from 0 to 12 A through the sensors:

  • INA240A2 on 5 mΩ: 0 V at 0 A, 3.0 V at 12 A. The whole range fits with 0.3 V to spare. Note that with the reference pins at ground it reads only positive current; a bidirectional reading needs the reference at mid-supply and half the span each way.
  • ACS712-05B straight into the ADC: 2.5 V at 0 A, and it leaves the 3.3 V range at (3.3−2.5)/0.185=4.32(3.3 - 2.5)/0.185 = 4.32 A. Above that the ADC clips: a current limit set at 6 A would never trip. At 12 A the sensor outputs 4.72 V, well beyond what the ADC can convert; check the microcontroller data sheet for what the pin itself may take.
  • ACS712-05B through a 2/3 divider (10 kΩ over 20 kΩ): 1.67 V at 0 A and 3.14 V at 12 A. It fits, at the cost of a third of the resolution.

The headroom is not wasted range. It is what lets the controller see an overcurrent instead of a flat line, absorbs gain error and offset, and keeps the pin within its rating. A useful rule is to put the largest current you must read (the current-limit trip, not the rated current) at about 80 to 90 % of full scale.

A checklist

  1. Write down the highest signal: tolerance, overshoot, ripple, and the fault current you must still read.
  2. Pick the sensor by what it costs you: loss (shunt), bandwidth and offset (Hall), delay (isolated amplifier).
  3. Scale it to about 80 to 90 % of the ADC's full scale at that highest signal, at the worst of the tolerances.
  4. Check the source resistance against the ADC data sheet, and the power in every resistor.
  5. Place the filter pole between the crossover and half the sampling rate, and add its lag to the loop budget.
  6. Route the shunt with a Kelvin connection, and move the ADC trigger by the sensor's delay.

Try it in Voltecx

  • ic.place puts the sensor ICs in the circuit as modules with named pins: shuntAmplifier (INA240A1 defaults), hallCurrentSensor (ACS712ELC-05B), isolatedAmplifierAmc1302 (AMC1302), isolatedAmplifier (AMC1301), isolatedVoltageSensor (AMC1311 with a divider) and closedLoopHall (LEM LA 55-P). Each parameter cites the data-sheet section it comes from, and rSense is your own shunt.
  • design.senseNetwork sizes the divider and the anti-alias capacitor in front of an STM32G474 ADC input from the spec, with the error budget, the resistor power and the phase lag at the crossover. It changes nothing in the circuit; bom.export can turn its parts into BOM lines.
  • circuit.problems with a run reports a sensor whose output saturated (sensor.saturated), the failure the scaling figure warns about.
  • The ADC sampling post continues from the ADC pin: when to sample, aliasing and the cost of delay.