Shop OBEX P1 Docs P2 Docs Learn Events
encoder2 — Parallax Forums

encoder2

BernardBernard Posts: 3
edited 2004-12-29 18:23 in BASIC Stamp
Hi
Thanks for your answer(So quick), i understood my mistake,
i was searching since 1 day, I saw your answer to somebody else bebore.

My problem is when the encoder increment or decrement. I have not the same numbers of points.
I's not i problem of quality of coder or rebounce.
decrement is always good 1 by 1.(increment always 2 by 2 or more)
if I change the order in the PGM of inc and decr like this:

Check_Encoder:
· encNew = EncPort & %0011 ·'IN0 coderA IN1 coderB
· IF ((encNew ^ encOld) <> 0) THEN
· IF (encOld.BIT0 ^ encNew.BIT1) THEN
· value = value +(Span - 1) // Span····· ' increment by·decrement value
· ELSE
· value = value + 1 // Span············· ' decrement by increment value
· ENDIF
· encOld = encNew
· ENDIF
· RETURN

The problem is reverse
Can I do something or it's a problem of Basic stamp speed.

Regards
Bernard

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2004-12-29 18:17
    Why are you checking encOld.Bit0 against encNew.Bit1?
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-12-29 18:23
    That test allows one to determine rotational direction if there was a change.

    Bernard: What are you trying to do? Are you saying you want to increment by value X and decrement by value Y? That is not a problem, it's a simple change in the code. Just remember that with any microcontroller, the rate you can change the encoder will depend on how frequently your check it. I've posted a program that shows how to put the encoder check in the top part of a main program loop that does everything else as a task, that way the encoder is checked every iteration of the loop and gives the best performance.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
Sign In or Register to comment.