now you set battery alert levels in volt per cell and set number of cells. less annoying battery alert beeps. small cleanup.

This commit is contained in:
larsm 2018-07-21 17:37:02 +02:00
parent dd5a128199
commit 3d0ed7e9c0
3 changed files with 737 additions and 681 deletions

View File

@ -12,9 +12,10 @@
#define BAT_CALIB_REAL_VOLTAGE 42.0 // input voltage measured by multimeter #define BAT_CALIB_REAL_VOLTAGE 42.0 // input voltage measured by multimeter
#define BAT_CALIB_ADC 1667 // adc-value measured by mainboard (value nr 4 on UART debug output) #define BAT_CALIB_ADC 1667 // adc-value measured by mainboard (value nr 4 on UART debug output)
#define BAT_LOW_LVL1 36.0 // gently beeps at this voltage level. ~3.6V/cell #define BAT_NUMBER_OF_CELLS 12 // normal Hoverboard battery: 10s
#define BAT_LOW_LVL2 33.0 // your battery is almost empty. Charge now! ~3.3V/cell #define BAT_LOW_LVL1 3.6 // gently beeps at this voltage level. [V/cell]
#define BAT_LOW_DEAD 31.0 // undervoltage lockout. ~3.1V/cell #define BAT_LOW_LVL2 3.5 // your battery is almost empty. Charge now! [V/cell]
#define BAT_LOW_DEAD 3.37 // undervoltage lockout. [V/cell]
// ################################################################################ // ################################################################################

View File

@ -221,11 +221,14 @@ int main(void) {
setScopeChannel(5, (int)(batteryVoltage * 100.0f)); // for verifying battery voltage calibration setScopeChannel(5, (int)(batteryVoltage * 100.0f)); // for verifying battery voltage calibration
// setScopeChannel(6, (int)); // setScopeChannel(6, (int));
// setScopeChannel(7, (int)); // setScopeChannel(7, (int));
consoleScope();
#ifdef ADDITIONAL_CODE #ifdef ADDITIONAL_CODE
ADDITIONAL_CODE; ADDITIONAL_CODE;
#endif #endif
// ####### SET OUTPUTS ####### // ####### SET OUTPUTS #######
if ((speedL < lastSpeedL + 50 && speedL > lastSpeedL - 50) && (speedR < lastSpeedR + 50 && speedR > lastSpeedR - 50) && timeout < TIMEOUT) { if ((speedL < lastSpeedL + 50 && speedL > lastSpeedL - 50) && (speedR < lastSpeedR + 50 && speedR > lastSpeedR - 50) && timeout < TIMEOUT) {
#ifdef INVERT_R_DIRECTION #ifdef INVERT_R_DIRECTION
@ -243,9 +246,8 @@ int main(void) {
lastSpeedL = speedL; lastSpeedL = speedL;
lastSpeedR = speedR; lastSpeedR = speedR;
// ####### LOG TO CONSOLE #######
consoleScope();
// ####### POWEROFF BY POWER-BUTTON #######
if (HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN)) { if (HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN)) {
enable = 0; enable = 0;
while (HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN)) {} while (HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN)) {}
@ -259,13 +261,15 @@ int main(void) {
while(1) {} while(1) {}
} }
if (batteryVoltage < BAT_LOW_LVL1 && batteryVoltage > BAT_LOW_LVL2) {
// ####### BATTERY VOLTAGE #######
if (batteryVoltage < ((float)BAT_LOW_LVL1 * (float)BAT_NUMBER_OF_CELLS) && batteryVoltage > ((float)BAT_LOW_LVL2 * (float)BAT_NUMBER_OF_CELLS)) {
buzzerFreq = 5; buzzerFreq = 5;
buzzerPattern = 8; buzzerPattern = 42;
} else if (batteryVoltage < BAT_LOW_LVL2 && batteryVoltage > BAT_LOW_DEAD) { } else if (batteryVoltage < ((float)BAT_LOW_LVL2 * (float)BAT_NUMBER_OF_CELLS) && batteryVoltage > ((float)BAT_LOW_DEAD * (float)BAT_NUMBER_OF_CELLS)) {
buzzerFreq = 5; buzzerFreq = 5;
buzzerPattern = 1; buzzerPattern = 6;
} else if (batteryVoltage < BAT_LOW_DEAD) { } else if (batteryVoltage < ((float)BAT_LOW_DEAD * (float)BAT_NUMBER_OF_CELLS)) {
buzzerPattern = 0; buzzerPattern = 0;
enable = 0; enable = 0;
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {

File diff suppressed because it is too large Load Diff