Thanks again guys.
Electric,
I have tried the code you corrected and it worked, does that mean the code from the book is wrong?, thanks.
Boriz,
Thanks fot the tips. I read the thread from the begining and you mentioned that the encoder you have is from a mouse, the encoder code you provided is for 3 pin encoder, is it anywhere similar to the one in this link:
http://www.bourns.com/components.aspx?cmsphid=7631383|7163299|2829252
ok the code from manual 3 page 14~15:
main: for b3 = 0 to 99 ‘ start a for...next loop
gosub lstep ‘ call left step sub-procedure
next b3 ‘ next loop
for b3 = 0 to 99 ‘ start a for...next loop
gosub rstep ‘ call left step sub-procedure
next b3 ‘ next loop
lstep: let b1 = b1 + 1 ‘ add 1 to variable b1
goto step ‘ goto the lookup table
rstep: let b1 = b1 - 1 ‘ subtract 1 from variable b1
step: let b1 = b1 & 2 ‘ mask lower two bits of b1
lookup b1,(%1010,%1001,%0101,%0110),b2 ‘ lookup code into b2
let pins = b2 ‘ output b2 onto control lines
return
I run this code I got the following error:
Error: Illegal character: ((0xFFFFFFA1))
Hilighted: "main: for b3 = 0 to 99"
Ok, I Think I have managed to upload a decent image after modifying it.
The code for the encoder from Gavin;
setfreq m8 ; Switch to 8 MHz operations - to improve reliability?
'A small program to test rotary encoding.
'Using 2 bit Grey code.
'BIN DEC
'00 = 0
'01 = 2
'11 = 6
'10 = 4
symbol new = pins 'Define the b2 register as new [value].
symbol old = b2 'Define the b3 register as old [value].
b1 = 180 ' used for testing (180 deg)
start: 'This code checks is there is any changes in the encoder, if not it just loops.
'debug b1
old=new 'If we set old and new to be the same so if new changes we do something...
new=pins 'Set the value of new to the value of the input pins.
debug pins
if new = old then goto start
pause 75
if old = 22 then goto increment 'check your own PINS value
if old = 6 then goto decrement 'check your own PINS value
nextup:
pause 10
if new = 6 then goto increment
nextdown:
pause 10
if new = 22 then goto decrement
goto start
I manage to run the above code with no problem, and the only thing I need tto know is which pin of the encoder goes to which pin of the picaxe'spin? and the same question to Boriz encoder code, below.
And here is athe Encoder form Boriz:
#picaxe 14m
do
do
bit2=bit0:bit3=bit1
bit0=pin0:bit1=pin1
loop until bit0<>bit2
if b0=11 or b0=4 then
gosub right_step
elseif b0=1 or b0=14 then
gosub left_step
endif
loop
right_step:
..stepper stuff here..
Return
left_step:
..stepper stuff here..
return
Freddy