Library to control the 12 Bits Analog Digital Converter MCP4921

Committer:
adelino
Date:
Fri Nov 15 14:53:04 2013 +0000
Revision:
0:38e03f9fa18a
Child:
1:1352606a60c6
Library to control the analog digital converter; MCp4921

Who changed what in which revision?

UserRevisionLine numberNew contents of line
adelino 0:38e03f9fa18a 1 #ifndef MCP4921_H
adelino 0:38e03f9fa18a 2 #define MCP4921_H
adelino 0:38e03f9fa18a 3
adelino 0:38e03f9fa18a 4 #include "mbed.h"
adelino 0:38e03f9fa18a 5
adelino 0:38e03f9fa18a 6 /**
adelino 0:38e03f9fa18a 7 * The MCP4921 is a single 12 bit DAC.
adelino 0:38e03f9fa18a 8 The maximum voltage output is limited by the input voltage at V_DD which can go up to about 5.5V.
adelino 0:38e03f9fa18a 9
adelino 0:38e03f9fa18a 10 * Datasheet: http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en020398
adelino 0:38e03f9fa18a 11 *
adelino 0:38e03f9fa18a 12 */
adelino 0:38e03f9fa18a 13
adelino 0:38e03f9fa18a 14 class Mcp4921
adelino 0:38e03f9fa18a 15 {
adelino 0:38e03f9fa18a 16
adelino 0:38e03f9fa18a 17 public:
adelino 0:38e03f9fa18a 18 /** Initializes the MCP 4921 DAC with the frequency
adelino 0:38e03f9fa18a 19 *
adelino 0:38e03f9fa18a 20 * for exemple:
adelino 0:38e03f9fa18a 21 * Mbed Mcp4921
adelino 0:38e03f9fa18a 22 * p11: Mosi <--->p4:Sdi
adelino 0:38e03f9fa18a 23 * p12: Miso No Connected
adelino 0:38e03f9fa18a 24 * p13: Sck <--->p3:Sck
adelino 0:38e03f9fa18a 25 * p14 <--->p2:Cs
adelino 0:38e03f9fa18a 26 * Vout <--->p1:Vdd
adelino 0:38e03f9fa18a 27 * Vout <--->p6: Vref
adelino 0:38e03f9fa18a 28 * Gnd <--->p7:Gnd
adelino 0:38e03f9fa18a 29 * Gnd <--->p5:Ldac
adelino 0:38e03f9fa18a 30 */
adelino 0:38e03f9fa18a 31 Mcp4921(PinName _mosi,PinName _sck,PinName _cs, int _frequency);
adelino 0:38e03f9fa18a 32
adelino 0:38e03f9fa18a 33 /** return the frequency use by the Mcp4921
adelino 0:38e03f9fa18a 34 */
adelino 0:38e03f9fa18a 35 int getFrequency(void);
adelino 0:38e03f9fa18a 36
adelino 0:38e03f9fa18a 37 /** Writes a value between 0-4095 to the currently selected DAC output
adelino 0:38e03f9fa18a 38 * @param dataIntNum a value from 0-4095 to write to the DAC register
adelino 0:38e03f9fa18a 39 */
adelino 0:38e03f9fa18a 40 void write(int dataIntNum);
adelino 0:38e03f9fa18a 41
adelino 0:38e03f9fa18a 42 /** Writes a float value between 0.0-1.0 to the currently selected DAC output
adelino 0:38e03f9fa18a 43 * @param dataFloat a value from 0.0-1.0 to write to the DAC register
adelino 0:38e03f9fa18a 44 */
adelino 0:38e03f9fa18a 45 void write(float dataFloat);
adelino 0:38e03f9fa18a 46
adelino 0:38e03f9fa18a 47 /** Writes a value in mV to the DAC outputs.
adelino 0:38e03f9fa18a 48 * The output will only be accurate if Vref is set to the appropriate voltage reference scaling factor.
adelino 0:38e03f9fa18a 49 * @param millivolt The desired voltage output in millivolts
adelino 0:38e03f9fa18a 50 */
adelino 0:38e03f9fa18a 51 void write_mV(int millivolt);
adelino 0:38e03f9fa18a 52
adelino 0:38e03f9fa18a 53 /**An operator for shorthand write(int)
adelino 0:38e03f9fa18a 54 */
adelino 0:38e03f9fa18a 55 void operator=(int dataIntNum);
adelino 0:38e03f9fa18a 56
adelino 0:38e03f9fa18a 57
adelino 0:38e03f9fa18a 58 /**An operator for shorthand write(float)
adelino 0:38e03f9fa18a 59 */
adelino 0:38e03f9fa18a 60 void operator=(float dataFloat);
adelino 0:38e03f9fa18a 61
adelino 0:38e03f9fa18a 62
adelino 0:38e03f9fa18a 63 protected:
adelino 0:38e03f9fa18a 64 //
adelino 0:38e03f9fa18a 65 void setup(void);
adelino 0:38e03f9fa18a 66 SPI mySPI;
adelino 0:38e03f9fa18a 67 DigitalOut myCs;
adelino 0:38e03f9fa18a 68 int myFrequency;
adelino 0:38e03f9fa18a 69
adelino 0:38e03f9fa18a 70 };
adelino 0:38e03f9fa18a 71
adelino 0:38e03f9fa18a 72 #endif