mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-30 03:26:13 +01:00
ack pulse length configurable from diag
This commit is contained in:
parent
3faa48476c
commit
edc39e7342
|
@ -49,8 +49,8 @@ const int HASH_KEYWORD_PROGBOOST = -6353;
|
||||||
const int HASH_KEYWORD_EEPROM = -7168;
|
const int HASH_KEYWORD_EEPROM = -7168;
|
||||||
const int HASH_KEYWORD_LIMIT = 27413;
|
const int HASH_KEYWORD_LIMIT = 27413;
|
||||||
const int HASH_KEYWORD_ETHERNET = -30767;
|
const int HASH_KEYWORD_ETHERNET = -30767;
|
||||||
//const int HASH_KEYWORD_MAX = 16244;
|
const int HASH_KEYWORD_MAX = 16244;
|
||||||
//const int HASH_KEYWORD_MIN = 15978;
|
const int HASH_KEYWORD_MIN = 15978;
|
||||||
|
|
||||||
int DCCEXParser::stashP[MAX_PARAMS];
|
int DCCEXParser::stashP[MAX_PARAMS];
|
||||||
bool DCCEXParser::stashBusy;
|
bool DCCEXParser::stashBusy;
|
||||||
|
@ -596,10 +596,18 @@ bool DCCEXParser::parseD(Print *stream, int params, int p[])
|
||||||
StringFormatter::send(stream, F("\nFree memory=%d\n"), freeMemory());
|
StringFormatter::send(stream, F("\nFree memory=%d\n"), freeMemory());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HASH_KEYWORD_ACK: // <D ACK ON/OFF>
|
case HASH_KEYWORD_ACK: // <D ACK ON/OFF> <D ACK [LIMIT|MIN|MAX] Value>
|
||||||
if (params >= 2 && p[1] == HASH_KEYWORD_LIMIT) {
|
if (params >= 3) {
|
||||||
|
if (p[1] == HASH_KEYWORD_LIMIT) {
|
||||||
DCCWaveform::progTrack.setAckLimit(p[2]);
|
DCCWaveform::progTrack.setAckLimit(p[2]);
|
||||||
StringFormatter::send(stream, F("\nAck limit=%dmA\n"), p[2]);
|
StringFormatter::send(stream, F("\nAck limit=%dmA\n"), p[2]);
|
||||||
|
} else if (p[1] == HASH_KEYWORD_MIN) {
|
||||||
|
DCCWaveform::progTrack.setMinAckPulseDuration(p[2]);
|
||||||
|
StringFormatter::send(stream, F("\nAck min=%dus\n"), p[2]);
|
||||||
|
} else if (p[1] == HASH_KEYWORD_MAX) {
|
||||||
|
DCCWaveform::progTrack.setMaxAckPulseDuration(p[2]);
|
||||||
|
StringFormatter::send(stream, F("\nAck max=%dus\n"), p[2]);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
StringFormatter::send(stream, F("\nAck diag %S\n"), onOff ? F("on") : F("off"));
|
StringFormatter::send(stream, F("\nAck diag %S\n"), onOff ? F("on") : F("off"));
|
||||||
Diag::ACK = onOff;
|
Diag::ACK = onOff;
|
||||||
|
@ -630,8 +638,8 @@ bool DCCEXParser::parseD(Print *stream, int params, int p[])
|
||||||
DCC::setProgTrackBoost(true);
|
DCC::setProgTrackBoost(true);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case HASH_KEYWORD_EEPROM:
|
case HASH_KEYWORD_EEPROM: // <D EEPROM NumEntries>
|
||||||
if (params >= 1)
|
if (params >= 2)
|
||||||
EEStore::dump(p[1]);
|
EEStore::dump(p[1]);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
|
@ -298,7 +298,7 @@ void DCCWaveform::setAckBaseline() {
|
||||||
if (Diag::ACK) DIAG(F("\nACK baseline=%d/%dmA Threshold=%d/%dmA Duration: %dus <= pulse <= %dus"),
|
if (Diag::ACK) DIAG(F("\nACK baseline=%d/%dmA Threshold=%d/%dmA Duration: %dus <= pulse <= %dus"),
|
||||||
baseline,motorDriver->raw2mA(baseline),
|
baseline,motorDriver->raw2mA(baseline),
|
||||||
ackThreshold,motorDriver->raw2mA(ackThreshold),
|
ackThreshold,motorDriver->raw2mA(ackThreshold),
|
||||||
MIN_ACK_PULSE_DURATION, MAX_ACK_PULSE_DURATION);
|
minAckPulseDuration, maxAckPulseDuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DCCWaveform::setAckPending() {
|
void DCCWaveform::setAckPending() {
|
||||||
|
@ -330,7 +330,7 @@ void DCCWaveform::checkAck() {
|
||||||
|
|
||||||
lastCurrent=motorDriver->getCurrentRaw();
|
lastCurrent=motorDriver->getCurrentRaw();
|
||||||
if (lastCurrent > ackMaxCurrent) ackMaxCurrent=lastCurrent;
|
if (lastCurrent > ackMaxCurrent) ackMaxCurrent=lastCurrent;
|
||||||
// An ACK is a pulse lasting between MIN_ACK_PULSE_DURATION and MAX_ACK_PULSE_DURATION uSecs (refer @haba)
|
// An ACK is a pulse lasting between minAckPulseDuration and maxAckPulseDuration uSecs (refer @haba)
|
||||||
|
|
||||||
if (lastCurrent>ackThreshold) {
|
if (lastCurrent>ackThreshold) {
|
||||||
if (ackPulseStart==0) ackPulseStart=micros(); // leading edge of pulse detected
|
if (ackPulseStart==0) ackPulseStart=micros(); // leading edge of pulse detected
|
||||||
|
@ -343,7 +343,7 @@ void DCCWaveform::checkAck() {
|
||||||
// detected trailing edge of pulse
|
// detected trailing edge of pulse
|
||||||
ackPulseDuration=micros()-ackPulseStart;
|
ackPulseDuration=micros()-ackPulseStart;
|
||||||
|
|
||||||
if (ackPulseDuration>=MIN_ACK_PULSE_DURATION && ackPulseDuration<=MAX_ACK_PULSE_DURATION) {
|
if (ackPulseDuration>=minAckPulseDuration && ackPulseDuration<=maxAckPulseDuration) {
|
||||||
ackCheckDuration=millis()-ackCheckStart;
|
ackCheckDuration=millis()-ackCheckStart;
|
||||||
ackDetected=true;
|
ackDetected=true;
|
||||||
ackPending=false;
|
ackPending=false;
|
||||||
|
|
|
@ -27,10 +27,6 @@ const int POWER_SAMPLE_ON_WAIT = 100;
|
||||||
const int POWER_SAMPLE_OFF_WAIT = 1000;
|
const int POWER_SAMPLE_OFF_WAIT = 1000;
|
||||||
const int POWER_SAMPLE_OVERLOAD_WAIT = 20;
|
const int POWER_SAMPLE_OVERLOAD_WAIT = 20;
|
||||||
|
|
||||||
// Ack time thresholds. Unit: microseconds
|
|
||||||
const int MIN_ACK_PULSE_DURATION = 2000;
|
|
||||||
const int MAX_ACK_PULSE_DURATION = 8500;
|
|
||||||
|
|
||||||
// Number of preamble bits.
|
// Number of preamble bits.
|
||||||
const int PREAMBLE_BITS_MAIN = 16;
|
const int PREAMBLE_BITS_MAIN = 16;
|
||||||
const int PREAMBLE_BITS_PROG = 22;
|
const int PREAMBLE_BITS_PROG = 22;
|
||||||
|
@ -79,6 +75,12 @@ class DCCWaveform {
|
||||||
inline void setAckLimit(int mA) {
|
inline void setAckLimit(int mA) {
|
||||||
ackLimitmA = mA;
|
ackLimitmA = mA;
|
||||||
}
|
}
|
||||||
|
inline void setMinAckPulseDuration(unsigned int i) {
|
||||||
|
minAckPulseDuration = i;
|
||||||
|
}
|
||||||
|
inline void setMaxAckPulseDuration(unsigned int i) {
|
||||||
|
maxAckPulseDuration = i;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static VirtualTimer * interruptTimer;
|
static VirtualTimer * interruptTimer;
|
||||||
|
@ -129,5 +131,8 @@ class DCCWaveform {
|
||||||
unsigned int ackPulseDuration; // micros
|
unsigned int ackPulseDuration; // micros
|
||||||
unsigned long ackPulseStart; // micros
|
unsigned long ackPulseStart; // micros
|
||||||
|
|
||||||
|
unsigned int minAckPulseDuration = 2000; // micros
|
||||||
|
unsigned int maxAckPulseDuration = 8500; // micros
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user