A wrapper library for easy access to DACs using the SPI interface. Individual devices will receive their own libraries.
Dependents: MAX500 MCP4922 MCP4822
DAC_SPI.h@1:679fa19d91b2, 2013-07-16 (annotated)
- Committer:
- JimmyTheHack
- Date:
- Tue Jul 16 05:52:01 2013 +0000
- Revision:
- 1:679fa19d91b2
attempted to merge with DAC_SPI
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JimmyTheHack | 1:679fa19d91b2 | 1 | #ifndef DAC_SPI_H |
JimmyTheHack | 1:679fa19d91b2 | 2 | #define DAC_SPI_H |
JimmyTheHack | 1:679fa19d91b2 | 3 | #include "mbed.h" |
JimmyTheHack | 1:679fa19d91b2 | 4 | |
JimmyTheHack | 1:679fa19d91b2 | 5 | /* a basic parent library for use with DACs controlled via SPI. Individual hardware implementations will need their own libraries. |
JimmyTheHack | 1:679fa19d91b2 | 6 | This provides basic initialization of common pins and provides a serial channel. Doesn't provide a lot of added functionality, but serves as an interface for the SPI library. |
JimmyTheHack | 1:679fa19d91b2 | 7 | */ |
JimmyTheHack | 1:679fa19d91b2 | 8 | class DAC_SPI |
JimmyTheHack | 1:679fa19d91b2 | 9 | { |
JimmyTheHack | 1:679fa19d91b2 | 10 | public: |
JimmyTheHack | 1:679fa19d91b2 | 11 | DAC_SPI(int SPIchannelNum, PinName CS, PinName LDAC); |
JimmyTheHack | 1:679fa19d91b2 | 12 | virtual void select(char DACvalue); //choose the active DAC |
JimmyTheHack | 1:679fa19d91b2 | 13 | virtual void write(int DACvalue) =0; //write a value to the Digital Analog Converter |
JimmyTheHack | 1:679fa19d91b2 | 14 | virtual void write_mV(int millivolts) =0; //write a value to the Digital Analog Converter specified in mV (may require appropriate scaling factor) |
JimmyTheHack | 1:679fa19d91b2 | 15 | |
JimmyTheHack | 1:679fa19d91b2 | 16 | /** Manually change the SPI frequency |
JimmyTheHack | 1:679fa19d91b2 | 17 | * @param freq Desired frequency in hertz: must be a value supported by both the mbed and DAC. The MCP4922 supports frequencies to 20MHz. |
JimmyTheHack | 1:679fa19d91b2 | 18 | */ |
JimmyTheHack | 1:679fa19d91b2 | 19 | void frequency(int freq); |
JimmyTheHack | 1:679fa19d91b2 | 20 | //set the number of bits for DAC |
JimmyTheHack | 1:679fa19d91b2 | 21 | void messageBits(int bits); |
JimmyTheHack | 1:679fa19d91b2 | 22 | //DigitalOut SCK; |
JimmyTheHack | 1:679fa19d91b2 | 23 | /** The currently selected DAC channel. 0 for DAC A, 1 for DAC B, etc*/ |
JimmyTheHack | 1:679fa19d91b2 | 24 | char DACselect; |
JimmyTheHack | 1:679fa19d91b2 | 25 | DigitalOut CS; //serial chip select pin |
JimmyTheHack | 1:679fa19d91b2 | 26 | DigitalOut LDAC; //synchronize pin to update both DACs together |
JimmyTheHack | 1:679fa19d91b2 | 27 | SPI * DACspi; //SPI channel. 0 for p5-p7, 1 for p11-p13 |
JimmyTheHack | 1:679fa19d91b2 | 28 | }; |
JimmyTheHack | 1:679fa19d91b2 | 29 | |
JimmyTheHack | 1:679fa19d91b2 | 30 | extern SPI SPI_A; //channel A SPI (pins 5,7) |
JimmyTheHack | 1:679fa19d91b2 | 31 | extern SPI SPI_B; //channel B SPI (pins 11,13) |
JimmyTheHack | 1:679fa19d91b2 | 32 | |
JimmyTheHack | 1:679fa19d91b2 | 33 | #endif //DAC_H |