Fix undervoltage detection
This commit is contained in:
parent
9dc857056b
commit
e7d5ada610
|
@ -491,12 +491,24 @@ void sensorTask(void *param){
|
||||||
}
|
}
|
||||||
// Charging detection
|
// Charging detection
|
||||||
float deltaV = sensors.batteryVoltage - sensors.batteryVoltage10;
|
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
|
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
|
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
|
// Send to NMEA200 bus as instance 10
|
||||||
if(!isnan(sensors.batteryVoltage)){
|
if(!isnan(sensors.batteryVoltage)){
|
||||||
SetN2kDCBatStatus(N2kMsg, 10, sensors.batteryVoltage, N2kDoubleNA, N2kDoubleNA, 0);
|
SetN2kDCBatStatus(N2kMsg, 10, sensors.batteryVoltage, N2kDoubleNA, N2kDoubleNA, 0);
|
||||||
|
|
|
@ -310,8 +310,8 @@ void registerAllPages(PageList &list){
|
||||||
// Undervoltage detection for shutdown display
|
// Undervoltage detection for shutdown display
|
||||||
void underVoltageDetection(GwApi *api, CommonData &common){
|
void underVoltageDetection(GwApi *api, CommonData &common){
|
||||||
// Read settings
|
// Read settings
|
||||||
float vslope = uint(api->getConfig()->getConfigItem(api->getConfig()->vSlope,true)->asFloat());
|
double voffset = (api->getConfig()->getConfigItem(api->getConfig()->vOffset,true)->asString()).toFloat();
|
||||||
float voffset = uint(api->getConfig()->getConfigItem(api->getConfig()->vOffset,true)->asFloat());
|
double vslope = (api->getConfig()->getConfigItem(api->getConfig()->vSlope,true)->asString()).toFloat();
|
||||||
// Read supply voltage
|
// Read supply voltage
|
||||||
#if defined VOLTAGE_SENSOR && defined LIPO_ACCU_1200
|
#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
|
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 actVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // Vin = 1/20 for OBP60
|
||||||
float minVoltage = MIN_VOLTAGE;
|
float minVoltage = MIN_VOLTAGE;
|
||||||
#endif
|
#endif
|
||||||
float corrVoltage = actVoltage * vslope + voffset; // Calibration
|
double calVoltage = actVoltage * vslope + voffset; // Calibration
|
||||||
if(corrVoltage < minVoltage){
|
if(calVoltage < minVoltage){
|
||||||
#if defined VOLTAGE_SENSOR && defined LIPO_ACCU_1200
|
#if defined VOLTAGE_SENSOR && defined LIPO_ACCU_1200
|
||||||
// Switch off all power lines
|
// Switch off all power lines
|
||||||
setPortPin(OBP_BACKLIGHT_LED, false); // Backlight Off
|
setPortPin(OBP_BACKLIGHT_LED, false); // Backlight Off
|
||||||
|
|
Loading…
Reference in New Issue