Shop OBEX P1 Docs P2 Docs Learn Events
Rotation direction detection and counter — Parallax Forums

Rotation direction detection and counter

Don MDon M Posts: 1,652
edited 2011-06-16 16:57 in Propeller 1
I have a machine that has a pulley with 2 hall effect sensors. I want to be able to detect CW or CCW direction (to count up or down). Does anyone have any favorite objects that they use or recommend for this? I was looking in the OBEX and was not sure what I should use. Would I use a quadrature encoder object?

Thanks.
Don

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-06-13 10:25
    If the Hall effect sensors are mounted such that their outputs are 90 degrees out of phase, a quadrature encoder object would do the trick for you.

    -Phil
  • idbruceidbruce Posts: 6,197
    edited 2011-06-13 10:58
    Sounds complicated. If it was me, I would drill a small hole at the edge of the pulley and use two slotted switches instead.

    With switch 1 on the right and switch 2 on the left. If switch 1 is read before switch 2, the direction is CCW. If switch 2 is read before switch 1, the direction is CW. For RPM, count the pulses and do the appropiate math.

    On the other hand, you already have the hall effects.

    Bruce

    EDIT: You could also do the same with the hall effects
  • HarpritHarprit Posts: 539
    edited 2011-06-13 12:05
    Re the two signals I seem to remember that....
    Ideally one signal has to stay on till the other one comes on to be 90 deg out of phase
    Then signal one has to go off before signal two goes off.
    If this is not true, it is hard to tell what the direction of motion is. ie which signal is leading.

    Harprit
  • Mark_TMark_T Posts: 1,981
    edited 2011-06-13 12:21
    To reliably detect direction of motion there must be at least 3 states so that no forward transition can be the same as a backwards transition. With more than 2 states there must be more than one bit for a digital detector, and to avoid race conditions only one bit should change at once. The simplest implementation of this is the 4-state quadrature encoding (00, 01, 11, 10 states). This gives the forwards transistions as 00->01, 01->11, 11->10, 10->00 and the reverse transitions as 00->10, 01->00, 11->01, 10->11, which are all different.

    The requirement for only one bit to change at once forces an even number of states, incidentally. For more states the usual scheme is a reflected Gray code which can be used to give absolute position as well as step-counting.
  • Don MDon M Posts: 1,652
    edited 2011-06-13 12:42
    I'll have to go look at this machine to see the orientation of the sensors. I don't remember if they are 90 deg. or not. I'm thinking that it will just have to be a logical expression.

    There will be a difference in time between T1 and T2. I could do some sort of code logic to distinguish between which sensor is read before the other by virtue of the time differences.

    For CW you would have 1, T1, 2, T2, 1, T1, 2, T2 and so on. For CCW you would have 1, T2, 2, T1, 1, T2, 2, T1, 1....
    768 x 547 - 27K
  • idbruceidbruce Posts: 6,197
    edited 2011-06-13 14:08
    Here is some documentation for a similar concept
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-06-13 14:36
    Don,

    As long as the rotation speed is fairly constant, the relative timing method should work okay. In that case, the closer the two sensors are to each other, the better. It's only during speed changes and starting and stopping that there might be some directional ambiguity from your readings.

    -Phil
  • Don MDon M Posts: 1,652
    edited 2011-06-16 16:14
    I had a chance today to go visit the machine to reacquaint myself with the sensor positioning. The sensors are mounted right by each other next to a 3.5" radius wheel. The wheel has 2 sensing positions per revolution.

    This wheel runs a gearbox that raises or lowers a table. I did some distance measuring of the table while rotating the wheel. The wheel provides 284.48 pulses per inch of table travel or .0070303712 inches of travel per revolution.

    I used my Salae Logic analyzer to record the pulse train in both forward and backward rotation from the sensors.

    So now I'll have to dream up some "logic" code to decipher whether the wheel is turning forward or backward. I don't care about position just the direction and to keep track of the pulse count.

    See attached.
    1024 x 220 - 37K
    640 x 480 - 121K
    1024 x 254 - 46K
    1024 x 221 - 37K
    1024 x 255 - 43K
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-06-16 16:57
    Oh, that's perfect! As long as the pulses overlap like that, you're golden for figuring out direction.

    -Phil
Sign In or Register to comment.