Fitted basic optical encode circuit to my , now figuring out optimal settings for calculating wheel speed. Notes:

Sane gurdy speed of 14 revs every 10 seconds = 1.4 RPS
52 markers on wheel = 52 * 1.4 = 72.8 transitions per second ≈ 73Hz minimal input signal

Timer nominal input freq is Fosc / 4 = 4MHz / 4 = 1Mhz
Max prescaling = 1:256, i.e. TMR0 increments once for every 256 Fosc/4 pulses
Resultant timer freq = 1Mhz / 256 = 0.00390625 Mhz = 3906.25 Hz

Input signal has ≈50% duty cycle so periods between pulses should be 1 / 73 = 13.69863014ms

Period of 3906.25Hz wave = 0.256ms
Num pulses @ 3906.25Hz after 13.7ms = 13.7 / 0.256 = 53.515625

1.4 RPS is minimal normal gurdy trompette playing speed, so counting 54 clicks per transition gives a little space for speeding up and a lot of space for slowing down.

High gurdy trompetting speed of 24 revs per 10 seconds = 2.4 RPS
TPS = 52 * 2.4 ≈ 124.8 = 125Hz maximum input signal = wavelength of 1 / 125 = 8ms
Num pulses @ 3906.25Hz after 8ms = 8 / 0.256 = 31.25

So these values should give a just-wide-enough span of ≈20 ticks between nominal and trompetting speed, with room to halve or potentially even quarter the prescaler if this turns out to not be enough. One advantage of these values is space to track much slower wheel movements, opening this up to be used for slower performance tools as well as speed measuring.

An external switch could always adjust the prescaler if necessary to cover both use cases.

— 1 likes