software:firmware
MakAir Firmware
|
Battery related functions. More...
#include "Arduino.h"
Go to the source code of this file.
Macros | |
#define | RAW_BATTERY_MULTIPLIER 0.0075196210 |
The divider between real battery voltage and STM32 input is 8.2K-1k resistors So, the multiplier is 1/(1+8.2)=0.1087 Considering 0.1% precision resistances, multiplier is between 0,108502 and 0,108889 The reference is 3.348V (measured on 53 HW V3 boards) RawValue = (Vbat*0.1087)*1024/3.348 So, Vbat = RawValue * (3.348/(1024*0.1087)) More... | |
#define | RAW_VOLTAGE_MAINS 3643u |
Expected voltage in volts when power cord is plugged 27,4 V => 27,4 / RAW_BATTERY_MULTIPLIER. More... | |
#define | RAW_VOLTAGE_ON_BATTERY_HIGH 3590u |
RCM_SW_16 Expected voltage in volts when power cord is unplugged = 27 => 27 / RAW_BATTERY_MULTIPLIER. More... | |
#define | RAW_VOLTAGE_HYSTERESIS 12u |
Hysteresis is used to prevent fast switching when voltage is at the limit of 2 states analogRead(PIN) * RAW_BATTERY_MULTIPLIER = 0,1 => 0,1 / RAW_BATTERY_MULTIPLIER = 3. More... | |
#define | RAW_VOLTAGE_ON_BATTERY 3085u |
RCM_SW_11 = 23,2 => 23,2 / RAW_BATTERY_MULTIPLIER. More... | |
#define | RAW_VOLTAGE_ON_BATTERY_LOW 3005u |
RCM_SW_12 = 22,6 => 22,6 / RAW_BATTERY_MULTIPLIER. More... | |
#define | RAW_VOLTAGE_ON_BATTERY_NOT_STARTING_THRESHOLD 3191u |
Below this value, the machine wont start = 22 => 22 / RAW_BATTERY_MULTIPLIER. More... | |
#define | RAW_VOLTAGE_ON_BATTERY_STOP_THRESHOLD 2660u |
Below this value, the machine will stop immediately = 20 => 20 / RAW_BATTERY_MULTIPLIER. More... | |
#define | BATTERY_MAX_SAMPLES 20u |
Number of samples of the moving average. More... | |
Functions | |
void | initBattery () |
Initialize battery abstraction. More... | |
void | batteryLoop (uint32_t p_cycleNumber) |
Handle battery events. More... | |
void | updateBatterySample () |
Handle battery voltage calculation. More... | |
void | updateBatteryState (uint32_t p_cycleNumber) |
Updates battery states. More... | |
uint32_t | getBatteryLevel () |
Returns battery level. More... | |
uint32_t | getBatteryLevelX10 () |
Returns battery level x10 for better accuracy. More... | |
uint32_t | getBatteryLevelX100 () |
Returns battery level x100 for better accuracy. More... | |
bool | isBatteryVeryLow () |
Check if battery level is very low. More... | |
bool | isBatteryDeepDischarged () |
Check if battery is deeply discharged. More... | |
bool | isMainsConnected () |
Check if mains are connected. More... | |
bool | isMainsAvailable () |
Check if the cable between power supply and expander input is connected. More... | |
Battery related functions.
Definition in file battery.h.
#define BATTERY_MAX_SAMPLES 20u |
#define RAW_BATTERY_MULTIPLIER 0.0075196210 |
The divider between real battery voltage and STM32 input is 8.2K-1k resistors So, the multiplier is 1/(1+8.2)=0.1087 Considering 0.1% precision resistances, multiplier is between 0,108502 and 0,108889 The reference is 3.348V (measured on 53 HW V3 boards) RawValue = (Vbat*0.1087)*1024/3.348 So, Vbat = RawValue * (3.348/(1024*0.1087))
1 bit = 3.348/(4096*0.1087) = 7.5mV
#define RAW_VOLTAGE_HYSTERESIS 12u |
#define RAW_VOLTAGE_MAINS 3643u |
#define RAW_VOLTAGE_ON_BATTERY 3085u |
#define RAW_VOLTAGE_ON_BATTERY_HIGH 3590u |
#define RAW_VOLTAGE_ON_BATTERY_LOW 3005u |
#define RAW_VOLTAGE_ON_BATTERY_NOT_STARTING_THRESHOLD 3191u |
#define RAW_VOLTAGE_ON_BATTERY_STOP_THRESHOLD 2660u |
void batteryLoop | ( | uint32_t | p_cycleNumber | ) |
Handle battery events.
p_cycleNumber | Number of cycles since boot |
Definition at line 117 of file battery.cpp.
uint32_t getBatteryLevel | ( | ) |
Returns battery level.
Definition at line 123 of file battery.cpp.
uint32_t getBatteryLevelX10 | ( | ) |
Returns battery level x10 for better accuracy.
Definition at line 126 of file battery.cpp.
uint32_t getBatteryLevelX100 | ( | ) |
Returns battery level x100 for better accuracy.
Definition at line 129 of file battery.cpp.
void initBattery | ( | ) |
Initialize battery abstraction.
Definition at line 33 of file battery.cpp.
bool isBatteryDeepDischarged | ( | ) |
Check if battery is deeply discharged.
Definition at line 136 of file battery.cpp.
bool isBatteryVeryLow | ( | ) |
Check if battery level is very low.
Definition at line 132 of file battery.cpp.
bool isMainsAvailable | ( | ) |
Check if the cable between power supply and expander input is connected.
Definition at line 144 of file battery.cpp.
bool isMainsConnected | ( | ) |
void updateBatterySample | ( | ) |
void updateBatteryState | ( | uint32_t | p_cycleNumber | ) |
Updates battery states.
p_cycleNumber | Number of cycle since start |
Definition at line 71 of file battery.cpp.