Hi,
Another option (still involving interrupts though) is to feed the pulses to the input of TMR1 and set that up as a counter. That way the the pulses are counted in hardware and you can just "collect" the count at a suitable interval - which is where the interrupt comes in (or you could use PAUSE if you don't need to do anything else at the same time).Now the TMR1 will count the pulses on the T1CKI-pin and you can read it likeCode:TMR1H = 0 'Clear count TMR1L = 0 T1CON.1 = 1 'Set TMR1 as counter, clock on T1CKIIf you don't want to reset the TRM1 count each time you can just take the difference between 'this' reading and the 'last' readingCode:PulseCount VAR WORD PulseCount.HighWord = TMR1H PulseCount.LowWord = TMR1LIf you call this code at a specified interval (by timer interrupt or a simple PAUSE) you'll always have the current 'speed' in the variable PulseCount. This could be done with ON INTERRUPT but DT-INTS would be 'better'. We tend to say it's easy, which it is once you know how to do it but it can be intimidating at first. However there are many examples for DT-INTS and timer interrupts on the forum. If you can't find it and/or you need help that's what we're here for but give it a try first - if this is a suitable approach to your project of course.Code:oldCount VAR WORD oldCount = PulseCount PulseCount.HighWord = TMR1H PulseCount.LowWord = TMR1L PulseCount = PulseCount - oldCount
/Henrik.




Bookmarks