cancel
Showing results for 
Search instead for 
Did you mean: 

How to calculate max encoder frequency

Konami
Senior II

I'm using the encoder mode of the hw timer on a STM32G0 to count pulses of a quadrature encoder, and trying to figure out how fast the encoder can be run before we start to lose pulses. For reference the encoder is 10k CPR, and is on a wheel that can spin at several rev/s.

If I'm understanding the RM correctly, the encoder pulses are essentially clocking the peripheral in this more so it seems to me that the theoretical limiting factor (signal noise aside) would be the max clock speed of the timer (64MHz). However, I'm not sure if I am misinterpreting or omitting something.

TL;DR: Looking for some help with calculating theoretical max pulse rate of a rotary encoder with the STM32G0's timer

4 REPLIES 4

Timer is synchronous, so it depends on the timer's internal clock frequency. You need at least 1/tclk between individual edges, so that would be the maximum count frequency too. However, this all is theoretical, for absolutely perfect timing, so for safety I'd say half that.

If you've set timer frequency to 64MHz, 100kcounts/s is surely safe.

JW

Konami
Senior II

Well, I can confirm that 120k counts/s is indeed safe. We're now looking at increasing that to ~10M tick/s. In theory, the hardware should be able to handle it. Given the timer is 16bit, we obviously need to make sure that we check the reading at ~300Hz at least (10M/2^16 * safety-factor-2). Any thoughts on whether this is crazy?

Is there any computational overhead from all the edges on the timer IO or is that completely handled in the peripheral?

Factor 2 is no safety but an absolute minimum to be able to distinguish direction of the overflows. I'd go for min. 3.

Counting is entirely done in the timer's hardware.

JW

Konami
Senior II

Makes sense, thanks! I think we'll limit at something like 8MHz for now, and sample at 1kHz and see how it goes :)