Page 1 of 1

Encoder Pulses

Posted: Sun May 12, 2013 7:12 am
by TrevorAppleton
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?

Re: Encoder Pulses

Posted: Sun May 12, 2013 8:03 am
by joan
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

Re: Encoder Pulses

Posted: Sun May 12, 2013 8:23 pm
by TrevorAppleton
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.

Re: Encoder Pulses

Posted: Sun May 12, 2013 8:57 pm
by joan
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.

Re: Encoder Pulses

Posted: Sun May 12, 2013 9:12 pm
by TrevorAppleton
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!