Calibrating test current in a closed loop
Why the supply's own reading is not enough
A deliberately simple control law
Where it fits in the test sequence
A snippet from the implementation
Straight from the example as deployed on the Raspberry PLC 19R — copy it freely:
def calibrate(supply, target_a):
"""Trim the setpoint until the shunt current matches the target.
Returns (final_setpoint, measured_current, converged).
"""
setpoint = target_a # first approximation: setpoint = target
supply.set_current(setpoint)
t0 = time.time()
while time.time() - t0 < TIMEOUT_S:
measured = read_shunt_current()
error = target_a - measured
if abs(error) <= TOLERANCE_A:
return setpoint, measured, True # converged
# Fixed 0.1 A correction steps in the direction of the error
setpoint += STEP_A if error > 0 else -STEP_A
setpoint = max(0.0, min(setpoint, 220.0)) # XG limits
supply.set_current(setpoint)
time.sleep(PERIOD_S)
return setpoint, read_shunt_current(), False # timed out without convergingThe full example is a complete program — wiring header, setup and main loop — ready to adapt to your application.
Frequently asked questions
Why not use a PID controller?
Because the plant is almost static. The supply holds its output rock-steady, so a fixed-step corrector with a dead band converges fast and can never overshoot or oscillate, which matters more than speed in a certification bench.
What if the loop never converges?
The 5 s timeout returns a not-converged flag. The bench treats it as an abort condition, typically meaning the sample blew during ramp-up, a connection is open, or the supply hit its compliance limit.
How accurate is the shunt measurement chain?
A class 0.5 60 mOhm shunt read differentially by an ADS1015 at gain 16 resolves better than 0.1 A. A final 1.02 correction factor, obtained against a reference meter, absorbs the residual chain error.