measure mark time if > 2 x then x ..= mark / 3 if < 2 x then x ..= mark measure space time if > 15 x if marking time < 15 x send letter else send marking time / 50 words ----------------------------- if marking clear idlebit if done marking set marking false do mark average zero space time (clock) else inc mark time else if start marking set marking true zero mark time (clock) else inc space time if > mark zero space time inc idling if idling > 50 set idlebit ------------------------------- set idle =pbx set keyin =pbx def marking =Rxx def clock =Rxx def idling =Rxx clocking: cp marking breq spacing mark: sbic portb,keyin rjmp count clr marking ; end of mark asr clock asr byout add byout,clock clr clock ret space: sbis portb,keyin rjmp idling cbi portb,idle ; end of space ldi marking,1 clr clock ret idling: cpi clock,byout brne,count clr clock ; space is dit long inc idling cpi idling,50 brne count dec idling ; space is word long sbic portb,idle return count: inc clock breq pc+2 dec clock ret ------------------------- slow filter x' = 255/256 x + 1/256 a x' = (x - 1/256 x) + 1/256 a xl = xl - xh xh = xh - 0 - borrow xl = xl + a hx = xh + 0 + carry ldi b,0 sub xl,xh sbc xh,b add xl,a adc xh,b po' = (1-r) po + r pi where r = 1/256 ldi b,0 sub c,po sbc po,b add c,pi adc po,b x' = x + 1/256 a - 1/256 x x' = x + 1/256 (a - x) ah = ah - xh xh = xh - 0 - borrow xl = xl + ah xh = xh + 0 + carry (refactoring is no faster and destroys a) ------------- perl simulation indicates time constant is 257 iterations or about 4 sec at tv rates ($xh, $xl) = (0, 0); $goal = 255 * (1 - exp(-1)); # value at t = tau for (1..300) { $ah = int(rand(256)); $ah = 255; $xl = $xl - $xh; if ($xl<0) {$xl += 256; $xh--;} $xl = $xl + $ah; if ($xl>255) {$xl -= 256; $xh++;} $met = ($xh >= $goal) ? "***" : ""; $i++; print "$i\t$ah\t-->\t$xh $xl\t$met\n"; } ------------------ cross-connected filters (hmm, need isolation of multiple inputs) propose si (secondary input) | | ------- | | | | +---- pi | | | | | +-- po | | | | | +---- si | | | | | | | | ------- | | ------- | | | | | +-- pi | | | | | +---- po | | | | | | +-- si | | | | | | | | ------- | | ------- | | | | +---- pi | | | | | +-- po | | | | | +---- si | | | | | | | | ------- | | ------- | | | | | +-- pi | | | | | +---- po | | | | | | +-- si | | | | | | | | ------- ah, but if I read and wrote from the same pin, px, then I could have two px on each part gaining isolation without increased pin count | ------- | | | +-- px | | | | +-- px | | | | | | ------- | ------- | | | +-- px | | | | +-- px | | | | | | ------- | ------- | | | +-- px | | | | +-- px | | | | | | ------- one useful filter recurrence relation for pins px (1 & 2) would be px1' = px2' = filter (px1 + px2) another interesting relation would be px1' = filter (px2) px2' = filter (px1) here each application of filter retains its own state so there is no internal crosstalk between the two signals passing in opposite directions -------------- bynase3 outputs (read every call to byop) px1, px2 inputs (set every 255th call to byop) px1, px2 filtered inputs (adjusted every 255th call to byop) px1f, px2f px1 the two different filters mentioned above would be coded as follows main: mov px1,px1f add px1,px2f ; sum filter outputs, not inputs asr px1 mov px2,px1 ; same output on px2 as px1 rjmp main main: mov px1,px2f mov px2,px1f rjmp main