Fix undervoltage detection
This commit is contained in:
parent
81cee58f14
commit
e4af6f9978
|
@ -54,7 +54,7 @@
|
||||||
#define TONE4 4000 // 4000Hz
|
#define TONE4 4000 // 4000Hz
|
||||||
// Analog Input
|
// Analog Input
|
||||||
#define OBP_ANALOG0 4 // Voltage power supplay
|
#define OBP_ANALOG0 4 // Voltage power supplay
|
||||||
#define MIN_VOLTAGE 9.0 // Min voltage for under voltage detection (then goto deep sleep)
|
#define MIN_VOLTAGE 10.0 // Min voltage for under voltage detection (then goto deep sleep)
|
||||||
#define POWER_FAIL_TIME 2 // in [ms] Accept min voltage until 2 x 1ms (for under voltage gaps by engine start)
|
#define POWER_FAIL_TIME 2 // in [ms] Accept min voltage until 2 x 1ms (for under voltage gaps by engine start)
|
||||||
// Touch buttons
|
// Touch buttons
|
||||||
#define TOUCHTHRESHOLD 50000// Touch sensitivity, lower values more sensitiv
|
#define TOUCHTHRESHOLD 50000// Touch sensitivity, lower values more sensitiv
|
||||||
|
|
|
@ -19,47 +19,7 @@
|
||||||
#include "movingAvg.h" // Lib for moving average building
|
#include "movingAvg.h" // Lib for moving average building
|
||||||
|
|
||||||
// Timer Interrupts for hardware functions
|
// Timer Interrupts for hardware functions
|
||||||
void underVoltageDetection();
|
Ticker Timer1(blinkingFlashLED, 500); // Satrt Timer2 for flash LED all 500ms
|
||||||
Ticker Timer1(underVoltageDetection, 1); // Start Timer1 with maximum speed with 1ms
|
|
||||||
Ticker Timer2(blinkingFlashLED, 500); // Satrt Timer2 for flash LED all 500ms
|
|
||||||
|
|
||||||
// Undervoltage function for shutdown display
|
|
||||||
void underVoltageDetection(){
|
|
||||||
float actVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // V = 1/20 * Vin
|
|
||||||
long starttime = 0;
|
|
||||||
static bool undervoltage = false;
|
|
||||||
|
|
||||||
if(actVoltage < MIN_VOLTAGE){
|
|
||||||
if(undervoltage == false){
|
|
||||||
starttime = millis();
|
|
||||||
undervoltage = true;
|
|
||||||
}
|
|
||||||
if(millis() > starttime + POWER_FAIL_TIME){
|
|
||||||
Timer1.stop(); // Stop Timer1
|
|
||||||
/*
|
|
||||||
setPortPin(OBP_BACKLIGHT_LED, false); // Backlight Off
|
|
||||||
setFlashLED(false); // Flash LED Off
|
|
||||||
*/
|
|
||||||
buzzer(TONE4, 20); // Buzzer tone 4kHz 20ms
|
|
||||||
setPortPin(OBP_POWER_50, false); // Power rail 5.0V Off
|
|
||||||
// Shutdown EInk display
|
|
||||||
/*
|
|
||||||
display.setPartialWindow(0, 0, display.width(), display.height()); // Set partial update
|
|
||||||
display.fillScreen(GxEPD_WHITE); // Draw white sreen
|
|
||||||
display.nextPage(); // Partial update
|
|
||||||
display.powerOff(); // Power off
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Stop system
|
|
||||||
while(true){
|
|
||||||
esp_deep_sleep_start(); // Deep Sleep without weakup. Weakup only after power cycle (restart).
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
undervoltage = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialization for all sensors (RS232, I2C, 1Wire, IOs)
|
// Initialization for all sensors (RS232, I2C, 1Wire, IOs)
|
||||||
//####################################################################################
|
//####################################################################################
|
||||||
|
@ -112,7 +72,7 @@ void sensorTask(void *param){
|
||||||
if(uvoltage == true){
|
if(uvoltage == true){
|
||||||
Timer1.start(); // Start Timer1 for undervoltage detection
|
Timer1.start(); // Start Timer1 for undervoltage detection
|
||||||
}
|
}
|
||||||
Timer2.start(); // Start Timer2 for blinking LED
|
Timer1.start(); // Start Timer2 for blinking LED
|
||||||
|
|
||||||
// Direction settings for NMEA0183
|
// Direction settings for NMEA0183
|
||||||
String nmea0183Mode = api->getConfig()->getConfigItem(api->getConfig()->serialDirection, true)->asString();
|
String nmea0183Mode = api->getConfig()->getConfigItem(api->getConfig()->serialDirection, true)->asString();
|
||||||
|
@ -387,8 +347,7 @@ void sensorTask(void *param){
|
||||||
|
|
||||||
while (true){
|
while (true){
|
||||||
delay(100); // Loop time 100ms
|
delay(100); // Loop time 100ms
|
||||||
Timer1.update(); // Update for Timer1
|
Timer1.update(); // Update for Timer2
|
||||||
Timer2.update(); // Update for Timer2
|
|
||||||
if (millis() > starttime0 + 100)
|
if (millis() > starttime0 + 100)
|
||||||
{
|
{
|
||||||
starttime0 = millis();
|
starttime0 = millis();
|
||||||
|
|
|
@ -221,6 +221,48 @@ void registerAllPages(PageList &list){
|
||||||
list.add(®isterPageGenerator);
|
list.add(®isterPageGenerator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Undervoltage detection for shutdown display
|
||||||
|
void underVoltageDetection(GwApi *api){
|
||||||
|
int textcolor = GxEPD_BLACK;
|
||||||
|
int pixelcolor = GxEPD_BLACK;
|
||||||
|
int bgcolor = GxEPD_WHITE;
|
||||||
|
// Read settings
|
||||||
|
String displaycolor = api->getConfig()->getConfigItem(api->getConfig()->displaycolor,true)->asString();
|
||||||
|
float vslope = uint(api->getConfig()->getConfigItem(api->getConfig()->vSlope,true)->asFloat());
|
||||||
|
float voffset = uint(api->getConfig()->getConfigItem(api->getConfig()->vOffset,true)->asFloat());
|
||||||
|
// Read supplay voltage
|
||||||
|
float actVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // V = 1/20 * Vin
|
||||||
|
actVoltage = actVoltage * vslope + voffset;
|
||||||
|
if(actVoltage < MIN_VOLTAGE){
|
||||||
|
// Switch off all power lines
|
||||||
|
setPortPin(OBP_BACKLIGHT_LED, false); // Backlight Off
|
||||||
|
setFlashLED(false); // Flash LED Off
|
||||||
|
buzzer(TONE4, 20); // Buzzer tone 4kHz 20ms
|
||||||
|
setPortPin(OBP_POWER_50, false); // Power rail 5.0V Off
|
||||||
|
// Shutdown EInk display
|
||||||
|
if(displaycolor == "Normal"){
|
||||||
|
textcolor = GxEPD_BLACK;
|
||||||
|
bgcolor = GxEPD_WHITE;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
textcolor = GxEPD_WHITE;
|
||||||
|
bgcolor = GxEPD_BLACK;
|
||||||
|
}
|
||||||
|
getdisplay().setPartialWindow(0, 0, getdisplay().width(), getdisplay().height()); // Set partial update
|
||||||
|
getdisplay().fillScreen(bgcolor); // Clear screen
|
||||||
|
getdisplay().setTextColor(textcolor);
|
||||||
|
getdisplay().setFont(&Ubuntu_Bold20pt7b);
|
||||||
|
getdisplay().setCursor(65, 150);
|
||||||
|
getdisplay().print("Undervoltage");
|
||||||
|
getdisplay().nextPage(); // Partial update
|
||||||
|
getdisplay().powerOff(); // Display power off
|
||||||
|
// Stop system
|
||||||
|
while(true){
|
||||||
|
esp_deep_sleep_start(); // Deep Sleep without weakup. Weakup only after power cycle (restart).
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// OBP60 Task
|
// OBP60 Task
|
||||||
//####################################################################################
|
//####################################################################################
|
||||||
void OBP60Task(GwApi *api){
|
void OBP60Task(GwApi *api){
|
||||||
|
@ -355,6 +397,7 @@ void OBP60Task(GwApi *api){
|
||||||
String backlightColor = api->getConfig()->getConfigItem(api->getConfig()->blColor,true)->asString();
|
String backlightColor = api->getConfig()->getConfigItem(api->getConfig()->blColor,true)->asString();
|
||||||
CHSV color = colorMapping(backlightColor);
|
CHSV color = colorMapping(backlightColor);
|
||||||
uint brightness = 2.55 * uint(api->getConfig()->getConfigItem(api->getConfig()->blBrightness,true)->asInt());
|
uint brightness = 2.55 * uint(api->getConfig()->getConfigItem(api->getConfig()->blBrightness,true)->asInt());
|
||||||
|
bool uvoltage = api->getConfig()->getConfigItem(api->getConfig()->underVoltage,true)->asBoolean();
|
||||||
|
|
||||||
// refreshmode defined in init section
|
// refreshmode defined in init section
|
||||||
// displaycolor defined in init section
|
// displaycolor defined in init section
|
||||||
|
@ -391,6 +434,12 @@ void OBP60Task(GwApi *api){
|
||||||
while (true){
|
while (true){
|
||||||
delay(100); // Delay 100ms (loop time)
|
delay(100); // Delay 100ms (loop time)
|
||||||
|
|
||||||
|
|
||||||
|
// Undervoltage detection
|
||||||
|
if(uvoltage == true){
|
||||||
|
underVoltageDetection(api);
|
||||||
|
}
|
||||||
|
|
||||||
if(millis() > starttime0 + 100){
|
if(millis() > starttime0 + 100){
|
||||||
starttime0 = millis();
|
starttime0 = millis();
|
||||||
commonData.data=shared->getSensorData();
|
commonData.data=shared->getSensorData();
|
||||||
|
|
Loading…
Reference in New Issue