Andre; If I were in your shoes, I would do this. If you have a relatively low period, say <10KHz Run the bit into the RB0 pin. On each int, toggle the edge on which to trigger, such that you will read every edge. Then, you measure the period between every edge, by capturing the TMR0 register value. Run a simple IIR low pass on it. Make a training period for say the first 10 pulses such that the software can get a good grip on the period. Hint, pre-stuff the filter with the first good read (discard the first two). Now you have the period of operation. If any period is recieved which exceeds a proportion of that, shazam! You set the alarm. That proportion could be simple, say twice the current period, or it could be complex, say using integer math (multiply then divide) to calculate say 20% over period. Do this benchmark proportion regularly, so that it tracks the incoming pulse train period. You must sit and calculate carefully, so that you can determine the outside boundaries of the valid period capture range. If you are working with slow periods, you must capture the TMR0 rollovers as well as the base TMR0 value, to create 16 bit words instead of 8 bit words. You would have to take into account the rollover of the TMR0 anyhow, even if you worked in 8 bit only. You can also leave TMR0 out of this and use TMR1 instead, if the pre/post scale bits are on your side. If you do that, you could clear TMR1 every time, whereas clearing TMR0 would prevent the concurrent use of TMR0 as a real time base (which I assumed above that you would be doing, when you merge the code in the interrupts). Theoretically, you have a 1uS resolution at 4MHz. Piece of cake for a fellow of your stature! Chris Eddy Pioneer Microsystems, Inc. Andre Abelian wrote: > Hi to all engineers, > > I started to work on a project that needs counting pulses and turn led on > and off > on cretin time. > this is the data > > 01010101010101010101010101010100001010101010101010101 > > on count of 10 I should turn the led on after 0000 on 5 I should turn the > led off. > my question is what is the best way to determine the gap (0000). the speed > of data may vary. > any example code or idea ?. The only problem is that I do not know where the > start is. any help will highly appreciated. > > Andre