12-Bit, 8-Channel, ADC System Monitor w/ Temp Sensor, Internal/External Reference, & I2C Interface

Dependents:   ADC128D818_HelloWorld

Revision:
0:9cc68ef524da
Child:
1:5f9dbbbc34c5
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ADC128D818.h	Tue Aug 27 11:38:38 2013 +0000
@@ -0,0 +1,115 @@
+
+
+#ifndef ADC128D818_H
+
+#define ADC128D818_H
+
+#include "mbed.h"
+
+
+//Library for the ADC128D818 12 BIT ADC.
+enum ADC_MODE {
+        ADC_MODE_0 = 0x00,
+        ADC_MODE_1 = 0x01,
+        ADC_MODE_2 = 0x02,
+        ADC_MODE_3 = 0x03
+    };
+    enum ADC_ADDRESS {
+        ADC_ADDRESS_LOW_LOW = 0x1D,
+        ADC_ADDRESS_LOW_MID = 0x1E,
+        ADC_ADDRESS_LOW_HIGH = 0x1F,
+        ADC_ADDRESS_MID_LOW = 0x2D,
+        ADC_ADDRESS_MID_MID = 0x2E,
+        ADC_ADDRESS_MID_HIGH = 0x2F,
+        ADC_ADDRESS_HIGH_LOW = 0x35,
+        ADC_ADDRESS_HIGH_MID = 0x36,
+        ADC_ADDRESS_HIGH_HIGH = 0x37
+    };
+    enum ADC_VREF {
+        ADC_VREF_INT = 0x00,
+        ADC_VREF_EXT = 0x01
+    };
+    enum ADC_RATE {
+        ADC_RATE_LOW_POWER = 0x00,
+        ADC_RATE_CONTINUOUS = 0x01
+    };
+    enum ADC_LIMIT {
+        ADC_LIMIT_HIGH = 0x00,
+        ADC_LIMIT_LOW = 0x01
+    };
+    enum ADC_CHANNEL {
+        ADC_CHANNEL_IN0 = 0x00,
+        ADC_CHANNEL_IN1 = 0x01,
+        ADC_CHANNEL_IN2 = 0x02,
+        ADC_CHANNEL_IN3 = 0x03,
+        ADC_CHANNEL_IN4 = 0x04,
+        ADC_CHANNEL_IN5 = 0x05,
+        ADC_CHANNEL_IN6 = 0x06,
+        ADC_CHANNEL_IN7 = 0x07,
+        ADC_CHANNEL_TEMP = 0x07
+    };
+    enum ADC_REG {
+        ADC_REG_Configuration_Register  = 0x00,
+        ADC_REG_Interrupt_Status_Register = 0x01,
+        ADC_REG_Interrupt_Mask_Register = 0x03,
+        ADC_REG_Conversion_Rate_Register = 0x07,
+        ADC_REG_Channel_Disable_Register = 0x08,
+        ADC_REG_One_Shot_Register = 0x09,
+        ADC_REG_Deep_Shutdown_Register = 0x0A,
+        ADC_REG_Advanced_Configuration_Register = 0x0B,
+        ADC_REG_Busy_Status_Register = 0x0C,
+        ADC_REG_Channel_Readings_Registers = 0x20,
+        ADC_REG_Limit_Registers = 0x2A,
+        ADC_REG_Manufacturer_ID_Register = 0x3E,
+        ADC_REG_Revision_ID_Register = 0x3F
+    };
+class ADC128D818
+{
+ protected:
+     
+    
+   enum Configuration_Register {
+        Configuration_Register_Start = 1<<0,
+        Configuration_Register_INT_Enable = 1<<1,
+        Configuration_Register_INT_Clear = 1<<3,
+        Configuration_Register_Initialization = 1<<7
+    };
+    
+    enum Busy_Status_Register {
+        Busy_Status_Register_Busy = 1<<0,
+        Busy_Status_Register_Not_Ready = 1<<1
+    };
+    
+    enum Advanced_Configuration_Register {
+        Advanced_Configuration_Register_External_Reference_Enable = 1<<0,
+        Advanced_Configuration_Register_Mode_Select_0 = 1<<1,
+        Advanced_Configuration_Register_Mode_Select_1 = 1<<2
+    };
+    
+    enum Conversion_Rate_Register {
+        Conversion_Rate_Register_Rate_Register = 1<<0
+    };
+    
+ 
+private:
+    I2C _i2c;
+    char _data[2];
+    char _address;
+    char _mode;
+    
+public:
+    
+    ADC128D818(PinName sda, PinName scl, PinName adc_int );
+    ~ADC128D818();
+
+    InterruptIn _Adc_Int;
+    int read_channel(char channel);
+    char read_register(char Register);
+    int init(char address, char mode, char vref, char rate, char mask_channel, char mask_int);
+    int init_limit(char channel, int limit, char high_low);
+    void start();
+    void stop();
+};
+
+#endif
+