SPI protocol with external DAC


good morning!
i have problem interfacing between arduino due board , external high resolution dac, ad5570http://www.analog.com/media/en/technical-documentation/data-sheets/ad5570.pdf
i obtain 2 different output:

1- constant voltage output: user select desired output voltage (1v, 100mv, -100mv...) , board sent dac proper binary code in order obtain thet voltage;

2-voltage ramp out;

i've written regarding first problem can't obtain result (i have no idea how solve second problem). code following:

code: [select]

#include <spi.h>

int dacr;
long din;                          //input signal
const int v_ref = 5;              //reference voltage
long tot_level = 65536;           //2^16 of output (16 bit dac)

void setup() {
 serial.begin(115200);
 spi.begin(pinsync_dac);
 spi.setbitorder(msbfirst);
 spi.setclockdivider(21);       
 spi.setdatamode(pinsync_dac,spi_mode1);
}

void loop() {
  if (serial.available()!=0){
    dacr = serial.parseint() ;
    serial.print("voltage selected: ");
    serial.println(dacr,dec);
    din = ((dacr + 2* v_ref)*tot_level)/(4*v_ref);         
    serial.println(din);
    delay(1000);
    if(din>=tot_level){
        din=tot_level;}
    byte msg1 = (din >> 8);
    byte msg2 = (din & 0xff);
    serial.println(msg1,bin);
    serial.println(msg2,bin);
    }
}



and obtain on serial monitor when run program:

code: [select]
voltage selected: 1
36044
10001100
11001100
voltage selected: 2
39321
10011001
10011001
voltage selected: 3
42598
10100110
1100110
voltage selected: 5
49152
11000000
0
voltage selected: -1
29491
1110011
110011
voltage selected: -2
26214
1100110
1100110


i don't know wrong don't know how solve problem. unfortunately i'm stuck on these 2 problem , can't go ahead. how can send binary code dac through arduino due?
thank attention!

quote
arduino: 1.6.2 (windows 8.1), td: 1.22-beta1, board: "arduino uno"

sketch_sep03a.ino: in function 'void setup()':

sketch_sep03a.ino:11:12: error: 'pinsync_dac' not declared in scope

error compiling.
please give real sketch running.

what did try enter when got outputs? did expect see in output?


Arduino Forum > Using Arduino > Networking, Protocols, and Devices (Moderator: fabioc84) > SPI protocol with external DAC


arduino

Comments