kohacraft Lab / DAC

Fork of DAC by Jimmy Hack

Files at this revision

API Documentation at this revision

Comitter:
JimmyTheHack
Date:
Wed Jun 13 23:41:08 2012 +0000
Child:
1:679fa19d91b2
Commit message:
changed to make use of pre-allocated SPI channels.

Changed in this revision

DAC.cpp Show annotated file Show diff for this revision Revisions of this file
DAC.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DAC.cpp	Wed Jun 13 23:41:08 2012 +0000
@@ -0,0 +1,16 @@
+#include "DAC.h"
+
+/*SPI Channels */
+SPI SPI_A(p5, NC, p7);  //since we only have two SPI channels, which must be shared, define them here.
+SPI SPI_B(p11, NC, p13);
+
+/*Initialize DAC */
+DAC::DAC(int SPIchannelNum, PinName _CS, PinName _LDAC) : CS(_CS), LDAC(_LDAC){  
+    if (SPIchannelNum ==1){
+        DACspi = &SPI_B;
+    }  
+    else{
+        DACspi = &SPI_A;
+    }
+    (*DACspi).format(16,0);
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DAC.h	Wed Jun 13 23:41:08 2012 +0000
@@ -0,0 +1,21 @@
+#ifndef DAC_H
+#define DAC_H
+#include "mbed.h"
+
+//a basic parent library for use with DACs controlled via SPI.  Individual hardware implementations will need their own libraries.
+class DAC
+{
+    public:
+    DAC(int SPIchannelNum, PinName CS,  PinName LDAC);
+    virtual void write(int millivolts) =0; //write a value to the Digital Analog Converter    
+    
+    //DigitalOut SCK;
+    DigitalOut CS;  //serial chip select pin
+    DigitalOut LDAC; //synchronize pin to update both DACs together    
+    SPI * DACspi;
+};
+
+extern SPI SPI_A;  //channel A SPI (pins 5,7)
+extern SPI SPI_B;  //channel B SPI (pins 11,13)
+
+#endif //DAC_H
\ No newline at end of file