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):
    pass

def teardown_vbat(net, device):
    pass

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

print("initialize coin cell")
coin.setup_battery(    
    sim_mode=SimMode.Dynamic,    
    soc=80,    
    voc=None,    
    voltage_full=3.2,    
    voltage_empty=2.5,    
    current_limit=0.2,    
    capacity=.22)

print("enable coin cell")
coin.enable()

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

print("measure coin cell voltage")
vbat_net = Net.get('VBAT',
    type=NetType.Analog,
    setup_function=setup_vbat,
   teardown_function=teardown_vbat)
vbat_net.enable()
v_avg = vbat_net.measurement.voltage_average() #Average voltage in Volts
print(f"Battery Voltage: {v_avg}")

print("erase DUT")
dut.erase()

print("flash dut")
dut.flash("app.hex")

print("reset dut")
dut.reset(halt=False)

print("blink led")
time.sleep(5)

print("disable coin cell")
coin.disable()
{% 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

hello@lagerdata.com