From 731bb41f49786122a69ef94aeec1031de6f687f2 Mon Sep 17 00:00:00 2001 From: midilab Date: Tue, 3 May 2022 16:11:59 -0300 Subject: [PATCH] change notes --- README.md | 12 ++++++------ library.properties | 4 ++-- src/uClock.cpp | 38 +++++++++++++++++++------------------- src/uClock.h | 24 ++++++++++++------------ 4 files changed, 39 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index c663d48..08d1864 100755 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # uClock -**BPM clock generator for Arduino and Teensy** is a library to implement BPM clock tick calls using **hardware interruption** for tight and solid timing clock ticks. Tested on ATmega168/328, ATmega16u4/32u4, ATmega2560 and Teensy LC. +**BPM clock generator for Arduino and Teensy** is a library to implement BPM clock tick calls using **hardware interruption** for tight and solid timing clock ticks. Tested on ATmega168/328, ATmega16u4/32u4, ATmega2560, Teensy ARM boards and Seedstudio XIAO M0. Generate your self tight BPM clock for music, audio/video productions, performances or installations. You can clock your MIDI setup or sync different protocols as you wish. @@ -34,7 +34,7 @@ Here is an example on how to create a simple MIDI Sync Box on Arduino boards #define MIDI_STOP 0xFC // The callback function wich will be called by Clock each Pulse of 96PPQN clock resolution. -void ClockOut96PPQN(uint32_t * tick) { +void ClockOut96PPQN(uint32_t tick) { // Send MIDI_CLOCK to external gears Serial.write(MIDI_CLOCK); } @@ -81,7 +81,7 @@ An example on how to create a simple MIDI Sync Box on Teensy boards and USB Midi #include // The callback function wich will be called by Clock each Pulse of 96PPQN clock resolution. -void ClockOut96PPQN(uint32_t * tick) { +void ClockOut96PPQN(uint32_t tick) { // Send MIDI_CLOCK to external gears usbMIDI.sendRealTime(usbMIDI.Clock); } @@ -185,13 +185,13 @@ void sendMidiMessage(uint8_t command, uint8_t byte1, uint8_t byte2) } // The callback function wich will be called by uClock each Pulse of 16PPQN clock resolution. Each call represents exactly one step. -void ClockOut16PPQN(uint32_t * tick) +void ClockOut16PPQN(uint32_t tick) { uint16_t step; uint16_t length = NOTE_LENGTH; // get actual step. - _step = *tick % _step_length; + _step = tick % _step_length; // send note on only if this step are not in rest mode if ( _sequencer[_step].rest == false ) { @@ -223,7 +223,7 @@ void ClockOut16PPQN(uint32_t * tick) } // The callback function wich will be called by uClock each Pulse of 96PPQN clock resolution. -void ClockOut96PPQN(uint32_t * tick) +void ClockOut96PPQN(uint32_t tick) { // Send MIDI_CLOCK to external hardware Serial.write(MIDI_CLOCK); diff --git a/library.properties b/library.properties index d213f22..310f3c8 100755 --- a/library.properties +++ b/library.properties @@ -1,9 +1,9 @@ name=uClock -version=1.0.0 +version=1.1.0 author=Romulo Silva maintainer=Romulo Silva sentence=BPM clock generator for Arduino and Teensy boards -paragraph=A Library to implement BPM clock tick calls using hardware interruption. Tested on ATmega168/328, ATmega16u4/32u4, ATmega2560, Teensy ARM boards and Seedstudio XIAO M0 SAMD.. +paragraph=A Library to implement BPM clock tick calls using hardware interruption. Tested on ATmega168/328, ATmega16u4/32u4, ATmega2560, Teensy ARM boards and Seedstudio XIAO M0 category=Timing url=https://github.com/midilab/uClock architectures=avr,arm,samd diff --git a/src/uClock.cpp b/src/uClock.cpp index 0c72666..1f9572b 100755 --- a/src/uClock.cpp +++ b/src/uClock.cpp @@ -1,10 +1,10 @@ /*! * @file uClock.cpp * Project BPM clock generator for Arduino - * @brief A Library to implement BPM clock tick calls using hardware timer interruption. Tested on ATmega168/328, ATmega16u4/32u4 and ATmega2560 and Teensy LC. - * @version 1.0.0 + * @brief A Library to implement BPM clock tick calls using hardware timer interruption. Tested on ATmega168/328, ATmega16u4/32u4, ATmega2560, Teensy ARM boards and Seedstudio XIAO M0 + * @version 1.1.0 * @author Romulo Silva - * @date 01/04/2022 + * @date 04/03/2022 * @license MIT - (c) 2022 - Romulo Silva - contact@midilab.co * * Permission is hereby granted, free of charge, to any person obtaining a @@ -45,7 +45,7 @@ TimerTCC0 _uclockTimer; void uclockInitTimer() { ATOMIC( - // Timer1 init + // 16bits Timer1 init // begin at 120bpm (48.0007680122882 Hz) TCCR1A = 0; // set entire TCCR1A register to 0 TCCR1B = 0; // same for TCCR1B @@ -66,23 +66,23 @@ void uclockInitTimer() { // begin at 120bpm (20833us) const uint16_t init_clock = 20833; -#if defined(TEENSYDUINO) - _uclockTimer.begin(uclockISR, init_clock); - - // Set the interrupt priority level, controlling which other interrupts - // this timer is allowed to interrupt. Lower numbers are higher priority, - // with 0 the highest and 255 the lowest. Most other interrupts default to 128. - // As a general guideline, interrupt routines that run longer should be given - // lower priority (higher numerical values). - _uclockTimer.priority(0); -#endif + #if defined(TEENSYDUINO) + _uclockTimer.begin(uclockISR, init_clock); + + // Set the interrupt priority level, controlling which other interrupts + // this timer is allowed to interrupt. Lower numbers are higher priority, + // with 0 the highest and 255 the lowest. Most other interrupts default to 128. + // As a general guideline, interrupt routines that run longer should be given + // lower priority (higher numerical values). + _uclockTimer.priority(0); + #endif -#if defined(SEEED_XIAO_M0) - _uclockTimer.initialize(init_clock); + #if defined(SEEED_XIAO_M0) + _uclockTimer.initialize(init_clock); - // attach to generic uclock ISR - _uclockTimer.attachInterrupt(uclockISR); -#endif + // attach to generic uclock ISR + _uclockTimer.attachInterrupt(uclockISR); + #endif } #endif diff --git a/src/uClock.h b/src/uClock.h index 083f1f8..46c667d 100755 --- a/src/uClock.h +++ b/src/uClock.h @@ -1,10 +1,10 @@ /*! * @file uClock.h * Project BPM clock generator for Arduino - * @brief A Library to implement BPM clock tick calls using hardware timer interruption. Tested on ATmega168/328, ATmega16u4/32u4 and ATmega2560 and Teensy LC. - * @version 1.0.0 + * @brief A Library to implement BPM clock tick calls using hardware timer interruption. Tested on ATmega168/328, ATmega16u4/32u4, ATmega2560, Teensy ARM boards and Seedstudio XIAO M0 + * @version 1.1.0 * @author Romulo Silva - * @date 01/04/2022 + * @date 04/03/2022 * @license MIT - (c) 2022 - Romulo Silva - contact@midilab.co * * Permission is hereby granted, free of charge, to any person obtaining a @@ -34,25 +34,25 @@ namespace umodular { namespace clock { -#define AVR_CLOCK_FREQ 16000000 - -#define PHASE_FACTOR 16 - -#define PLL_X 220 - // for smooth slave tempo calculate display you should raise this value // in between 64 to 128. // note: this doesn't impact on sync time, only display time getTempo() // if you dont want to use it, set it to 1 for memory save #define EXT_INTERVAL_BUFFER_SIZE 24 +#define MIN_BPM 1 +#define MAX_BPM 300 + +// want a different avr clock support? +#define AVR_CLOCK_FREQ 16000000 + +#define PHASE_FACTOR 16 +#define PLL_X 220 + #define SECS_PER_MIN (60UL) #define SECS_PER_HOUR (3600UL) #define SECS_PER_DAY (SECS_PER_HOUR * 24L) -#define MIN_BPM 1 -#define MAX_BPM 300 - #define ATOMIC(X) noInterrupts(); X; interrupts(); class uClockClass {