From 3b7325f9485852243cc736cfaa1d6e6c0a5e148b Mon Sep 17 00:00:00 2001 From: Asbelos Date: Fri, 14 Aug 2020 09:41:14 +0100 Subject: [PATCH] Cleaner prog/main sync Trying to reduce gap between prog and main signals when joined as a siding. --- DCCWaveform.cpp | 3 +-- Hardware.cpp | 16 ++++++++++++++++ Hardware.h | 1 + 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/DCCWaveform.cpp b/DCCWaveform.cpp index 9c317b5..20c5205 100644 --- a/DCCWaveform.cpp +++ b/DCCWaveform.cpp @@ -183,8 +183,7 @@ void DCCWaveform::setSignal(bool high) { if (progTrackSyncMain) { if (!isMainTrack) return; // ignore PROG track waveform while in sync // set both tracks to same signal - Hardware::setSignal(true, high); - Hardware::setSignal(false, high); + Hardware::setSyncSignal(high); return; } Hardware::setSignal(isMainTrack,high); diff --git a/Hardware.cpp b/Hardware.cpp index df40a06..51a1e68 100644 --- a/Hardware.cpp +++ b/Hardware.cpp @@ -64,6 +64,22 @@ void Hardware::setSignal(bool isMainTrack, bool high) { if (pin2 != UNUSED_PIN) WritePin(pin2, high ? LOW : HIGH); } +void Hardware::setSyncSignal(bool high) { + // This sets the same signal down both tracks at the same time. + // Speed notes.... + // Objective is to get the two track signals to change as close as possible + // the high ? HIGH:LOW will only be evaluated once + // The UNUSED_PIN check will be done at compile time. + // If even more speed is required, its possible (not SAMD) to pre-prepare the + // DIO pinnumber->pincode translation so the WritePin (digitalWrite2) does not + // have to calculate the register and bit numbers every time. + + WritePin(MAIN_SIGNAL_PIN, high ? HIGH : LOW); + WritePin(PROG_SIGNAL_PIN, high ? HIGH : LOW); + if (MAIN_SIGNAL_PIN_ALT != UNUSED_PIN) WritePin(MAIN_SIGNAL_PIN_ALT, high ? LOW : HIGH); + if (PROG_SIGNAL_PIN_ALT != UNUSED_PIN) WritePin(PROG_SIGNAL_PIN_ALT, high ? LOW : HIGH); +} + int Hardware::getCurrentRaw(bool isMainTrack) { // tooo much crap for a interrupt routine. Will see how that goes. byte faultpin = isMainTrack ? MAIN_FAULT_PIN : PROG_FAULT_PIN; diff --git a/Hardware.h b/Hardware.h index 4c86a70..2362741 100644 --- a/Hardware.h +++ b/Hardware.h @@ -24,6 +24,7 @@ class Hardware { static void init(); static void setPower(bool isMainTrack, bool on); static void setSignal(bool isMainTrack, bool high); + static void setSyncSignal( bool high); static unsigned int getCurrentMilliamps(bool isMainTrack, int rawValue); static int getCurrentRaw(bool isMainTrack); static void setBrake(bool isMainTrack, bool on);