Teensy 4.1 with DAC714P, not working properly

tian_qhcn

Member
Dear fiends,
I am a new user of Teensy 4.1 with a digital-to-analog converter (DAC). Actually I am not an expert of Microcontrollers.
I want a 16-bit DAC to Teensy 4.1 with SPI interface or I2C bus. The DAC I am using is TI DAC714P. I have connected as is shown in the following figure. I don't see any correct values. Can someone help me out?
The code I am using:
Code:
#include <SPI.h>  // include the SPI library:
#define analogVin A0           // Analog voltage input to A0

const int spi_ss = 23; //DAC71.4P A0 shift regsiter
const int dac_lch = 22; // DAC714 A1 DAC Latch
uint16_t input_0, input_1; // 16 bit input values 
uint8_t byte_0, byte_1, byte_2, byte_3; // bytes for SPI transfer

uint16_t setValue;
float expected_output;

int adcValueRead = 0;
float voltageRead = 0;

void setup(void) {
  Serial.begin(9600);
  pinMode(spi_ss, OUTPUT);
  pinMode(dac_lch, OUTPUT);
  digitalWrite(spi_ss, HIGH);
  digitalWrite(dac_lch, HIGH);
  SPI.setDataMode(SPI_MODE0);
  SPI.setBitOrder(MSBFIRST);
  SPI.setClockDivider(SPI_CLOCK_DIV8);
  SPI.begin();
}

void setDAC714(uint16_t count) {
  // static uint16_t count = 0;
  input_0 = count;
  input_1 = -count;
  count += 1;
  Serial.println(input_0);
  Serial.println(input_1);
  //
  digitalWrite(spi_ss, LOW); // A0
  byte_0 = (input_1 >> 8);
  byte_1 = (input_1 & 0xFF); 
  byte_2 = (input_0 >> 8);
  byte_3 = (input_0 & 0xFF);

  SPI.transfer(byte_0);
  SPI.transfer(byte_1);
  SPI.transfer(byte_2);
  SPI.transfer(byte_3);
  digitalWrite(spi_ss, HIGH);

  digitalWrite(dac_lch, LOW);
  digitalWrite(dac_lch, HIGH);

}

void loop(void) {

  for (setValue = 0; setValue < 66635; setValue = setValue + 255) {

    expected_output = (3.3 / 65536.0) * setValue;     // In volts. 

    setDAC714(setValue);
    delay(1000);
    adcValueRead = analogRead(analogVin);
    voltageRead = (adcValueRead * 3.3) / 1024.0;

    Serial.print("DAC714P Value: ");
    Serial.print(setValue);

    Serial.print("\tExpected Voltage: ");
    Serial.print(expected_output, 3);

    Serial.print("\tADC Value: ");
    Serial.print(adcValueRead);

    Serial.print("\tVoltage: ");
    Serial.println(voltageRead, 3);
  }
}

Thanks a lot!
Best,
tian_qhcn Screenshot 2023-07-14 at 20.31.19.jpgScreenshot 2023-07-14 at 20.31.25.jpg
 
Others have posted about SPI ADC's - this may not be the best but demonstrates some good use - for a different SPI ADC - and patient process of debugging to get it working.

pjrc.com/threads/69988-Teensy-4-and-MCP4921-noise-problem

One important thing is the coding using this style: SPI.beginTransaction(SPISettings(20000000, MSBFIRST, SPI_MODE3));

Also important to note in reading that, things like this work at incredibly high speed and the resulting 'blip' will be single digit nanoseconds:
Code:
  digitalWrite(dac_lch, LOW);
  digitalWrite(dac_lch, HIGH);
 
A quick glance at the datasheet shows that this DAC needs to be powered from ±12V or ±15V supplies. A single 3V3 supply connected to pin7 +Vcc will not suffice.
Using these voltages, the voltage outputted on the Teensy MOSI pin [0V-3V3] will be OK for the DAC714P. However, the MISO signal voltages outputted from the DAC [0V-5V] will kill the Teensy...

Does your project really need this particular DAC? You could consider DAC's with an I2S interface. DAC's proven to work with Teensy are listed here.

Paul
 
Audio DACs are only for audio, an I2S DAC is not general purpose nor calibrated.

Why not try one of the MicroChip parts like the MCP4921/4922 - 5V or 3V operation, nice and simple.
 
Others have posted about SPI ADC's - this may not be the best but demonstrates some good use - for a different SPI ADC - and patient process of debugging to get it working.

pjrc.com/threads/69988-Teensy-4-and-MCP4921-noise-problem

One important thing is the coding using this style: SPI.beginTransaction(SPISettings(20000000, MSBFIRST, SPI_MODE3));

Also important to note in reading that, things like this work at incredibly high speed and the resulting 'blip' will be single digit nanoseconds:
Code:
  digitalWrite(dac_lch, LOW);
  digitalWrite(dac_lch, HIGH);

As a new user of these electronical stuff, I accept your critisization and your help. I am not a genius, I will learn that step by step.
 
A quick glance at the datasheet shows that this DAC needs to be powered from ±12V or ±15V supplies. A single 3V3 supply connected to pin7 +Vcc will not suffice.
Using these voltages, the voltage outputted on the Teensy MOSI pin [0V-3V3] will be OK for the DAC714P. However, the MISO signal voltages outputted from the DAC [0V-5V] will kill the Teensy...

Does your project really need this particular DAC? You could consider DAC's with an I2S interface. DAC's proven to work with Teensy are listed here.

Paul

That's very helpful infomration. Thanks a lot. I also though about that, but I am afraid of damaging the board, so I did not connect a high voltage.
 
Audio DACs are only for audio, an I2S DAC is not general purpose nor calibrated.

Why not try one of the MicroChip parts like the MCP4921/4922 - 5V or 3V operation, nice and simple.

Yes, that's also correct. I have tried something like MCP4725, and it worked really well. However, I would need 0~10V output range and higher resolution (if possible). So I searched and found this DAC714P. It does not mean everything would be perfect, but if it works, it would be the perfect.
 
You could still use the DAC714P but you will need a level-shifter like the SN74LV1T125 for the SPI signals.
Do not connect the DAC's Vout pin to the Teensy ever [I'm referring to your wiring diagram].
Perhaps MarkT has some useful recommendations in the analog & power area as well.

Paul
 
Yes, that's also correct. I have tried something like MCP4725, and it worked really well. However, I would need 0~10V output range and higher resolution (if possible). So I searched and found this DAC714P. It does not mean everything would be perfect, but if it works, it would be the perfect.

Tian_qhcn:
As MarkT said, using a more Teensy compatible part has many advantages, and you could easily add an Op-Amp buffer to the output to scale the normal output to what ever you like. This also has the advantage of providing a low impedance buffer for any follow-on circuitry.

Regards,
Ed
 
Thank you guys all!
I have somehow solved my problem. I just posted it here for your reference.
The time is not very important for me. Here is the somehow working code:
Code:
#include <SPI.h>
...
SPISettings SPIsettings(16000000, MSBFIRST, SPI_MODE0);
...
void setDAC714(uint16_t count) {
  digitalWrite(pin_clear, HIGH);

  uint16_t mask = 255;
  byte low = count & mask;
  byte high = (count >> 8) & mask;

  SPI.beginTransaction(SPIsettings);
  digitalWrite(pin_input, LOW);
  digitalWrite(pin_latch, LOW);
  
  SPI.transfer(high);
  SPI.transfer(low);

  digitalWrite(pin_input, HIGH);
  SPI.endTransaction();

  digitalWrite(pin_latch, HIGH);
}
 
Back
Top