Battery
Nets that are assigned the type battery
are attached to a battery simulator. The battery simulator works first by modeling a real physical battery, e.g. a 1500mAh 3.7V LiPo, and capturing it's charge and discharge curve. It then uses these curves to simulate a real voltage and current on the battery
net.
The advantage of using a battery simulator versus a physical battery during test and development is that you can very quickly change parameter like State of Charge. You can also peg the State of Charge by setting the simulator to static
mode. This can be useful if, for example, you want to test power down firmware, and need the battery to stay at 5% State of Charge, without dying completely.
Setting Up A Battery Net
A battery net has a number of parameters that can be set to change how the battery model operates.
from lager import Net, NetType, SimMode
battery = Net.get('VBAT',
type=NetType.Battery,
setup_function=setup_nets,
teardown_function=teardown_nets)
battery.setup_battery(
sim_mode=SimMode.Static,
soc=50,
voc=None,
voltage_full=4.2,
voltage_empty=3.0,
current_limit=1,
capacity=1.8)
Note
Battery models are created during setup by sending Lager the physical battery or batteries to be modeled.
~ lager battery VBAT mode pl103449 --dut 1
~ lager battery VBAT soc 50 --dut 1
~ lager battery VBAT batt-empty 3.0 --dut 1
~ lager battery VBAT batt-full 4.2 --dut 1
~ lager battery VBAT capacity 1.8 --dut 1
~ lager battery VBAT current-limit 1 --dut 1
~ lager battery VBAT mode dynamic --dut 1
~ lager battery VBAT enable --dut 1
Enable Net? [y/N]:
~
Over Voltage and Current Protection
Over voltage and over current protections are important to make sure you don't damage the electronics on your board.
from lager import Net, NetType, SimMode
battery = Net.get('VBAT',
type=NetType.Battery,
setup_function=setup_nets,
teardown_function=teardown_nets)
battery.set_over_current(1)
battery.set_over_voltage(4.3)
~ lager battery VBAT ovp 4.3 --dut 1
~ lager battery VBAT ocp 1.1 --dut 1
Note
It is highly recommended to ALWAYS set an over current and over voltage limit when using a battery
net.
Battery State
from lager import Net, NetType, SimMode
battery = Net.get('VBAT',
type=NetType.Battery,
setup_function=setup_nets,
teardown_function=teardown_nets)
print(f"Voltage:{battery.voltage()}")
print(f"Current:{battery.current()}")
print(f"ESR:{battery.esr()}")
print(f"SOC:{battery.soc()}")
print(f"Capacity:{battery.capacity()}")
print(f"Capacity Limit:{battery.capacity_limit()}")
print(f"Voltage Full:{battery.voltage_full()}")
print(f"Voltage Empty:{battery.voltage_empty()}")
print(f"Current Limit:{battery.current_limit()}")
print(f"Terminal Voltage:{battery.terminal_voltage()}")
print(f"OVP:{battery.ovp_level()}")
print(f"OCP:{battery.ocp_level()}")
print(f"Mode:{battery.mode()}")
~ lager battery VBAT enable --dut 1
~ lager battery VBAT state --dut 1
Terminal Voltage:4.1991
Current:-0.0
ESR:1.0457
SOC:100.0
VOC:4.2
Capacity:1.1959
~