On Sun, 24 May 1998, Dominic Gualtieri wrote: > I would really appreciate any advice from the list on a program I am > going to write for a 16c54. The program will basically "pick out" a > pulse of a certain duration ( about 10 microseconds ) at one of the > inputs from other pulses which are a little larger and a little > smaller.I have a pretty good idea on how to write the code for this > program, and I would like some advice from more experienced programmers > on how they would write code for this program. Thanx in advance Dominic, It depends. If the frequency of the pulses is high, or in bursts, then you can sample the bit stream at a 'sufficiently high rate' and search for the pulse after a block of data has been collected. In one application, I had to do this for a burst of pulses. If the frequency of the pulses is low then you can use the routine David Reid and I wrote a couple of weeks ago. For your application, something like this might do the job. Assume a 20Mhz clock = 250ns per instruction IOlow: BTFSC IOPORT,IOBIT goto IOhigh nop ;Interlace your system code BTFSC IOPORT,IOBIT goto IOhigh nop ;with the I/O sampling BTFSC IOPORT,IOBIT goto IOhigh nop ;repeat as often as needed BTFSC IOPORT,IOBIT goto IOhigh nop ;I mean it. BTFSC IOPORT,IOBIT goto IOhigh nop ;But this is the last for this ex. BTFSS IOPORT,IOBIT ;note, now check if high goto IOlow ;and loop if it's low IOhigh ;If we get here, then the output has been high somewhere ;between 750ns and 1.25us or so ago (maybe someone else ;can clarify where in the Q-cycle the IO is sampled) ;Delay 8.25 us (or whatever margin you'd like to have) nop ;These first two nop's are for the nop ;special case below BTFSS IOPORT,IOBIT ;Sample time: 9us to 9.5us goto found_10us ;Actually a little short, but.... BTFSS IOPORT,IOBIT ;Sample time: 9.5us to 10.0us goto found_10us BTFSS IOPORT,IOBIT ;Sample time: 10.0us to 10.5us goto found_10us too_wide BTFSS IOPORT,IOBIT ;Sample until the IOBIT goes low goto IOlow nop ;System code... BTFSS IOPORT,IOBIT goto IOlow nop ;more System code... BTFSC IOPORT,IOBIT ;loop while high goto too_wide ;IOBIT just went low. Repeat the first instruction of the 'IOlow' loop nop BTFSS IOPORT,IOBIT ;If the IOBIT is still low then jump goto IOlow + 3 ;a little ways into the IOlow loop goto IOhigh+2 ;Special case, IObit went high after ;a brief low pulse found_10us Oh btw, this is untested (and was written around midnight...) Scott