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;
|
currentPin=current_pin;
|
||||||
if (currentPin!=UNUSED_PIN) {
|
if (currentPin!=UNUSED_PIN)
|
||||||
int ret = ADCee::init(currentPin);
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
senseOffset=0; // value can not be obtained until waveform is activated
|
senseOffset=0; // value can not be obtained until waveform is activated
|
||||||
|
|
||||||
if (fault_pin != UNUSED_PIN) {
|
if (fault_pin != UNUSED_PIN) {
|
||||||
|
@ -374,13 +369,12 @@ void MotorDriver::checkPowerOverload(bool useProgLimit, byte trackno) {
|
||||||
switch (powerMode) {
|
switch (powerMode) {
|
||||||
case POWERMODE::OFF:
|
case POWERMODE::OFF:
|
||||||
if (overloadNow) {
|
if (overloadNow) {
|
||||||
// reset overload condition as we have just turned off power
|
|
||||||
// DIAG(F("OVERLOAD POFF OFF"));
|
|
||||||
overloadNow=false;
|
overloadNow=false;
|
||||||
lastPowerChange = micros();
|
lastPowerChange = micros();
|
||||||
|
DIAG(F("OVERLOAD POFF OFF"));
|
||||||
}
|
}
|
||||||
if (microsSinceLastPowerChange() > POWER_SAMPLE_ALL_GOOD) {
|
if (microsSinceLastPowerChange() > 5000000UL) {
|
||||||
power_sample_overload_wait = POWER_SAMPLE_OVERLOAD_WAIT;
|
power_sample_overload_wait = 100UL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case POWERMODE::ON:
|
case POWERMODE::ON:
|
||||||
|
@ -389,10 +383,9 @@ void MotorDriver::checkPowerOverload(bool useProgLimit, byte trackno) {
|
||||||
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) {
|
if (!overloadNow) {
|
||||||
// turn on overload condition as fault pin has gone active
|
|
||||||
// DIAG(F("OVERLOAD FPIN ON"));
|
|
||||||
overloadNow=true;
|
overloadNow=true;
|
||||||
lastPowerChange = micros();
|
lastPowerChange = micros();
|
||||||
|
DIAG(F("OVERLOAD FPIN ON"));
|
||||||
}
|
}
|
||||||
lastCurrent = -lastCurrent;
|
lastCurrent = -lastCurrent;
|
||||||
if (commonFaultPin) {
|
if (commonFaultPin) {
|
||||||
|
@ -405,80 +398,73 @@ void MotorDriver::checkPowerOverload(bool useProgLimit, byte trackno) {
|
||||||
DIAG(F("COMMON FAULT PIN ACTIVE: POWERTOGGLE TRACK %c"), trackno + 'A');
|
DIAG(F("COMMON FAULT PIN ACTIVE: POWERTOGGLE TRACK %c"), trackno + 'A');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
unsigned long us;
|
||||||
if (lastCurrent < tripValue) {
|
if (lastCurrent < tripValue) {
|
||||||
if (power_sample_overload_wait <= (POWER_SAMPLE_OVERLOAD_WAIT * 10) && // almost virgin
|
if (power_sample_overload_wait <= 1000UL && // almost virgin
|
||||||
microsSinceLastPowerChange() < POWER_SAMPLE_IGNORE_FAULT_LOW) {
|
(us = microsSinceLastPowerChange()) < 50000UL) { // Ignore 50ms fault pin if no current
|
||||||
// Ignore 50ms fault pin if no current
|
DIAG(F("TRACK %c FAULT PIN ACTIVE - 50ms ignore %lus"), trackno + 'A', us);
|
||||||
DIAG(F("TRACK %c FAULT PIN 50ms ignore"), trackno + 'A');
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
lastCurrent = tripValue; // exaggerate so condition below (*) is true
|
lastCurrent = tripValue; // exaggerate
|
||||||
} else {
|
} else {
|
||||||
if (power_sample_overload_wait <= POWER_SAMPLE_OVERLOAD_WAIT && // virgin
|
if (power_sample_overload_wait <= 100UL && // virgin
|
||||||
microsSinceLastPowerChange() < POWER_SAMPLE_IGNORE_FAULT_HIGH) {
|
microsSinceLastPowerChange() < 5000UL) { // Ignore 5ms fault pin if we see current
|
||||||
// Ignore 5ms fault pin if we see current
|
DIAG(F("TRACK %c FAULT PIN ACTIVE - 5ms ignore"), trackno + 'A');
|
||||||
DIAG(F("TRACK %c FAULT PIN 5ms ignore"), trackno + 'A');
|
|
||||||
break;
|
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) {
|
||||||
// // //
|
|
||||||
if (lastCurrent < tripValue) { // see above (*)
|
|
||||||
if (overloadNow) {
|
if (overloadNow) {
|
||||||
// current is below trip value, turn off overload condition
|
|
||||||
// DIAG(F("OVERLOAD PON OFF"));
|
|
||||||
overloadNow=false;
|
overloadNow=false;
|
||||||
lastPowerChange = micros();
|
lastPowerChange = micros();
|
||||||
|
DIAG(F("OVERLOAD PON OFF"));
|
||||||
}
|
}
|
||||||
if (microsSinceLastPowerChange() > POWER_SAMPLE_ALL_GOOD) {
|
if (microsSinceLastPowerChange() > 5000000UL) {
|
||||||
power_sample_overload_wait = POWER_SAMPLE_OVERLOAD_WAIT;
|
power_sample_overload_wait = 100UL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// too much current
|
// too much current
|
||||||
if (!overloadNow) {
|
if (!overloadNow) {
|
||||||
// current is over trip value, turn on overload condition
|
|
||||||
// DIAG(F("OVERLOAD PON ON"));
|
|
||||||
overloadNow=true;
|
overloadNow=true;
|
||||||
lastPowerChange = micros();
|
lastPowerChange = micros();
|
||||||
|
DIAG(F("OVERLOAD PON ON"));
|
||||||
}
|
}
|
||||||
unsigned long uSecs = microsSinceLastPowerChange();
|
unsigned long us = microsSinceLastPowerChange();
|
||||||
if (power_sample_overload_wait > POWER_SAMPLE_OVERLOAD_WAIT || // not virgin
|
if (power_sample_overload_wait > 100UL || // not virgin
|
||||||
uSecs > POWER_SAMPLE_OFF_DELAY) {
|
us > 10000UL) { // Longer than 10ms
|
||||||
// Overload has existed longer than delay (typ. 10ms)
|
|
||||||
setPower(POWERMODE::OVERLOAD);
|
setPower(POWERMODE::OVERLOAD);
|
||||||
if (overloadNow) {
|
|
||||||
// the setPower just turned off, so overload is now gone
|
// the setPower just turned off, so overload is now gone
|
||||||
// DIAG(F("OVERLOAD PON OFF"));
|
if (overloadNow) {
|
||||||
overloadNow=false;
|
overloadNow=false;
|
||||||
lastPowerChange = micros();
|
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 after %lus for %lus"),
|
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;
|
break;
|
||||||
case POWERMODE::OVERLOAD:
|
case POWERMODE::OVERLOAD:
|
||||||
if (overloadNow) {
|
if (overloadNow) {
|
||||||
// state overload mode means power is off, turn off overload condition flag as well
|
|
||||||
// DIAG(F("OVERLOAD POVER OFF"));
|
|
||||||
overloadNow=false;
|
overloadNow=false;
|
||||||
lastPowerChange = micros();
|
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
|
||||||
power_sample_overload_wait *= 2;
|
power_sample_overload_wait *= 2;
|
||||||
if (power_sample_overload_wait > POWER_SAMPLE_RETRY_MAX)
|
if (power_sample_overload_wait > 10000000UL)
|
||||||
power_sample_overload_wait = POWER_SAMPLE_RETRY_MAX;
|
power_sample_overload_wait = 10000000UL;
|
||||||
// power on test
|
// power on test
|
||||||
setPower(POWERMODE::ON);
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -237,19 +237,10 @@ class MotorDriver {
|
||||||
int maxmA;
|
int maxmA;
|
||||||
int tripmA;
|
int tripmA;
|
||||||
|
|
||||||
// Times for overload management. Unit: microseconds.
|
// Wait times for power management. Unit: milliseconds
|
||||||
// Base for wait time until power is turned on again
|
static const int POWER_SAMPLE_ON_WAIT = 1;
|
||||||
static const unsigned long POWER_SAMPLE_OVERLOAD_WAIT = 100UL;
|
static const int POWER_SAMPLE_OFF_WAIT = 100;
|
||||||
// Time after we consider all faults old and forgotten
|
static const int POWER_SAMPLE_OVERLOAD_WAIT = 500UL;
|
||||||
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;
|
|
||||||
|
|
||||||
// Trip current for programming track, 250mA. Change only if you really
|
// Trip current for programming track, 250mA. Change only if you really
|
||||||
// need to be non-NMRA-compliant because of decoders that are not either.
|
// need to be non-NMRA-compliant because of decoders that are not either.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user