|
|
|
|
@ -27,6 +27,11 @@
|
|
|
|
|
#define MIDI_NOTE_OFFSET 24 |
|
|
|
|
#define MIDI_NOTE_LENGTH 61 |
|
|
|
|
|
|
|
|
|
// NOTE: the max output from the MCP4921 DAC is 5.5V, but we have enough DAC
|
|
|
|
|
// resolution to use a voltage amplifier with a gain of 2 to extend the range
|
|
|
|
|
// to a full 10V. this gives us a range of 121 notes, most of the full MIDI
|
|
|
|
|
// range
|
|
|
|
|
#define USE_10V_MAX_CV true |
|
|
|
|
#define MAX_DAC_INPUT 4095 // 2^12 - 1
|
|
|
|
|
#define TEST_DELAY 5 // seconds to sleep in the test loop
|
|
|
|
|
|
|
|
|
|
@ -48,11 +53,15 @@ showUsage(const char* prog_name)
|
|
|
|
|
u32 |
|
|
|
|
convertNoteToDACInput(u8 midi_note) |
|
|
|
|
{ |
|
|
|
|
#if USE_10V_MAX_CV |
|
|
|
|
u32 dac = midi_note * 68 / 2; |
|
|
|
|
#else |
|
|
|
|
// NOTE: assuming
|
|
|
|
|
// DAC: 5V = 4080 / 4095 * Vref, Vref ~= 5.0184
|
|
|
|
|
// 1 half step/note = 1/12V = dac 68
|
|
|
|
|
// 1 octave = 1V = dac 816
|
|
|
|
|
u32 dac = midi_note * 68; |
|
|
|
|
#endif |
|
|
|
|
(dac > MAX_DAC_INPUT) ? dac = MAX_DAC_INPUT : dac; |
|
|
|
|
|
|
|
|
|
return dac; |
|
|
|
|
@ -120,12 +129,15 @@ loopMIDI(alsa_sequencer* seq, spi_connection* spi, gpio_info* gpio)
|
|
|
|
|
void |
|
|
|
|
loopTestVoltages(spi_connection* spi) |
|
|
|
|
{ |
|
|
|
|
u32 zero_volts = 0; |
|
|
|
|
u32 one_volt = 816; |
|
|
|
|
u32 one_volt = 408; |
|
|
|
|
|
|
|
|
|
for (u32 i = 0;; i++) { |
|
|
|
|
u32 volts = (i % 2 == 0) ? zero_volts : one_volt; |
|
|
|
|
#if 0 |
|
|
|
|
u32 volts = (i % 2 == 0) ? 0 : one_volt; |
|
|
|
|
spiSendVoltage(spi, volts); |
|
|
|
|
#else |
|
|
|
|
spiSendVoltage(spi, 10 * one_volt); |
|
|
|
|
#endif |
|
|
|
|
sleep(TEST_DELAY); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|