Skip to content

Commit

Permalink
Merge pull request #26 from mxmxmx/offset_mod
Browse files Browse the repository at this point in the history
[TU] options (offset) / encoder directions.
  • Loading branch information
mxmxmx authored Jun 30, 2017
2 parents de8281c + 1c4e0f4 commit 60eed33
Show file tree
Hide file tree
Showing 14 changed files with 243 additions and 105 deletions.
52 changes: 33 additions & 19 deletions soft/t_u_REV/APP_CLK.ino
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,10 @@ public:
if (get_cv_playmode() == _ARP) // to do
cv_pattern_changed(get_cv_mask(),true);
}

int16_t dac_correction() const {
return dac_overflow_;
}

uint16_t get_clock_cnt() const {
return clk_cnt_;
Expand Down Expand Up @@ -872,6 +876,7 @@ public:
logic_ = false;
prev_mask_rotate_ = 0xFF;
menu_page_ = PARAMETERS;
dac_overflow_ = 0xFFF;

pending_multiplier_ = prev_multiplier_ = get_multiplier();
pending_sync_ = false;
Expand All @@ -882,7 +887,7 @@ public:
channel_frequency_in_ticks_ = 0xFFFFFFFF;
pulse_width_in_ticks_ = get_pulsewidth() << 10;

_ZERO = TU::calibration_data.dac.calibration_points[0x0][0x2];
_ZERO = TU::calibration_data.dac.calibration_points[0x0][TU::OUTPUTS::kOctaveZero];

display_sequence_ = get_sequence();
display_mask_ = get_mask(display_sequence_);
Expand Down Expand Up @@ -1677,15 +1682,23 @@ public:
int8_t _offset = dac_offset();

if (get_DAC_offset_cv_source())
_offset += (TU::ADC::value(static_cast<ADC_CHANNEL>(get_DAC_offset_cv_source() - 1)) + 256) >> 9;
_offset += (TU::ADC::value(static_cast<ADC_CHANNEL>(get_DAC_offset_cv_source() - 1)) + 256) >> 9;
_out += _offset * v_oct;

while (_out > 4095) {

bool corrected = false;
while (_out > TU::OUTPUTS::PITCH_LIMIT) {
_out -= v_oct;
corrected = true;
}
while (_out < 0) {
while (_out < TU::calibration_data.dac.calibration_points[0x0][0x0]) {
_out += v_oct;
corrected = true;
}
if (corrected)
dac_overflow_ = _out;
else
dac_overflow_ = 0xFFF;

return _out;
}

Expand Down Expand Up @@ -1834,10 +1847,6 @@ public:

if (dac_mode() < _SEQ_CV)
*settings++ = CHANNEL_SETTING_DAC_RANGE_CV_SOURCE;
else if (get_cv_playmode() == _ARP)
*settings++ = CHANNEL_SETTING_ARP_RANGE_CV_SOURCE;
else
*settings++ = CHANNEL_SETTING_DUMMY; // todo: reenable range...

switch (dac_mode()) {
case _BINARY:
Expand All @@ -1861,8 +1870,10 @@ public:
else
*settings++ = CHANNEL_SETTING_MASK_CV;
*settings++ = CHANNEL_SETTING_CV_SEQUENCE_PLAYMODE;
if (get_cv_playmode() == _ARP)
if (get_cv_playmode() == _ARP) {
*settings++ = CHANNEL_SETTING_ARP_DIRECTION_CV_SOURCE;
*settings++ = CHANNEL_SETTING_ARP_RANGE_CV_SOURCE;
}
break;
default:
break;
Expand Down Expand Up @@ -1936,11 +1947,7 @@ public:

if (dac_mode() < _SEQ_CV)
*settings++ = CHANNEL_SETTING_DAC_RANGE;
else if (get_cv_playmode() == _ARP)
*settings++ = CHANNEL_SETTING_ARP_RANGE;
else
*settings++ = CHANNEL_SETTING_DUMMY;


switch (dac_mode()) {

case _BINARY:
Expand All @@ -1961,8 +1968,10 @@ public:
case _SEQ_CV:
*settings++ = CHANNEL_SETTING_MASK_CV;
*settings++ = CHANNEL_SETTING_CV_SEQUENCE_PLAYMODE;
if (get_cv_playmode() == _ARP)
if (get_cv_playmode() == _ARP) {
*settings++ = CHANNEL_SETTING_ARP_DIRECTION;
*settings++ = CHANNEL_SETTING_ARP_RANGE;
}
break;
default:
break;
Expand Down Expand Up @@ -2035,6 +2044,7 @@ private:
uint8_t menu_page_;
uint16_t bpm_last_;
int16_t prev_mask_rotate_;
int16_t dac_overflow_;

util::TuringShiftRegister turing_machine_;
util::Arpeggiator arpeggiator_;
Expand Down Expand Up @@ -2093,12 +2103,16 @@ SETTINGS_DECLARE(Clock_channel, CHANNEL_SETTING_LAST) {
{ 1, 0, NUM_CHANNELS - 1, "op_2", TU::Strings::channel_id, settings::STORAGE_TYPE_U8 },
{ 0, 0, 1, "track -->", TU::Strings::logic_tracking, settings::STORAGE_TYPE_U4 },
{ 128, 1, 255, "DAC: range", NULL, settings::STORAGE_TYPE_U8 },
#ifdef MOD_OFFSET
{ 0, -1, 5, "DAC: offset", NULL, settings::STORAGE_TYPE_I8 },
#else
{ 0, -3, 3, "DAC: offset", NULL, settings::STORAGE_TYPE_I8 },
#endif
{ 0, 0, _DAC_MODES_LAST - 1, "DAC: mode", TU::Strings::dac_modes, settings::STORAGE_TYPE_U4 },
{ 0, 0, 1, "track -->", TU::Strings::binary_tracking, settings::STORAGE_TYPE_U4 },
{ 0, 0, 255, "rnd hist.", NULL, settings::STORAGE_TYPE_U8 }, /// "history"
{ 0, 0, TU::OUTPUTS::kHistoryDepth - 1, "hist. depth", NULL, settings::STORAGE_TYPE_U8 }, /// "history"
{ LFSR_MIN<<1, LFSR_MIN, LFSR_MAX, "LFSR length", NULL, settings::STORAGE_TYPE_U8 },
{ LFSR_MIN << 1, LFSR_MIN, LFSR_MAX, "LFSR length", NULL, settings::STORAGE_TYPE_U8 },
{ 128, 0, 255, "LFSR p(x)", NULL, settings::STORAGE_TYPE_U8 },
{ 1, 1, 255, "LGST(R)", NULL, settings::STORAGE_TYPE_U8 },
{ 0, 0, 4, "arp.range", NULL, settings::STORAGE_TYPE_U4 },
Expand Down Expand Up @@ -2421,7 +2435,7 @@ void CLOCKS_handleEncoderEvent(const UI::Event &event) {
ChannelSetting setting = selected.enabled_setting_at(clocks_state.cursor_pos());

if (CHANNEL_SETTING_MASK1 != setting || CHANNEL_SETTING_MASK2 != setting || CHANNEL_SETTING_MASK3 != setting || CHANNEL_SETTING_MASK4 != setting || CHANNEL_SETTING_MASK_CV != setting) {

if (selected.change_value(setting, event.value))
selected.force_update();

Expand All @@ -2445,7 +2459,7 @@ void CLOCKS_handleEncoderEvent(const UI::Event &event) {
selected.update_enabled_settings(clocks_state.selected_channel);
clocks_state.cursor.AdjustEnd(selected.num_enabled_settings() - 1);
break;
// special cases:
// special cases:
case CHANNEL_SETTING_EUCLID_N:
case CHANNEL_SETTING_EUCLID_K:
{
Expand Down
23 changes: 15 additions & 8 deletions soft/t_u_REV/TU_calibration.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,16 @@

namespace TU {

enum EncoderConfig : uint32_t {
ENCODER_CONFIG_NORMAL,
ENCODER_CONFIG_R_REVERSED,
ENCODER_CONFIG_L_REVERSED,
ENCODER_CONFIG_LR_REVERSED,
ENCODER_CONFIG_LAST
};

enum CalibrationFlags {
CALIBRATION_FLAG_ENCODERS_REVERSED = (0x1 << 0)
CALIBRATION_FLAG_ENCODER_MASK = 0x3
};

struct CalibrationData {
Expand All @@ -33,15 +41,14 @@ struct CalibrationData {
uint32_t reserved0;
uint32_t reserved1;

bool encoders_reversed() const {
return flags & CALIBRATION_FLAG_ENCODERS_REVERSED;
EncoderConfig encoder_config() const {
return static_cast<EncoderConfig>(flags & CALIBRATION_FLAG_ENCODER_MASK);
}

void reverse_encoders() {
if (flags & CALIBRATION_FLAG_ENCODERS_REVERSED)
flags &= ~flags & CALIBRATION_FLAG_ENCODERS_REVERSED;
else
flags |= CALIBRATION_FLAG_ENCODERS_REVERSED;
EncoderConfig next_encoder_config() {
uint32_t raw_config = ((flags & CALIBRATION_FLAG_ENCODER_MASK) + 1) % ENCODER_CONFIG_LAST;
flags = (flags & ~CALIBRATION_FLAG_ENCODER_MASK) | raw_config;
return static_cast<EncoderConfig>(raw_config);
}
};

Expand Down
22 changes: 18 additions & 4 deletions soft/t_u_REV/TU_calibration.ino
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@
*/

#include "TU_calibration.h"
#include "TU_options.h"

using TU::OUTPUTS;

#ifdef MOD_OFFSET
static constexpr uint16_t _DAC_OFFSET = 30; // DAC offset, initial approx., ish --> 0v
#else
static constexpr uint16_t _DAC_OFFSET = 2200; // DAC offset, initial approx., ish --> 0v
#endif

static constexpr uint16_t _ADC_OFFSET = (uint16_t)((float)pow(2,TU::ADC::kAdcResolution)*0.5f); // ADC offset

namespace TU {
Expand All @@ -24,7 +30,7 @@ static constexpr unsigned kCalibrationAdcSmoothing = 4;
const TU::CalibrationData kCalibrationDefaults = {
// DAC
{ {
{514, 1375, 2236, 3097, 3960} // -4V, -2V, 0V, +2V, +4V // 1 octave ~ 430
{514, 1375, 2236, 3097, 3960} // 1 octave ~ 430
},
},
// ADC
Expand Down Expand Up @@ -120,11 +126,19 @@ const char *select_help = "[R] => Select";
const CalibrationStep calibration_steps[CALIBRATION_STEP_LAST] = {
{ HELLO, "T_U calibration", "use defaults? ", select_help, start_footer, CALIBRATE_NONE, 0, TU::Strings::no_yes, 0, 1 },
{ CENTER_DISPLAY, "center display", "pixel offset ", default_help_r, default_footer, CALIBRATE_DISPLAY, 0, nullptr, 0, 2 },
#ifdef MOD_OFFSET
{ DAC_4VM, "DAC -2.0 volts", "--> -2.0V ", default_help_r, default_footer, CALIBRATE_DAC_OUTPUT, 0, nullptr, 0, OUTPUTS::MAX_VALUE },
{ DAC_2VM, "DAC 0.0 volts", "--> 0.0V ", default_help_r, default_footer, CALIBRATE_DAC_OUTPUT, 1, nullptr, 0, OUTPUTS::MAX_VALUE },
{ DAC_ZERO,"DAC +2.0 volts", "--> +2.0V ", default_help_r, default_footer, CALIBRATE_DAC_OUTPUT, 2, nullptr, 0, OUTPUTS::MAX_VALUE },
{ DAC_2V, "DAC +4.0 volts", "--> +4.0V ", default_help_r, default_footer, CALIBRATE_DAC_OUTPUT, 3, nullptr, 0, OUTPUTS::MAX_VALUE },
{ DAC_4V, "DAC +6.0 volts", "--> +6.0V ", default_help_r, default_footer, CALIBRATE_DAC_OUTPUT, 4, nullptr, 0, OUTPUTS::MAX_VALUE },
#else
{ DAC_4VM, "DAC -4.0 volts", "--> -4.0V ", default_help_r, default_footer, CALIBRATE_DAC_OUTPUT, 0, nullptr, 0, OUTPUTS::MAX_VALUE },
{ DAC_2VM, "DAC -2.0 volts", "--> -2.0V ", default_help_r, default_footer, CALIBRATE_DAC_OUTPUT, 1, nullptr, 0, OUTPUTS::MAX_VALUE },
{ DAC_ZERO,"DAC 0.0 volts", "--> 0.0V ", default_help_r, default_footer, CALIBRATE_DAC_OUTPUT, 2, nullptr, 0, OUTPUTS::MAX_VALUE },
{ DAC_2V, "DAC +2.0 volts", "--> +2.0V ", default_help_r, default_footer, CALIBRATE_DAC_OUTPUT, 3, nullptr, 0, OUTPUTS::MAX_VALUE },
{ DAC_4V, "DAC +4.0 volts", "--> +4.0V ", default_help_r, default_footer, CALIBRATE_DAC_OUTPUT, 4, nullptr, 0, OUTPUTS::MAX_VALUE },
#endif
{ CV_OFFSET_0, "ADC CV1", "--> 0V", default_help_r, default_footer, CALIBRATE_ADC_OFFSET, ADC_CHANNEL_1, nullptr, 0, 4095 },
{ CV_OFFSET_1, "ADC CV2", "--> 0V", default_help_r, default_footer, CALIBRATE_ADC_OFFSET, ADC_CHANNEL_2, nullptr, 0, 4095 },
{ CV_OFFSET_2, "ADC CV3", "--> 0V", default_help_r, default_footer, CALIBRATE_ADC_OFFSET, ADC_CHANNEL_3, nullptr, 0, 4095 },
Expand Down Expand Up @@ -192,9 +206,9 @@ void TU::Ui::Calibrate() {
calibration_state.encoder_value += event.value;
break;
case CONTROL_BUTTON_DOWN:
SERIAL_PRINTLN("Reversing encoders...");
calibration_data.reverse_encoders();
reverse_encoders(calibration_data.encoders_reversed());
case CONTROL_BUTTON_UP:
configure_encoders(calibration_data.next_encoder_config());
break;
default:
break;
}
Expand Down
6 changes: 3 additions & 3 deletions soft/t_u_REV/TU_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ static constexpr uint32_t TU_CORE_ISR_FREQ = 16666U;
static constexpr uint32_t TU_CORE_TIMER_RATE = (1000000UL / TU_CORE_ISR_FREQ);
static constexpr uint32_t TU_UI_TIMER_RATE = 1000UL;

static constexpr int TU_CORE_TIMER_PRIO = 112; // higher
static constexpr int TU_GPIO_ISR_PRIO = 128; // default
static constexpr int TU_UI_TIMER_PRIO = 144; // lower
static constexpr int TU_CORE_TIMER_PRIO = 80; // yet higher
static constexpr int TU_GPIO_ISR_PRIO = 112; // higher
static constexpr int TU_UI_TIMER_PRIO = 128; // default

static constexpr unsigned long REDRAW_TIMEOUT_MS = 1;
static constexpr unsigned long SCREENSAVER_TIMEOUT_MS = 25000; // time out menu (in ms)
Expand Down
6 changes: 1 addition & 5 deletions soft/t_u_REV/TU_gpio.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#ifndef TU_GPIO_H_
#define TU_GPIO_H_

/*
* uncomment L#8 if using revision 0 pcbs (typically, yellow pcbs):
*/

//#define _TEMPS_UTILE_REV_0
#include "TU_options.h"

#define CV1 A3
#define CV2 A6
Expand Down
11 changes: 11 additions & 0 deletions soft/t_u_REV/TU_options.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef TU_OPTIONS_H_
#define TU_OPTIONS_H_
//
// options ...
//
/* ------------ DAC offset modification (use 10k) ----------------------------- */
//#define MOD_OFFSET
/* ------------ uncomment if using a pre-rev 1 PCB ---------------------------- */
//#define _TEMPS_UTILE_REV_0

#endif
8 changes: 7 additions & 1 deletion soft/t_u_REV/TU_outputs.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include <stdint.h>
#include <string.h>
#include "TU_config.h"
#include "TU_options.h"
#include "util/util_math.h"
#include "util/util_macros.h"
#include "Arduino.h"

extern void set_Output1(uint8_t data);
extern void set_Output2(uint8_t data);
Expand Down Expand Up @@ -37,6 +37,12 @@ class OUTPUTS {
static constexpr size_t kHistoryDepth = 8;
static constexpr uint16_t MAX_VALUE = 4095; // DAC fullscale
static constexpr int CALIBRATION_POINTS = 5; // -4v, -2v, 0v, 2v, 4v
static constexpr int16_t PITCH_LIMIT = 4000;
#ifdef MOD_OFFSET
static constexpr int kOctaveZero = 1;
#else
static constexpr int kOctaveZero = 2;
#endif

struct CalibrationData {
uint16_t calibration_points[NUM_DACS][CALIBRATION_POINTS];
Expand Down
Loading

0 comments on commit 60eed33

Please sign in to comment.