cancel
Showing results for 
Search instead for 
Did you mean: 

Possible bug in HAL quadrature encoder implementation

srinath mallikarjunan
Associate II

HI

We bought a AMT102-V encoder from CUI devices. It is a 1024 pulses per rev encoder.

We are using a STM32H745 nucleo board and the HAL library with inbuilt pulse detection for quadrature encoders. Code is being run on the CM7 core.

Every pulse increments the counter (Motor is rotating in only one direction) and when an index pulse is detected, the counter is reset to 0.

As this video shows, the number of pulses per revolution detected varies quite significantly (From 955 to 1024). Clearly something is wrong and seems to indicate that pulses are being missed.

The code with the HAL initialisation is attached. Please let me know what is wrong .

3 REPLIES 3

What is the frequency of the pulses?

The reset being done in software? What's the latency there?

Would it be better to let the counter free run, and snap-shot the values at the sync pulse.

If you use a simpler count mode does that miss pulses?

What about an EXTI implementation?

If these give wrong values you'd want to look at the signals.

Are these outputting 5V? Are you level shifting them?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
TDK
Guru

How are you detecting the number of pulses per revolution specifically? I don't see any of the three variables (encoder_count*) you show in the video in your code.

If you feel a post has answered your question, please click "Accept as Solution".
srinath mallikarjunan
Associate II

The pulse frequency is about 10Hz, but could go upto 200Hz

The problem was the latency, because there is a bunch of other tasks running at about 10KHz which had higher priority.

So we increased the priority of the IRQ handler for the sync pulse and problem was solved.

@TDK The IRQ handler is around line 140