Testing Firmware Against Battery State-Of-Charge

Testing the firmware against a battery’s State-Of-Charge (SoC) is crucial for ensuring that battery powered devices work properly throughout the charge and discharge cycle. For many teams testing against different battery SoC can be tedious, requiring constant swapping in and out of batteries, to make sure each test is being run against the right SoC.

Here’s how Lager greatly simplifies testing the firmware throughout the battery curve.

Step 1:

Share the specified battery’s part number and ordering info

Step 2:

Lager creates a battery model by hooking the physical battery up to a Keithley 2281S precision battery simulator.

Step 3:

Using the battery model created in Step 2, the battery simulator is connected to the physical Device-Under-Test (DUT).

Step 4:

The user can now define various battery parameters (e.g. SoC) using Lager’s API

Here’s an example of setting up the battery test conditions for a CR2032 coin cell using Lager’s API:

{% c-block language="python" %}
from lager import DUT, Net, NetType
from lager.pcb.net
import SimMode
import time

def setup_vbat(net, device):

def teardown_vbat(net, device):

print("Create coin cell")
coin = Net.get('COIN',

print("initialize coin cell")

print("enable coin cell")

print("put DUT into reset halt state")
dut = DUT()

print("measure coin cell voltage")
vbat_net = Net.get('VBAT',
v_avg = vbat_net.measurement.voltage_average() #Average voltage in Volts
print(f"Battery Voltage: {v_avg}")

print("erase DUT")

print("flash dut")

print("reset dut")

print("blink led")

print("disable coin cell")
{% c-block-end %}

Once the battery is enabled, the physical device is then erased, flashed with a hex image and then allowed to run for 5 seconds.

Here’s a video showing this script powering a RP2040 Pico and running a simple blinky demo:

By using a battery simulator, test engineers can quickly test the firmware and hardware against various points in a battery’s voltage curve, without ever needing to swap batteries in or out.

Reach out to learn more about Lager's hardware test automation platform.

Try One Month Free