mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2025-02-16 22:19:14 +01:00
Rauilcom cutout
This commit is contained in:
parent
76d7be0ef8
commit
0b9f4cf574
@ -59,11 +59,19 @@ DCCWaveform::DCCWaveform(byte powerPinNo, byte directionPinNo, byte sensePinNo,
|
||||
bytes_sent=0;
|
||||
bits_sent=0;
|
||||
nextSampleDue=0;
|
||||
|
||||
}
|
||||
void DCCWaveform::beginTrack() {
|
||||
pinMode2f(powerPin,OUTPUT);
|
||||
pinMode2f(directionPin,OUTPUT);
|
||||
pinMode(sensePin,INPUT);
|
||||
|
||||
if (isMainTrack && RAILCOM_CUTOUT) {
|
||||
railcomBrakePin=Arduino_to_GPIO_pin(RAILCOM_BRAKE_PIN);
|
||||
pinMode2f(railcomBrakePin, OUTPUT);
|
||||
digitalWrite2f(railcomBrakePin, LOW);
|
||||
}
|
||||
|
||||
setPowerMode(POWERMODE::ON);
|
||||
DIAG(F("\nTrack started sensePin=%d\n"),sensePin);
|
||||
}
|
||||
@ -121,20 +129,23 @@ bool DCCWaveform::interrupt1() {
|
||||
switch (state) {
|
||||
case 0: // start of bit transmission
|
||||
digitalWrite2f(directionPin, HIGH);
|
||||
checkRailcom();
|
||||
state = 1;
|
||||
return true; // must call interrupt2
|
||||
return true; // must call interrupt2 to set currentBit
|
||||
|
||||
case 1: // 58Ms after case 0
|
||||
case 1: // 58us after case 0
|
||||
if (currentBit) {
|
||||
digitalWrite2f(directionPin, LOW);
|
||||
state = 0;
|
||||
}
|
||||
else state = 2;
|
||||
break;
|
||||
case 2: digitalWrite2f(directionPin, LOW);
|
||||
case 2: // 116us after case 0
|
||||
digitalWrite2f(directionPin, LOW);
|
||||
state = 3;
|
||||
break;
|
||||
case 3: state = 0;
|
||||
case 3: // finished sending zero bit
|
||||
state = 0;
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
@ -187,6 +198,17 @@ void DCCWaveform::interrupt2() {
|
||||
}
|
||||
}
|
||||
|
||||
void DCCWaveform::checkRailcom() {
|
||||
if (isMainTrack && RAILCOM_CUTOUT) {
|
||||
byte preamble=PREAMBLE_BITS_MAIN - remainingPreambles;
|
||||
if (preamble == RAILCOM_PREAMBLES_BEFORE_CUTOUT) {
|
||||
digitalWrite2f(railcomBrakePin,HIGH);
|
||||
}
|
||||
else if (preamble== RAILCOM_PREAMBLES_BEFORE_CUTOUT+RAILCOM_PREAMBLES_SKIPPED_IN_CUTOUT) {
|
||||
digitalWrite2f(railcomBrakePin,LOW);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Wait until there is no packet pending, then make this pending
|
||||
void DCCWaveform::schedulePacket(const byte buffer[], byte byteCount, byte repeats) {
|
||||
|
@ -19,9 +19,17 @@ const int ACK_TIMEOUT = 25 ; // millis getAck is prepared to wait for a signa
|
||||
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 PREAMBLE_BITS_MAIN=16;
|
||||
const int PREAMBLE_BITS_MAIN = 20;
|
||||
const int PREAMBLE_BITS_PROG = 22;
|
||||
|
||||
// Railcom settings
|
||||
const bool RAILCOM_CUTOUT = true;
|
||||
const byte RAILCOM_PREAMBLES_BEFORE_CUTOUT = 1; // how far into the preamble do we cutout
|
||||
const byte RAILCOM_PREAMBLES_SKIPPED_IN_CUTOUT = 5;
|
||||
const byte RAILCOM_BRAKE_PIN = 9;
|
||||
|
||||
|
||||
|
||||
const byte MAX_PACKET_SIZE = 12;
|
||||
// NOTE: static functions are used for the overall controller, then
|
||||
// one instance is created for each track.
|
||||
@ -57,7 +65,7 @@ class DCCWaveform {
|
||||
bool interrupt1();
|
||||
void interrupt2();
|
||||
|
||||
POWERMODE powerMode;
|
||||
bool isMainTrack;
|
||||
|
||||
// Transmission controller
|
||||
byte transmitPacket[MAX_PACKET_SIZE]; // packet being transmitted
|
||||
@ -66,24 +74,24 @@ class DCCWaveform {
|
||||
byte remainingPreambles;
|
||||
byte requiredPreambles;
|
||||
bool currentBit; // bit to be transmitted
|
||||
|
||||
byte bits_sent; // 0-8 (yes 9 bits) sent for current byte
|
||||
byte bytes_sent; // number of bytes sent from transmitPacket
|
||||
|
||||
byte state; // wave generator state machine
|
||||
void checkRailcom();
|
||||
|
||||
byte pendingPacket[MAX_PACKET_SIZE];
|
||||
byte pendingLength;
|
||||
byte pendingRepeats;
|
||||
|
||||
// Hardware pins
|
||||
// Hardware fast pins
|
||||
GPIO_pin_t directionPin;
|
||||
GPIO_pin_t powerPin;
|
||||
GPIO_pin_t railcomBrakePin;
|
||||
|
||||
// current sampling
|
||||
bool isMainTrack;
|
||||
POWERMODE powerMode;
|
||||
byte sensePin;
|
||||
unsigned long nextSampleDue;
|
||||
int ackBaseCurrent;
|
||||
|
||||
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user