Arduino MIDI clock to BPM issues

Hi folks,

I tinkered a while with my Arduino based arpeggiator now and continuously fail to make it MIDI sync capable. My attempt is based on simple counting between two timestamps of the clock signal. I experience two issues

a) the beat calculated has a huge jitter (e.g. about 10% in the below pasted example1 of the debug output for an input of 120)

b) the beat calculated does not increase beyond 186bpm if sending higher clock rates as in example2 (here: 360bpm input)

Extract of the debug output for example1:

tickTime: 19320
tickBeat: 129

tickTime: 23156
tickBeat: 107

tickTime: 18872
tickBeat: 132

tickTime: 22740
tickBeat: 109

Extract of the debug output for example2:

tickTime: 13440
tickBeat: 186

tickTime: 13440
tickBeat: 186

tickTime: 13440
tickBeat: 186

tickTime: 13440
tickBeat: 186

Do you have a clue about the issue? Thanks in advance for having a look into the code added below.

#include <Arduino.h>
#define DEBUG 1

// Variables for midi clock
unsigned long tickBeat;
unsigned long tickTime;
unsigned long currentTick;
unsigned long previousTick;

byte static midi_start = 0xfa;
byte static midi_stop = 0xfc;
byte static midi_clock = 0xf8;
byte static midi_continue = 0xfb;

byte data;

void setup() {

tickBeat = 0;
tickTime = 0;
currentTick = 0;
previousTick = 0;


void loop() {
if(Serial.available()>0) {
data =;
if((data==midi_clock)) {

currentTick = micros();
tickTime = (currentTick - previousTick);
tickBeat = 60000000 / (tickTime * 24);
previousTick = currentTick;

#ifdef DEBUG

Serial.print(“tickTime: “);
Serial.print(tickTime );

Serial.print(“tickBeat: “);
Serial.print(tickBeat );

All that debug printing will slow down the responsiveness. Record a set of times, then print them all out
when timing isn't critical.

I think given the inherent jitter you'll need a software PLL of some form to lock in to a stable frequency.
It could be as simple as recording a set of times and comparing current time to the Nth one back
in the set, and dividing by N for a better estimate of the period.

Hi Mark,

thanks for the quick response. Let me try to include a simple Software PLL to limit the jitter.

Unfortunately, this will not Impact my second observation (limited BPM to 186) - any clue about that?