Dual ADC library

Dependents:   elixys

Committer:
henryeherman
Date:
Wed Aug 14 00:21:42 2013 +0000
Revision:
0:b58572ce83b6
Initial commit of a library to communicate with the MCP482X SPI based DAC from microchip.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
henryeherman 0:b58572ce83b6 1 #include "mbed.h"
henryeherman 0:b58572ce83b6 2 #include "bit.h"
henryeherman 0:b58572ce83b6 3 #ifndef MCP482X_H
henryeherman 0:b58572ce83b6 4 #define MCP482X_H
henryeherman 0:b58572ce83b6 5
henryeherman 0:b58572ce83b6 6 #define MCP482X_VREF 2048
henryeherman 0:b58572ce83b6 7
henryeherman 0:b58572ce83b6 8 #define DACSELBIT BIT(15)
henryeherman 0:b58572ce83b6 9 #define DACUNDEF BIT(14)
henryeherman 0:b58572ce83b6 10 #define GAINBIT BIT(13)
henryeherman 0:b58572ce83b6 11 #define SHDNBIT BIT(12)
henryeherman 0:b58572ce83b6 12
henryeherman 0:b58572ce83b6 13 #define SELECTDACA(VALUE) CLEARBITS(VALUE,DACSELBIT)
henryeherman 0:b58572ce83b6 14 #define SELECTDACB(VALUE) SETBITS(VALUE,DACSELBIT)
henryeherman 0:b58572ce83b6 15 #define SELECT1XGAIN(VALUE) SETBITS(VALUE,GAINBIT)
henryeherman 0:b58572ce83b6 16 #define SELECT2XGAIN(VALUE) CLEARBITS(VALUE,GAINBIT)
henryeherman 0:b58572ce83b6 17 #define SELECTPWRON(VALUE) SETBITS(VALUE, SHDNBIT)
henryeherman 0:b58572ce83b6 18 #define SELECTPWROFF(VALUE) CLEARBITS(VALUE, SHDNBIT)
henryeherman 0:b58572ce83b6 19
henryeherman 0:b58572ce83b6 20 // BITS 0-11 set the output voltage!!!
henryeherman 0:b58572ce83b6 21
henryeherman 0:b58572ce83b6 22 class MCP482X {
henryeherman 0:b58572ce83b6 23 public:
henryeherman 0:b58572ce83b6 24
henryeherman 0:b58572ce83b6 25 /*
henryeherman 0:b58572ce83b6 26 * Constructor
henryeherman 0:b58572ce83b6 27 */
henryeherman 0:b58572ce83b6 28 MCP482X(SPI &spi, DigitalOut &cspin);
henryeherman 0:b58572ce83b6 29
henryeherman 0:b58572ce83b6 30 /*
henryeherman 0:b58572ce83b6 31 * Destructor
henryeherman 0:b58572ce83b6 32 */
henryeherman 0:b58572ce83b6 33 ~MCP482X();
henryeherman 0:b58572ce83b6 34
henryeherman 0:b58572ce83b6 35 /*
henryeherman 0:b58572ce83b6 36 * Write to DAC A
henryeherman 0:b58572ce83b6 37 */
henryeherman 0:b58572ce83b6 38 int writeA(int value);
henryeherman 0:b58572ce83b6 39
henryeherman 0:b58572ce83b6 40
henryeherman 0:b58572ce83b6 41 /*
henryeherman 0:b58572ce83b6 42 * Write to DAC B
henryeherman 0:b58572ce83b6 43 */
henryeherman 0:b58572ce83b6 44 int writeB(int value);
henryeherman 0:b58572ce83b6 45
henryeherman 0:b58572ce83b6 46
henryeherman 0:b58572ce83b6 47 /*
henryeherman 0:b58572ce83b6 48 * Set Gain for DAC A 1 or 2
henryeherman 0:b58572ce83b6 49 */
henryeherman 0:b58572ce83b6 50 void setGainA(int value);
henryeherman 0:b58572ce83b6 51
henryeherman 0:b58572ce83b6 52
henryeherman 0:b58572ce83b6 53 /*
henryeherman 0:b58572ce83b6 54 * Set Gain for DAC B 1 or 2
henryeherman 0:b58572ce83b6 55 */
henryeherman 0:b58572ce83b6 56 void setGainB(int value);
henryeherman 0:b58572ce83b6 57
henryeherman 0:b58572ce83b6 58 /*
henryeherman 0:b58572ce83b6 59 * Shutdown DAC
henryeherman 0:b58572ce83b6 60 */
henryeherman 0:b58572ce83b6 61 void disable();
henryeherman 0:b58572ce83b6 62
henryeherman 0:b58572ce83b6 63 /*
henryeherman 0:b58572ce83b6 64 * Power On DAC
henryeherman 0:b58572ce83b6 65 */
henryeherman 0:b58572ce83b6 66 void enable();
henryeherman 0:b58572ce83b6 67
henryeherman 0:b58572ce83b6 68 private:
henryeherman 0:b58572ce83b6 69
henryeherman 0:b58572ce83b6 70 int gainA;
henryeherman 0:b58572ce83b6 71 int gainB;
henryeherman 0:b58572ce83b6 72 int valA;
henryeherman 0:b58572ce83b6 73 int valB;
henryeherman 0:b58572ce83b6 74 bool bshutdown;
henryeherman 0:b58572ce83b6 75 SPI &_spi;
henryeherman 0:b58572ce83b6 76 DigitalOut &_cspin;
henryeherman 0:b58572ce83b6 77
henryeherman 0:b58572ce83b6 78 void configspi();
henryeherman 0:b58572ce83b6 79 void sendValue(int value);
henryeherman 0:b58572ce83b6 80 }; // end class MCP482X
henryeherman 0:b58572ce83b6 81
henryeherman 0:b58572ce83b6 82 #endif //MCP482X_H