>On Tue, 1 Jul 1997 00:11:00 -0700 Antonio Benci > writes: >>I am in the process of putting together a Pulse Width measurement >>controller for a laser trigger unit. I need to measure an incomming >>pulse , 20uS min to 10mS max, delay this pulse by 150uS and resend the >>measured pulse. A fixed delay pulse trigger would describe it. I've >>got >>the delay and output triggers nutted out and working on an 8MHz 16C84. >>The pulse measurement side is causing insomnia. I've looked at Andy >>Kunz >The PIC16C84 does not have a CCP module that makes this task so simple. >The job could be done, but it would require considerable use of "tricks" >to achieve 1 instruction cycle resolution. I would probably approach it >by using the TIMER0 running continuous as a time base, the RB0 interrupt >for capture, and software synchronized to TIMER0 for generating the >output pulse. For a one-off project it would be much simpler to switch >to a PIC having the hardware capture/compare features. I agree, it would be easier with a 16c74 or anything with a CCP module, however, in the interests of a challenge why not try something along the following lines. 1. Wait in a tight loop for rising edge. 2. Start TIMER0 interrupts running at say 100us (200*.5us) that would mean presetting TMR0 to 56. (I think 256-200) 3. Wait in a tight loop for falling edge, during which time the interrupt routine is ticking along every 100us 4. When you get the falling edge, Immediately read TMR0 and add (100-TMR0) to the 100us count. Disable interrupts at this point. Fine Tuning Time. Count the clock cycles (latency) and derive the constant overhead to subract from the measured time above. Problems may have. Keep the interrupt service routine short. Forget about doing other stuff while in this pulse measuring mode. In the worst case (20us pulse) you should get +-1or2 cycles Is this sufficiently accurate for your needs? If not then consider a redesign using a pic with the counter module. Ray Gardiner Technical Director DSP systems Pty. Ltd. ray@dsp-systems.com private email to:- ray@netspace.net.au http://www.dsp-systems.com