Shop OBEX P1 Docs P2 Docs Learn Events
edge detection encoder (counting) — Parallax Forums

edge detection encoder (counting)

jacko87jacko87 Posts: 6
edited 2009-07-01 21:46 in BASIC Stamp
Hi guys,

I have a problem with detecting the encoder signal. Can Basic Stamp detect the change of input state from low to high and high to low, and then it count the number of change?
An encoder will give a signal for example 1-0-1-0-1-0-1-0 when my motor rotates, so can I have the BS counts the number of change (from the example, it should give 7)?
In other word, I want to detect the edge (either falling edge and rising edge)...

Comments

  • SandgroperSandgroper Posts: 62
    edited 2009-07-01 15:32
    No problem - just set up a loop that increments a variable by 1 on each pass through, if the pin state =·"1", for example.· Set the program so that the loop will only increment the counter·after the pin has gone back to zero, otherwise it·will "double count" the pin if it·hasn't changed states since the previous reading.

    You can change "edges" by setting it to count either the 1's or the 0's.

    Watch the timing.· The program loop will need to run faster than the time it takes for the pin to cycle between states, otherwise it will skip counts.· Normally this isn't a problem unless you have large wheel diameters, high RPM's, and encoders with a large number of counts per rev.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-07-01 21:24
    You could also use the COUNT command. [noparse];)[/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • ercoerco Posts: 20,256
    edited 2009-07-01 21:46
    You'll probably get some amount of noise during the transition, depending on your encoder hardware. You may have to add hysteresis such as a Schmitt trigger to filter the noise for a reliable count. Alternatively, I have had good results with my low-res optical wheel encoder (60 RPM, 32 holes around the wheel) by just sampling the phototransistor as quickly as possible and verifying 3 consecutive zeroes or ones in a row in the software. That is, I can sample 9 or 10 consecutive ones or zeroes per pulse, but I test for at least 3 in a row to be sure that I'm past a transition where noise may·yield a sequence such as·0000000000101111111110011000000000...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."

    Post Edited (erco) : 7/1/2009 11:38:50 PM GMT
Sign In or Register to comment.