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.
MCP4822.h@0:74353da3eacd, 2013-02-13 (annotated)
- Committer:
- NickRyder
- Date:
- Wed Feb 13 16:08:13 2013 +0000
- Revision:
- 0:74353da3eacd
- Child:
- 1:68b3a24fd2a4
Added documentation.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| NickRyder | 0:74353da3eacd | 1 | #ifndef __MCP4822_H__ |
| NickRyder | 0:74353da3eacd | 2 | #define __MCP4822_H__ |
| NickRyder | 0:74353da3eacd | 3 | |
| NickRyder | 0:74353da3eacd | 4 | #include "mbed.h" |
| NickRyder | 0:74353da3eacd | 5 | |
| NickRyder | 0:74353da3eacd | 6 | //! MCP4822 dual 12-bit DAC |
| NickRyder | 0:74353da3eacd | 7 | class MCP4822 { |
| NickRyder | 0:74353da3eacd | 8 | public: |
| NickRyder | 0:74353da3eacd | 9 | /** Create an MCP4822 instance |
| NickRyder | 0:74353da3eacd | 10 | * @param dataout SPI MOSI pin (should be p5 or p11) |
| NickRyder | 0:74353da3eacd | 11 | * @param clock SPI clock pin (should be p7 or p13) |
| NickRyder | 0:74353da3eacd | 12 | * @param chipselect SPI chip select pin (can be any) |
| NickRyder | 0:74353da3eacd | 13 | * @param latch Latch pin updates the DAC out. Can be any pin or NC, if NC then the latch pin on the DAC chip should be held to GND. |
| NickRyder | 0:74353da3eacd | 14 | */ |
| NickRyder | 0:74353da3eacd | 15 | MCP4822(PinName dataout, PinName clock, PinName chipselect, PinName latch); |
| NickRyder | 0:74353da3eacd | 16 | //! Set output A to voltage |
| NickRyder | 0:74353da3eacd | 17 | void setA(float voltage); |
| NickRyder | 0:74353da3eacd | 18 | //! Set output B to voltage |
| NickRyder | 0:74353da3eacd | 19 | void setB(float voltage); |
| NickRyder | 0:74353da3eacd | 20 | //! Set both output A to voltageA and outputB to voltageB |
| NickRyder | 0:74353da3eacd | 21 | void set(float voltageA, float voltageB); |
| NickRyder | 0:74353da3eacd | 22 | //! Latch the stored values to the output pins |
| NickRyder | 0:74353da3eacd | 23 | void latch(); |
| NickRyder | 0:74353da3eacd | 24 | //! shut down output from the DAC chip |
| NickRyder | 0:74353da3eacd | 25 | void shutdown(); |
| NickRyder | 0:74353da3eacd | 26 | private: |
| NickRyder | 0:74353da3eacd | 27 | DigitalOut cs, latchpin; |
| NickRyder | 0:74353da3eacd | 28 | SPI spi; |
| NickRyder | 0:74353da3eacd | 29 | void write(bool chanB, bool gain1, unsigned int voltage, bool shutdown = false); |
| NickRyder | 0:74353da3eacd | 30 | void setvoltage(float voltage, bool chanB = false); |
| NickRyder | 0:74353da3eacd | 31 | }; |
| NickRyder | 0:74353da3eacd | 32 | |
| NickRyder | 0:74353da3eacd | 33 | |
| NickRyder | 0:74353da3eacd | 34 | #endif |
