Help with syncing Teensy drum machine to external source via sync pulse

I have been plugging away at this for a while and cannot seem to find a solid solution.

A drum machine I am working on is set up to receive voltage pulses from an external device (such as a Korg Volca Beats). I want to be able to quickly ascertain the external source's tempo in BPM, apply it to my drum machine and have the drum machine's step sequencer in lock-step with the external device. The external source's tempo is subject to change at the user's whim.

Per Korg's documentation the Volca Beats, for example, sends a 15ms pulse and the rising edge is the trigger. Pulses are typically sent at 2 or 4 pulses per quarter note, based on configuration.

Can anyone suggest some pseudocode or logical approach to get started? I'm just stuck, mentally. As is, my drum machine can get the proper BPM momentarily then drifts wildly.
 
Use TeensyDuino library FreqMeasureMulti. It measures the time (t) between rising edges and you can compute frequency f = 1/t. This approach (period measurement) is much faster than pulse counting. See the library examples to get started.
 
Back
Top