mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2025-03-14 18:13:09 +01:00
First working
This commit is contained in:
parent
945af43500
commit
7e58165db9
21
DCCTimer.cpp
21
DCCTimer.cpp
@ -164,7 +164,7 @@ void DCCTimer::read(uint8_t word, uint8_t *mac, uint8_t offset) {
|
|||||||
#define TIMER1_B_PIN 12
|
#define TIMER1_B_PIN 12
|
||||||
#define TIMER1_C_PIN 13
|
#define TIMER1_C_PIN 13
|
||||||
//railcom timer facility
|
//railcom timer facility
|
||||||
// #define TIMER4_A_PIN 6
|
#define TIMER4_A_PIN 6
|
||||||
#define TIMER4_B_PIN 7
|
#define TIMER4_B_PIN 7
|
||||||
#define TIMER4_C_PIN 8
|
#define TIMER4_C_PIN 8
|
||||||
#else
|
#else
|
||||||
@ -178,17 +178,18 @@ void DCCTimer::read(uint8_t word, uint8_t *mac, uint8_t offset) {
|
|||||||
ADCSRA = (ADCSRA & 0b11111000) | 0b00000100; // speed up analogRead sample time
|
ADCSRA = (ADCSRA & 0b11111000) | 0b00000100; // speed up analogRead sample time
|
||||||
TCCR1A = 0;
|
TCCR1A = 0;
|
||||||
ICR1 = CLOCK_CYCLES;
|
ICR1 = CLOCK_CYCLES;
|
||||||
TCNT1 = 0;
|
|
||||||
TCCR1B = _BV(WGM13) | _BV(CS10); // Mode 8, clock select 1
|
TCCR1B = _BV(WGM13) | _BV(CS10); // Mode 8, clock select 1
|
||||||
TIMSK1 = _BV(TOIE1); // Enable Software interrupt
|
TIMSK1 = _BV(TOIE1); // Enable Software interrupt
|
||||||
|
TCNT1 = 0;
|
||||||
|
|
||||||
#if defined(TIMER4_A_PIN)
|
#if defined(TIMER4_A_PIN)
|
||||||
//railcom timer facility
|
//railcom timer facility
|
||||||
TCCR4A = 0;
|
TCCR4A = 0;
|
||||||
ICR4 = CLOCK_CYCLES;
|
ICR4 = CLOCK_CYCLES;
|
||||||
TCNT4 = CLOCK_CYCLES/2; // this timer fires half cycle after Timer 1
|
TCCR4B = _BV(WGM43) | _BV(CS40); // Mode 8, clock select 1
|
||||||
TCCR4B = _BV(WGM13) | _BV(CS10); // Mode 8, clock select 1
|
|
||||||
TIMSK4 = 0; // Disable Software interrupt
|
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
|
#endif
|
||||||
|
|
||||||
interrupts();
|
interrupts();
|
||||||
@ -218,7 +219,7 @@ void DCCTimer::read(uint8_t word, uint8_t *mac, uint8_t offset) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DCCTimer::setPWM(byte pin, bool high) {
|
void DCCTimer::setPWM(byte pin, bool high) {
|
||||||
byte val=high?1024:0;
|
uint16_t val=high?1024:0;
|
||||||
if (pin==TIMER1_A_PIN) {
|
if (pin==TIMER1_A_PIN) {
|
||||||
TCCR1A |= _BV(COM1A1);
|
TCCR1A |= _BV(COM1A1);
|
||||||
OCR1A= val;
|
OCR1A= val;
|
||||||
@ -235,19 +236,15 @@ void DCCTimer::read(uint8_t word, uint8_t *mac, uint8_t offset) {
|
|||||||
#endif
|
#endif
|
||||||
#ifdef TIMER4_A_PIN
|
#ifdef TIMER4_A_PIN
|
||||||
else if (pin==TIMER4_A_PIN) {
|
else if (pin==TIMER4_A_PIN) {
|
||||||
TCCR4A |= _BV(COM4A1); //??????????????????????????????????
|
TCCR4A |= _BV(COM4A1);
|
||||||
OCR4A= val;
|
OCR4A= val;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
#ifdef TIMER4_B_PIN
|
|
||||||
else if (pin==TIMER4_B_PIN) {
|
else if (pin==TIMER4_B_PIN) {
|
||||||
TCCR4B |= _BV(COM4B1); //??????????????????????????????????
|
TCCR4A |= _BV(COM4B1);
|
||||||
OCR4B= val;
|
OCR4B= val;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
#ifdef TIMER4_C_PIN
|
|
||||||
else if (pin==TIMER4_C_PIN) {
|
else if (pin==TIMER4_C_PIN) {
|
||||||
TCCR4C |= _BV(COM4C1); //??????????????????????????????????
|
TCCR4A |= _BV(COM4C1);
|
||||||
OCR4C= val;
|
OCR4C= val;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -210,12 +210,12 @@ void DCCWaveform::interrupt2() {
|
|||||||
state=WAVE_MID_1; // switch state to trigger LOW on next interrupt
|
state=WAVE_MID_1; // switch state to trigger LOW on next interrupt
|
||||||
remainingPreambles--;
|
remainingPreambles--;
|
||||||
// Railcom cutout
|
// Railcom cutout
|
||||||
if (remainingPreambles==requiredPreambles-2) motorDriver->setRailcomCutout(true);
|
if (remainingPreambles==(requiredPreambles-2)) motorDriver->setRailcomCutout(true);
|
||||||
else if (remainingPreambles==requiredPreambles-4) motorDriver->setRailcomCutout(false);
|
else if (remainingPreambles==(requiredPreambles-4)) motorDriver->setRailcomCutout(false);
|
||||||
|
|
||||||
// Update free memory diagnostic as we don't have anything else to do this time.
|
// 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.
|
// Allow for checkAck and its called functions using 22 bytes more.
|
||||||
updateMinimumFreeMemory(22);
|
else updateMinimumFreeMemory(22);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user