From 40aad3ff9608f8fadeba544ebb08e04166bb2976 Mon Sep 17 00:00:00 2001 From: midilab Date: Fri, 21 Aug 2020 07:40:46 -0300 Subject: [PATCH] added a drift voodo variable to make it easier to get better clock timming with PCs. Check README.md for more info --- README.md | 8 ++++++++ src/uClock.cpp | 14 ++++++++++---- src/uClock.h | 2 ++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0b758cf..858ce4c 100755 --- a/README.md +++ b/README.md @@ -275,3 +275,11 @@ void loop() //processYourPots(); } ``` + +## Troubleshooting + +If you slave host are not showing correct of close bpm on sync, please try to use the drift variable to adjust. It normaly goes from value 4(good for clock over USB) to 11(good for common MIDI interfaces running at 31250 speed). The default value is 11. + +To use MIDI via USB please start setting the drift to 4: +uClock.setDrift(4); + \ No newline at end of file diff --git a/src/uClock.cpp b/src/uClock.cpp index 44e284a..40b3b51 100755 --- a/src/uClock.cpp +++ b/src/uClock.cpp @@ -53,6 +53,9 @@ static inline uint16_t clock_diff(uint16_t old_clock, uint16_t new_clock) uClockClass::uClockClass() { + // 4 is good for usb-to-midi hid + // 11 is good for native 31250bps midi interface + drift = 11; pll_x = 220; mode = INTERNAL_CLOCK; resetCounters(); @@ -138,10 +141,8 @@ void uClockClass::setTempo(uint16_t bpm) _tmpSREG = SREG; cli(); tempo = bpm; - // 4 is good for usb-to-midi hid - // 11 is good for native 31400bps midi interface - //interval = 62500 / (tempo * 24 / 60) - 4; - interval = (uint16_t)(156250 / tempo) - 4; + //interval = 62500 / (tempo * 24 / 60) - drift; + interval = (uint16_t)(156250 / tempo) - drift; SREG = _tmpSREG; } @@ -153,6 +154,11 @@ uint16_t uClockClass::getTempo() return tempo; } +void uClockClass::setDrift(uint8_t value) +{ + drift = value; +} + uint8_t uClockClass::getMode() { return mode; diff --git a/src/uClock.h b/src/uClock.h index 5edb0fc..46ed483 100755 --- a/src/uClock.h +++ b/src/uClock.h @@ -73,6 +73,7 @@ class uClockClass { uint16_t last_interval; uint32_t indiv96th_counter; uint16_t pll_x; + uint8_t drift; uint16_t tempo; uint32_t start_timer; uint8_t mode; @@ -114,6 +115,7 @@ class uClockClass { void pause(); void setTempo(uint16_t bpm); uint16_t getTempo(); + void setDrift(uint8_t value); // external timming control void setMode(uint8_t tempo_mode);