Fix undervoltage detection

This commit is contained in:
norbert-walter 2025-01-26 15:01:47 +01:00
parent 9dc857056b
commit e7d5ada610
2 changed files with 21 additions and 9 deletions

View File

@ -491,12 +491,24 @@ void sensorTask(void *param){
}
// Charging detection
float deltaV = sensors.batteryVoltage - sensors.batteryVoltage10;
if(deltaV > 0.045){
// Higher limits for lower voltages
if(sensors.batteryVoltage10 < 4.0){
if(deltaV > 0.045 && deltaV < 4,15){
sensors.BatteryChargeStatus = 1; // Charging active
}
if(deltaV < -0.04){
if(deltaV < -0.04 || deltaV >= 4,15){ // Charging stops by grater than 4,15V
sensors.BatteryChargeStatus = 0; // Discharging
}
}
// Lower limits for higher voltages
else{
if(deltaV > 0.03 && deltaV < 4,15){
sensors.BatteryChargeStatus = 1; // Charging active
}
if(deltaV < -0.03 || deltaV >= 4,15){ // Charging stops by grater than 4,15V
sensors.BatteryChargeStatus = 0; // Discharging
}
}
// Send to NMEA200 bus as instance 10
if(!isnan(sensors.batteryVoltage)){
SetN2kDCBatStatus(N2kMsg, 10, sensors.batteryVoltage, N2kDoubleNA, N2kDoubleNA, 0);

View File

@ -310,8 +310,8 @@ void registerAllPages(PageList &list){
// Undervoltage detection for shutdown display
void underVoltageDetection(GwApi *api, CommonData &common){
// Read settings
float vslope = uint(api->getConfig()->getConfigItem(api->getConfig()->vSlope,true)->asFloat());
float voffset = uint(api->getConfig()->getConfigItem(api->getConfig()->vOffset,true)->asFloat());
double voffset = (api->getConfig()->getConfigItem(api->getConfig()->vOffset,true)->asString()).toFloat();
double vslope = (api->getConfig()->getConfigItem(api->getConfig()->vSlope,true)->asString()).toFloat();
// Read supply voltage
#if defined VOLTAGE_SENSOR && defined LIPO_ACCU_1200
float actVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.53) * 2; // Vin = 1/2 for OBP40
@ -320,8 +320,8 @@ void underVoltageDetection(GwApi *api, CommonData &common){
float actVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // Vin = 1/20 for OBP60
float minVoltage = MIN_VOLTAGE;
#endif
float corrVoltage = actVoltage * vslope + voffset; // Calibration
if(corrVoltage < minVoltage){
double calVoltage = actVoltage * vslope + voffset; // Calibration
if(calVoltage < minVoltage){
#if defined VOLTAGE_SENSOR && defined LIPO_ACCU_1200
// Switch off all power lines
setPortPin(OBP_BACKLIGHT_LED, false); // Backlight Off
@ -350,7 +350,7 @@ void underVoltageDetection(GwApi *api, CommonData &common){
setPortPin(OBP_POWER_50, false); // Power rail 5.0V Off
// Shutdown EInk display
getdisplay().setPartialWindow(0, 0, getdisplay().width(), getdisplay().height()); // Set partial update
getdisplay().fillScreen(common.bgcolor); // Clear screen
getdisplay().fillScreen(common.bgcolor);// Clear screen
getdisplay().setTextColor(common.fgcolor);
getdisplay().setFont(&Ubuntu_Bold20pt7b);
getdisplay().setCursor(65, 150);