I try using this code. But only get forward and backward only. The value of pulse is totaly depend on rotation per second. How I need to maintain pulse / rotation regardless how fast I rotate the encoder. So the distance are varies depend on speed, although the distance is same. Please help



DEFINE LOADER_USED 1

' Define LCD pins
Define LCD_DREG PORTD
Define LCD_DBIT 4
Define LCD_RSREG PORTE
Define LCD_RSBIT 0
Define LCD_EREG PORTE
Define LCD_EBIT 1
define PULSIN_MAX 200
ADCON1 = 4 ' Set PortA 0, 1, 3 to A/D inputs

old var word
new var word
dir var byte
cnt var word ' pulse/rotation

Encoder: ' Routine to read rotary encoder
old = PortB & %00000011 ' Read PortB.0 and PortB.1

pause 2 ' Add some time between reads
new = PortB & %00000011 ' Read PortB.0 and PortB.1


if old = new then goto Encoder ' If old and new equal, read again

old = old & %00000001 ' Only need PortB.0

new = new >> 1 ' Only need PortB.1

dir = old ^ new ' Dir equals PortB.0 XOR PortB.1

If dir = 1 then ' If Dir = 1 then...
cnt = cnt + 1 ' ...Count up
else ' Otherwise
cnt = cnt - 1 ' ...Count down
endif ' End If statement
Lcdout $fe, 1 ' Clear LCD screen
Lcdout #cnt ' Display Hello
Lcdout $fe,$C0, 1 ' Clear LCD screen
Lcdout #dir
pause 10
goto encoder ' Do it forever (I hope)

End