Hi everyone,
I built the following Arduino MIDI-to-CV Converter design on a custom PCB, which utilises the MCP4822 DAC and ATMega328P microcontroller: GitHub - elkayem/midi2cv: Arduino-based MIDI to CV converter. Originally I prototyped it using an Arduino Uno.
Everything works perfectly, however I have redesigned it to utilise a LTC2632A-LZ12 DAC instead of the MCP4822 for the note CV, as I would like one that has a lower INL and more accuracy.
My question is regarding the programming of the note CV output and how I can adapt the code to the LTC2632A-LZ12 from the MCP4822. They are both 12-bit DACs, however the LTC2632A-LZ12 has a minimum 24-bit input word, which is increased over the MCP4822, which has a 16-bit input word.
The datasheet is here:
The code for the note CV output is given below:
#define NOTE_SF 47.069f // This value can be tuned if CV output isn't exactly 1V/octave
void commandNote(int noteMsg) {
digitalWrite(GATE,HIGH);
digitalWrite(TRIG,HIGH);
trigTimer = millis();
unsigned int mV = (unsigned int) ((float) noteMsg * NOTE_SF + 0.5);
setVoltage(DAC1, 0, 1, mV); // DAC1, channel 0, gain = 2X
}
void setVoltage(int dacpin, bool channel, bool gain, unsigned int mV)
{
unsigned int command = channel ? 0x9000 : 0x1000;
command |= gain ? 0x0000 : 0x2000;
command |= (mV & 0x0FFF);
SPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE0));
digitalWrite(dacpin,LOW);
SPI.transfer(command>>8);
SPI.transfer(command&0xFF);
digitalWrite(dacpin,HIGH);
SPI.endTransaction();
}
Just curious to know if it's possible to amend the above code; specifically the setVoltage function to suit the LTC2632A-LZ12?
Forgive my lack of knowledge or if I'm going down a dead end, but I'm still learning. Any assistance with this would be appreciated.
Many thanks,
Chris