Hello,
This question has nothing to do with the normal questions based around _delay_us() and friends!
Instead, I am trying to use a mega168 to really delay a pulse train in the microsecond range (20-50us). Read "delay line"
Ideally, I want to work with an input signal of 3MHz, but an AVR can't cope, so I've divided down my input signal to 500kHz. Dividing down the input more to say 250kHz is not a problem.
My tactic was to poll for input changes, stick them in a buffer, then some time later bang the square wave out on another pin:
// Put debugging symbols on Release mode to see why the NOP()S are where they are. // We want a duty-cycle of the same as the input at ALL times. All paths must take equal time. cli(); while (1){ uint8_t& myb = buf[i++]; uint8_t in_state = PINC & IN_HIGH; if (in_state){ myb = 1; }else{ myb = 0; } if (buf[c++]){ if (in_state){ NOP();NOP(); } PORTC |= OUT_HIGH; }else{ NOP(); PORTC &= ~OUT_HIGH; } };
This works. The NOPs are there to keep the timing consistent (in the Sim)
However, the output has jitter, even at 250kHz. I am surprised by this. Interrupts are off as you can see. I clearly see up to 2uS of jitter on the 'scope, and this won't do once the input is multiplied back up in frequency :(
Has anyone any tips on how to do this jitter free? I just want to exactly delay the pulse train: no artifacts!
Thanks!