[sdiy] MIDI Clock sync advice

brianw brianw at audiobanshee.com
Sat Mar 9 03:27:19 CET 2024

On Mar 8, 2024, at 3:29 PM, Tom Wiltshire wrote:
> At the same time, you need something that is keeping track of how long has passed since the last MIDI Clock pulse. That's going to be *another* timer peripheral, prescaled to to give you a good number of counts for likely tempos. There's no point counting 64MHz clock pulses with a 16-bit timer if it's going to overflow five times before you even get your next pulse. Equally, you don't want to lose resolution by finishing up with counts of only a few dozen for typical tempos. If realistic tempos are in the range 30BPM to 300BPM (a decade) then we'd ideally like those tempos to give timer results between (say) 60,000 and 6000 for a 16-bit timer. Reality will intrude here and we'll take whatever we can get that's closest, but that's the general idea.

You're definitely on the right track. It's possible that you'll get stuck between a rock and a hard place, where a 16-bit timer can't possibly have both enough resolution and enough range.

One possible solution is that some chips allow a pair of 16-bit timer/counter peripherals to be combined into a single 32-bit timer/counter.

Another solution is to remember that overflow can cause an interrupt, and you can increment a state variable on every overflow. Thus, if it turns out that you do need 64 MHz timing resolution (for some reason, I'm not worried about whether that's a realistic number at the moment), then you can count the overflows and end up with a count that is both very precise AND very large. This, by the way, is how stacking 16-bit timers into a 32-bit timer works - it's just more convenient to have the hardware count the overflows and present the entire thing as a 32-bit count.


p.s. I've been working with ARM for the last decade, having finished with the PIC18F before that. The timer/counter peripherals in certain ARM chips can be even more powerful than what the PIC has. Regardless, there's usually a way to solve these problems no matter what.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://synth-diy.org/pipermail/synth-diy/attachments/20240308/594bf8c9/attachment.htm>

More information about the Synth-diy mailing list