Shop OBEX P1 Docs P2 Docs Learn Events
Erratic code?? BS2 cannot follow optical encoder reliably — Parallax Forums

Erratic code?? BS2 cannot follow optical encoder reliably

vaclav_salvaclav_sal Posts: 451
edited 2006-09-15 22:30 in BASIC Stamp
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:
  1. Check only for one Gray Codc· combination – “00” (this may improve slightly)
  2. 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 SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-09-15 21:08
    The BASIC Stamp is not fast enough to read that type of encoder, especially with that high of a resolution at that high of a speed.· If you look at the SX/B Help File you will see an example of an SX Chip (which is much faster) reading an encoder.· I hope this helps.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • vaclav_salvaclav_sal Posts: 451
    edited 2006-09-15 22:01
    OK Chris , I buy that ( explanation - not SX Hi) However, can you tell me (estimate will do) how many "instructions" does this simple loop actually executes?
    I think I will go for "selfcorrecting Gray Code " approach. ( Just looking for punshment!)
    Thanks for you help.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-09-15 22:30
    Okay, two things to consider...The BS2 executes approximately 4000 PBASIC instructions per second.· The actual execution time will depend on the actual instruction.· The time required to read your encoder is actually going to depend on how many RPMs it is turning and how many PPMs it is.· 126 positions is a lot...We have used 16 position encoders with good success, but as soon as you start rotating the knob too fast it cannot keep up.· Our Solder Pot Controller listed in our 2006 catalog uses a Grayhill 16 position optical rotary encoder with a pushbutton.· In order to keep up with reading that and updating the display a BS2px24 was used, and that executes ~19000 PBASIC instructions per second.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
Sign In or Register to comment.