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
Diff: AD7390.cpp
- Revision:
- 3:37ec9ea72264
- Parent:
- 1:19818c103c9c
- Child:
- 5:1ce3ec1e5f8b
--- a/AD7390.cpp Sat Apr 05 21:06:17 2014 +0000 +++ b/AD7390.cpp Sun Apr 06 20:07:38 2014 +0000 @@ -1,11 +1,13 @@ # include "AD7390.h" +#include "mbed.h" -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. - reset(resetpin), latch(latchpin), spi(data, NC, clock) +AD7390::AD7390(SPI& _spi, PinName resetpin, PinName latchpin) : //Mosi, sclk 2x digital out refV, previously missed scope operator. + spi(_spi),reset(resetpin), latch(latchpin){ + } + void AD7390::Init() { //Vout = (Vref*D)/2^n spi.format(12,0); - spi.frequency(freq); latch = 1; //Pull low to pass shift register to DAC register reset = 1; } @@ -13,28 +15,25 @@ void AD7390::Reset() //Reset ADC to 0V by pulling reset pin low { reset = 0; - wait_us(25); reset = 1; //Set back to high so it can be written to again } void AD7390::Latch() //Latch data from shift register to DAC { latch = 0; - wait_us(25); latch = 1; } - void AD7390::Write(float Volts) //write will require seperate latch after + void AD7390::Write(float Volts, float RefV) //write will require seperate latch after { unsigned int send = 0x0000; - send = (unsigned int) ((4096/RefV)*Volts); + send = (unsigned int) (4096/RefV)*Volts; spi.write(send); } - void AD7390::WriteL(float volts) //Same as write but with latch attached + 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 + Send = (unsigned int) (4096/RefV)*volts; //parse float into unsigned int to send to DAC spi.write(Send); latch = 0; - wait_us(25); latch = 1; }