Simvik

Water meter: will the battery last?

Work out a battery's life in days from the meter's sleep, wake-up and radio currents. A medium embedded C problem (Low-power design techniques), run and…

medium · Low-power design techniques · power-budget · units · overflow · product

Product: Smart water meter (Energy)

Requirement. A water meter is sealed underground and must run for 15 years on its battery. Before the hardware is built, firmware estimates the battery's life from a power budget:

  • it sleeps at sleep_ua microamps all the time,
  • every period_s seconds it wakes at active_ma milliamps for active_ms milliseconds,
  • once a day its radio transmits at tx_ma milliamps for tx_ms_per_day milliseconds in total.

Only 80 % of the battery's capacity_mah is usable (temperature and ageing). Return the battery life in whole days (rounded down). period_s divides 86,400 exactly.

Units help: one mA for one ms is one µA for one s (a µA·s).

Starter code

uint32_t battery_life_days(uint32_t capacity_mah, uint32_t sleep_ua, uint32_t active_ma, uint32_t active_ms,
                           uint32_t period_s, uint32_t tx_ma, uint32_t tx_ms_per_day) {
  uint32_t per_day = sleep_ua * 86400 + active_ma * active_ms * (86400 / period_s) + tx_ma * tx_ms_per_day;
  return capacity_mah * 3600000 * 80 / 100 / per_day;
}

Example tests

Waking every second

printf("%u\n", battery_life_days(2400, 5, 3, 20, 1, 120, 2000));

Expected output:

1180

Waking every minute

printf("%u\n", battery_life_days(2400, 5, 3, 20, 60, 120, 2000));

Expected output:

9113

Learn it first

More Low-power design techniques problems