1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-23 08:06:13 +01:00

overload detection different timestamps and verbose diag

This commit is contained in:
Harald Barth 2023-06-14 22:57:28 +02:00
parent f5d4dcb97c
commit f99deb4276
3 changed files with 37 additions and 13 deletions

View File

@ -1 +1 @@
#define GITHUB_SHA "devel-202306132257Z" #define GITHUB_SHA "devel-202306142056Z"

View File

@ -364,18 +364,15 @@ void MotorDriver::getFastPin(const FSH* type,int pin, bool input, FASTPIN & res
} }
void MotorDriver::checkPowerOverload(bool useProgLimit, byte trackno) { void MotorDriver::checkPowerOverload(bool useProgLimit, byte trackno) {
//if (millis() - lastSampleTaken < sampleDelay) return;
//lastSampleTaken = millis();
int tripValue= useProgLimit?progTripValue:getRawCurrentTripValue(); int tripValue= useProgLimit?progTripValue:getRawCurrentTripValue();
// check if there was a change from last time
if (powerMode != oldPowerMode) {
lastPowerChange = micros();
oldPowerMode = powerMode;
}
switch (powerMode) { switch (powerMode) {
case POWERMODE::OFF: case POWERMODE::OFF:
if (overloadNow) {
overloadNow=false;
lastPowerChange = micros();
DIAG(F("OVERLOAD POFF OFF"));
}
if (microsSinceLastPowerChange() > 5000000UL) { if (microsSinceLastPowerChange() > 5000000UL) {
power_sample_overload_wait = 100UL; power_sample_overload_wait = 100UL;
} }
@ -385,6 +382,11 @@ void MotorDriver::checkPowerOverload(bool useProgLimit, byte trackno) {
lastCurrent=getCurrentRaw(); lastCurrent=getCurrentRaw();
if (lastCurrent < 0) { if (lastCurrent < 0) {
// We have a fault pin condition to take care of // We have a fault pin condition to take care of
if (!overloadNow) {
overloadNow=true;
lastPowerChange = micros();
DIAG(F("OVERLOAD FPIN ON"));
}
lastCurrent = -lastCurrent; lastCurrent = -lastCurrent;
if (commonFaultPin) { if (commonFaultPin) {
if (lastCurrent < tripValue) { if (lastCurrent < tripValue) {
@ -416,22 +418,44 @@ void MotorDriver::checkPowerOverload(bool useProgLimit, byte trackno) {
} }
// // // // // //
if (lastCurrent < tripValue) { if (lastCurrent < tripValue) {
if (overloadNow) {
overloadNow=false;
lastPowerChange = micros();
DIAG(F("OVERLOAD PON OFF"));
}
if (microsSinceLastPowerChange() > 5000000UL) { if (microsSinceLastPowerChange() > 5000000UL) {
power_sample_overload_wait = 100UL; power_sample_overload_wait = 100UL;
} }
} else { } else {
// too much current // too much current
if (!overloadNow) {
overloadNow=true;
lastPowerChange = micros();
DIAG(F("OVERLOAD PON ON"));
}
unsigned long us = microsSinceLastPowerChange();
if (power_sample_overload_wait > 100UL || // not virgin if (power_sample_overload_wait > 100UL || // not virgin
microsSinceLastPowerChange() > 10000UL) { // Longer than 10ms us > 10000UL) { // Longer than 10ms
setPower(POWERMODE::OVERLOAD); setPower(POWERMODE::OVERLOAD);
// the setPower just turned off, so overload is now gone
if (overloadNow) {
overloadNow=false;
lastPowerChange = micros();
DIAG(F("OVERLOAD PON OFF"));
}
unsigned int mA=raw2mA(lastCurrent); unsigned int mA=raw2mA(lastCurrent);
unsigned int maxmA=raw2mA(tripValue); unsigned int maxmA=raw2mA(tripValue);
DIAG(F("TRACK %c POWER OVERLOAD %dmA (limit %dmA) shutdown for %lus"), DIAG(F("TRACK %c POWER OVERLOAD %dmA (limit %dmA) shutdown after %lus for %lus"),
trackno + 'A', mA, maxmA, power_sample_overload_wait); trackno + 'A', mA, maxmA, us, power_sample_overload_wait);
} }
} }
break; break;
case POWERMODE::OVERLOAD: case POWERMODE::OVERLOAD:
if (overloadNow) {
overloadNow=false;
lastPowerChange = micros();
DIAG(F("OVERLOAD POVER OFF"));
}
// Try setting it back on after the OVERLOAD_WAIT // Try setting it back on after the OVERLOAD_WAIT
if (microsSinceLastPowerChange() > power_sample_overload_wait) { if (microsSinceLastPowerChange() > power_sample_overload_wait) {
// adjust next wait time // adjust next wait time

View File

@ -226,7 +226,7 @@ class MotorDriver {
int rawCurrentTripValue; int rawCurrentTripValue;
// current sampling // current sampling
POWERMODE powerMode; POWERMODE powerMode;
POWERMODE oldPowerMode; bool overloadNow = false;
unsigned long lastPowerChange; // timestamp in microseconds unsigned long lastPowerChange; // timestamp in microseconds
int progTripValue; int progTripValue;
int lastCurrent; int lastCurrent;