MCP4822 dual 12-bit Digital to Analog Converter (DAC) chip.

Dependents:   ADC2DAC

The MCP4822 is a dual 12-bit Digital to Analog Converter that is controlled via an SPI interface. It is available in PDIP, SOIC or MSOP packages. The documentation for the chip is available at Microchip's MC4822 page.

The range also includes 8 or 10-bit DACs, which this library could easily be converted to.

Revision:
0:74353da3eacd
Child:
1:68b3a24fd2a4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MCP4822.h	Wed Feb 13 16:08:13 2013 +0000
@@ -0,0 +1,34 @@
+#ifndef __MCP4822_H__
+#define __MCP4822_H__
+
+#include "mbed.h"
+
+//! MCP4822 dual 12-bit DAC
+class MCP4822   {
+    public:
+        /** Create an MCP4822 instance
+        * @param dataout SPI MOSI pin (should be p5 or p11)
+        * @param clock  SPI clock pin (should be p7 or p13)
+        * @param chipselect SPI chip select pin (can be any)
+        * @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.
+        */
+        MCP4822(PinName dataout, PinName clock, PinName chipselect, PinName latch);
+        //! Set output A to voltage
+        void setA(float voltage);
+        //! Set output B to voltage
+        void setB(float voltage);
+        //! Set both output A to voltageA and outputB to voltageB
+        void set(float voltageA, float voltageB);
+        //! Latch the stored values to the output pins
+        void latch();
+        //! shut down output from the DAC chip
+        void shutdown();
+    private:
+        DigitalOut cs, latchpin;
+        SPI spi;
+        void write(bool chanB, bool gain1, unsigned int voltage, bool shutdown = false);
+        void setvoltage(float voltage, bool chanB = false);
+};
+
+
+#endif
\ No newline at end of file