1-Constant voltage output selectable by user (ex. 100mV, 1V). The user will select the desired voltage using the serial monitor and the software will sent to DAC the proper binary code in order to obtain the correct voltage;
2-Voltage ramp output, with the slope adjustable by user in order to perform a different measuerement.
I read some examples online but i haven't understand them completely. I tried to write something about the first point but i could not obtain a good result.
int DACR;
float DACR_MILLI;
long Din; //Input signal
String Din_Bin; //binary code
const int V_ref = 5; //reference voltage
const int tot_level = 65536; //2^16of the output (16 bit DAC)
float millivolt = 0.001; //conversion in millivolt
if (Serial.available()!=0){
DACR = Serial.parseInt() ;
DACR_MILLI = DACR*millivolt;
Serial.print("Voltage selected [mV]: ");
Serial.println(DACR,DEC);
Din = (DACR_MILLI/(4*V_ref) + 0.5)*tot_level;
Din_Bin = Din_Bin + String(Din,BIN);
Serial.println(Din_Bin);
delay(1000);
digitalWrite(pinSYNC_DAC,LOW); //SPI transfer
SPI.transfer(pinSYNC_DAC, highByte(Din_Byte), SPI_CONTINUE);
SPI.transfer(pinSYNC_DAC, lowByte(Din_Byte), SPI_LAST);
digitalWrite(pinSYNC_DAC,HIGH);
}
}
Please post a complete sketch. You are missing the SPI.begin() which may be part of the problem.
The use of Serial.parseInt() is a little problematic. You should check that you got a good value from that before you apply it to the output. Your description of the problem does not say if you have got the correct value echoed by Serial.print() or if the aparrent problem is elsewhere.
On the Due the SPI hardware uses one of pins 4, 10 or 52 as chip select and drives it
automatically I think. This is the difference between SPI_CONTINUE and SPI_LAST (which
releases the relevant chip select). Thus you must call SPI.begin (N) where N is one of these
three possible CS pins to configure the hardware. You must not call just SPI.begin(),
call SPI.begin (pinSYNC_DAC)
[ Assuming I've remembered correctly - my Due SPI code always passes a pin to begin ]
Does this really do what you expect it to? Are those large numbers printing what you expect for 100V, 200V, 50V as inputs?
Now how about fixing it so that it's using millivolts instead?
byte msg2=(byte)Din;
byte msg1=(byte)(Din>>8);
It looks like you're trying to pull the bottom two bytes off a 4-byte integer. This doesn't seem like it's the right thing to do. All of the values you've printed are larger than 65536 so they can't be represented with 2 bytes.
I don't understand why Msg1 keeps printing out as 255. I did not expect that to occur. It may just be a coincidence due to the 3 input values chosen.
Mmm seems that there are lot of problems here.
Can someone give me some advices in order to solve my problems? and this is only the first one.
I'm sorry but i'm new to this language and board so i have a lot of problem.
You are getting close. It won't take much more work until the "aha!" moment strikes you.
The Due treats SPI slightly differently to the other Arduinos. It is better, but in this case "better" means more control and more stuff you have to set in advance before you can use it.
I'm sorry the forum isn't more helpful to you but this is one of those things that you just have to work out for yourself. Then you can report back here and tell us, so perhaps the next person in your position is given a better clue to the "Aha!"
That didn't take long. I'll be the next in line looking for the solution.
Fortunately, i'm much slower than you guys. I don't even have the hardware, but i know i'll need it as i'll need the high resolution as well. Problem is.... where can i purchase this AD5570? I can DL the spec sheet without issue, but if I google the unit, i come up with nothing but data sheets.... hold the phone. Is this an IC? I thought i'd be looking for a pcb like the DUE. If an IC, does it fit in a breadboard well?
Georgia_Dan:
Problem is.... where can i purchase this AD5570? I can DL the spec sheet without issue, but if I google the unit, i come up with nothing but data sheets.... hold the phone. Is this an IC? I thought i'd be looking for a pcb like the DUE. If an IC, does it fit in a breadboard well?
It is available from any of the major electronics component suppliers: Mouser, Digi-Key, Element14 and more.
The datasheet only shows a surface-mount package, so it's not breadboardable without an adaptor board. The datasheet also contains instructions on keeping the analog side very clean because you won't be able to achieve 16 bits accuracy on a breadboard. They do mention an "evaluation board" which might be more like what you're looking for. That would be the best way to get your hands on one for testing.