Hello people,
Can somebody please explain me the logic/algorithm behind this code. I could figure out a couple things but wasn't able to connect them.
This section is for BiPhase encoded data capture:
void biphase_capture(void) { #ifdef DEBUG_EMDB409 sbi(PORTA,DEC5); #endif uint8_t y,delta; uint16_t capt; uint16_t icr = ICR1; TCCR1B ^= (1<<ICES1); // Switchover of sensitive ICP edge capt = icr - last_capture; last_capture = icr; // counter1 is now free-running if(capt>255) delta = 255; else delta = (uint8_t)capt; if (debug_mode > 2) { if(debug_mode==4) store_pulse_lenght(delta); else { store_pulse(delta); return; } } y = 0; delta += halfDataRate >> (TOLERANCE_SHIFT); // dynamic resolution (dependent on datarate) !!!!! >> 2 delta -= halfDataRate; // always subtract datarate/2 if (delta > halfDataRate) { // when longer than that, try to subtract once more y++; delta -= halfDataRate; } if (delta > halfDataRate) { // check overflow of counter and range // this check is also dynamic, depends on current datarate // the faster datarate the more precise must the signal be if (last_valid == 0) { store_bit(bit_pos^1, 0); // rtf feature store_bit ( 0, 1); // store bad bit last_valid = 1; } bit_pos = 0; } else { if (y) { store_bit(1, 0); bit_pos = 0; last_valid = 0; } else { if (bit_pos++) { store_bit(0, 0); bit_pos = 0; last_valid = 0; } } } #ifdef DEBUG_EMDB409 cbi(PORTA,DEC5); #endif
This section is for Manchester encoded data capture:
void manchester_capture(void) { #ifdef DEBUG_EMDB409 sbi(PORTA,DEC5); //debug port set #endif uint8_t y, delta; uint16_t capt; uint16_t icr = ICR1; // T/C 1 input capture register edge = TCCR1B; //Timer/Counter 1 Control and Status Register TCCR1B = edge ^ (1<<ICES1); //T/C 1 Control and Status Register Bit // Switchover of sensitive ICP edge capt = icr - last_capture; last_capture = icr; // counter1 is now free-running if(capt>255) delta = 255; else delta = (uint8_t)capt; if (debug_mode > 2) { if(debug_mode==4) store_pulse_lenght(delta); else { store_pulse(delta); return; } } if ((first != 0) && (forward_link_type == EM4150)) { // according to the first pulse length, manchester decoder is synchronized first = 0; last_bit = 0; capt = maxCaptureTimeLow + icr; if (capt < (uint16_t)(2*halfDataRate) ) //with setup latency of about 12 RF clocks bit_pos = last_bit = 1; else store_bit(last_bit, 0); return; } y = 0; delta += halfDataRate >> 2; // dynamic resolution (dependent on datarate) // delta += (halfDataRate >> TOLERANCE_SHIFT); // dynamic resolution (dependent on datarate) delta -= halfDataRate; // always subtract datarate/2 if (delta > halfDataRate) { // when longer than that, try to subtract once more y++; delta -= halfDataRate; } if ((delta<<1) > halfDataRate) { // check overflow of counter and range // this check is also dynamic, depends on current datarate // the faster datarate the more precise must the signal be if(last_valid == 0) { last_bit = ((~edge)>>ICES1)&1; // rtf feature 4026 store_bit(last_bit, 0); // rtf feature 4026 store_bit ( 1, 1 ); // store bad bit last_valid = 1; bit_pos++; // change! 4026 } last_bit = 0; } else { if (y) { last_bit = ((~edge)>>ICES1)&1; store_bit(last_bit, 0); last_valid = 0; bit_pos = 0; } else { if (bit_pos++) { store_bit(last_bit, 0); bit_pos = 0; last_valid = 0; } } } #ifdef DEBUG_EMDB409 cbi(PORTA,DEC5); #endif }
Really appreciate if someone could give me any input.
Thanks
AM