Class for AD7390, a 12 bit SPI driven external DAC from Analog Devices.
Datasheet - http://www.analog.com/static/imported-files/data_sheets/AD7390_7391.pdf
AD7390.cpp
- Committer:
- cassar10
- Date:
- 2014-04-13
- Revision:
- 5:1ce3ec1e5f8b
- Parent:
- 3:37ec9ea72264
File content as of revision 5:1ce3ec1e5f8b:
# include "AD7390.h"
#include "mbed.h"
AD7390::AD7390(SPI& _spi, PinName resetpin, PinName latchpin) : //Mosi, sclk 2x digital out refV
spi(_spi),reset(resetpin), latch(latchpin){
}
void AD7390::Init(int Frequency)
{
//Vout = (Vref*D)/2^n
spi.frequency(Frequency);
spi.format(12,0);
latch = 1;
reset = 0;
reset = 1;
}
void AD7390::Reset()
{
reset = 0;
reset = 1;
}
void AD7390::Latch()
{
latch = 0;
latch = 1;
}
void AD7390::Write(float Volts, float RefV) //write will require seperate latch after
{
unsigned int send = 0x0000;
send = (unsigned int) (4096/RefV)*Volts;
spi.write(send);
}
void AD7390::WriteL(float volts, float RefV) //Same as write but with latch attached
{
unsigned int Send = 0x0000;
Send = (unsigned int) (4096/RefV)*volts; //parse float into unsigned int to send to DAC
spi.write(Send);
latch = 0;
latch = 1;
}