Hi All,
I have purchased a Keyes Rotary Encoder, the following code was used on a 28X2, a toggle switch is used to set the count jumps in steps of 1 or 10. The unit is designed for a boat autohelm so the numbers dialled by the encoder is 1 to 359.
The problem is that the whole thing works fine while rotating the encoder slowly, on higher rotation speed he number do not go up or down.
Any idea why?
Thanks
init:
symbol lega=pina.0
symbol legb=pina.1
symbol sethdg=w0
symbol cw=b2
symbol cw1=b3
symbol lasta=b4
symbol mult=b5
pause 500
serout B.4,N2400,(254,1)
pause 50
serout B.4,N2400,(254,128)
serout B.4,N2400,("SET")
serout B.4,N2400,(254,132)
serout B.4,N2400,("000")
sethdg=0
mult=1
main:
if pinb.3=1 then
mult=10
else mult=1
end if
if lega=1 and legb=1 then
cw=1
lasta=1
end if
if lega=0 and legb=0 then
cw1=1
lasta=0
end if
if lega=1 and legb=0 then
cw=0
lasta=1
end if
if lega=0 and legb=1 then
cw1=0
lasta=0
end if
if lasta=lega then goto main
if cw=1 or cw1=1 then
sethdg=sethdg-mult
if sethdg>360 then
sethdg=359
end if
if sethdg<10 then gosub dig1
if sethdg>9 and sethdg<100 then gosub dig2
if sethdg>99 then gosub dig3
end if
if cw=0 or cw1=0 then
sethdg=sethdg+mult
if sethdg>359 then
sethdg=0
end if
if sethdg<10 then gosub dig1
if sethdg>9 and sethdg<100 then gosub dig2
if sethdg>99 then gosub dig3
end if
goto main
dig1:
serout B.4,N2400,(254,132)
serout B.4,N2400,("00")
serout B.4,N2400,(254,134)
serout B.4,N2400,(#sethdg)
return
dig2:
serout B.4,N2400,(254,132)
serout B.4,N2400,("0")
serout B.4,N2400,(254,133)
serout B.4,N2400,(#sethdg)
return
dig3:
serout B.4,N2400,(254,132)
serout B.4,N2400,(#sethdg)
return
I have purchased a Keyes Rotary Encoder, the following code was used on a 28X2, a toggle switch is used to set the count jumps in steps of 1 or 10. The unit is designed for a boat autohelm so the numbers dialled by the encoder is 1 to 359.
The problem is that the whole thing works fine while rotating the encoder slowly, on higher rotation speed he number do not go up or down.
Any idea why?
Thanks
init:
symbol lega=pina.0
symbol legb=pina.1
symbol sethdg=w0
symbol cw=b2
symbol cw1=b3
symbol lasta=b4
symbol mult=b5
pause 500
serout B.4,N2400,(254,1)
pause 50
serout B.4,N2400,(254,128)
serout B.4,N2400,("SET")
serout B.4,N2400,(254,132)
serout B.4,N2400,("000")
sethdg=0
mult=1
main:
if pinb.3=1 then
mult=10
else mult=1
end if
if lega=1 and legb=1 then
cw=1
lasta=1
end if
if lega=0 and legb=0 then
cw1=1
lasta=0
end if
if lega=1 and legb=0 then
cw=0
lasta=1
end if
if lega=0 and legb=1 then
cw1=0
lasta=0
end if
if lasta=lega then goto main
if cw=1 or cw1=1 then
sethdg=sethdg-mult
if sethdg>360 then
sethdg=359
end if
if sethdg<10 then gosub dig1
if sethdg>9 and sethdg<100 then gosub dig2
if sethdg>99 then gosub dig3
end if
if cw=0 or cw1=0 then
sethdg=sethdg+mult
if sethdg>359 then
sethdg=0
end if
if sethdg<10 then gosub dig1
if sethdg>9 and sethdg<100 then gosub dig2
if sethdg>99 then gosub dig3
end if
goto main
dig1:
serout B.4,N2400,(254,132)
serout B.4,N2400,("00")
serout B.4,N2400,(254,134)
serout B.4,N2400,(#sethdg)
return
dig2:
serout B.4,N2400,(254,132)
serout B.4,N2400,("0")
serout B.4,N2400,(254,133)
serout B.4,N2400,(#sethdg)
return
dig3:
serout B.4,N2400,(254,132)
serout B.4,N2400,(#sethdg)
return