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

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers AD7390.cpp Source File

AD7390.cpp

00001 # include "AD7390.h"
00002 #include "mbed.h"
00003 
00004 AD7390::AD7390(SPI& _spi, PinName resetpin, PinName latchpin) : //Mosi, sclk 2x digital out refV
00005     spi(_spi),reset(resetpin), latch(latchpin){
00006     }
00007     void AD7390::Init(int Frequency)
00008     {
00009         //Vout = (Vref*D)/2^n
00010         spi.frequency(Frequency);
00011         spi.format(12,0);
00012         latch = 1;                                              
00013         reset = 0;
00014         reset = 1;
00015     }
00016     
00017     void AD7390::Reset()                                        
00018     {
00019         reset = 0;
00020         reset = 1;                                              
00021     }
00022     void AD7390::Latch()                                        
00023     {
00024         latch = 0;
00025         latch = 1;
00026     }
00027     void AD7390::Write(float Volts, float RefV)                 //write will require seperate latch after
00028     {
00029         unsigned int send = 0x0000;
00030         send = (unsigned int) (4096/RefV)*Volts;
00031         spi.write(send);
00032     }
00033     void AD7390::WriteL(float volts, float RefV)                //Same as write but with latch attached
00034     {
00035         unsigned int Send = 0x0000;
00036         Send = (unsigned int) (4096/RefV)*volts;                //parse float into unsigned int to send to DAC
00037         spi.write(Send);
00038         latch = 0;
00039         latch = 1;
00040     }
00041         
00042         
00043     
00044