Kyle Cassar / Mbed 2 deprecated DACAD7390

Dependencies:   mbed

Committer:
cassar10
Date:
Sat Apr 05 19:08:44 2014 +0000
Revision:
0:82cd70f9fc3f
Child:
2:8633e348822f
Class looks to be set up. Need to test and set up a conversion to get correct voltage out.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cassar10 0:82cd70f9fc3f 1 #include "mbed.h"
cassar10 0:82cd70f9fc3f 2
cassar10 0:82cd70f9fc3f 3 SPI DAC(p5, p6, p7); //mosi, miso, sclck
cassar10 0:82cd70f9fc3f 4 DigitalOut CLR (p10); //Resets DAC register to 0 when pulled low
cassar10 0:82cd70f9fc3f 5 DigitalOut LD (p8); //Pull low to load DAC register from shift register
cassar10 0:82cd70f9fc3f 6 DigitalOut led(LED2);
cassar10 0:82cd70f9fc3f 7
cassar10 0:82cd70f9fc3f 8 int main()
cassar10 0:82cd70f9fc3f 9 {
cassar10 0:82cd70f9fc3f 10 DAC.format(12,0); //Set to 12 bit data transfer with no change in clock polarity or phase
cassar10 0:82cd70f9fc3f 11 DAC.frequency(2000000);
cassar10 0:82cd70f9fc3f 12
cassar10 0:82cd70f9fc3f 13 while(1) {
cassar10 0:82cd70f9fc3f 14
cassar10 0:82cd70f9fc3f 15 CLR = 1; //Pull this low to set back to 0;
cassar10 0:82cd70f9fc3f 16 LD = 1; //Send high as the DAC register is loaded once pulled low.
cassar10 0:82cd70f9fc3f 17 DAC.write(0x3ff); //Write 256 to DAC
cassar10 0:82cd70f9fc3f 18 LD = 0; //Send to DAC register from shift register
cassar10 0:82cd70f9fc3f 19 wait_us(10); //Give time to update
cassar10 0:82cd70f9fc3f 20 LD = 1; //Send back into read mode
cassar10 0:82cd70f9fc3f 21 wait(2);
cassar10 0:82cd70f9fc3f 22 DAC.write(0xBff); //Write 256 to DAC
cassar10 0:82cd70f9fc3f 23 LD = 0; //Send to DAC register from shift register
cassar10 0:82cd70f9fc3f 24 wait_us(10); //Give time to update
cassar10 0:82cd70f9fc3f 25 LD = 1;
cassar10 0:82cd70f9fc3f 26 wait(2);
cassar10 0:82cd70f9fc3f 27
cassar10 0:82cd70f9fc3f 28
cassar10 0:82cd70f9fc3f 29 }
cassar10 0:82cd70f9fc3f 30 }