TrevorAppleton
Posts: 74
Joined: Wed May 30, 2012 7:26 pm
Contact: Website

Encoder Pulses

Sun May 12, 2013 7:12 am

I am looking to replace a PLC and have been looking into using the raspberry pi. The idea is I need to track items as they move down a production line. As the items hits a trigger I need to keep track of encoder pulses, and after a certain number of pulses fire off some outputs to control certain bits of equipment.

I will need to keep track of multiple items at once.

What seems to be the difficult bit is I need to track the encoder at 10kHz. I have written a program in python and one in c which takes the input of the encoder pulses and then turns this into an output. Measuring the speed which the pi can do this shows it is consistent in both languages up to roughly 2kHz. However after that it seems to lose encoder pulses. I appreciate that turning an encoder input into an output is not what I would be doing in real life, but it gives me a way to measure achievable speed. I am beginning to wonder if it is trying to output each encoder pulse that is causing the problems.

If the pi has to do anything else other than track the encoder it falls down at much lower speeds.

I have seen people quote speeds of mHz in relation to the raspberry pi. However I think that is just generating the pulses and not tracking the encoder.

I was thinking I may have to use something like an arduino board instead, but I am unsure if that would work.

Anyone have any experience with this sort of thing?
Check out my blog post for Raspberry Pi and Python tutorials.

http://trevorappleton.blogspot.co.uk/

User avatar
joan
Posts: 14935
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Encoder Pulses

Sun May 12, 2013 8:03 am

The Pi can do what you want. You may have to use DMA techniques if you want reliability.

http://www.raspberrypi.org/phpBB3/viewt ... 67#p342467

TrevorAppleton
Posts: 74
Joined: Wed May 30, 2012 7:26 pm
Contact: Website

Re: Encoder Pulses

Sun May 12, 2013 8:23 pm

Hi joan, had a look through the post you linked to and it looks promising.

However using both Python and C I used an interrupt, but could only manage to get the output to match the encoder input up to about 2kHz which is a lot slower than your mHz data!

I will look into DMA, but do you have any hints on how I can improve matters? Is there any example code kicking around you could point me to? I appreciate your help.
Check out my blog post for Raspberry Pi and Python tutorials.

http://trevorappleton.blogspot.co.uk/

User avatar
joan
Posts: 14935
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Encoder Pulses

Sun May 12, 2013 8:57 pm

I've just released a new library.

http://www.raspberrypi.org/phpBB3/viewt ... 30#p347830

If you have your encoders connected to a Pi you should be able to use notifications to capture the pulses (see the example session in the post).

It should allow you to get a feel for what can be achieved.

TrevorAppleton
Posts: 74
Joined: Wed May 30, 2012 7:26 pm
Contact: Website

Re: Encoder Pulses

Sun May 12, 2013 9:12 pm

Thank you for the reply, that looks great. I will look into it tomorrow and let you know how I get on. Thanks for the help!
Check out my blog post for Raspberry Pi and Python tutorials.

http://trevorappleton.blogspot.co.uk/

Return to “Automation, sensing and robotics”