Erratic code?? BS2 cannot follow optical encoder reliably
vaclav_sal
Posts: 451
The attached code snipped works erratically.
·
I am using 126-position optical encoder and cannot make it work reliably at anything over 1 revolution per second. My project needs at least 3 rev per second,
·
I thought that BS2 could execute 4000 instructions per second. Am I pushing it?
·
The DO / WHILE· Old=New gets "executed " 4 * 126 times per revolution.
I did remove the “DEBUG ? new” and it did not make any difference.
I added external pull–up resistors to pins 0 and 1 and have same results.
·
·
Because the encoder Gray Code gets out of sequence the encoder direction changes!
·
·
I see two immediate options:
Any other suggestions?
Thanks for reading.
·
·
·
ReadEncoderLoop:
DO
GrayCode_3:
··· DO
····· New = INA & 3
··· LOOP WHILE Old = New
··· DEBUG ? new
··· Old = New
LOOP
END
·
·
I am using 126-position optical encoder and cannot make it work reliably at anything over 1 revolution per second. My project needs at least 3 rev per second,
·
I thought that BS2 could execute 4000 instructions per second. Am I pushing it?
·
The DO / WHILE· Old=New gets "executed " 4 * 126 times per revolution.
I did remove the “DEBUG ? new” and it did not make any difference.
I added external pull–up resistors to pins 0 and 1 and have same results.
·
·
Because the encoder Gray Code gets out of sequence the encoder direction changes!
·
·
I see two immediate options:
- Check only for one Gray Codc· combination – “00” (this may improve slightly)
- Add validity check for Gray Code sequence “0132” only
Any other suggestions?
Thanks for reading.
·
·
·
ReadEncoderLoop:
DO
GrayCode_3:
··· DO
····· New = INA & 3
··· LOOP WHILE Old = New
··· DEBUG ? new
··· Old = New
LOOP
END
·
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
I think I will go for "selfcorrecting Gray Code " approach. ( Just looking for punshment!)
Thanks for you help.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support