The MCP4922 is a 12 bit DAC. This library should provide easy access to its basic functionality.
DAC_SPI/DAC_SPI.h@0:4e1ee1c4d3bb, 2012-07-04 (annotated)
- Committer:
- JimmyTheHack
- Date:
- Wed Jul 04 01:29:05 2012 +0000
- Revision:
- 0:4e1ee1c4d3bb
updated SPI_DAC library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JimmyTheHack | 0:4e1ee1c4d3bb | 1 | #ifndef DAC_SPI_H |
JimmyTheHack | 0:4e1ee1c4d3bb | 2 | #define DAC_SPI_H |
JimmyTheHack | 0:4e1ee1c4d3bb | 3 | #include "mbed.h" |
JimmyTheHack | 0:4e1ee1c4d3bb | 4 | |
JimmyTheHack | 0:4e1ee1c4d3bb | 5 | /* a basic parent library for use with DACs controlled via SPI. Individual hardware implementations will need their own libraries. |
JimmyTheHack | 0:4e1ee1c4d3bb | 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 | 0:4e1ee1c4d3bb | 7 | */ |
JimmyTheHack | 0:4e1ee1c4d3bb | 8 | class DAC_SPI |
JimmyTheHack | 0:4e1ee1c4d3bb | 9 | { |
JimmyTheHack | 0:4e1ee1c4d3bb | 10 | public: |
JimmyTheHack | 0:4e1ee1c4d3bb | 11 | DAC_SPI(int SPIchannelNum, PinName CS, PinName LDAC); |
JimmyTheHack | 0:4e1ee1c4d3bb | 12 | virtual void select(char DACvalue); //choose the active DAC |
JimmyTheHack | 0:4e1ee1c4d3bb | 13 | virtual void write(int DACvalue) =0; //write a value to the Digital Analog Converter |
JimmyTheHack | 0:4e1ee1c4d3bb | 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 | 0:4e1ee1c4d3bb | 15 | |
JimmyTheHack | 0:4e1ee1c4d3bb | 16 | /** Manually change the SPI frequency |
JimmyTheHack | 0:4e1ee1c4d3bb | 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 | 0:4e1ee1c4d3bb | 18 | */ |
JimmyTheHack | 0:4e1ee1c4d3bb | 19 | void frequency(int freq); |
JimmyTheHack | 0:4e1ee1c4d3bb | 20 | //set the number of bits for DAC |
JimmyTheHack | 0:4e1ee1c4d3bb | 21 | void messageBits(int bits); |
JimmyTheHack | 0:4e1ee1c4d3bb | 22 | //DigitalOut SCK; |
JimmyTheHack | 0:4e1ee1c4d3bb | 23 | /** The currently selected DAC channel. 0 for DAC A, 1 for DAC B, etc*/ |
JimmyTheHack | 0:4e1ee1c4d3bb | 24 | char DACselect; |
JimmyTheHack | 0:4e1ee1c4d3bb | 25 | DigitalOut CS; //serial chip select pin |
JimmyTheHack | 0:4e1ee1c4d3bb | 26 | DigitalOut LDAC; //synchronize pin to update both DACs together |
JimmyTheHack | 0:4e1ee1c4d3bb | 27 | SPI * DACspi; //SPI channel. 0 for p5-p7, 1 for p11-p13 |
JimmyTheHack | 0:4e1ee1c4d3bb | 28 | }; |
JimmyTheHack | 0:4e1ee1c4d3bb | 29 | |
JimmyTheHack | 0:4e1ee1c4d3bb | 30 | extern SPI SPI_A; //channel A SPI (pins 5,7) |
JimmyTheHack | 0:4e1ee1c4d3bb | 31 | extern SPI SPI_B; //channel B SPI (pins 11,13) |
JimmyTheHack | 0:4e1ee1c4d3bb | 32 | |
JimmyTheHack | 0:4e1ee1c4d3bb | 33 | #endif //DAC_H |