Hello friends! I am looking for help figuring out how to use an AD5686R DAC chip with Teensy 4.1
Some details about the project:
This is for a hardware synthesizer instrument that has 4 analog oscillators, each of which are independently quantized up to an 11 octave range with at least +/- 1 cent accuracy. Based on button and knob interactions, the Teensy will tell a DAC exactly what pitch CV (DC voltage) to apply to each of the 4 oscillators. The final output range needs to be 0V -11V, with minimum +/- 0.83mv accuracy. If you do the math you’ll see I could probably get away with a 14-bit DAC but opted for the 16-bit so that I could correct for any linearity error that the extremes of the output range may produce. It is important to the project goals that the pitch control be extremely accurate.
The chip:
https://www.analog.com/media/en/technical-documentation/data-sheets/ad5686r_5685r_5684r.pdf
I selected this one because compared to other options:
- it seemed like a good price per channel
- pretty good linearity
- convenience, it has all 4 channels at the bit depth I want in one tiny package
- it is currently available
I got the “R” variant with onboard Vref, because at the time of ordering I think I was confused about what the Vref was for, so I thought I needed it. Do I? Please let me know your thoughts on this chip or if there are others that have worked well in your projects. I’m not married to it, just got a couple to prototype to see how I like them. All I need are 4 channels of HIGHLY accurate and stable DC.
Pin connections:
DAC pin-1, Vref —> NC (putting out 2.5v)
DAC pin-2, VoutB —> NC
DAC pin-3, VoutA —> connected to the multimeter
DAC pin-4, GND —> Teensy GND
DAC pin-5, Vdd —> Teensy +5.5V
DAC pin-6, VoutC —> NC
DAC pin-7, VoutD —> NC
DAC pin-8, SDO —> NC
DAC pin-9, LDAC (latch) —> Teensy pin-0, set LOW
DAC pin-10, Gain —> Teensy GND
DAC pin-11, Vlogic —> Teensy +3.3V
DAC pin-12, SCLK —> Teensy “SCK”, pin-13
DAC pin-13, SYNC —> Teensy “CS”, pin-10, set HIGH initially
DAC pin-14, SDIN —> Teensy “MOSI”, pin-11
DAC pin-15, RESET —> NC
DAC pin-16, RSTSEL —> Teensy GND
Teensy powered via USB
Some nomenclature assumptions I’ve made:
- AD5686R’s “SYNC” should connect to Teensy’s “CS”
- AD5686R’s “SDIN” should connect to Teensy’s “MOSI”
- AD5686R’s “SCLK” should connect to Teensy’s “SCK”
I found a few tutorials that indicate I can use the SPI library like I have in the code above, maybe there is a better way? Right now all I’m trying to do is get all channels to alternate its output level from approximately low to medium parts of the 16-bit range in a slow loop. If I can do that I think I can figure out the rest of what I need to do. Currently I am getting no voltage at all from any of the 4 channels.
My questions:
- Why does my setup not work?
- Does my DAC choice make sense for my use case?
Some details about the project:
This is for a hardware synthesizer instrument that has 4 analog oscillators, each of which are independently quantized up to an 11 octave range with at least +/- 1 cent accuracy. Based on button and knob interactions, the Teensy will tell a DAC exactly what pitch CV (DC voltage) to apply to each of the 4 oscillators. The final output range needs to be 0V -11V, with minimum +/- 0.83mv accuracy. If you do the math you’ll see I could probably get away with a 14-bit DAC but opted for the 16-bit so that I could correct for any linearity error that the extremes of the output range may produce. It is important to the project goals that the pitch control be extremely accurate.
The chip:
https://www.analog.com/media/en/technical-documentation/data-sheets/ad5686r_5685r_5684r.pdf
I selected this one because compared to other options:
- it seemed like a good price per channel
- pretty good linearity
- convenience, it has all 4 channels at the bit depth I want in one tiny package
- it is currently available
I got the “R” variant with onboard Vref, because at the time of ordering I think I was confused about what the Vref was for, so I thought I needed it. Do I? Please let me know your thoughts on this chip or if there are others that have worked well in your projects. I’m not married to it, just got a couple to prototype to see how I like them. All I need are 4 channels of HIGHLY accurate and stable DC.
Pin connections:
DAC pin-1, Vref —> NC (putting out 2.5v)
DAC pin-2, VoutB —> NC
DAC pin-3, VoutA —> connected to the multimeter
DAC pin-4, GND —> Teensy GND
DAC pin-5, Vdd —> Teensy +5.5V
DAC pin-6, VoutC —> NC
DAC pin-7, VoutD —> NC
DAC pin-8, SDO —> NC
DAC pin-9, LDAC (latch) —> Teensy pin-0, set LOW
DAC pin-10, Gain —> Teensy GND
DAC pin-11, Vlogic —> Teensy +3.3V
DAC pin-12, SCLK —> Teensy “SCK”, pin-13
DAC pin-13, SYNC —> Teensy “CS”, pin-10, set HIGH initially
DAC pin-14, SDIN —> Teensy “MOSI”, pin-11
DAC pin-15, RESET —> NC
DAC pin-16, RSTSEL —> Teensy GND
Teensy powered via USB
Some nomenclature assumptions I’ve made:
- AD5686R’s “SYNC” should connect to Teensy’s “CS”
- AD5686R’s “SDIN” should connect to Teensy’s “MOSI”
- AD5686R’s “SCLK” should connect to Teensy’s “SCK”
Code:
#include <SPI.h>
const int ldac = 0;
const int slaveSelect = SS; // 10 (teensy 'CS' connected to AD5686R 'SYNC')
void setup()
{
pinMode(ldac, OUTPUT);
pinMode(slaveSelect, OUTPUT);
digitalWrite(ldac, LOW);
digitalWrite(slaveSelect, HIGH);
SPI.begin();
delay(1000);
}
void loop()
{
// Setting all channels to ~middle of range
Serial.println("Setting to middle");
for (int i = 0; i < 4; i++)
{
setDacChannelLevel(i, 35532);
}
delay(1000);
// Setting all channels to ~bottom of range
Serial.println("Setting to low");
for (int i = 0; i < 4; i++)
{
setDacChannelLevel(i, 24);
}
delay(1000);
}
int setDacChannelLevel(int address, int value)
{
digitalWrite(slaveSelect, LOW);
SPI.transfer(address);
SPI.transfer(value);
digitalWrite(slaveSelect, HIGH);
}
I found a few tutorials that indicate I can use the SPI library like I have in the code above, maybe there is a better way? Right now all I’m trying to do is get all channels to alternate its output level from approximately low to medium parts of the 16-bit range in a slow loop. If I can do that I think I can figure out the rest of what I need to do. Currently I am getting no voltage at all from any of the 4 channels.
My questions:
- Why does my setup not work?
- Does my DAC choice make sense for my use case?