1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-12-24 13:21:23 +01:00

Cleaner prog/main sync

Trying to reduce gap between prog and main signals when joined as a siding.
This commit is contained in:
Asbelos 2020-08-14 09:41:14 +01:00
parent 9cc8843e15
commit 3b7325f948
3 changed files with 18 additions and 2 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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);