Midi to CV  with DAC

Hi, Ive been working on this MIDI to Cv converter that uses an AD 5668 DAC:Homebrew midi-cv box
code is in the next post.
So far on the arduino side , the sketch seems to be running fine, but I get no output from the DAC. While the project is pretty well documented on the linked site, there is no schematic. The wiring has to be deduced by the sketch and datasheet. Im Pretty sure I got it:

optoisolated Midi in >> to ardiuino #0

arduino pins DAC pins
3,(data out) >> 15(Din),
4, (spi clk) >> 16 (sclk),
5, (slave select) >> 2 (sync),
6, (Ldac) >> 1 (ldac),
7 (clr) >> 9 (clr)

arduino pins 8 and 9 are to leds
dac pins 4-7 and 10-13 are the output pins.
dac pin 8 is vref in/out and is reportedly left unconnected.
5v+ and gnd from arduino.
the Dac power pin # has a 10uf cap in parallel and a .1uf to ground, as recommended in the data sheet. http://www.analog.com/static/imported-files/data_sheets/AD5628_5648_5668.pdf
I dont have a lot of experience with DACs, but if it were working i should be able to measure a voltage between the dac outs and ground, right? I changed the baud rate in the sketch for MiDI (31250)
Is there something I missing? Thanks in advance.

PIN CONFIGURATIONS AND FUNCTION DESCRIPTIONS

LDAC
Pulsing this pin low allows any or all DAC registers to be updated if the input registers have new data. This allows all DAC outputs to simultaneously update. Alternatively, this pin can be tied permanently low.
1
2
SYNC
Active Low Control Input. This is the frame synchronization signal for the input data. When SYNC goes low, it powers on the SCLK and DIN buffers and enables the input shift register. Data is transferred in on the falling edges of the next 32 clocks. If SYNC is taken high before the 32nd falling edge, the rising edge of SYNC acts as an interrupt and the write sequence is ignored by the device.
2
3
VDD
Power Supply Input. These parts can be operated from 2.7 V to 5.5 V, and the supply should be decoupled with a 10 [ch956]F capacitor in parallel with a 0.1 [ch956]F capacitor to GND.
3
4
VOUTA
Analog Output Voltage from DAC A. The output amplifier has rail-to-rail operation.
11
13
VOUTB
Analog Output Voltage from DAC B. The output amplifier has rail-to-rail operation.
4
5
VOUTC
Analog Output Voltage from DAC C. The output amplifier has rail-to-rail operation.
10
12
VOUTD
Analog Output Voltage from DAC D. The output amplifier has rail-to-rail operation.
7
8
VREFIN/VREFOUT
The AD5628/AD5648/AD5668 have a common pin for reference input and reference output. When using the internal reference, this is the reference output pin. When using an external reference, this is the reference input pin. The default for this pin is as a reference input.
N/A
9
CLR
Asynchronous Clear Input. The CLR input is falling edge sensitive. When CLR is low, all LDAC pulses are ignored. When CLR is activated, the input register and the DAC register are updated with the data contained in the CLR code register—zero, midscale, or full scale. Default setting clears the output to 0 V.
5
6
VOUTE
Analog Output Voltage from DAC E. The output amplifier has rail-to-rail operation.
9
11
VOUTF
Analog Output Voltage from DAC F. The output amplifier has rail-to-rail operation.
6
7
VOUTG
Analog Output Voltage from DAC G. The output amplifier has rail-to-rail operation.
8
10
VOUTH
Analog Output Voltage from DAC H. The output amplifier has rail-to-rail operation.
12
14
GND
Ground Reference Point for All Circuitry on the Part.
13
15
DIN
Serial Data Input. This device has a 32-bit shift register. Data is clocked into the register on the falling edge of the serial clock input.
14
16
SCLK
Serial Clock Input. Data is clocked into the input shift register on the falling edge of the serial clock input. Data can be transferred at rates

//MIDI DAC V11 by Robin Price 2009
#define ENVELOPE 0 //Analog in on Arduino to test output of AD5668
#define ZEROIN 2 //Zero crossing interupt
#define DATAOUT 3 //MOSI, DIN Pin 15 on AD5668
#define SPICLK 4 //Serial Clock In, SCLK Pin 16
#define SLAVESELECT 5//SYNC Active Low Control Input, Pin 2
#define LDAC 6//LDAC, Pin 1, Pulse this pin low to update DAC registers, can be tied permanently low.
#define CLR 7
#define PWRLED 8
#define RXLED 9

#define GATE 0
#define CV 1
#define ACC 2
#define SLD 3
#define FILT 4

//AD5668 Command definitions
#define WRITE 0
#define UPDATE 1
#define WRITE_UPDATE_ALL 2
#define WRITE_UPDATE_N 3
#define POWER 4
#define LOAD_CC_REG 5
#define LOAD_LDAC_REG 6
#define RESET 7
#define SETUP_INTERNAL_REGISTER 8

byte incomingByte;
int action = 0; //0 not implemented/do nothing, 1 note on, 2 note off, 3 cc, 4 sysex
int note = -1;
int velocity = -1;
int extra1 = -1;
int extra2 = -1;

int RX = LOW;                // previous value of the LED
unsigned long previousMillis = 0;        // will store last time LED was updated
unsigned long interval = 100;           // interval at which to blink (milliseconds)
volatile unsigned int count = 0;
extern volatile unsigned long timer0_millis;
unsigned long previous_clock = 0;
unsigned long start;
unsigned long finish;
int amp = 0;
float freq = 0;
volatile unsigned int period;
boolean note_on = false;
boolean sysex = false;
unsigned int voltage1 = 13400;
unsigned int voltage2 = 26500;
unsigned int voltage3 = 39550;
unsigned int voltage4 = 52625;
long voltage5 = 65735;

unsigned char timerLoadValue;
#define TIMER_CLOCK_FREQ 2000000.0 //2MHz for /8 prescale from 16MHz
unsigned int latency;
volatile unsigned long clock;
//This timer code is for to setup the interrupt from the pitch detection part of the circuit
//and is largely nicked from uchobby.com if you're only interested in the midi-cv stuff just
//ignore it.

//Setup Timer2.
//Configures the ATMega168 8-Bit Timer2 to generate an interrupt at the specified frequency.
//Returns the time load value which must be loaded into TCNT2 inside your ISR routine.
unsigned char SetupTimer2(float timeoutFrequency){
  unsigned char result; //The value to load into the timer to control the timeout interval.

  //Calculate the timer load value
  result=(int)((257.0-(TIMER_CLOCK_FREQ/timeoutFrequency))+0.5); //the 0.5 is for rounding;
  //The 257 really should be 256 but I get better results with 257, dont know why.

  //Timer2 Settings: Timer Prescaler /8, mode 0
  //Timmer clock = 16MHz/8 = 2Mhz or 0.5us
  //The /8 prescale gives us a good range to work with so we just hard code this for now.
  TCCR2A = 0;
  TCCR2B = 0<<CS22 | 1<<CS21 | 0<<CS20; 

  //set our clock to zero
  clock = 0;

  //Timer2 Overflow Interrupt Enable   
  TIMSK2 = 1<<TOIE2;

  //load the timer for its first cycle
  TCNT2=result; 
  
  return(result);
}

//Timer2 overflow interrupt vector handler
ISR(TIMER2_OVF_vect) {

  //Increment clock, at some point we're going to have to handle overflows
  clock++;
  
  //Capture the current timer value. This is how much error we have
  //due to interrupt latency and the work in this function
  latency=TCNT2; //consider getting rid of the latency stuff and allowing the clock to be reset to zero

  //Reload the timer and correct for latency.
  TCNT2=latency+timerLoadValue; 
}

void setup() {
  //set pin modes
  pinMode(ENVELOPE, INPUT);
  pinMode(ZEROIN, INPUT);
  pinMode(DATAOUT, OUTPUT);
  pinMode(SPICLK, OUTPUT);
  pinMode(SLAVESELECT, OUTPUT);
  pinMode(LDAC, OUTPUT);
  pinMode(CLR, OUTPUT);
  pinMode(PWRLED, OUTPUT);
  pinMode(RXLED, OUTPUT);
  //disable DAC to start with
  digitalWrite(DATAOUT,LOW);
  digitalWrite(SPICLK, LOW);
  digitalWrite(SLAVESELECT, LOW);
  digitalWrite(LDAC, HIGH);
  digitalWrite(PWRLED, HIGH);
  digitalWrite(RXLED, HIGH);
  digitalWrite(CLR, LOW);
  delay(500);
  digitalWrite(CLR, HIGH);
  delay(500);
  delay(1000);
  write_dac(SETUP_INTERNAL_REGISTER, 0, 1); //set up internal register on DAC
  delay(1000);
  write_dac(POWER, 0, 0);
  delay(1000);
  write_dac(RESET, 0, 0);
  delay(1000);
  digitalWrite(RXLED, LOW);
  //Start the timer and get the timer reload value.
  timerLoadValue=SetupTimer2(40000);
  //set up interupt for zero crossing detector
  attachInterrupt(0, zero, RISING);
  Serial.begin(31250 
  ) ; //change this when you want to graduate from usb midi to real midi
}

void zero() {
  period = (clock - previous_clock); //how many 25 microsecond ticks have elapsed
  previous_clock = clock;
}

void write_dac(byte command, byte address, unsigned int data) {
  switch (command) {
    case WRITE_UPDATE_N:
    {
      byte b1 = B11110000|command; //padding at beginning of byte
      //Serial.print("b1 ");
      //Serial.println(b1, BIN);
      byte b2 = address << 4 | data >> 12; //4 address bits and 4 MSBs of data
      //Serial.print("b2 ");
      //Serial.println(b2, BIN);
      byte b3 = (data << 4) >> 8; // middle 8 bits of data
      //Serial.print("b3 ");
      //Serial.println(b3, BIN);
      byte b4 = (data << 12) >> 8 | B00001111;
      //Serial.print("b4 ");
      //Serial.println(b4, BIN);
      //Serial.println();
      digitalWrite(SLAVESELECT, LOW);
      delayMicroseconds(1);
      shiftOut(DATAOUT, SPICLK, MSBFIRST, b1);
      shiftOut(DATAOUT, SPICLK, MSBFIRST, b2);
      shiftOut(DATAOUT, SPICLK, MSBFIRST, b3);
      shiftOut(DATAOUT, SPICLK, MSBFIRST, b4);
      delayMicroseconds(1);
      digitalWrite(LDAC, LOW);
      delayMicroseconds(1);
      digitalWrite(LDAC, HIGH);
      delayMicroseconds(1);
      digitalWrite(SLAVESELECT, HIGH);
      break;
    }
    case SETUP_INTERNAL_REGISTER:
    {
      byte b1 = B11111000; //padding at beginning of byte
      //Serial.print("b1 ");
      //Serial.println(b1, BIN);
      byte b2 = B00000000;
      //Serial.print("b2 ");
      //Serial.println(b2, BIN);
      byte b3 = B00000000;
      //Serial.print("b2 ");
      //Serial.println(b3, BIN);
      byte b4 = B00000000|data;
      //Serial.print("b4 ");
      //Serial.println(b4, BIN);
      //Serial.println();
      digitalWrite(SLAVESELECT, LOW);
      delayMicroseconds(1);
      shiftOut(DATAOUT, SPICLK, MSBFIRST, b1);
      shiftOut(DATAOUT, SPICLK, MSBFIRST, b2);
      shiftOut(DATAOUT, SPICLK, MSBFIRST, b3);
      shiftOut(DATAOUT, SPICLK, MSBFIRST, b4);
      delayMicroseconds(1);
      digitalWrite(SLAVESELECT, HIGH);
      break;
    }
    case RESET:
    {
      byte b1 = B11110111; //padding at beginning of byte
      //Serial.print("b1 ");
      //Serial.println(b1, BIN);
      byte b2 = B00000000;
      //Serial.print("b2 ");
      //Serial.println(b2, BIN);
      byte b3 = B00000000;
      //Serial.print("b2 ");
      //Serial.println(b3, BIN);
      byte b4 = B00000000|data;
      //Serial.print("b4 ");
      //Serial.println(b4, BIN);
      //Serial.println();
      digitalWrite(SLAVESELECT, LOW);
      delayMicroseconds(1);
      shiftOut(DATAOUT, SPICLK, MSBFIRST, b1);
      shiftOut(DATAOUT, SPICLK, MSBFIRST, b2);
      shiftOut(DATAOUT, SPICLK, MSBFIRST, b3);
      shiftOut(DATAOUT, SPICLK, MSBFIRST, b4);
      delayMicroseconds(1);
      digitalWrite(SLAVESELECT, HIGH);
      break;
    }
    case POWER:
    {
      byte b1 = B11110100; //padding at beginning of byte
      //Serial.print("b1 ");
      //Serial.println(b1, BIN);
      byte b2 = B00000000;
      //Serial.print("b2 ");
      //Serial.println(b2, BIN);
      byte b3 = B00000000;
      //Serial.print("b2 ");
      //Serial.println(b3, BIN);
      byte b4 = B11111111;
      //Serial.print("b4 ");
      //Serial.println(b4, BIN);
      //Serial.println();
      digitalWrite(SLAVESELECT, LOW);
      delayMicroseconds(1);
      shiftOut(DATAOUT, SPICLK, MSBFIRST, b1);
      shiftOut(DATAOUT, SPICLK, MSBFIRST, b2);
      shiftOut(DATAOUT, SPICLK, MSBFIRST, b3);
      shiftOut(DATAOUT, SPICLK, MSBFIRST, b4);
      delayMicroseconds(1);
      digitalWrite(SLAVESELECT, HIGH);
      break;
    }
  }
}

void playNote(int note_, int velocity) {
  unsigned int note = note_;
  unsigned int voltage = 0;
  if ((note >= 12) && (note < 24)) {
    //Serial.println("note >= 12 && note < 24");
    voltage = (voltage1)*((note - 12)/12.0);
  } else if ((note >= 24) && (note < 36)) {
    //Serial.println("note >= 24 && note < 36");
    voltage = (voltage2 - voltage1)*((note - 24)/12.0) + voltage1;
  } else if ((note >= 36) && (note < 48)) {
    //Serial.println("note >= 36 && note < 48");
    voltage = (voltage3 - voltage2)*((note - 36)/12.0) + voltage2;
  } else if ((note >= 48) && (note < 60)) {
    //Serial.println("note >= 48 && note < 60");
    voltage = (voltage4 - voltage3)*((note - 48)/12.0) + voltage3;
  } else if ((note >= 60) && (note < 72)) {
    //Serial.println("note >= 60 && note < 72");
    voltage = (voltage5 - voltage4)*((note - 60)/12.0) + voltage4;
  }
  note_on = true;
  if ((velocity >= 1) && (velocity < 64)) { //normal note
    write_dac(WRITE_UPDATE_N, ACC, 0);
    write_dac(WRITE_UPDATE_N, CV, voltage);
    write_dac(WRITE_UPDATE_N, GATE, 65535);

sorry, ran out of characters...heres the rest:

 Serial.print("cv = ");
    Serial.print(voltage);
    Serial.println(", accent = OFF");
  } else if (velocity >= 64) { //accent 
    write_dac(WRITE_UPDATE_N, ACC, 65535);
    write_dac(WRITE_UPDATE_N, CV, voltage);
    write_dac(WRITE_UPDATE_N, GATE, 65535);
    Serial.print("cv = ");
    Serial.print(voltage);
    Serial.println(", accent = ON");
  }
}

void stopNote(int note, int velocity) {
  Serial.println("Note off, GATE = 0");
  write_dac(WRITE_UPDATE_N, GATE, 0);
  note_on = false;
}

void cc(int note_, int velocity_) {
  write_dac(SETUP_INTERNAL_REGISTER, 0, 1); 
  unsigned int note = note_;
  unsigned int velocity = velocity_; //you wouldn't have to convert the ints if you used something other than -1 to indicate they were empty, just keep them as bytes through out and use 128 as empty for MSB and LSB data byte
  if (note == 1) {
    if (velocity >= 64) {
      write_dac(SETUP_INTERNAL_REGISTER, 0, 1);
      Serial.println("INTERNAL REGISTER ON");
    } else {
      write_dac(SETUP_INTERNAL_REGISTER, 0, 0);
      Serial.println("INTERNAL REGISTER OFF");
    }
  } else if (note == 13) {
    unsigned int voltage = 65535*velocity/127.0;
    write_dac(WRITE_UPDATE_N, 3, voltage);
    Serial.print("OUTPUT 3 = ");
    Serial.println(voltage);
  } else if (note == 14) {
    unsigned int voltage = 65535*velocity/127.0;
    write_dac(WRITE_UPDATE_N, 4, voltage);
    Serial.print("OUTPUT 4 = ");
    Serial.println(voltage);
  } else if (note == 20) {
    unsigned int voltage = 65535*velocity/127.0;
    write_dac(WRITE_UPDATE_N, 5, voltage);
    Serial.print("OUTPUT 5 = ");
    Serial.println(voltage);
  } else if (note == 21) {
    unsigned int voltage = 65535*velocity/127.0;
    write_dac(WRITE_UPDATE_N, 6, voltage);
    Serial.print("OUTPUT 6 = ");
    Serial.println(voltage);
  } else if (note == 22) {
    unsigned int voltage = 65535*velocity/127.0;
    write_dac(WRITE_UPDATE_N, 7, voltage);
    Serial.print("OUTPUT 7 = ");
    Serial.println(voltage);
  }
}

void loop() {
  if (Serial.available() > 0) {
    //recieved something so note time for working out if the RX Led should flash
    previousMillis = timer0_millis;
    // read the incoming byte:
    incomingByte = Serial.read();
    if ((incomingByte == 144) &! sysex) {
      //incoming note on
      action = 1;
    } else if ((incomingByte == 128) &! sysex) {
      //incoming note off
      action = 2;
    } else if ((incomingByte == 176) &! sysex) {
      action = 3;
    } else if ((incomingByte == 240) &! sysex) {
      action = 4;
      sysex = true;
      Serial.println("incoming sysex");
    } else if ((incomingByte == 247) && sysex) {
      sysex = false;
      Serial.println("sysex finished");
    } else if ((action == 1) && (note == -1)) {
      note = incomingByte;
    } else if ((action == 1) && (note != -1)) {
      velocity = incomingByte;
      Serial.print("note on 144 ");
      Serial.print(note, DEC);
      Serial.print(" ");
      Serial.println(velocity, DEC);
      if (velocity == 0) {
        stopNote(note,velocity);
      } else {
        playNote(note,velocity);
      }
      action = 0;
      note = -1;
      velocity = -1;
    } else if ((action == 2) && (note == -1)) {
      note = incomingByte;
    } else if ((action == 2) && (note != -1)) {
      velocity = incomingByte;
      Serial.print("note off 128 ");
      Serial.print(note, DEC);
      Serial.print(" ");
      Serial.println(velocity, DEC);
      stopNote(note,velocity);
      action = 0;
      note = -1;
      velocity = -1;
    } else if ((action == 3) && (note == -1)) {
      note = incomingByte;
    } else if ((action == 3) && (note != -1)) {
      velocity = incomingByte;
      Serial.print("cc ");
      Serial.print(note, DEC);
      Serial.print(" ");
      Serial.println(velocity, DEC);
      cc(note,velocity);
      action = 0;
      note = -1;
      velocity = -1;
    } else if ((action == 4) && (note == -1)) {
      note = incomingByte;
    } else if ((action == 4) && (note != -1) && (velocity == -1)) {
      velocity = incomingByte;
    } else if ((action == 4) && (note != -1) && (velocity != -1) && (extra1 == -1)) {
      extra1 = incomingByte;
    } else if ((action == 4) && (note != -1) && (velocity != -1) && (extra1 != -1) && (extra2 == -1)) {
      extra2 = incomingByte;
      Serial.print("sysex: ");
      Serial.print(note);
      Serial.print(" ");
      Serial.print(velocity);
      Serial.print(" ");
      Serial.print(extra1);
      Serial.print(" ");
      Serial.println(extra2);
      switch (note) {
        case 1: 
          voltage1 = velocity*512 + extra1*4 + extra2;
          Serial.print("voltage1 = ");
          Serial.println(voltage1);
          break;
        case 2:
          voltage2 = velocity*512 + extra1*4 + extra2;
          Serial.print("voltage2 = ");
          Serial.println(voltage2);
          break;
        case 3: 
          voltage3 = velocity*512 + extra1*4 + extra2;
          Serial.print("voltage3 = ");
          Serial.println(voltage3);
          break;
        case 4:
          voltage4 = velocity*512 + extra1*4 + extra2;
          Serial.print("voltage4 = ");
          Serial.println(voltage4);
          break;
        case 5:
          voltage5 = 65535 + velocity*512 + extra1*4 + extra2;
          Serial.print("voltage5 = ");
          Serial.println(voltage5);
          break;
      }
      action = 0;
      note = -1;
      velocity = -1;
      extra1 = -1;
      extra2 = -1;
    }
  }
  //pitch and amp detection stuff starts here
  amp = analogRead(0);
  if (amp > 500) {
    previousMillis = timer0_millis;
  }
  if (period != 0 && amp > 0) {
    Serial.print("Amp ");
    Serial.println(amp);
    Serial.print("Period ");
    Serial.println(period, DEC);
    //Serial.println("Freq ");
    //freq = (40000/period);
    //Serial.println(freq,DEC);
  }
  if (timer0_millis - previousMillis < interval) {
    RX = HIGH;
  } else {
    RX = LOW;
  }
  digitalWrite(RXLED, RX);
}