Hi there, I like to use microcontrollers for musical projects and my latest endeavor has been using the ESP32 in tandem with an AD1866 16-bit dual DAC.
The program to communicate with the chip uses SPI, as it was the fastest and most similar to the expected control signals. I have the MOSI signal representing the DR and DL signals, as the datasheet implies they can be tied together, and the CS signal represents the LL signal, while every other 16 bit transfer toggles pin 33 to represent the LR signal.
The left channel output of the DAC outputs the correct test signal (a downward ramp), while the right output stays at around 4.5vDC, when it is programmed to output an upwards sawtooth. Upon swapping the latch signals, the left channel outputs the upwards sawtooth , while the right output remains at 4.5vDC. Attached is the source code and annotated scope traces of the control signal. The chip is outfitted with decoupling capacitors, as well as the noise reduction capacitors, and the outputs are buffered as specified in the datasheet. As a side note,, the ESP32 was programmed using the Arduino IDE. I have reseated the IC and rewired the circuit multiple times to check for shorts but still no luck. Let me know if you have experience in working with this DAC or SPI and if I were to miss a quirk. I appreciate the collective community of knowledgeable individuals that has been built with this site and I hope to hear back soon.
The program to communicate with the chip uses SPI, as it was the fastest and most similar to the expected control signals. I have the MOSI signal representing the DR and DL signals, as the datasheet implies they can be tied together, and the CS signal represents the LL signal, while every other 16 bit transfer toggles pin 33 to represent the LR signal.
The left channel output of the DAC outputs the correct test signal (a downward ramp), while the right output stays at around 4.5vDC, when it is programmed to output an upwards sawtooth. Upon swapping the latch signals, the left channel outputs the upwards sawtooth , while the right output remains at 4.5vDC. Attached is the source code and annotated scope traces of the control signal. The chip is outfitted with decoupling capacitors, as well as the noise reduction capacitors, and the outputs are buffered as specified in the datasheet. As a side note,, the ESP32 was programmed using the Arduino IDE. I have reseated the IC and rewired the circuit multiple times to check for shorts but still no luck. Let me know if you have experience in working with this DAC or SPI and if I were to miss a quirk. I appreciate the collective community of knowledgeable individuals that has been built with this site and I hope to hear back soon.
Code:
#include <SPI.h>
#define LR 33
#define VSPI_MISO MISO
#define VSPI_MOSI MOSI
#define VSPI_SCLK SCK
#define VSPI_SS SS
static const int spiClk = 1000000;
SPIClass * vspi = NULL;
void setup() {
//initialise two instances of the SPIClass attached to VSPI and HSPI respectively
vspi = new SPIClass(VSPI);
//SCLK = 18, MISO = 19, MOSI = 23, SS = 5
vspi->begin();
//set up slave select pins as outputs as the Arduino API
//doesn't handle automatically pulling SS low
pinMode(vspi->pinSS(), OUTPUT); //VSPI SS
pinMode(LR, OUTPUT); //LATCH RIGHT
}
int16_t left;
int16_t right;
void loop() {
//use the SPI buses
spiCommand(vspi, left,right);
left+=100; //upwards saw
right=left*-1; //downwards saw
delay(100); //DELAY for scope readability
}
void spiCommand(SPIClass *spi, int16_t data,int16_t dataR) {
//use it as you would the regular arduino SPI API
spi->beginTransaction(SPISettings(spiClk, MSBFIRST, SPI_MODE0));
digitalWrite(spi->pinSS(), HIGH);
spi->transfer(data>>8);
spi->transfer(data);
digitalWrite(spi->pinSS(), LOW);
digitalWrite(LR, HIGH);
spi->transfer(dataR>>8);
spi->transfer(dataR);
digitalWrite(LR, LOW);
spi->endTransaction();
}