CC26xx Driver Library
[aon_batmon.h] AON Battery Monitor

Functions

static void AONBatMonEnable (void)
 Enable the temperature and battery monitoring. More...
 
static void AONBatMonDisable (void)
 Disable the temperature and battery monitoring. More...
 
int32_t AONBatMonTemperatureGetDegC (void)
 Get the current temperature measurement as a signed value in Deg Celsius. More...
 
static uint32_t AONBatMonBatteryVoltageGet (void)
 Get the battery monitor measurement. More...
 
static bool AONBatMonNewBatteryMeasureReady (void)
 Check if battery monitor measurement has changed. More...
 
static bool AONBatMonNewTempMeasureReady (void)
 Check if temperature monitor measurement has changed. More...
 

Detailed Description

Function Documentation

§ AONBatMonBatteryVoltageGet()

static uint32_t AONBatMonBatteryVoltageGet ( void  )
inlinestatic

Get the battery monitor measurement.

This function will return the current battery monitor measurement. The battery voltage measurements are updated every cycle.

Note
The returned value is NOT sign-extended!
Use the function AONBatMonNewBatteryMeasureReady() to test for a change in measurement.
Returns
Returns the current battery monitor value of the battery voltage measurement in a <int.frac> format size <3.8> in units of volt.
See also
AONBatMonNewBatteryMeasureReady()
186 {
187  uint32_t ui32CurrentBattery;
188 
189  ui32CurrentBattery = HWREG(AON_BATMON_BASE + AON_BATMON_O_BAT);
190 
191  // Return the current battery voltage measurement.
192  return (ui32CurrentBattery >> AON_BATMON_BAT_FRAC_S);
193 }

§ AONBatMonDisable()

static void AONBatMonDisable ( void  )
inlinestatic

Disable the temperature and battery monitoring.

This function will disable the measurements of the temperature and the battery voltage.

Returns
None
141 {
142  // Disable the measurements.
143  HWREG(AON_BATMON_BASE + AON_BATMON_O_CTL) = 0;
144 }
Here is the call graph for this function:

§ AONBatMonEnable()

static void AONBatMonEnable ( void  )
inlinestatic

Enable the temperature and battery monitoring.

This function will enable the measurements of the temperature and the battery voltage.

To speed up the measurement of the levels the measurement can be enabled before configuring the battery and temperature settings. When all of the AON_BATMON registers are configured, the calculation of the voltage and temperature values can be enabled (the measurement will now take effect/propagate to other blocks).

It is possible to enable both at the same time, after the AON_BATMON registers are configured, but then the first values will be ready at a later point compared to the scenario above.

Note
Temperature and battery voltage measurements are not done in parallel. The measurement cycle is controlled by a hardware Finite State Machine. First the temperature and then the battery voltage each taking one cycle to complete. However, if the comparator measuring the battery voltage detects a change on the reference value, a new measurement of the battery voltage only is performed immediately after. This has no impact on the cycle count.
Returns
None
122 {
123  // Enable the measurements.
127 }

§ AONBatMonNewBatteryMeasureReady()

static bool AONBatMonNewBatteryMeasureReady ( void  )
inlinestatic

Check if battery monitor measurement has changed.

This function checks if a new battery monitor value is available. If the measurement value has changed since last clear the function returns true.

If the measurement has changed the function will automatically clear the status bit.

Note
It is always possible to read out the current value of the battery level using AONBatMonBatteryVoltageGet() but this function can be used to check if the measurement has changed.
Returns
Returns true if the measurement value has changed and false otherwise.
See also
AONBatMonNewTempMeasureReady(), AONBatMonBatteryVoltageGet()
217 {
218  bool bStatus;
219 
220  // Check the status bit.
221  bStatus = HWREG(AON_BATMON_BASE + AON_BATMON_O_BATUPD) &
222  AON_BATMON_BATUPD_STAT ? true : false;
223 
224  // Clear status bit if set.
225  if(bStatus)
226  {
228  }
229 
230  // Return status.
231  return (bStatus);
232 }

§ AONBatMonNewTempMeasureReady()

static bool AONBatMonNewTempMeasureReady ( void  )
inlinestatic

Check if temperature monitor measurement has changed.

This function checks if a new temperature value is available. If the measurement value has changed since last clear the function returns true.

If the measurement has changed the function will automatically clear the status bit.

Note
It is always possible to read out the current value of the temperature using AONBatMonTemperatureGetDegC() but this function can be used to check if the measurement has changed.
Returns
Returns true if the measurement value has changed and false otherwise.
See also
AONBatMonNewBatteryMeasureReady(), AONBatMonTemperatureGetDegC()
256 {
257  bool bStatus;
258 
259  // Check the status bit.
260  bStatus = HWREG(AON_BATMON_BASE + AON_BATMON_O_TEMPUPD) &
261  AON_BATMON_TEMPUPD_STAT ? true : false;
262 
263  // Clear status bit if set.
264  if(bStatus)
265  {
267  }
268 
269  // Return status.
270  return (bStatus);
271 }

§ AONBatMonTemperatureGetDegC()

int32_t AONBatMonTemperatureGetDegC ( void  )

Get the current temperature measurement as a signed value in Deg Celsius.

This function returns an calibrated and rounded value in degree Celsius. The temperature measurements are updated every cycle.

Note
The temperature drifts slightly depending on the battery voltage. This function compensates for this drift and returns a calibrated temperature.
Use the function AONBatMonNewTempMeasureReady() to test for a new measurement.
Returns
Returns signed integer part of temperature in Deg C (-256 .. +255)
See also
AONBatMonNewTempMeasureReady()

Referenced by AONBatMonDisable(), OSCHF_GetStartupTime(), OSCHF_SwitchToRcOscTurnOffXosc(), and SysCtrlSetRechargeBeforePowerDown().

59 {
60  int32_t signedTemp ; // Signed extended temperature with 8 fractional bits
61  int32_t tempCorrection ; // Voltage dependent temp correction with 8 fractional bits
62  int8_t voltageSlope ; // Signed byte value representing the TEMP slope with battery voltage, in degrees C/V, with 4 fractional bits.
63 
64  // Shift left then right to sign extend the BATMON_TEMP field
65  signedTemp = ((((int32_t)HWREG( AON_BATMON_BASE + AON_BATMON_O_TEMP ))
68 
69  // Typecasting voltageSlope to int8_t prior to assignment in order to make sure sign extension works properly
70  // Using byte read (HWREGB) in order to make more efficient code since voltageSlope is assigned to bits[7:0] of FCFG1_O_MISC_TRIM
71  voltageSlope = ((int8_t)HWREGB( FCFG1_BASE + FCFG1_O_MISC_TRIM ));
72  tempCorrection = (( voltageSlope * (((int32_t)HWREG( AON_BATMON_BASE + AON_BATMON_O_BAT )) - 0x300 )) >> 4 );
73 
74  return ((( signedTemp - tempCorrection ) + 0x80 ) >> 8 );
75 }