LTC1257 with arduino

Hello!

I am not able to use the LTC1257 DAC with arudino.

I have tried everything, but somehow I just can not get it work.

#include "SPI.h"

void setup(){
  
  Serial.begin(19200);
  pinMode(10, OUTPUT);
  pinMode(11,OUTPUT);
  pinMode(12,OUTPUT);

  SPI.begin(); 
  SPI.setBitOrder(MSBFIRST);

}
 
void loop() {
  digitalPotWrite(0b0000111111111111);
  //digitalPotWrite(2000);
  //setDac2(1000);
  //setDac(2010);
 
 delay(100);

}

void digitalPotWrite(uint16_t value) {
 
  digitalWrite(10, LOW);
  
  SPI.transfer (lowByte(value));
  SPI.transfer (highByte(value));

  digitalWrite(10, HIGH);
  
  Serial.println(analogRead(4));
  
 
}



void setDacClk(bool v) {
  digitalWrite(11, v);
}

void setDacData(bool v) {
  digitalWrite(10, v);
}

void setDacLoad(bool v) {
  digitalWrite(12, v);
}

void setDac(uint16_t value) {
  setDacLoad(true);
  for (int i = 11; i >= 0; i--) {
    setDacClk(false);
    setDacData(((value & (1 << i)) != 0));
    setDacClk(true);
  }
  setDacLoad(false);
  setDacLoad(true);
    Serial.println(analogRead(4));
}

void setDac2(uint16_t value) {
  setDacClk(false);
  setDacLoad(true);
  for (int i = 11; i >= 0; i--) {
    
    setDacData(true);

    setDacClk(true);

    setDacClk(false);
  }
  setDacClk(false);
  setDacLoad(false);

  setDacLoad(true);
    Serial.println(analogRead(4));
}

SerialMonitor output:
14
411
404
391
365
312
207
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
.
.
.

Can you please help me what am I doing wrong?

Thanks!

What type of Arduino do you have? What Arduino uses pins 10, 11, and 12 for SPI? How do you have things connected? Why are you using SPI.h but appear to be bit-banging the SPI protocol? Is SPI.h from the SPI library or something of your own?

Where is your "... SPI.beginTransaction() to begin using the SPI port." ?

I could be wrong, but I don't think anyone can help you until you provide a lot more information.

I admit that I have not used SPI, but this doesn't look right.

Why are you using SPI.h but appear to be bit-banging the SPI protocol?

This is not bit banging:

SPI.transfer (lowByte(value));
SPI.transfer (highByte(value));

But this is bit banging:

void setDac(uint16_t value) {
  setDacLoad(true);
  for (int i = 11; i >= 0; i--) {
    setDacClk(false);
    setDacData(((value & (1 << i)) != 0));
    setDacClk(true);
  }
  setDacLoad(false);
  setDacLoad(true);
    Serial.println(analogRead(4));
}

hence my confusion.

Hello!

Sorry, I told I have tried many ways but non of them were working or just partly.
Now I have figured it how it works with bit banging.

Arduino PiN D13 - LTC PiN 1 CLK
Arduino PiN D11 - LTC PiN 2 Din
Arduino PiN D10 - LTC PiN 3 Load
Arduino PiN A4 - LTC PiN 7 Vout
Arduino PiN 5V - LTC PiN 8 Vcc
Arduino PiN Vin - LTC PiN 6 Vref
Arduino PiN GND - LTC PiN 5 GND

Arduino PiN Vin is around 12 Volt.

Here is one:

void setup(){
  Serial.begin(19200);
  pinMode(10, OUTPUT);
  pinMode(11,OUTPUT);
  pinMode(13,OUTPUT);
}
 
void loop() {
 for (int i = 0; i < 4096; i++) {
   Serial.print(i);
   Serial.print(": ");
   setDac(i); 
 }
}


void setDacClk(bool v) {
  digitalWrite(13, v);
}

void setDacData(bool v) {
  digitalWrite(11, v);
}

void setDacLoad(bool v) {
  digitalWrite(10, v);
}

void setDac(uint16_t value) {
  setDacLoad(true);
  for (int i = 11; i >= 0; i--) {
    setDacClk(false);
    setDacData(((value & (1 << i)) != 0));
    setDacClk(true);
  }
  setDacLoad(false);
  setDacLoad(true);
    Serial.println(analogRead(4));
}

Serial output:
: 0
1: 0
2: 0
3: 0
4: 0
5: 1
6: 1
7: 2
8: 3
9: 3
10: 4
11: 4
12: 5
13: 5
14: 6
15: 7
16: 7
17: 8
18: 8
19: 9
20: 10
21: 10
22: 11
23: 11
24: 12
25: 13
26: 13
27: 14
28: 14
29: 15
30: 15
31: 16
32: 17
33: 17
34: 18
35: 18
36: 19
37: 19
38: 20
39: 20
40: 21
41: 22
42: 22
43: 23
44: 23
45: 24
46: 24
47: 25
48: 25
49: 26
50: 27
51: 27
52: 28
53: 28
54: 29
55: 29
56: 30
57: 31
58: 31
59: 31
60: 32
61: 33
62: 33
63: 34
64: 34
65: 35
66: 36
67: 36
68: 37
69: 37
70: 38
71: 38
72: 39
73: 40
74: 40
75: 41
76: 41
77: 42
78: 42
79: 43
80: 43
81: 44
82: 44
83: 45
84: 46
85: 47
86: 47
87: 47
88: 48
89: 49
90: 49
91: 50
92: 50
93: 51
94: 52
95: 52
96: 53
97: 53
98: 54
99: 54
100: 55
101: 56
102: 56
103: 56
104: 57
105: 58
106: 58
107: 59
108: 59
109: 60
110: 61
111: 61
112: 62
113: 63
114: 63
115: 64
116: 64
117: 65
118: 66
119: 66
120: 66
121: 67
122: 68
123: 68
124: 69
125: 69
126: 70
127: 71
128: 71
129: 71
130: 72
131: 73
132: 73
133: 74
134: 74
135: 75
136: 76
137: 76
138: 77
139: 77
140: 78
141: 79
142: 79
143: 79
.
.
.
710: 402
711: 404
712: 406
713: 404
714: 407
715: 404
716: 407
717: 409
718: 406
719: 409
720: 411
721: 409
722: 411
723: 409
724: 411
725: 414
726: 411
727: 413
728: 415
729: 413
730: 415
731: 415
.
.
1103: 626
1104: 627
1105: 628
1106: 630
1107: 631
1108: 632
1109: 633
1110: 628
1111: 630
1112: 631
1113: 632
1114: 634
1115: 635
1116: 636
.
.
.
.
1323: 753
1324: 755
1325: 757
1326: 757
1327: 753
1328: 754
1329: 755
1330: 757
1331: 759
1332: 760
1333: 762
1334: 760
1335: 757
1336: 758
1337: 761
1338: 762
1339: 763
1340: 765
1341: 765
1342: 764
1343: 763
1344: 764
1345: 766
1346: 767
1347: 767
1348: 768
1349: 768
1350: 768
1351: 768
1352: 769
1353: 769
1354: 769

So now it is working, only does not want to the ltc out more than 3.7 V. Why is that?
I would need 0-12 V. Thanks!

According to the data sheet at http://cds.linear.com/docs/en/datasheet/1257fc.pdf (page 6):
"VOUT (Pin 7): The buffered DAC output is capable of
sourcing 2mA over temperature while pulling within 2.7V
of VCC. ... "

You are pulling within 1.3 volts (5 - 3.7) of Vcc. You are getting better than specification value. [Perhaps. You are not pulling 2mA.] What did you expect?

You cannot get an output of 12 volts using a Vcc of 5 volts.

Notice also (same URL, page 1): "... An external reference can be used to override
the internal reference and extend the output voltage range
to 12V. ..."

You also appear to have violated (same URL, page 8 ): "... The external reference must be greater
than 2.475V and less than VCC – 2.7V, ..." because your reference is 12 volts but your Vcc is 5 volts.

You may get close to 12 volts out with 12 volts input IF YOU USE A DIFFERENT PART. The LTC1257 would need a Vcc of almost 15 volts to get 12 volts out.

I wanted to help, but the time to help would have been prior to selecting this part. It's a nice part, but it can't accomplish this task. This could be fixed with an op amp, some resistors and some capacitors, but I suspect you don't want more parts.

Tread carefully, read the data sheet, and perhaps get more education as an electrical engineer. So far, you have gone about this incorrectly. Fortunately, you do not appear to have destroyed anything - yet.

This was my first reading of this data sheet. I do not plan to delve any deeper. I don't intend to sound harsh, I am just frustrated.

Hello!

First of all I would like to thank you your help.

You are absolutely right, I am not an electric guy. i am more into web developing, but I have a project that i need to solve.
I wanted to hire someone, but I could not find anybody...

I am not sure that LTC1257 is good for me after your explanation.

Can any recommend a DAC that does not need any extra component and works with arduino without any extra component, that can be output 0-Vref. 0 Volt on code 0, Vref/2 Volt on code 2048, Vref Volt on code 4095, etc.
If it is not 12 bit but 10 bit, that is also good.

Vcc, and Vref is from a battery around 11-15 V.

Thanks

Hello,

If this is still relevant, I will use a +15V source for Vcc, and a linear regulator to make a +10V for the Vref. The digital interface will still be +5V, as the LTC1257 has an internal reference for it. It will have only 1 external component: the linear regulator.

Thanks for the code BTW :slight_smile: