mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-22 23:56:13 +01:00
Tidying
Moved pre-delay into timeout so detect ACK ASAP
This commit is contained in:
parent
efc2197a7e
commit
76d7be0ef8
|
@ -140,6 +140,8 @@ bool DCCWaveform::interrupt1() {
|
|||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void DCCWaveform::interrupt2() {
|
||||
// set currentBit to be the next bit to be sent.
|
||||
|
||||
|
@ -209,29 +211,30 @@ bool DCCWaveform::getAck()
|
|||
|
||||
if (isMainTrack) return false; // cant do this on main track
|
||||
|
||||
while(packetPending) delay(1); // wait until transmitter has gont into reset packets
|
||||
delay(20); // time for enough resets
|
||||
while(packetPending) delay(1); // wait until transmitter has started transmitting the message
|
||||
unsigned long timeout=millis()+ACK_TIMEOUT;
|
||||
int maxCurrent=0;
|
||||
bool result=false;
|
||||
int upsamples=0;
|
||||
int downsamples=0;
|
||||
|
||||
// Monitor looking for a reading high enough to be an ack
|
||||
while(result==false && timeout>millis()) {
|
||||
upsamples++;
|
||||
delay(1);
|
||||
int current=analogRead(sensePin);
|
||||
maxCurrent=max(maxCurrent,current);
|
||||
result=current > ACK_MIN_PULSE;
|
||||
}
|
||||
|
||||
// Monitor current until ack signal dies back
|
||||
if (result) while( true) {
|
||||
downsamples++;
|
||||
delay(1);
|
||||
int current=analogRead(sensePin);
|
||||
maxCurrent=max(maxCurrent,current);
|
||||
if (current<= ACK_MAX_NOT_PULSE)break;
|
||||
if (current<= ACK_MAX_NOT_PULSE) break;
|
||||
}
|
||||
// The following DIAG is really useful as it can show how long and how far the
|
||||
// current changes during an ACK from the decoder.
|
||||
// DIAG(F("\nack=%d max=%d, up=%d, down=%d "),result,maxCurrent, upsamples,downsamples);
|
||||
// DIAG(F("\nack=%d max=%d, up=%d, down=%d "),result,maxCurrent, upsamples,downsamples);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ const int POWER_SAMPLE_OVERLOAD_WAIT=4000;
|
|||
|
||||
|
||||
// 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_MIN_PULSE = 50 ; // current above which a pulse is recognised
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user