I'm trying to make a cycle with a voltage varying from 0 to 5V, then from 5V to -5V and finally from 5 to 0V.
In order to do this, I'm using a SPI DAC (MAX 5312). I already succeed to get the DAC output voltages between -5 and +5V.
But now I have issues to get the right voltage cycle. Here is my loop code. The two fist loops (to go from 0 to 5 and then from 5 to 0) work.
But there are problems as soon as there are negative numbers. The loop which is supposed to go from 0 to -5, goes from +10V to -5. And the last one which is supposed to go from -5V to 0 goes from -5V to +10V.
I tried to write the numbers in 16 bits binary code as well as in decimal numbers, but the issues are still the same ones.
Moreover, the "transfer" function just transfer the code to the DAC.
void loop() {
int command = 0b0100000000000000; // Command which allows DAC output to be updated
int data;
int commandPlusData;
//Signal incremented from 0 up to 5V
for (data=0b0000100000000000; data <0b0000110000000000; data++){
commandPlusData = command | data;
transfer(commandPlusData);
delay(30);
}
// Signal decremented from 5 to 0V
for (data=3072; data > 2048; data--){
commandPlusData = command | data;
transfer(commandPlusData);
delay(30);
}
// Signal decremented from 0 to -5V
for (data=2048; data > 512; data--){
commandPlusData = command | data;
transfer(commandPlusData);
delay(30);
}
//Signal incremented from -5V up to 0V
for (data=0b0000001000000000; data < 0b0000100000000000; data++){
commandPlusData = command | data;
transfer(commandPlusData);
delay(30);
}
}
If you are using 5V for REF you should be using the constants:
0x400 or 1024 = -5V
0x800 or 2048 = 0V
0xC00 or or 3072 = +5V
If you want more precision, use a 2.5V REF:
0x000 or 0 = -5V
0x800 or 2048 = 0V
0xFFF or or 4095 = +5V minus 1 LSB
Looks like you are using 5V REF. I have converted all your constants to HEX for clarity
//Signal incremented from 0 up to 5V
for (data=0x800; data < 0xC00; data++){
// Signal decremented from 5 to 0V
for (data=0xC00; data > 0x800; data--){
// Signal decremented from 0 to -5V
for (data=0x800; data > 0x200; data--) { // That 0x200 should be 0x400
//Signal incremented from -5V up to 0V
for (data=0x200; data < 0x800; data++){ // That 0x200 should be 0x400
Those 512 values should produce an output of -7.5V instead of the desired -5V.
You can go from +5 to -5 directly:
// Signal decremented from +5V to -5V
for (data=0xC00; data > 0x400; data--) {
If you don't mind starting at +5V you can do it all in two loops:
// Signal decremented from +5V to -5V
for (data=0xC00; data => 0x400; data--) {
// Signal incremented from -5V to +5V
for (data=0x400; data <= 0xC00; data++) {
Vdd and Vss are respectively connected to +15V and -15V.
Yes I'm using a 5V REF, but I can't use any power supply exept the Arduino Power, that's why I'm using the 5V Arduino power.
At the beginning I also thought that I was supposed to get -5V with the constant 1024. But it didn't work. The weird thing is I get -5V when I send 512 to the DAC, -7,5V when I send 256 and also -2,5V when I send 768.
So when I want to send the constant 1024 or 0x400 as you said, the voltage on the DAC output is almost 0V.
I tried to change the 0x200 to 0x400 anyway, and now the voltage loop goes from 0 to 5V, then 5V to 0V, then it jumps to +10V to 0V, and finally it goes from 0V to 10V.
The number format (hex,bin,dec,oct) as you write it it your code makes no difference to the way the number is represented inside the program. Allowing different formats is done because sometimes it is easier to write the number in octal than in decimal (for example).
Aurelied:
Vdd and Vss are respectively connected to +15V and -15V.
I tried to change the 0x200 to 0x400 anyway, and now the voltage loop goes from 0 to 5V, then 5V to 0V, then it jumps to +10V to 0V, and finally it goes from 0V to 10V.
I know nothing about that DAC, but have you thought that the +10V you're getting may be your +15V supply -5V?
To get more accuracy you could use the 3.3V output of the Arduino for REF. That would give an output range from -6.6V to +6.6V. The 0V value would still be 0x800 and the voltages would be +/- 0x60F (1,551) or 0x1F1 for -5V and 0xE0F for +5V. That would be 3102 steps between -5 and -5 instead of 2048.
Have you got SGND connected to AGND? Are you measuring your output relative to AGND/SGND?
johnwasser:
Have you got SGND connected to AGND? Are you measuring your output relative to AGND/SGND?
I connected all the grounds SGND, AGND, DGND, the Arduino ground and the -/+15V power supply ground all together. And I'm measuring my output relative to one of these grounds.
johnwasser:
To get more accuracy you could use the 3.3V output of the Arduino for REF.
As you suggested, I even used a 2,5V REF by using a voltage divider with the 5V output of the Arduino. But the issue is still the same : at first it's fine, the voltage goes from 0 to 5V, then decreases from 5V to 0V, but then jumps to 5V again, decreases to -5V and increases to 5V. Here is my code.
void loop() {
int command = 0b0100000000000000; // Command which allows DAC output to be updated
int data;
int commandPlusData;
//Signal incremented from 0 up to 5V
for (data=0x800; data < 0xFFF; data++){
commandPlusData = command | data;
transfer(commandPlusData);
delay(15);
}
// Signal decremented from 5 to -5V
for (data=0xFFF; data > 0x000; data--){
commandPlusData = command | data;
transfer(commandPlusData);
delay(15);
}
//Signal incremented from -5V up to 0V
for (data=0x000; data < 0x800; data++){
commandPlusData = command | data;
transfer(commandPlusData);
delay(15);
}
}
Henry_Best:
I know nothing about that DAC, but have you thought that the +10V you're getting may be your +15V supply -5V?
I don't really get what you mean, why would the DAC power supply affect the output ? I rather tought that the +10V I got was related to the maximum value, which is 2*REF and my REF was +5V.
This might make sense because when I changed my REF to +2,5V, it also jumps to the maximum value, +5V.
Aurelied:
But the issue is still the same : at first it's fine, the voltage goes from 0 to 5V, then decreases from 5V to 0V, but then jumps to 5V again, decreases to -5V and increases to 5V. Here is my code.
I have no clue how that is happening.
I think it is time to put in some debug prints to see if it is the code or the DAC that is going wonky. Fortunately that is something I can try on my Arduino here.
johnwasser:
Are you sure the UNI/BIP pin is tied LOW (=Bipolar)?
Yes this pin is tied low.
johnwasser:
I have no clue how that is happening.
I think it is time to put in some debug prints to see if it is the code or the DAC that is going wonky. Fortunately that is something I can try on my Arduino here.
I soldered the DAC to the adapter by myself so maybe I did something wrong, but I checked all the DAC pins and they seemed to be good.
Thank you anyways for trying and for the help.