This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AM4378: Reading high frequency encoder on GPIO

Part Number: AM4378

Hi,

My setup involves 4 brushed DC motors with high resolution encoders (55000 ticks/ rotation) which I am controlling with an AM437x board. I am using EHRPWM to vary the motor speeds by varying the PWM duty cycle. The output from the encoders are connected to a plain GPI pin which I have configured to trigger on a rising edge using the /sys/ interface. I have had a look at the eCAP module however they are currently being used up by some other hardware and aren't available for this.

An epoll_wait notifies me when the value file changes i.e an encoder tick is received. Four such threads are running for each of the motors which increment the encoder count and one thread does the rest of the processing (PID, error checks etc.). Each of threads are really light weight and the processing thread takes up around 20us. This setup works fine at low speeds when the encoder output frequency is in the range of 8-10kHz. But as I increase the speed and the encoder frequency goes up to around 20 kHz things, the encoder thread misses quite a few ticks. I understand that some time will be spent in context switching and other processing but even so I shouldn't be missing more than 50% of ticks, which is happening in my case. This is despite giving the encoder threads a very high scheduling priority. Is there a way to increase the thread switching frequency? Am I hitting any hardware upper limits? And is there any better way to deal with this?

Thank you for your time!

Puneeth