// DCC Receive Routine//// Howto: uses two interrupts: a rising edge in DCC polarity triggers INTx// in INTx handler, Timer0 CompareB with a delay of 80us is started.// On Timer0 CompareB Match the level of DCC is evaluated and// parsed.//// |<-----116us----->|//// DCC 1: _________XXXXXXXXX_________XXXXXXXXX_________// ^-INTx// |----87us--->|// ^Timer-INT: reads zero//// DCC 0: _________XXXXXXXXXXXXXXXXXX__________________// ^-INTx// |----------->|// ^Timer-INT: reads one//// new DCC Receive Routine without Timer0 ........................................................//// Howto: uses only one interrupt at the rising or falling edge of the DCC signal// The time between two edges is measured to determine the bit value// Synchronising to the edge of the first part of a bit is done after recognizing the start bit// During synchronizing each part of a bit is detected ( Interruptmode 'change' )
// Bit evaluation without Timer 0 ------------------------------ uint8_t DccBitVal; static int8_t bit1, bit2 ; static unsigned int lastMicros = 0; static byte halfBit, DCC_IrqRunning, preambleBitCount; unsigned int actMicros, bitMicros; #ifdef ALLOW_NESTED_IRQ if (DCC_IrqRunning) { // nested DCC IRQ - obviously there are glitches // ignore this interrupt and increment glitchcounter CLR_TP3; #ifdef DCC_DEBUG DccProcState.NestedIrqCount++; #endif SET_TP3; return; //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> abort IRQ } #endif actMicros = micros(); bitMicros = actMicros-lastMicros;
void DCC_Decoder::DCC_Interrupt(){ unsigned long ms = micros(); gInterruptTime[gInterruptTimeIndex] = ms - gInterruptMicros; gInterruptMicros = ms; gInterruptChaos += gInterruptTimeIndex; gInterruptTimeIndex ^= 0x01; }
3 Leds op poorten 1, 3 en 4 met mode 8 (flikkeren) en adressen 1, 2 en 3 en grenswaardes van 10 en 200.In config mode werken ze alle drie met de T-functie.In normal mode werkt alleen poort 1.De commando's voor de poorten 3 en 4 ziet Mardec wel en laat dat ook zien in Putty.
const byte pwmports[] = {0,1,0,1,1,0,0,0,0,1,0, 0, 0, 0, 0, 0, 0}; //valid pwm poort 1,3,4,9=pin 3,5,6,11// port= 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Dcc.init(MAN_ID_DIY, VERSION_ID, FLAGS_OUTPUT_ADDRESS_MODE | FLAGS_DCC_ACCESSORY_DECODER, CV_MULTIFUNCTION_EXTENDED_ADDRESS_MSB);
TCCR0A &= ~((1<<WGM01)|(1<<WGM00));
maar ik snap niet hoe 1, 3, 4, 9 zich vertaalt naar 3, 5, 6, 11
const byte p[MAXTERM] = {0,3,4,5,6,7,8,9,10,11,12,14,15,16,17,18,19};// port= 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
const byte pwmports[] = {0,1,0,1,1,0,0,1,1,1,0, 0, 0, 0, 0, 0, 0}; //valid pwm poort 1,3,4,9=pin 3,5,6,11// port= 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16