library for MAX9611 /9612 Current-Sense Amplifiers

Revision:
6:32b5eb1df932
Parent:
5:6fec24c37e2a
Child:
7:012f5b39405e
--- a/max9611.h	Sat Nov 08 20:45:21 2014 +0000
+++ b/max9611.h	Tue Nov 11 02:25:05 2014 +0000
@@ -30,28 +30,24 @@
 
 
 class MAX9611{
-        
- private: 
- 
- typedef struct{
-      
       
       
- }ControlReg1;
-      
+ /**********private members and methods********************************/       
+ private: 
+     
  typedef enum {
-    CHANNEL_A_0=0,
-    CHANNEL_A_1,
-    CHANNEL_A_2,
-    CHANNEL_B,
-    CHANNEL_C,
-    CHANNEL_D,
-    CHANNEL_E,
-    ALL_CHANNELS
+    CHANNEL_A_0=0,  /*Read current-sense amplifier output from ADC, gain = 1x*/
+    CHANNEL_A_1,    /*Read current-sense amplifier output from ADC, gain = 4x*/
+    CHANNEL_A_2,    /*Read current-sense amplifier output from ADC, gain = 8x*/
+    CHANNEL_B,      /*Read average voltage of RS+ (input common-mode voltage) from ADC*/
+    CHANNEL_C,      /*Read voltage of OUT from ADC*/
+    CHANNEL_D,      /*Read voltage of SET from ADC*/
+    CHANNEL_E,      /*Read internal die temperature from ADC*/
+    ALL_CHANNELS    /*Read all channels in fast-read mode, sequentially every 2ms. Uses last gain setting.*/
  }eCtrlReg1MUX;
  
  typedef enum {
-   NORMAL_OPERATION_SHDN=0,
+   NORMAL_OPERATION_SHDN=0, 
    SHUTDOWN_MODE
  }eCtrlReg1SHDN;
  
@@ -93,58 +89,8 @@
     CONTROL_REGISTER_1_ADRR= 0x0A,
     CONTROL_REGISTER_2_ADRR= 0x0B
  }eRegAddresses;  
-   
-   
-   public:
-
-    /** Create an MAX9611 instance
-     * @param sda pin 
-     * @param scl pin 
-     * @param address: I2C slave address 
-     */
-    MAX9611(PinName sda, PinName scl,int i2cFrequency=100000,int address = MAX9611_I2C_ADDRESS); 
-
-    /** Create a MAX9611 instance
-     * @param i2c object
-     * @param address: I2C slave address 
-     */
-    MAX9611(I2C& i2c, int address = MAX9611_I2C_ADDRESS); 
-
-    /** Initialization: set member values and 
-     * @returns
-     *    true on success,
-     *    false on error
-     */
-    bool initMax9611(eCtrlReg1MUX mux=  ALL_CHANNELS, 
-                    eCtrlReg1SHDN shdn= NORMAL_OPERATION_SHDN, 
-                    eCtrlReg1LR lr=NORMAL_OPERATION_LR, 
-                    eCtrlReg1MODE mode=NORMAL_OPERATION_MODE, 
-                    eCtrlReg2DTIM watchdogDelay= _1MS, 
-                    eCtrlReg2RTIM watchdogRetryDelay=_50MS);
-
-    /** Read temperature from the MAX9611.
-     * @param temperature (C) 
-     * @returns
-     *   1 on success,
-     *   0 on error
-     */    
-    bool readTemp();
-    
-    /** Get temperature from the last measurement 
-     *  
-     * @returns
-     *   temperature (C)
-     */    
-   inline float getTemp(void) {return mTemperature;}
-
-protected:
-       
-    I2C i2c;   
-    int i2cAddr;
-        
-private: 
-
-    float mTemperature;
+ 
+ 
  
     /** Write data to the given register
      *  
@@ -181,13 +127,94 @@
     inline uint16_t get9BitData(uint8_t msbByte,uint8_t lsbByte){
         uint16_t data9Bit= (msbByte<<1)|((lsbByte>>6)&0x01);
         return data9Bit; 
+        
+      
+
     }
     
+    /**********protected methods********************************/
+    protected:
+       
+    I2C mI2c;   
+    int mI2cAddr;
+    float mTemperature;  
+    float mCurrentSenseAmplifierOutput;
+     const uint16_t csaCurrentValueOffset=0x0a;//0x10;   
+   
+   
+   /**********public methods********************************/
+    public:
+
+    /** Create an MAX9611 instance
+     * @param sda pin 
+     * @param scl pin 
+     * @param address: I2C slave address 
+     */
+    MAX9611(PinName sda, PinName scl,int i2cFrequency=100000,int address = MAX9611_I2C_ADDRESS); 
+
+
+    /** Create a MAX9611 instance
+     * @param i2c object
+     * @param address: I2C slave address 
+     */
+    MAX9611(I2C& i2c, int address = MAX9611_I2C_ADDRESS); 
+
+
+    /** Initialization: set member values and configuration registers, ought to be invoked in the body of constructor 
+     * @returns
+     *    true on success,
+     *    false on error
+     */
+    bool initMax9611(eCtrlReg1MUX mux= CHANNEL_A_1, 
+                    eCtrlReg1SHDN shdn= NORMAL_OPERATION_SHDN, 
+                    eCtrlReg1LR lr=NORMAL_OPERATION_LR, 
+                    eCtrlReg1MODE mode= NORMAL_OPERATION_MODE, 
+                    eCtrlReg2DTIM watchdogDelay= _1MS, 
+                    eCtrlReg2RTIM watchdogRetryDelay=_50MS);
+
+
+    /** Read temperature from the MAX9611.
+     * @param none
+     * @returns
+     *   1 on success,
+     *   0 on error
+     */    
+    bool readTemp(void);
     
     
+    /** Get temperature from the last measurement 
+     *  
+     * @returns
+     *   temperature (C)
+     */    
+   inline float getTemp(void) {return mTemperature;}
+   
+   
+   /** Read CSA output value from the MAX9611.
+     * @param none 
+     * @returns
+     *   1 on success,
+     *   0 on error
+     */    
+    bool readCSAOutputValue(void);
+   
+   
+   /** Get value of CSA output from the last measurement 
+     *  
+     * @returns
+     *   Current Value [A]
+     */    
+   inline float getCSAOutput(void) {return mCurrentSenseAmplifierOutput;}
+
+   //DEBUG
+   uint16_t mRawInt;
+   
+   uint16_t readControl(void);
+   uint16_t readRsValue(void);
+   uint16_t readOutValue(void);
+   
+
     
-        
-
 };
 
 #endif
\ No newline at end of file