If you want the application to automatically synch to the incoming signal and not have to change code for each new frequency. You could measure the incoming waveform period and the apply an appropriate duty cycle as follows. (results in 8 bit resolution for 130Hz and 10bit for 30Hz) Your frequency range is 30Hz to 120Hz (8.3ms to 33.3ms) 1) Set up a timer to 32.5us 2) Count how times the timer times out between 2 leading edges 3) Set the timer to n x 32.5 us to suit duty cycle. 4) Set output port pin High 5) On timeout set port pin low. Step 1 and 2 only need to be done on initial setup or periodically as required. Example: Let incoming signal = 50Hz Period = 20ms 1) micro counts 615 x 32.5us timeout periods 2) Required duty cycle = 20% so let timer = 2 x 615 / 10 = 123 (123 * 32.5us = 4ms = 20% of 20ms) 3) Output pin = High, Start timer 4) On timeout, output pin = low There will no doubt be many ways to accomplish this and above is but one example of how it could be done. This approach will result in output signal be synchronised with the input and at same frequency but the duty cycle can be varied. You can increase the accuracy by using a smaller timeout period. Regards David Huisman -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu