Skip to main content

calibration

Function calibration 

Source
pub fn calibration(current_lsb_microamps: u32, shunt_milliohms: u32) -> u16
Expand description

Computes the calibration register value for a chosen current resolution and shunt.

This is the datasheet’s calibration equation, CAL = 0.00512 / (Current_LSB * R_SHUNT), expressed in integer micro-units: with the current LSB in microamps and the shunt in milliohms, the fixed 0.00512 becomes 5_120_000.

§Arguments

  • current_lsb_microamps - the amps-per-count the current register should carry.
  • shunt_milliohms - the shunt resistor value, in milliohms.

§Returns

The value to program into the calibration register, truncated as the datasheet does and capped at the register’s 15-bit width. Returns 0 if either argument is 0, which is the chip’s own uncalibrated state.