Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of DAC by
Revision 0:bce9b1450b19, committed 2012-06-13
- 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
