|
Avionics
Core avionics package for CURE flight computers
|
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>

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. | |
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.
|
inline |
| adcPin | The ADC pin connected to the battery voltage divider. |
| factor | The scaling factor to convert the pin voltage to battery voltage. |
| numAdcBits | The resolution of the ADC (e.g., 12 for 12-bit ADC). |
| voltageThreshold | A 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.
|
inline |
Check whether voltage exceeds a minimal threshold.
Definition at line 53 of file PowerManagement.h.
|
inline |
Sample the ADC and convert to battery voltage.
Definition at line 35 of file PowerManagement.h.