1
\$\begingroup\$

I am working on a project that uses a rotary encoder,
I am using a locally made encoder of 200 PPR(pulses per revolution), The encoder has 2 inputs wires (0-5 volts) and 2 output wires (output pulses). I have connected the output wires of the encoder to GPIO ports of raspberry pi and am using this library to get output. It works great.

Now I need to do the same with 4000-5000 PPR encoder: http://uk.rs-online.com/web/p/rotary-encoders/2914349/ like this one. the raspberry pi is unable to gauge the output of this encoder using the above library.

Issues I need help with:
1)Should I use or design a decoder circuit and then feed output to pi?

2)Is is possible to solve this problem programmatically ? how ?

\$\endgroup\$
7
  • \$\begingroup\$ *the raspberry pi is unable to gauge the output of this encoder using the above library. * Do you know why? Is it because it can't keep up? \$\endgroup\$
    – Trevor_G
    Mar 20, 2017 at 13:11
  • \$\begingroup\$ @Trevor Frankly, I Don't know why it just seems to miss the output . works fine for 200 PPR though. \$\endgroup\$
    – Mr.Sky
    Mar 20, 2017 at 13:13
  • \$\begingroup\$ How fast is the encoder turning? \$\endgroup\$
    – Trevor_G
    Mar 20, 2017 at 13:13
  • \$\begingroup\$ @Trevor I am turning it by hand so not more that 3-4 RPM \$\endgroup\$
    – Mr.Sky
    Mar 20, 2017 at 13:14
  • \$\begingroup\$ @Trevor should it work with pi? I mean theoretically? \$\endgroup\$
    – Mr.Sky
    Mar 20, 2017 at 13:15

1 Answer 1

2
\$\begingroup\$

Well, let's have a look at your library's documentation:

The current implementation of the RotaryEncoder class uses polling to monitor the inputs rather than using GPIO interrupts. It looks like the plumbing is in place within wiringpi to use interrupts on GPIOs, but I’ll leave that for another day. Instead I have included an optional worker thread class that can be used to monitor the inputs, leaving the main thread free to go about its business.

On a preemptive multitasking system like the Pi, the OS will run each process in turn whenever they need to run. Therefore, any system relying on polling will miss events when the CPU is busy doing something else than running the polling code. I'm quite surprised this library doesn't miss pulses even with a low PPR encoder... it should happen if cpu load was high.

Therefore, it doesn't work.

The encoder docs mentions a maximum pulse frequency of 200kHz. This is quite high.

If the Pi can handle such a high interrupt rate, use pin-change interrupts.

Else, use a hardware decoder (or a dedicated micro wired as a such, and reporting to the Pi).

\$\endgroup\$
1
  • \$\begingroup\$ Thankyou! Any suggestions on alternate library or hardware decoder circuit? \$\endgroup\$
    – Mr.Sky
    Mar 20, 2017 at 13:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.