Skip to main content
Konami
Senior
December 7, 2022
Question

How to calculate max encoder frequency

  • December 7, 2022
  • 4 replies
  • 3378 views

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

This topic has been closed for replies.

4 replies

waclawek.jan
Super User
December 7, 2022

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
KonamiAuthor
Senior
March 21, 2023

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?

waclawek.jan
Super User
March 21, 2023

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
KonamiAuthor
Senior
March 21, 2023

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