Hi Daniel, you can also use the timer1 as an asynchronous counter, and connect your encoder directly to portB.6 (pin 12) and with two words variable one for the count one for the delay you will govern the counting process. You can also set (using DT interrupt) an overflow routine which will tell you when the setted delay time is too much.
All the time you will call the subroutine Get_Count the word Counter will contain the count from time0 and time0+delay. Setting delay appropriatly the counter could give you the speed without any additional maths.
Al.
Code:
Counter var word
Delay var word
Get_Count:
TCON1 = 6
TMR1L = 0
TMR1H = 0
TCON1 = 7
Pauseus Dalay
TCON1 = 6
Counter.Byte0 = TMR1L
Counter.byte1 = TMR1H
Return
All progress began with an idea
Bookmarks