Skip to content

Commit

Permalink
Fix undervoltage detection
Browse files Browse the repository at this point in the history
  • Loading branch information
norbert-walter committed Jan 26, 2025
1 parent 9dc8570 commit e7d5ada
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
20 changes: 16 additions & 4 deletions lib/obp60task/OBPSensorTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,11 +491,23 @@ void sensorTask(void *param){
}
// Charging detection
float deltaV = sensors.batteryVoltage - sensors.batteryVoltage10;
if(deltaV > 0.045){
sensors.BatteryChargeStatus = 1; // Charging active
// 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 || deltaV >= 4,15){ // Charging stops by grater than 4,15V
sensors.BatteryChargeStatus = 0; // Discharging
}
}
if(deltaV < -0.04){
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)){
Expand Down
10 changes: 5 additions & 5 deletions lib/obp60task/obp60task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit e7d5ada

Please sign in to comment.