Skip to content

Commit 1fede7b

Browse files
author
mars
committed
changed to uint32_t and updated tap tempo clock logic
1 parent d110607 commit 1fede7b

2 files changed

Lines changed: 15 additions & 15 deletions

File tree

firmware/Source/TapTempo.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#define TIMER_PERIOD 300 // 20kHz sampling rate
1212
#define TRIGGER_THRESHOLD 16 // 1250Hz at 20kHz sampling rate
1313
#define TAP_THRESHOLD 256 // 78Hz at 20kHz sampling rate, or 16th notes at 293BPM
14-
#define TRIGGER_LIMIT INT32_MAX
14+
#define TRIGGER_LIMIT UINT32_MAX
1515
/* At 20kHz sampling frequency (TIMER_PERIOD 300), a 32-bit counter will
1616
* overflow every 59.65 hours. With 63 bits it overflows every 14623560 years.
1717
*/
@@ -54,8 +54,8 @@ enum SynchroniserMode {
5454

5555
class Synchroniser {
5656
private:
57-
int32_t trig;
58-
int32_t period;
57+
volatile uint32_t trig;
58+
uint32_t period;
5959
bool isHigh;
6060
SynchroniserMode mode;
6161
public:
@@ -107,10 +107,10 @@ class Synchroniser {
107107

108108
class TapTempo {
109109
private:
110-
int32_t counter;
111-
int32_t goLow;
112-
int32_t goHigh;
113-
int32_t trig;
110+
volatile uint32_t counter;
111+
uint32_t goLow;
112+
uint32_t goHigh;
113+
uint32_t trig;
114114
bool isHigh;
115115
bool on;
116116
public:
@@ -155,17 +155,17 @@ class TapTempo {
155155
void clock(){
156156
if(trig < TRIGGER_LIMIT)
157157
trig++;
158-
if(++counter >= goHigh)
159-
counter = 0;
160158
if(on){
161-
if(counter == 0)
159+
if(++counter >= goHigh){
162160
setHigh();
163-
else if(counter >= goLow && isHigh)
161+
counter = 0;
162+
}else if(counter >= goLow && isHigh){
164163
setLow();
165-
else if(isSineMode())
166-
setLed(LED_FULL*(goHigh-counter)/goHigh);
164+
}
165+
if(isSineMode())
166+
setLed(LED_FULL*(goHigh-counter)/(goHigh+1));
167167
else
168-
setLed(LED_FULL*counter/goHigh);
168+
setLed(LED_FULL*counter/(goHigh+1));
169169
}
170170
}
171171
void setLow(){

firmware/Source/device.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <inttypes.h>
22

3-
#define FIRMWARE_VERSION "001"
3+
#define FIRMWARE_VERSION "003"
44
#define HARDWARE_VERSION "TapTempo Rev03"
55

66
/*

0 commit comments

Comments
 (0)