Skip to content

Commit

Permalink
TB3PO: fix tick handling (int vs. uint32_t)
Browse files Browse the repository at this point in the history
Fixes gate output stuck high after 36+ hours
  • Loading branch information
djphazer committed Nov 28, 2024
1 parent 983e060 commit 9457cb9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion software/src/HSApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class HSApplication {
// Buffered I/O functions for use in Views
int ViewIn(int ch) {return frame.inputs[ch];}
int ViewOut(int ch) {return frame.outputs[ch];}
int ClockCycleTicks(int ch) {return frame.cycle_ticks[ch];}
uint32_t ClockCycleTicks(int ch) {return frame.cycle_ticks[ch];}

/* ADC Lag: There is a small delay between when a digital input can be read and when an ADC can be
* read. The ADC value lags behind a bit in time. So StartADCLag() and EndADCLag() are used to
Expand Down
2 changes: 1 addition & 1 deletion software/src/HemisphereApplet.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class HemisphereApplet {
// Buffered I/O functions
int ViewIn(int ch) {return frame.inputs[io_offset + ch];}
int ViewOut(int ch) {return frame.outputs[io_offset + ch];}
int ClockCycleTicks(int ch) {return frame.cycle_ticks[io_offset + ch];}
uint32_t ClockCycleTicks(int ch) {return frame.cycle_ticks[io_offset + ch];}
bool Changed(int ch) {return frame.changed_cv[io_offset + ch];}

//////////////// Offset I/O methods
Expand Down
16 changes: 8 additions & 8 deletions software/src/applets/TB3PO.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class TB_3PO: public HemisphereApplet {

num_steps = 16;

gate_off_clock = 0;
gate_off_tick = 0;
cycle_time = 0;

curr_gate_cv = 0;
Expand All @@ -82,7 +82,7 @@ class TB_3PO: public HemisphereApplet {
}

void Controller() {
const int this_tick = OC::CORE::ticks;
const uint32_t this_tick = OC::CORE::ticks;

if (Clock(1) || manual_reset_flag) {
Reset();
Expand Down Expand Up @@ -129,16 +129,16 @@ class TB_3PO: public HemisphereApplet {
if (step_is_gated(step) || step_is_slid(step_pv)) {
curr_gate_cv = step_is_accent(step) ? HEMISPHERE_MAX_CV : HEMISPHERE_3V_CV;

int gate_time = (cycle_time / 2); // multiplier of 2
gate_off_clock = this_tick + gate_time;
uint32_t gate_time = (cycle_time / 2); // multiplier of 2
gate_off_tick = this_tick + gate_time;
}

curr_step_semitone = get_semitone_for_step(step);

}

if (curr_gate_cv > 0 && gate_off_clock > 0 && this_tick >= gate_off_clock) {
gate_off_clock = 0;
if (curr_gate_cv > 0 && gate_off_tick > 0 && this_tick >= gate_off_tick) {
gate_off_tick = 0;

if (!step_is_slid(step)) {
curr_gate_cv = 0;
Expand Down Expand Up @@ -341,8 +341,8 @@ class TB_3PO: public HemisphereApplet {
uint8_t current_pattern_scale_size; // Track what size scale was used to render the current pattern (for change detection)

// For gate timing as ~32nd notes at tempo, detect clock rate like a clock multiplier
int gate_off_clock; // Scheduled cycle at which the gate should be turned off (when applicable)
int cycle_time; // Cycle time between the last two clock inputs
uint32_t gate_off_tick; // Scheduled cycle at which the gate should be turned off (when applicable)
uint32_t cycle_time; // Cycle time between the last two clock inputs

// CV output values
int32_t curr_gate_cv = 0;
Expand Down

0 comments on commit 9457cb9

Please sign in to comment.