1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2025-02-19 23:46:02 +01:00

only set TCCR1A register for pins that are signal pins, done by calling setRailcomCutout() at right place instead of doing it for all pins in the timer code

This commit is contained in:
Harald Barth 2022-07-03 10:22:30 +02:00
parent 3f57c1210d
commit ce892974ab
2 changed files with 12 additions and 17 deletions

View File

@ -217,23 +217,14 @@ void DCCTimer::read(uint8_t word, uint8_t *mac, uint8_t offset) {
TIMSK1 = _BV(TOIE1); // Enable Software interrupt
TCNT1 = 0;
#if defined(TIMER4_A_PIN)
//railcom timer facility
TCCR4A = 0;
ICR4 = CLOCK_CYCLES;
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
// turn on PWM for the pins here (instead of in setPWM())
// only needed if RailCom is inactive as otherwise RailCom
// takes care of that. Does not hurt tough
onoffPWM(TIMER1_A_PIN, true);
onoffPWM(TIMER1_B_PIN, true);
#ifdef TIMER1_C_PIN
onoffPWM(TIMER1_C_PIN, true);
#if defined(TIMER4_A_PIN)
//railcom timer facility
TCCR4A = 0;
ICR4 = CLOCK_CYCLES;
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();
}

View File

@ -56,6 +56,10 @@ MotorDriver::MotorDriver(byte power_pin, byte signal_pin, byte signal_pin2, int8
setBrake(false);
}
else brakePin=UNUSED_PIN;
// Initiate state of railcom cutout as off. This must be done
// independent of if railcom is used later or not.
setRailcomCutout(false);
currentPin=current_pin;
if (currentPin!=UNUSED_PIN) {