1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-27 01:56:14 +01:00
Moved pre-delay into timeout so detect ACK ASAP
This commit is contained in:
Asbelos 2020-05-24 09:07:54 +01:00
parent efc2197a7e
commit 76d7be0ef8
2 changed files with 10 additions and 7 deletions

View File

@ -140,6 +140,8 @@ bool DCCWaveform::interrupt1() {
return false; return false;
} }
void DCCWaveform::interrupt2() { void DCCWaveform::interrupt2() {
// set currentBit to be the next bit to be sent. // set currentBit to be the next bit to be sent.
@ -209,23 +211,24 @@ bool DCCWaveform::getAck()
if (isMainTrack) return false; // cant do this on main track if (isMainTrack) return false; // cant do this on main track
while(packetPending) delay(1); // wait until transmitter has gont into reset packets while(packetPending) delay(1); // wait until transmitter has started transmitting the message
delay(20); // time for enough resets
unsigned long timeout=millis()+ACK_TIMEOUT; unsigned long timeout=millis()+ACK_TIMEOUT;
int maxCurrent=0; int maxCurrent=0;
bool result=false; bool result=false;
int upsamples=0; int upsamples=0;
int downsamples=0; int downsamples=0;
// Monitor looking for a reading high enough to be an ack
while(result==false && timeout>millis()) { while(result==false && timeout>millis()) {
upsamples++; upsamples++;
delay(1);
int current=analogRead(sensePin); int current=analogRead(sensePin);
maxCurrent=max(maxCurrent,current); maxCurrent=max(maxCurrent,current);
result=current > ACK_MIN_PULSE; result=current > ACK_MIN_PULSE;
} }
// Monitor current until ack signal dies back
if (result) while( true) { if (result) while( true) {
downsamples++; downsamples++;
delay(1);
int current=analogRead(sensePin); int current=analogRead(sensePin);
maxCurrent=max(maxCurrent,current); maxCurrent=max(maxCurrent,current);
if (current<= ACK_MAX_NOT_PULSE) break; if (current<= ACK_MAX_NOT_PULSE) break;

View File

@ -15,7 +15,7 @@ const int POWER_SAMPLE_OVERLOAD_WAIT=4000;
// ACK current analogRead values (vary depending on motor shield and cpu voltage) // ACK current analogRead values (vary depending on motor shield and cpu voltage)
const int ACK_TIMEOUT = 5 ; // millis getAck is prepared to wait for a signal const int ACK_TIMEOUT = 25 ; // millis getAck is prepared to wait for a signal
const int ACK_MAX_NOT_PULSE = 10 ; // current below which this is NOT a pulse any more const int ACK_MAX_NOT_PULSE = 10 ; // current below which this is NOT a pulse any more
const int ACK_MIN_PULSE = 50 ; // current above which a pulse is recognised const int ACK_MIN_PULSE = 50 ; // current above which a pulse is recognised