Shop OBEX P1 Docs P2 Docs Learn Events
Cool Motor Encoders — Parallax Forums

Cool Motor Encoders

SouLJahSouLJah Posts: 35
edited 2008-04-08 19:00 in General Discussion
Hey I have a motor encoder connected to the javelin, the motor encoder provides a square wave with frequency corresponding to the speed of the motor, can anyone tell me how to accurately measure the frequency of the square wave?

Thanks

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2008-04-08 19:00
    You can try doing 2 CPU.pulseIn(), one for a low pulse and one for a high pulse.
    Add the 2 results together to get the timeperiod in 8.68 usec units.
    Then F = 1/T = 1 / (count*8.68usec) = 57600 / (count/2) = 28800 / (count/4)
    so F = 28800 / (count >>> 2)
    Edit:
    if you know the squarewave always has a 50% dutycycle, you can do with
    just one CPU.pulseIn() and use
    F = 28800 / (count >>> 1)

    regards peter
Sign In or Register to comment.