mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-22 23:56:13 +01:00
throttleInrush() (tested on ESP32)
This commit is contained in:
parent
9b75026eef
commit
ec0499e9da
|
@ -347,7 +347,33 @@ void MotorDriver::setDCSignal(byte speedcode) {
|
||||||
interrupts();
|
interrupts();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void MotorDriver::throttleInrush(bool on) {
|
||||||
|
if (brakePin == UNUSED_PIN)
|
||||||
|
return;
|
||||||
|
byte duty = on ? 208 : 0;
|
||||||
|
if (invertBrake)
|
||||||
|
duty = 255-duty;
|
||||||
|
#if defined(ARDUINO_ARCH_ESP32)
|
||||||
|
if(on) {
|
||||||
|
DCCTimer::DCCEXanalogWrite(brakePin,duty);
|
||||||
|
DCCTimer::DCCEXanalogWriteFrequency(brakePin, 62500);
|
||||||
|
} else {
|
||||||
|
ledcDetachPin(brakePin);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if(on){
|
||||||
|
#if defined(ARDUINO_AVR_UNO)
|
||||||
|
TCCR2B = (TCCR2B & B11111000) | B00000001; // div 1 is max
|
||||||
|
#endif
|
||||||
|
#if defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560)
|
||||||
|
TCCR2B = (TCCR2B & B11111000) | B00000001; // div 1 is max
|
||||||
|
TCCR4B = (TCCR4B & B11111000) | B00000001; // div 1 is max
|
||||||
|
TCCR5B = (TCCR5B & B11111000) | B00000001; // div 1 is max
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
analogWrite(brakePin,duty);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
unsigned int MotorDriver::raw2mA( int raw) {
|
unsigned int MotorDriver::raw2mA( int raw) {
|
||||||
//DIAG(F("%d = %d * %d / %d"), (int32_t)raw * senseFactorInternal / senseScale, raw, senseFactorInternal, senseScale);
|
//DIAG(F("%d = %d * %d / %d"), (int32_t)raw * senseFactorInternal / senseScale, raw, senseFactorInternal, senseScale);
|
||||||
return (int32_t)raw * senseFactorInternal / senseScale;
|
return (int32_t)raw * senseFactorInternal / senseScale;
|
||||||
|
@ -481,11 +507,7 @@ void MotorDriver::checkPowerOverload(bool useProgLimit, byte trackno) {
|
||||||
// check how long we have been in this state
|
// check how long we have been in this state
|
||||||
unsigned long mslpc = microsSinceLastPowerChange(POWERMODE::ALERT);
|
unsigned long mslpc = microsSinceLastPowerChange(POWERMODE::ALERT);
|
||||||
if(checkFault()) {
|
if(checkFault()) {
|
||||||
#define INRUSH
|
throttleInrush(true);
|
||||||
#ifdef INRUSH
|
|
||||||
DCCTimer::DCCEXanalogWrite(brakePin,208);
|
|
||||||
DCCTimer::DCCEXanalogWriteFrequency(brakePin, 62500);
|
|
||||||
#endif
|
|
||||||
lastBadSample = now;
|
lastBadSample = now;
|
||||||
unsigned long timeout = checkCurrent(useProgLimit) ? POWER_SAMPLE_IGNORE_FAULT_HIGH : POWER_SAMPLE_IGNORE_FAULT_LOW;
|
unsigned long timeout = checkCurrent(useProgLimit) ? POWER_SAMPLE_IGNORE_FAULT_HIGH : POWER_SAMPLE_IGNORE_FAULT_LOW;
|
||||||
if ( mslpc < timeout) {
|
if ( mslpc < timeout) {
|
||||||
|
@ -494,9 +516,7 @@ void MotorDriver::checkPowerOverload(bool useProgLimit, byte trackno) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
DIAG(F("TRACK %c FAULT PIN detected after %4M. Pause %4M)"), trackno + 'A', mslpc, power_sample_overload_wait);
|
DIAG(F("TRACK %c FAULT PIN detected after %4M. Pause %4M)"), trackno + 'A', mslpc, power_sample_overload_wait);
|
||||||
#ifdef INRUSH
|
throttleInrush(false);
|
||||||
DCCTimer::DCCEXanalogWrite(brakePin,0);
|
|
||||||
#endif
|
|
||||||
setPower(POWERMODE::OVERLOAD);
|
setPower(POWERMODE::OVERLOAD);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -513,9 +533,7 @@ void MotorDriver::checkPowerOverload(bool useProgLimit, byte trackno) {
|
||||||
unsigned int maxmA=raw2mA(tripValue);
|
unsigned int maxmA=raw2mA(tripValue);
|
||||||
DIAG(F("TRACK %c POWER OVERLOAD %4dmA (max %4dmA) detected after %4M. Pause %4M"),
|
DIAG(F("TRACK %c POWER OVERLOAD %4dmA (max %4dmA) detected after %4M. Pause %4M"),
|
||||||
trackno + 'A', mA, maxmA, mslpc, power_sample_overload_wait);
|
trackno + 'A', mA, maxmA, mslpc, power_sample_overload_wait);
|
||||||
#ifdef INRUSH
|
throttleInrush(false);
|
||||||
DCCTimer::DCCEXanalogWrite(brakePin,0);
|
|
||||||
#endif
|
|
||||||
setPower(POWERMODE::OVERLOAD);
|
setPower(POWERMODE::OVERLOAD);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -526,9 +544,7 @@ void MotorDriver::checkPowerOverload(bool useProgLimit, byte trackno) {
|
||||||
unsigned int mA=raw2mA(lastCurrent);
|
unsigned int mA=raw2mA(lastCurrent);
|
||||||
DIAG(F("TRACK %c NORMAL (after %M/%M) %dmA"), trackno + 'A', goodtime, mslpc, mA);
|
DIAG(F("TRACK %c NORMAL (after %M/%M) %dmA"), trackno + 'A', goodtime, mslpc, mA);
|
||||||
}
|
}
|
||||||
#ifdef INRUSH
|
throttleInrush(false);
|
||||||
DCCTimer::DCCEXanalogWrite(brakePin,0);
|
|
||||||
#endif
|
|
||||||
setPower(POWERMODE::ON);
|
setPower(POWERMODE::ON);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -149,6 +149,7 @@ class MotorDriver {
|
||||||
};
|
};
|
||||||
inline pinpair getSignalPin() { return pinpair(signalPin,signalPin2); };
|
inline pinpair getSignalPin() { return pinpair(signalPin,signalPin2); };
|
||||||
void setDCSignal(byte speedByte);
|
void setDCSignal(byte speedByte);
|
||||||
|
void throttleInrush(bool on);
|
||||||
inline void detachDCSignal() {
|
inline void detachDCSignal() {
|
||||||
#if defined(__arm__)
|
#if defined(__arm__)
|
||||||
pinMode(brakePin, OUTPUT);
|
pinMode(brakePin, OUTPUT);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user