Avionics
Core avionics package for CURE flight computers
Loading...
Searching...
No Matches
BatteryVoltage Class Reference

Simple ADC-based battery voltage helper. This class provides a way to read the battery voltage using an ADC pin and a scaling factor. More...

#include <PowerManagement.h>

Collaboration diagram for BatteryVoltage:
Collaboration graph

Public Member Functions

 BatteryVoltage (uint8_t adcPin, float factor, int numAdcBits, float voltageThreshold)
float readVoltage ()
 Sample the ADC and convert to battery voltage.
bool isLow ()
 Check whether voltage exceeds a minimal threshold.

Detailed Description

Simple ADC-based battery voltage helper. This class provides a way to read the battery voltage using an ADC pin and a scaling factor.

The correct pin can be found in the hardware scematics under "ADC_VOLTAGE" and the scaling factor can be calculated based on the voltage divider used in the hardware design. For MARTHA 1.4, the voltage divider is 200k and 1k5, so the factor is (200k + 1k5) / 1k5 = 134.33333.

The voltage at the pin is calculated as: vPin = (rawValue / (2^numAdcBits - 1)) * vRef where rawValue is the ADC reading, numAdcBits is the resolution of the ADC, and vRef is the reference voltage for the ADC (3.3V for MARTHA 1.4). The battery voltage is then calculated as: vBat = vPin * factor

Definition at line 20 of file PowerManagement.h.

Constructor & Destructor Documentation

◆ BatteryVoltage()

BatteryVoltage::BatteryVoltage ( uint8_t adcPin,
float factor,
int numAdcBits,
float voltageThreshold )
inline
Parameters
adcPinThe ADC pin connected to the battery voltage divider.
factorThe scaling factor to convert the pin voltage to battery voltage.
numAdcBitsThe resolution of the ADC (e.g., 12 for 12-bit ADC).
voltageThresholdA threshold voltage for low battery checks (not used in current implementation but can be useful for future extensions).

Definition at line 28 of file PowerManagement.h.

Member Function Documentation

◆ isLow()

bool BatteryVoltage::isLow ( )
inline

Check whether voltage exceeds a minimal threshold.

Returns
true if voltage is above the survival threshold.
Note
Could be useful for future extension, like triggering a low power mode

Definition at line 53 of file PowerManagement.h.

◆ readVoltage()

float BatteryVoltage::readVoltage ( )
inline

Sample the ADC and convert to battery voltage.

Returns
Converted voltage reading.

Definition at line 35 of file PowerManagement.h.


The documentation for this class was generated from the following file: