From a2636b129610ef53347c1c2174644c876f625769 Mon Sep 17 00:00:00 2001 From: Asbelos Date: Fri, 3 Jul 2020 17:57:24 +0100 Subject: [PATCH] ACK pulse durations Refer @haba --- DCCWaveform.cpp | 4 ++-- DCCWaveform.h | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/DCCWaveform.cpp b/DCCWaveform.cpp index 519640c..f0045ee 100644 --- a/DCCWaveform.cpp +++ b/DCCWaveform.cpp @@ -277,7 +277,7 @@ void DCCWaveform::checkAck() { lastCurrent=Hardware::getCurrentRaw(false); if (lastCurrent > ackMaxCurrent) ackMaxCurrent=lastCurrent; - // An ACK is a pulse lasting between 4.5 and 8.5 mSecs (refer @haba) + // An ACK is a pulse lasting between MIN_ACK_PULSE_DURATION and MAX_ACK_PULSE_DURATION uSecs (refer @haba) if (lastCurrent>ackThreshold) { if (ackPulseStart==0) ackPulseStart=micros(); // leading edge of pulse detected @@ -290,7 +290,7 @@ void DCCWaveform::checkAck() { // detected trailing edge of pulse ackPulseDuration=micros()-ackPulseStart; - if (ackPulseDuration>1000 && ackPulseDuration<9000) { + if (ackPulseDuration>=MIN_ACK_PULSE_DURATION && ackPulseDuration<=MAX_ACK_PULSE_DURATION) { ackCheckDuration=millis()-ackCheckStart; ackDetected=true; ackPending=false; diff --git a/DCCWaveform.h b/DCCWaveform.h index 12cd96c..537a05b 100644 --- a/DCCWaveform.h +++ b/DCCWaveform.h @@ -24,7 +24,9 @@ const int POWER_SAMPLE_ON_WAIT = 100; const int POWER_SAMPLE_OFF_WAIT = 1000; const int POWER_SAMPLE_OVERLOAD_WAIT = 4000; - +const int MIN_ACK_PULSE_DURATION = 3000; +const int MAX_ACK_PULSE_DURATION = 8500; + const int PREAMBLE_BITS_MAIN = 20; const int PREAMBLE_BITS_PROG = 22;