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
Revision 5:1ce3ec1e5f8b, committed 2014-04-13
- Comitter:
- cassar10
- Date:
- Sun Apr 13 19:45:35 2014 +0000
- Parent:
- 4:0c327b37ddc1
- Commit message:
- Set SPI Frequency during initialization. Test program includes for loop to ramp up to reference voltage.
Changed in this revision
diff -r 0c327b37ddc1 -r 1ce3ec1e5f8b AD7390.cpp --- a/AD7390.cpp Sun Apr 06 20:19:56 2014 +0000 +++ b/AD7390.cpp Sun Apr 13 19:45:35 2014 +0000 @@ -1,37 +1,39 @@ # include "AD7390.h" #include "mbed.h" -AD7390::AD7390(SPI& _spi, PinName resetpin, PinName latchpin) : //Mosi, sclk 2x digital out refV, previously missed scope operator. +AD7390::AD7390(SPI& _spi, PinName resetpin, PinName latchpin) : //Mosi, sclk 2x digital out refV spi(_spi),reset(resetpin), latch(latchpin){ } - void AD7390::Init() + void AD7390::Init(int Frequency) { //Vout = (Vref*D)/2^n + spi.frequency(Frequency); spi.format(12,0); - latch = 1; //Pull low to pass shift register to DAC register + latch = 1; + reset = 0; reset = 1; } - void AD7390::Reset() //Reset ADC to 0V by pulling reset pin low + void AD7390::Reset() { reset = 0; - reset = 1; //Set back to high so it can be written to again + reset = 1; } - void AD7390::Latch() //Latch data from shift register to DAC + void AD7390::Latch() { latch = 0; latch = 1; } - void AD7390::Write(float Volts, float RefV) //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; spi.write(send); } - void AD7390::WriteL(float volts, float RefV) //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; latch = 1;
diff -r 0c327b37ddc1 -r 1ce3ec1e5f8b AD7390.h --- a/AD7390.h Sun Apr 06 20:19:56 2014 +0000 +++ b/AD7390.h Sun Apr 13 19:45:35 2014 +0000 @@ -3,14 +3,14 @@ #include "mbed.h" -class AD7390 { //Create an AD7390 instance +class AD7390 { //Create an AD7390 instance SPI& spi; DigitalOut reset, latch; public: AD7390(SPI& spi, PinName resetpin, PinName latchpin); //RefV set up for user reference voltage void Reset(); void Latch(); - void Init(); + void Init(int Frequency); //Set SPI frequency during initialisation void Write(float Volts, float RefV); void WriteL(float volts, float RefV); private:
diff -r 0c327b37ddc1 -r 1ce3ec1e5f8b main.cpp --- a/main.cpp Sun Apr 06 20:19:56 2014 +0000 +++ b/main.cpp Sun Apr 13 19:45:35 2014 +0000 @@ -3,22 +3,15 @@ SPI spi(p5,p6,p7); AD7390 Test(spi,p10,p11); -DigitalOut Led(LED1); int main(){ - Test.Init(); + Test.Init(10000000); while (true){ Test.Reset(); - Test.WriteL(2.5,3.3); - Led = 1; - wait(5); - Test.Reset(); - Led = 0; - Test.WriteL(1.5,3.3); - Led = 1; - wait(5); - Led = 0; - + for (float V = 0; V !=3.3; V=V+0.005){ + Test.WriteL(V,3.3); + wait(0.02); + } } }