1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2025-03-13 17:43:08 +01:00

First working

This commit is contained in:
Asbelos 2021-05-11 16:33:12 +01:00
parent 945af43500
commit 7e58165db9
2 changed files with 14 additions and 17 deletions

View File

@ -164,7 +164,7 @@ void DCCTimer::read(uint8_t word, uint8_t *mac, uint8_t offset) {
#define TIMER1_B_PIN 12
#define TIMER1_C_PIN 13
//railcom timer facility
// #define TIMER4_A_PIN 6
#define TIMER4_A_PIN 6
#define TIMER4_B_PIN 7
#define TIMER4_C_PIN 8
#else
@ -178,19 +178,20 @@ void DCCTimer::read(uint8_t word, uint8_t *mac, uint8_t offset) {
ADCSRA = (ADCSRA & 0b11111000) | 0b00000100; // speed up analogRead sample time
TCCR1A = 0;
ICR1 = CLOCK_CYCLES;
TCNT1 = 0;
TCCR1B = _BV(WGM13) | _BV(CS10); // Mode 8, clock select 1
TIMSK1 = _BV(TOIE1); // Enable Software interrupt
TCNT1 = 0;
#if defined(TIMER4_A_PIN)
//railcom timer facility
TCCR4A = 0;
ICR4 = CLOCK_CYCLES;
TCNT4 = CLOCK_CYCLES/2; // this timer fires half cycle after Timer 1
TCCR4B = _BV(WGM13) | _BV(CS10); // Mode 8, clock select 1
TCCR4B = _BV(WGM43) | _BV(CS40); // Mode 8, clock select 1
TIMSK4 = 0; // Disable Software interrupt
delayMicroseconds(DCC_SIGNAL_TIME/2);
TCNT4 = 0; // this timer fires half cycle after Timer 1 (no idea why /4 !)
#endif
interrupts();
}
@ -208,7 +209,7 @@ void DCCTimer::read(uint8_t word, uint8_t *mac, uint8_t offset) {
}
// Alternative pin manipulation via PWM control.
bool DCCTimer::isRailcomPin(byte pin) {
return
return
#ifdef TIMER4_A_PIN
pin==TIMER4_A_PIN ||
pin==TIMER4_B_PIN ||
@ -218,7 +219,7 @@ void DCCTimer::read(uint8_t word, uint8_t *mac, uint8_t offset) {
}
void DCCTimer::setPWM(byte pin, bool high) {
byte val=high?1024:0;
uint16_t val=high?1024:0;
if (pin==TIMER1_A_PIN) {
TCCR1A |= _BV(COM1A1);
OCR1A= val;
@ -235,19 +236,15 @@ void DCCTimer::read(uint8_t word, uint8_t *mac, uint8_t offset) {
#endif
#ifdef TIMER4_A_PIN
else if (pin==TIMER4_A_PIN) {
TCCR4A |= _BV(COM4A1); //??????????????????????????????????
TCCR4A |= _BV(COM4A1);
OCR4A= val;
}
#endif
#ifdef TIMER4_B_PIN
else if (pin==TIMER4_B_PIN) {
TCCR4B |= _BV(COM4B1); //??????????????????????????????????
TCCR4A |= _BV(COM4B1);
OCR4B= val;
}
#endif
#ifdef TIMER4_C_PIN
else if (pin==TIMER4_C_PIN) {
TCCR4C |= _BV(COM4C1); //??????????????????????????????????
TCCR4A |= _BV(COM4C1);
OCR4C= val;
}
#endif

View File

@ -210,12 +210,12 @@ void DCCWaveform::interrupt2() {
state=WAVE_MID_1; // switch state to trigger LOW on next interrupt
remainingPreambles--;
// Railcom cutout
if (remainingPreambles==requiredPreambles-2) motorDriver->setRailcomCutout(true);
else if (remainingPreambles==requiredPreambles-4) motorDriver->setRailcomCutout(false);
if (remainingPreambles==(requiredPreambles-2)) motorDriver->setRailcomCutout(true);
else if (remainingPreambles==(requiredPreambles-4)) motorDriver->setRailcomCutout(false);
// Update free memory diagnostic as we don't have anything else to do this time.
// Allow for checkAck and its called functions using 22 bytes more.
updateMinimumFreeMemory(22);
else updateMinimumFreeMemory(22);
return;
}