mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-22 23:56:13 +01:00
turn off signal pin during cutout as that might switch some H-bridges between high and low side
This commit is contained in:
parent
c9195f8035
commit
3f57c1210d
33
DCCTimer.cpp
33
DCCTimer.cpp
|
@ -227,6 +227,14 @@ void DCCTimer::read(uint8_t word, uint8_t *mac, uint8_t offset) {
|
||||||
TCNT4 = 0; // this timer fires half cycle after Timer 1 (no idea why /4 !)
|
TCNT4 = 0; // this timer fires half cycle after Timer 1 (no idea why /4 !)
|
||||||
#endif
|
#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);
|
||||||
|
#endif
|
||||||
interrupts();
|
interrupts();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,19 +261,38 @@ void DCCTimer::read(uint8_t word, uint8_t *mac, uint8_t offset) {
|
||||||
false;
|
false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DCCTimer::onoffPWM(byte pin, bool on) {
|
||||||
|
if (pin==TIMER1_A_PIN) {
|
||||||
|
if (on)
|
||||||
|
TCCR1A |= _BV(COM1A1);
|
||||||
|
else
|
||||||
|
TCCR1A &= ~(_BV(COM1A1));
|
||||||
|
}
|
||||||
|
else if (pin==TIMER1_B_PIN) {
|
||||||
|
if (on)
|
||||||
|
TCCR1A |= _BV(COM1B1);
|
||||||
|
else
|
||||||
|
TCCR1A &= ~(_BV(COM1B1));
|
||||||
|
}
|
||||||
|
#ifdef TIMER1_C_PIN
|
||||||
|
else if (pin==TIMER1_C_PIN) {
|
||||||
|
if (on)
|
||||||
|
TCCR1A |= _BV(COM1C1);
|
||||||
|
else
|
||||||
|
TCCR1A &= ~(_BV(COM1C1));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
void DCCTimer::setPWM(byte pin, bool high) {
|
void DCCTimer::setPWM(byte pin, bool high) {
|
||||||
uint16_t val=high?1024:0;
|
uint16_t val=high?1024:0;
|
||||||
if (pin==TIMER1_A_PIN) {
|
if (pin==TIMER1_A_PIN) {
|
||||||
TCCR1A |= _BV(COM1A1);
|
|
||||||
OCR1A= val;
|
OCR1A= val;
|
||||||
}
|
}
|
||||||
else if (pin==TIMER1_B_PIN) {
|
else if (pin==TIMER1_B_PIN) {
|
||||||
TCCR1A |= _BV(COM1B1);
|
|
||||||
OCR1B= val;
|
OCR1B= val;
|
||||||
}
|
}
|
||||||
#ifdef TIMER1_C_PIN
|
#ifdef TIMER1_C_PIN
|
||||||
else if (pin==TIMER1_C_PIN) {
|
else if (pin==TIMER1_C_PIN) {
|
||||||
TCCR1A |= _BV(COM1C1);
|
|
||||||
OCR1C= val;
|
OCR1C= val;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -11,6 +11,7 @@ class DCCTimer {
|
||||||
static bool isPWMPin(byte pin);
|
static bool isPWMPin(byte pin);
|
||||||
static bool isRailcomPin(byte pin);
|
static bool isRailcomPin(byte pin);
|
||||||
static void setPWM(byte pin, bool high);
|
static void setPWM(byte pin, bool high);
|
||||||
|
static void onoffPWM(byte pin, bool on);
|
||||||
#if (defined(TEENSYDUINO) && !defined(__IMXRT1062__))
|
#if (defined(TEENSYDUINO) && !defined(__IMXRT1062__))
|
||||||
static void read_mac(byte mac[6]);
|
static void read_mac(byte mac[6]);
|
||||||
static void read(uint8_t word, uint8_t *mac, uint8_t offset);
|
static void read(uint8_t word, uint8_t *mac, uint8_t offset);
|
||||||
|
|
|
@ -115,6 +115,7 @@ void MotorDriver::setBrake(bool on) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MotorDriver::setRailcomCutout(bool on) {
|
void MotorDriver::setRailcomCutout(bool on) {
|
||||||
|
DCCTimer::onoffPWM(signalPin,!on);
|
||||||
DCCTimer::setPWM(brakePin,on ^ invertBrake);
|
DCCTimer::setPWM(brakePin,on ^ invertBrake);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user