From 85d60dfbbd9a23caba84d926d55b373a8f9e50a8 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Sun, 27 Sep 2020 13:03:46 +0200 Subject: [PATCH 1/2] D PROGBOOST ON command --- DCC.cpp | 3 +++ DCC.h | 1 + DCCEXParser.cpp | 6 ++++++ DCCWaveform.cpp | 3 ++- DCCWaveform.h | 1 + 5 files changed, 13 insertions(+), 1 deletion(-) diff --git a/DCC.cpp b/DCC.cpp index ebf51de..29fa9d7 100644 --- a/DCC.cpp +++ b/DCC.cpp @@ -207,6 +207,9 @@ void DCC::writeCVBitMain(int cab, int cv, byte bNum, bool bValue) { void DCC::setProgTrackSyncMain(bool on) { DCCWaveform::progTrackSyncMain=on; } +void DCC::setProgTrackBoost(bool on) { + DCCWaveform::progTrackBoosted=on; +} __FlashStringHelper* DCC::getMotorShieldName() { return shieldName; diff --git a/DCC.h b/DCC.h index 1e1058b..0e8fcc6 100644 --- a/DCC.h +++ b/DCC.h @@ -76,6 +76,7 @@ public: static void setAccessory(int aAdd, byte aNum, bool activate); static bool writeTextPacket(byte *b, int nBytes); static void setProgTrackSyncMain(bool on); // when true, prog track becomes driveable + static void setProgTrackBoost(bool on); // when true, special prog track current limit does not apply // ACKable progtrack calls bitresults callback 0,0 or -1, cv returns value or -1 static void readCV(int cv, ACK_CALLBACK callback, bool blocking = false); diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index 82cd9d9..b52a968 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -45,6 +45,7 @@ const int HASH_KEYWORD_ACK = 3113; const int HASH_KEYWORD_ON = 2657; const int HASH_KEYWORD_DCC = 6436; const int HASH_KEYWORD_SLOW = -17209; +const int HASH_KEYWORD_PROGBOOST = -6353; int DCCEXParser::stashP[MAX_PARAMS]; bool DCCEXParser::stashBusy; @@ -598,6 +599,11 @@ bool DCCEXParser::parseD(Print *stream, int params, int p[]) case HASH_KEYWORD_DCC: DCCWaveform::setDiagnosticSlowWave(params >= 1 && p[1] == HASH_KEYWORD_SLOW); return true; + + case HASH_KEYWORD_PROGBOOST: + DCC::setProgTrackBoost(true); + return true; + default: // invalid/unknown break; } diff --git a/DCCWaveform.cpp b/DCCWaveform.cpp index dc4b503..c67dcd6 100644 --- a/DCCWaveform.cpp +++ b/DCCWaveform.cpp @@ -30,6 +30,7 @@ DCCWaveform DCCWaveform::progTrack(PREAMBLE_BITS_PROG, false); bool DCCWaveform::progTrackSyncMain=false; +bool DCCWaveform::progTrackBoosted=false; VirtualTimer * DCCWaveform::interruptTimer=NULL; void DCCWaveform::begin(MotorDriver * mainDriver, MotorDriver * progDriver, byte timerNumber) { @@ -128,7 +129,7 @@ void DCCWaveform::checkPowerOverload() { if (millis() - lastSampleTaken < sampleDelay) return; lastSampleTaken = millis(); int tripValue= motorDriver->rawCurrentTripValue; - if (!isMainTrack && !ackPending && !progTrackSyncMain) + if (!isMainTrack && !ackPending && !progTrackSyncMain && !progTrackBoosted) tripValue=progTripValue; switch (powerMode) { diff --git a/DCCWaveform.h b/DCCWaveform.h index 5af7144..d0f6d6e 100644 --- a/DCCWaveform.h +++ b/DCCWaveform.h @@ -67,6 +67,7 @@ class DCCWaveform { void setAckPending(); //prog track only byte getAck(); //prog track only 0=NACK, 1=ACK 2=keep waiting static bool progTrackSyncMain; // true when prog track is a siding switched to main + static bool progTrackBoosted; // true when prog track is not current limited inline void doAutoPowerOff() { if (autoPowerOff) { setPowerMode(POWERMODE::OFF); From 1f03d9759ddfa15e99d137052b69394ecb8baf25 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Sun, 27 Sep 2020 13:12:02 +0200 Subject: [PATCH 2/2] cap overcurrent off time to 10sec --- DCCWaveform.cpp | 5 ++++- DCCWaveform.h | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/DCCWaveform.cpp b/DCCWaveform.cpp index c67dcd6..a70ab16 100644 --- a/DCCWaveform.cpp +++ b/DCCWaveform.cpp @@ -152,7 +152,10 @@ void DCCWaveform::checkPowerOverload() { DIAG(F("\n*** %S TRACK POWER OVERLOAD current=%d max=%d offtime=%l ***\n"), isMainTrack ? F("MAIN") : F("PROG"), mA, maxmA, power_sample_overload_wait); power_good_counter=0; sampleDelay = power_sample_overload_wait; - power_sample_overload_wait *= 2; + if (power_sample_overload_wait >= 10000) + power_sample_overload_wait = 10000; + else + power_sample_overload_wait *= 2; } break; case POWERMODE::OVERLOAD: diff --git a/DCCWaveform.h b/DCCWaveform.h index d0f6d6e..d607420 100644 --- a/DCCWaveform.h +++ b/DCCWaveform.h @@ -22,14 +22,16 @@ #include "MotorDriver.h" #include "ArduinoTimers.h" +// Wait times for power management. Unit: milliseconds const int POWER_SAMPLE_ON_WAIT = 100; const int POWER_SAMPLE_OFF_WAIT = 1000; const int POWER_SAMPLE_OVERLOAD_WAIT = 20; +// Ack time thresholds. Unit: microseconds const int MIN_ACK_PULSE_DURATION = 2000; const int MAX_ACK_PULSE_DURATION = 8500; - +// Number of preamble bits. const int PREAMBLE_BITS_MAIN = 16; const int PREAMBLE_BITS_PROG = 22;