Hi all,
I am trying to interface DAC1220, 20 bit high resolution DAC from TI, with Teensy 3.5. I attached the code I am using, wiring schematic and DAC1220 datasheet. I can control the DAC1220 with Arduino uno, but I cannot control it with teensy 3.5. The details are as follows.
DAC1220 AVDD and DVDD are supplied with 5V. Teensy 3.5 is powered from USB. I checked the teensy 3.5, input voltages have 5V tolerance. Also, DAC1220 logic input levels are ok with teensy logic levels. (DAC1220 min input high voltage is 2V, output high voltage is max around DVDD, i.e 5V in my case) When I am trying to control DAC with Arduino, I can easily set whatever voltage I want, but when I am trying to control it with teensy 3.5, DAC1220 output is always stays at around 2.5V and no change occurs. I tried to power DAC with 3.3V and see if the issue is related to DAC power supplies, but this time output stayed at 3.3V and no change occured whatever voltage I set in software.
Wiring:
Teensy 37 -> DAC SCLK
Teensy 38 -> DAC SDIO
Teensy 20 -> DAC CS
Could you please look at my code and help me where I am making mistake. I am new to teensy and any help would be great.
I used the code posted in this web page (https://www.breadboarding.de/programmable-voltage-reference-part-1/) and slightly modified it.
Thank you very much for your help in advance.
Ahmet
I am trying to interface DAC1220, 20 bit high resolution DAC from TI, with Teensy 3.5. I attached the code I am using, wiring schematic and DAC1220 datasheet. I can control the DAC1220 with Arduino uno, but I cannot control it with teensy 3.5. The details are as follows.
DAC1220 AVDD and DVDD are supplied with 5V. Teensy 3.5 is powered from USB. I checked the teensy 3.5, input voltages have 5V tolerance. Also, DAC1220 logic input levels are ok with teensy logic levels. (DAC1220 min input high voltage is 2V, output high voltage is max around DVDD, i.e 5V in my case) When I am trying to control DAC with Arduino, I can easily set whatever voltage I want, but when I am trying to control it with teensy 3.5, DAC1220 output is always stays at around 2.5V and no change occurs. I tried to power DAC with 3.3V and see if the issue is related to DAC power supplies, but this time output stayed at 3.3V and no change occured whatever voltage I set in software.
Wiring:
Teensy 37 -> DAC SCLK
Teensy 38 -> DAC SDIO
Teensy 20 -> DAC CS
Could you please look at my code and help me where I am making mistake. I am new to teensy and any help would be great.
I used the code posted in this web page (https://www.breadboarding.de/programmable-voltage-reference-part-1/) and slightly modified it.
Thank you very much for your help in advance.
Ahmet
Code:
#define PIN_CS 20//enable
#define PIN_CLK 37//spi clock
#define PIN_DAT 38//spi data
uint32_t Millis = 0;
uint8_t Buf[10];
uint8_t Len = 0;
float cal = 1.00015;
float offset = 0.0004;
float voltageLimit = 4.99;
float v=3.58; // DAC out voltage
void setup() {
Serial.begin(9600);
pinMode(PIN_CS, OUTPUT);
pinMode(PIN_CLK, OUTPUT);
pinMode(PIN_DAT, OUTPUT);
pinMode(13, OUTPUT);
digitalWrite(PIN_CS, HIGH);
digitalWrite(13, HIGH);
reset();
}
void loop() {
sendData(v);
delay(1000);
}
void sendData (float setVoltage) {
if (setVoltage < offset) {
setVoltage = offset;
}
else if (setVoltage > voltageLimit) {
setVoltage = voltageLimit;
}
uint32_t bitCode = voltageToBits(setVoltage * cal - offset);
if (bitCode > 0xFFFFF) {
bitCode = 0xFFFFF;
Serial.println("input value clipped.");
}
Serial.print("Voltage: ");
Serial.print(setVoltage, 4);
Serial.print(" Bits: ");
Serial.println(bitCode);
Serial.println("-----------------------");
Serial.println("");
bitCode = bitCode << 4;
digitalWrite(13, HIGH);
digitalWrite(PIN_CS, LOW);
shiftOut(PIN_DAT, PIN_CLK, MSBFIRST, 0x40);
shiftOut(PIN_DAT, PIN_CLK, MSBFIRST, (bitCode & 0x00FF0000) >> 16);
shiftOut(PIN_DAT, PIN_CLK, MSBFIRST, (bitCode & 0x0000FF00) >> 8);
shiftOut(PIN_DAT, PIN_CLK, MSBFIRST, (bitCode & 0x000000FF));
digitalWrite(PIN_CS, HIGH);
digitalWrite(13, LOW);
}
uint32_t voltageToBits(float voltage) {
return (voltage / 5.0) * pow(2, 20);
}
void reset () {
digitalWrite(13, HIGH);
digitalWrite(PIN_CS, LOW);
//Reset DAC
pinMode(PIN_CLK, OUTPUT);
digitalWrite(PIN_CLK, LOW);
delay(1);
digitalWrite(PIN_CLK, HIGH);
delayMicroseconds(240); //First high period (600 clocks)
digitalWrite(PIN_CLK, LOW);
delayMicroseconds(5);
digitalWrite(PIN_CLK, HIGH);
delayMicroseconds(480); //Second high period (1200 clocks)
digitalWrite(PIN_CLK, LOW);
delayMicroseconds(5);
digitalWrite(PIN_CLK, HIGH);
delayMicroseconds(960); //Second high period (2400 clocks)
digitalWrite(PIN_CLK, LOW);
delay(1);
//Start Self-Calibration
shiftOut(PIN_DAT, PIN_CLK, MSBFIRST, 0x05);
//20-bit resolution
shiftOut(PIN_DAT, PIN_CLK, MSBFIRST, 0xA1); //20-bit resolution
digitalWrite(PIN_CS, HIGH);
delay(600);
digitalWrite(13, LOW);
Serial.println("DAC reset sucessful");
sendData(2.5);
}
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, int val, uint8_t bits = 8, uint8_t del = 10) {
uint8_t i;
for (i = 0; i < bits; i++) {
if (bitOrder == LSBFIRST)
digitalWrite(dataPin, !!(val & (1 << i)));
else
digitalWrite(dataPin, !!(val & (1 << ((bits - 1 - i)))));
digitalWrite(clockPin, HIGH);
delayMicroseconds(del);
digitalWrite(clockPin, LOW);
}
}