From 0c9b2d962bcfa30fd6f1f9497ec0615c521f8eeb Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Fri, 3 Jul 2020 16:03:10 +0200 Subject: [PATCH] Correct place for checkAck() so ack pulse lenth is correct --- DCCWaveform.cpp | 14 +++++--------- DCCWaveform.h | 2 +- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/DCCWaveform.cpp b/DCCWaveform.cpp index f9e45b5..c696575 100644 --- a/DCCWaveform.cpp +++ b/DCCWaveform.cpp @@ -135,8 +135,9 @@ bool DCCWaveform::interrupt1() { state = 0; break; } + // ACK check is prog track only + if (ackPending) checkAck(); return false; - } @@ -185,11 +186,6 @@ void DCCWaveform::interrupt2() { } } } - - // ACK check is prog track only and will only be checked if bits_sent=4 ... - // This means only once per 9-bit-byte AND never at the same cycle as the - // relatively expensive packet change code just above. - if (ackPending && bits_sent==4) checkAck(); } @@ -265,13 +261,13 @@ void DCCWaveform::checkAck() { // detected trailing edge of pulse ackPulseDuration=micros()-ackPulseStart; - - if (ackPulseDuration>1000 && ackPulseDuration<9000) { + + if (ackPulseDuration>3000 && ackPulseDuration<8500) { ackCheckDuration=millis()-ackCheckStart; ackDetected=true; ackPending=false; transmitRepeats=0; // shortcut remaining repeat packets return; // we have a genuine ACK result - } + } ackPulseStart=0; // We have detected a too-short or too-long pulse so ignore and wait for next leading edge } diff --git a/DCCWaveform.h b/DCCWaveform.h index 5c6cd15..fff524d 100644 --- a/DCCWaveform.h +++ b/DCCWaveform.h @@ -2,7 +2,7 @@ #define DCCWaveform_h -const int POWER_SAMPLE_MAX = 300; +const int POWER_SAMPLE_MAX = 1000; // XXX only until correct short detection on prog rail is implemented const int POWER_SAMPLE_ON_WAIT = 100; const int POWER_SAMPLE_OFF_WAIT = 1000; const int POWER_SAMPLE_OVERLOAD_WAIT = 4000;