Class for AD7390, a 12 bit SPI driven external DAC from Analog Devices.

Dependencies:   mbed

Datasheet - http://www.analog.com/static/imported-files/data_sheets/AD7390_7391.pdf

Committer:
cassar10
Date:
Sat Apr 05 20:45:08 2014 +0000
Revision:
1:19818c103c9c
Parent:
0:82cd70f9fc3f
Child:
3:37ec9ea72264
All compiles with write and writeL added.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cassar10 0:82cd70f9fc3f 1 # include "AD7390.h"
cassar10 0:82cd70f9fc3f 2
cassar10 1:19818c103c9c 3 AD7390::AD7390(PinName data, PinName clock, PinName resetpin, PinName latchpin, float RefV, unsigned int freq) : //Mosi, sclk 2x digital out refV, previously missed scope operator.
cassar10 0:82cd70f9fc3f 4 reset(resetpin), latch(latchpin), spi(data, NC, clock)
cassar10 0:82cd70f9fc3f 5 {
cassar10 0:82cd70f9fc3f 6 //Vout = (Vref*D)/2^n
cassar10 0:82cd70f9fc3f 7 spi.format(12,0);
cassar10 1:19818c103c9c 8 spi.frequency(freq);
cassar10 1:19818c103c9c 9 latch = 1; //Pull low to pass shift register to DAC register
cassar10 1:19818c103c9c 10 reset = 1;
cassar10 0:82cd70f9fc3f 11 }
cassar10 0:82cd70f9fc3f 12
cassar10 1:19818c103c9c 13 void AD7390::Reset() //Reset ADC to 0V by pulling reset pin low
cassar10 0:82cd70f9fc3f 14 {
cassar10 0:82cd70f9fc3f 15 reset = 0;
cassar10 0:82cd70f9fc3f 16 wait_us(25);
cassar10 1:19818c103c9c 17 reset = 1; //Set back to high so it can be written to again
cassar10 0:82cd70f9fc3f 18 }
cassar10 1:19818c103c9c 19 void AD7390::Latch() //Latch data from shift register to DAC
cassar10 0:82cd70f9fc3f 20 {
cassar10 0:82cd70f9fc3f 21 latch = 0;
cassar10 0:82cd70f9fc3f 22 wait_us(25);
cassar10 0:82cd70f9fc3f 23 latch = 1;
cassar10 0:82cd70f9fc3f 24 }
cassar10 1:19818c103c9c 25 void AD7390::Write(float Volts) //write will require seperate latch after
cassar10 1:19818c103c9c 26 {
cassar10 1:19818c103c9c 27 unsigned int send = 0x0000;
cassar10 1:19818c103c9c 28 send = (unsigned int) ((4096/RefV)*Volts);
cassar10 1:19818c103c9c 29 spi.write(send);
cassar10 1:19818c103c9c 30 }
cassar10 1:19818c103c9c 31 void AD7390::WriteL(float volts) //Same as write but with latch attached
cassar10 1:19818c103c9c 32 {
cassar10 1:19818c103c9c 33 unsigned int Send = 0x0000;
cassar10 1:19818c103c9c 34 Send = (unsigned int) ((4096/RefV)*volts); //parse float into unsigned int to send to DAC
cassar10 1:19818c103c9c 35 spi.write(Send);
cassar10 1:19818c103c9c 36 latch = 0;
cassar10 1:19818c103c9c 37 wait_us(25);
cassar10 1:19818c103c9c 38 latch = 1;
cassar10 1:19818c103c9c 39 }
cassar10 1:19818c103c9c 40
cassar10 1:19818c103c9c 41
cassar10 1:19818c103c9c 42
cassar10 0:82cd70f9fc3f 43