mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-25 09:06:13 +01:00
Compare commits
No commits in common. "cade89ba1692f12b610368c4f67897a2d4fe7fa8" and "f99deb4276e5059382e3f6d96accaeb7cde2ace6" have entirely different histories.
cade89ba16
...
f99deb4276
|
@ -1 +1 @@
|
|||
#define GITHUB_SHA "devel-202306180700Z"
|
||||
#define GITHUB_SHA "devel-202306142056Z"
|
||||
|
|
|
@ -108,13 +108,8 @@ MotorDriver::MotorDriver(int16_t power_pin, byte signal_pin, byte signal_pin2, i
|
|||
}
|
||||
|
||||
currentPin=current_pin;
|
||||
if (currentPin!=UNUSED_PIN) {
|
||||
int ret = ADCee::init(currentPin);
|
||||
if (ret < -1010) { // XXX give value a name later
|
||||
DIAG(F("ADCee::init error %d, disable current pin %d"), ret, currentPin);
|
||||
currentPin = UNUSED_PIN;
|
||||
}
|
||||
}
|
||||
if (currentPin!=UNUSED_PIN)
|
||||
ADCee::init(currentPin);
|
||||
senseOffset=0; // value can not be obtained until waveform is activated
|
||||
|
||||
if (fault_pin != UNUSED_PIN) {
|
||||
|
@ -374,13 +369,12 @@ void MotorDriver::checkPowerOverload(bool useProgLimit, byte trackno) {
|
|||
switch (powerMode) {
|
||||
case POWERMODE::OFF:
|
||||
if (overloadNow) {
|
||||
// reset overload condition as we have just turned off power
|
||||
// DIAG(F("OVERLOAD POFF OFF"));
|
||||
overloadNow=false;
|
||||
lastPowerChange = micros();
|
||||
DIAG(F("OVERLOAD POFF OFF"));
|
||||
}
|
||||
if (microsSinceLastPowerChange() > POWER_SAMPLE_ALL_GOOD) {
|
||||
power_sample_overload_wait = POWER_SAMPLE_OVERLOAD_WAIT;
|
||||
if (microsSinceLastPowerChange() > 5000000UL) {
|
||||
power_sample_overload_wait = 100UL;
|
||||
}
|
||||
break;
|
||||
case POWERMODE::ON:
|
||||
|
@ -389,10 +383,9 @@ void MotorDriver::checkPowerOverload(bool useProgLimit, byte trackno) {
|
|||
if (lastCurrent < 0) {
|
||||
// We have a fault pin condition to take care of
|
||||
if (!overloadNow) {
|
||||
// turn on overload condition as fault pin has gone active
|
||||
// DIAG(F("OVERLOAD FPIN ON"));
|
||||
overloadNow=true;
|
||||
lastPowerChange = micros();
|
||||
DIAG(F("OVERLOAD FPIN ON"));
|
||||
}
|
||||
lastCurrent = -lastCurrent;
|
||||
if (commonFaultPin) {
|
||||
|
@ -405,80 +398,73 @@ void MotorDriver::checkPowerOverload(bool useProgLimit, byte trackno) {
|
|||
DIAG(F("COMMON FAULT PIN ACTIVE: POWERTOGGLE TRACK %c"), trackno + 'A');
|
||||
}
|
||||
} else {
|
||||
unsigned long us;
|
||||
if (lastCurrent < tripValue) {
|
||||
if (power_sample_overload_wait <= (POWER_SAMPLE_OVERLOAD_WAIT * 10) && // almost virgin
|
||||
microsSinceLastPowerChange() < POWER_SAMPLE_IGNORE_FAULT_LOW) {
|
||||
// Ignore 50ms fault pin if no current
|
||||
DIAG(F("TRACK %c FAULT PIN 50ms ignore"), trackno + 'A');
|
||||
if (power_sample_overload_wait <= 1000UL && // almost virgin
|
||||
(us = microsSinceLastPowerChange()) < 50000UL) { // Ignore 50ms fault pin if no current
|
||||
DIAG(F("TRACK %c FAULT PIN ACTIVE - 50ms ignore %lus"), trackno + 'A', us);
|
||||
break;
|
||||
}
|
||||
lastCurrent = tripValue; // exaggerate so condition below (*) is true
|
||||
lastCurrent = tripValue; // exaggerate
|
||||
} else {
|
||||
if (power_sample_overload_wait <= POWER_SAMPLE_OVERLOAD_WAIT && // virgin
|
||||
microsSinceLastPowerChange() < POWER_SAMPLE_IGNORE_FAULT_HIGH) {
|
||||
// Ignore 5ms fault pin if we see current
|
||||
DIAG(F("TRACK %c FAULT PIN 5ms ignore"), trackno + 'A');
|
||||
if (power_sample_overload_wait <= 100UL && // virgin
|
||||
microsSinceLastPowerChange() < 5000UL) { // Ignore 5ms fault pin if we see current
|
||||
DIAG(F("TRACK %c FAULT PIN ACTIVE - 5ms ignore"), trackno + 'A');
|
||||
break;
|
||||
}
|
||||
}
|
||||
DIAG(F("TRACK %c FAULT PIN ACTIVE"), trackno + 'A');
|
||||
DIAG(F("TRACK %c FAULT PIN ACTIVE - for real"), trackno + 'A');
|
||||
}
|
||||
}
|
||||
// // //
|
||||
// above we looked at fault pin, below we look at current
|
||||
// // //
|
||||
if (lastCurrent < tripValue) { // see above (*)
|
||||
if (lastCurrent < tripValue) {
|
||||
if (overloadNow) {
|
||||
// current is below trip value, turn off overload condition
|
||||
// DIAG(F("OVERLOAD PON OFF"));
|
||||
overloadNow=false;
|
||||
lastPowerChange = micros();
|
||||
DIAG(F("OVERLOAD PON OFF"));
|
||||
}
|
||||
if (microsSinceLastPowerChange() > POWER_SAMPLE_ALL_GOOD) {
|
||||
power_sample_overload_wait = POWER_SAMPLE_OVERLOAD_WAIT;
|
||||
if (microsSinceLastPowerChange() > 5000000UL) {
|
||||
power_sample_overload_wait = 100UL;
|
||||
}
|
||||
} else {
|
||||
// too much current
|
||||
if (!overloadNow) {
|
||||
// current is over trip value, turn on overload condition
|
||||
// DIAG(F("OVERLOAD PON ON"));
|
||||
overloadNow=true;
|
||||
lastPowerChange = micros();
|
||||
DIAG(F("OVERLOAD PON ON"));
|
||||
}
|
||||
unsigned long uSecs = microsSinceLastPowerChange();
|
||||
if (power_sample_overload_wait > POWER_SAMPLE_OVERLOAD_WAIT || // not virgin
|
||||
uSecs > POWER_SAMPLE_OFF_DELAY) {
|
||||
// Overload has existed longer than delay (typ. 10ms)
|
||||
unsigned long us = microsSinceLastPowerChange();
|
||||
if (power_sample_overload_wait > 100UL || // not virgin
|
||||
us > 10000UL) { // Longer than 10ms
|
||||
setPower(POWERMODE::OVERLOAD);
|
||||
// the setPower just turned off, so overload is now gone
|
||||
if (overloadNow) {
|
||||
// the setPower just turned off, so overload is now gone
|
||||
// DIAG(F("OVERLOAD PON OFF"));
|
||||
overloadNow=false;
|
||||
lastPowerChange = micros();
|
||||
DIAG(F("OVERLOAD PON OFF"));
|
||||
}
|
||||
unsigned int mA=raw2mA(lastCurrent);
|
||||
unsigned int maxmA=raw2mA(tripValue);
|
||||
DIAG(F("TRACK %c POWER OVERLOAD %dmA (limit %dmA) shutdown after %lus for %lus"),
|
||||
trackno + 'A', mA, maxmA, uSecs, power_sample_overload_wait);
|
||||
trackno + 'A', mA, maxmA, us, power_sample_overload_wait);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case POWERMODE::OVERLOAD:
|
||||
if (overloadNow) {
|
||||
// state overload mode means power is off, turn off overload condition flag as well
|
||||
// DIAG(F("OVERLOAD POVER OFF"));
|
||||
overloadNow=false;
|
||||
lastPowerChange = micros();
|
||||
DIAG(F("OVERLOAD POVER OFF"));
|
||||
}
|
||||
// Try setting it back on after the OVERLOAD_WAIT
|
||||
if (microsSinceLastPowerChange() > power_sample_overload_wait) {
|
||||
// adjust next wait time
|
||||
power_sample_overload_wait *= 2;
|
||||
if (power_sample_overload_wait > POWER_SAMPLE_RETRY_MAX)
|
||||
power_sample_overload_wait = POWER_SAMPLE_RETRY_MAX;
|
||||
if (power_sample_overload_wait > 10000000UL)
|
||||
power_sample_overload_wait = 10000000UL;
|
||||
// power on test
|
||||
setPower(POWERMODE::ON);
|
||||
DIAG(F("TRACK %c POWER RESTORE (was off %lus)"), trackno + 'A', power_sample_overload_wait);
|
||||
DIAG(F("TRACK %c POWER RESTORE (check %lus)"), trackno + 'A', power_sample_overload_wait);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -237,19 +237,10 @@ class MotorDriver {
|
|||
int maxmA;
|
||||
int tripmA;
|
||||
|
||||
// Times for overload management. Unit: microseconds.
|
||||
// Base for wait time until power is turned on again
|
||||
static const unsigned long POWER_SAMPLE_OVERLOAD_WAIT = 100UL;
|
||||
// Time after we consider all faults old and forgotten
|
||||
static const unsigned long POWER_SAMPLE_ALL_GOOD = 5000000UL;
|
||||
// How long to ignore fault pin if current is under limit
|
||||
static const unsigned long POWER_SAMPLE_IGNORE_FAULT_LOW = 50000UL;
|
||||
// How long to ignore fault pin if current is higher than limit
|
||||
static const unsigned long POWER_SAMPLE_IGNORE_FAULT_HIGH = 5000UL;
|
||||
// How long to wait between overcurrent and turning off
|
||||
static const unsigned long POWER_SAMPLE_OFF_DELAY = 10000UL;
|
||||
// Upper limit for retry period
|
||||
static const unsigned long POWER_SAMPLE_RETRY_MAX = 10000000UL;
|
||||
// Wait times for power management. Unit: milliseconds
|
||||
static const int POWER_SAMPLE_ON_WAIT = 1;
|
||||
static const int POWER_SAMPLE_OFF_WAIT = 100;
|
||||
static const int POWER_SAMPLE_OVERLOAD_WAIT = 500UL;
|
||||
|
||||
// Trip current for programming track, 250mA. Change only if you really
|
||||
// need to be non-NMRA-compliant because of decoders that are not either.
|
||||
|
|
Loading…
Reference in New Issue
Block a user