Dear PICers, Combining Ray Gardiner's ideas with Bob Ammerman's clever ideas, we have a frequency-locked-loop (FLL). Basic idea: Count both input pulses and output pulses. Try to force both to be equal. [tangential rambling] I've been told there used to be a guy at electric power stations who watched 2 clocks. The "reference" clock always told the exact time ( traceable to the National Bureau of Standards, which has since been renamed NIST). The other was a simple, cheap electric clock running off the power lines from his station. It would run fast or slow when the power grid ran above or below the precisely 60 Hz. The guy would tweak the generators at his plant to try to get both clocks to read the same time (more or less). [/tangential rambling] * Output pulse generator, generate a pulse every P (variable period) cycles. * Input pulse counter: every input pulse, add Ki (constant) to a 24 bit error counter. * Output pulse counter: every output pulse, subtract Ko (constant) from that 24 bit error counter. * Hope the counter doesn't overflow :-). Then periodically tweak P: * When error counter is negative (too many output pulses), make P bigger (slow down output frequency). * When error counter is positive (too many input pulses), make P shorter (speed up output frequency). You can have some complicated PID method of adjusting P if you want. Or do something simple like increment/decrement P once every 8 input pulses. This forces the output frequency (at steady state) to converge on output frequency = Ki/Ko * input frequency. . Advantages: * no need to measure periods with any kind of accuracy. Just count pulses. * Jitter in input pulses is completely ignored. * If the output frequency uses a hardware timer, it has very low jitter, and can change frequency very smoothly. Disadvantages: * Initial output frequency when you first turn it on might be *way* off. * After a step change in input frequency, might take a long time to settle. * After a step change in input frequency, might cause output frequency to overshoot, maybe even oscillate, if the "tweak P" code isn't properly tuned. If you *know* a step change in input frequency just occurred, you might be able jump immediately to almost exactly the correct output frequency by directly forcing period P to the (estimated) new frequency. Then let it slowly converge. -- David Cary -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics