Texas Instruments INA226 High-or Low-Side Measurement, Bi-Directional CURRENT/POWER MONITOR with I 2C™ Interface http://www.ti.com/product/ina226&DCMP=analog_signalchain_mr&HQS=ina226-pr
INA226.h@0:3984961a3725, 2013-08-07 (annotated)
- Committer:
- gizmo69the2nd
- Date:
- Wed Aug 07 22:51:12 2013 +0000
- Revision:
- 0:3984961a3725
Working version, not tested
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gizmo69the2nd | 0:3984961a3725 | 1 | /* |
gizmo69the2nd | 0:3984961a3725 | 2 | * Texas Instruments INA226 voltage/ current/ power monitor library |
gizmo69the2nd | 0:3984961a3725 | 3 | * |
gizmo69the2nd | 0:3984961a3725 | 4 | * |
gizmo69the2nd | 0:3984961a3725 | 5 | * Copyright (c) 2013 Davy Van Belle, MIT License |
gizmo69the2nd | 0:3984961a3725 | 6 | * |
gizmo69the2nd | 0:3984961a3725 | 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
gizmo69the2nd | 0:3984961a3725 | 8 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
gizmo69the2nd | 0:3984961a3725 | 9 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
gizmo69the2nd | 0:3984961a3725 | 10 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
gizmo69the2nd | 0:3984961a3725 | 11 | * furnished to do so, subject to the following conditions: |
gizmo69the2nd | 0:3984961a3725 | 12 | * |
gizmo69the2nd | 0:3984961a3725 | 13 | * The above copyright notice and this permission notice shall be included in all copies or |
gizmo69the2nd | 0:3984961a3725 | 14 | * substantial portions of the Software. |
gizmo69the2nd | 0:3984961a3725 | 15 | * |
gizmo69the2nd | 0:3984961a3725 | 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
gizmo69the2nd | 0:3984961a3725 | 17 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
gizmo69the2nd | 0:3984961a3725 | 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
gizmo69the2nd | 0:3984961a3725 | 19 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
gizmo69the2nd | 0:3984961a3725 | 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
gizmo69the2nd | 0:3984961a3725 | 21 | */ |
gizmo69the2nd | 0:3984961a3725 | 22 | |
gizmo69the2nd | 0:3984961a3725 | 23 | /** @file |
gizmo69the2nd | 0:3984961a3725 | 24 | * @brief INA226 I2C |
gizmo69the2nd | 0:3984961a3725 | 25 | */ |
gizmo69the2nd | 0:3984961a3725 | 26 | |
gizmo69the2nd | 0:3984961a3725 | 27 | #ifndef INA226_H |
gizmo69the2nd | 0:3984961a3725 | 28 | #define INA226_H |
gizmo69the2nd | 0:3984961a3725 | 29 | |
gizmo69the2nd | 0:3984961a3725 | 30 | #include "mbed.h" |
gizmo69the2nd | 0:3984961a3725 | 31 | |
gizmo69the2nd | 0:3984961a3725 | 32 | #define CONF 0x00 |
gizmo69the2nd | 0:3984961a3725 | 33 | |
gizmo69the2nd | 0:3984961a3725 | 34 | #define VSHUNT 0x01 |
gizmo69the2nd | 0:3984961a3725 | 35 | #define VBUS 0x02 |
gizmo69the2nd | 0:3984961a3725 | 36 | #define POWER 0x03 |
gizmo69the2nd | 0:3984961a3725 | 37 | #define CURRENT 0x04 |
gizmo69the2nd | 0:3984961a3725 | 38 | #define CAL 0x05 |
gizmo69the2nd | 0:3984961a3725 | 39 | #define MASK 0x06 |
gizmo69the2nd | 0:3984961a3725 | 40 | #define ALERT 0x07 |
gizmo69the2nd | 0:3984961a3725 | 41 | |
gizmo69the2nd | 0:3984961a3725 | 42 | #define DIE_ID 0xFF |
gizmo69the2nd | 0:3984961a3725 | 43 | |
gizmo69the2nd | 0:3984961a3725 | 44 | #define SHUNT_LSB 0.0000025 |
gizmo69the2nd | 0:3984961a3725 | 45 | #define BUS_LSB 0.00125 |
gizmo69the2nd | 0:3984961a3725 | 46 | |
gizmo69the2nd | 0:3984961a3725 | 47 | |
gizmo69the2nd | 0:3984961a3725 | 48 | |
gizmo69the2nd | 0:3984961a3725 | 49 | /** INA226 class |
gizmo69the2nd | 0:3984961a3725 | 50 | */ |
gizmo69the2nd | 0:3984961a3725 | 51 | class INA226 { |
gizmo69the2nd | 0:3984961a3725 | 52 | public: |
gizmo69the2nd | 0:3984961a3725 | 53 | /** init INA226 class |
gizmo69the2nd | 0:3984961a3725 | 54 | * @param *i2c pointer to I2C serial interface |
gizmo69the2nd | 0:3984961a3725 | 55 | * @param addr sensor I2C address |
gizmo69the2nd | 0:3984961a3725 | 56 | */ |
gizmo69the2nd | 0:3984961a3725 | 57 | INA226 (I2C* i2c, char addr); |
gizmo69the2nd | 0:3984961a3725 | 58 | |
gizmo69the2nd | 0:3984961a3725 | 59 | /** Set the configuration of the device |
gizmo69the2nd | 0:3984961a3725 | 60 | * @param reg desired Configure Register bits |
gizmo69the2nd | 0:3984961a3725 | 61 | */ |
gizmo69the2nd | 0:3984961a3725 | 62 | void setConfig (unsigned short reg); |
gizmo69the2nd | 0:3984961a3725 | 63 | |
gizmo69the2nd | 0:3984961a3725 | 64 | /** Get device Configuration register |
gizmo69the2nd | 0:3984961a3725 | 65 | */ |
gizmo69the2nd | 0:3984961a3725 | 66 | unsigned short getConfig(); |
gizmo69the2nd | 0:3984961a3725 | 67 | |
gizmo69the2nd | 0:3984961a3725 | 68 | /** Get the voltage over the shunt |
gizmo69the2nd | 0:3984961a3725 | 69 | */ |
gizmo69the2nd | 0:3984961a3725 | 70 | float getShuntVolt(); |
gizmo69the2nd | 0:3984961a3725 | 71 | |
gizmo69the2nd | 0:3984961a3725 | 72 | /** Get the voltage of the bus rail |
gizmo69the2nd | 0:3984961a3725 | 73 | */ |
gizmo69the2nd | 0:3984961a3725 | 74 | float getBusVolt(); |
gizmo69the2nd | 0:3984961a3725 | 75 | |
gizmo69the2nd | 0:3984961a3725 | 76 | /** Get the current measured through the shunt. |
gizmo69the2nd | 0:3984961a3725 | 77 | * in order to get the current you need to set the shut resistor value first |
gizmo69the2nd | 0:3984961a3725 | 78 | */ |
gizmo69the2nd | 0:3984961a3725 | 79 | float getCurrent(); |
gizmo69the2nd | 0:3984961a3725 | 80 | |
gizmo69the2nd | 0:3984961a3725 | 81 | float getPower(); |
gizmo69the2nd | 0:3984961a3725 | 82 | |
gizmo69the2nd | 0:3984961a3725 | 83 | /** Set the Calibartion register |
gizmo69the2nd | 0:3984961a3725 | 84 | */ |
gizmo69the2nd | 0:3984961a3725 | 85 | void setCalibration(unsigned short reg); |
gizmo69the2nd | 0:3984961a3725 | 86 | |
gizmo69the2nd | 0:3984961a3725 | 87 | /** Get the Calibration register |
gizmo69the2nd | 0:3984961a3725 | 88 | */ |
gizmo69the2nd | 0:3984961a3725 | 89 | unsigned short getCalibration(); |
gizmo69the2nd | 0:3984961a3725 | 90 | |
gizmo69the2nd | 0:3984961a3725 | 91 | /** Set the mask/enable Register |
gizmo69the2nd | 0:3984961a3725 | 92 | */ |
gizmo69the2nd | 0:3984961a3725 | 93 | void setMaskEnable(unsigned short reg); |
gizmo69the2nd | 0:3984961a3725 | 94 | |
gizmo69the2nd | 0:3984961a3725 | 95 | /** Get the mask/enable Register |
gizmo69the2nd | 0:3984961a3725 | 96 | */ |
gizmo69the2nd | 0:3984961a3725 | 97 | unsigned short getMaskEnable(); |
gizmo69the2nd | 0:3984961a3725 | 98 | |
gizmo69the2nd | 0:3984961a3725 | 99 | void setAlertLimit(unsigned short reg); |
gizmo69the2nd | 0:3984961a3725 | 100 | |
gizmo69the2nd | 0:3984961a3725 | 101 | unsigned short getAlertLimit(); |
gizmo69the2nd | 0:3984961a3725 | 102 | |
gizmo69the2nd | 0:3984961a3725 | 103 | /** Get the unique ID of the device |
gizmo69the2nd | 0:3984961a3725 | 104 | */ |
gizmo69the2nd | 0:3984961a3725 | 105 | unsigned short getID(); |
gizmo69the2nd | 0:3984961a3725 | 106 | |
gizmo69the2nd | 0:3984961a3725 | 107 | /** Set the shunt resistor |
gizmo69the2nd | 0:3984961a3725 | 108 | *@param val value in ohm |
gizmo69the2nd | 0:3984961a3725 | 109 | */ |
gizmo69the2nd | 0:3984961a3725 | 110 | void setShuntRValue(float val); |
gizmo69the2nd | 0:3984961a3725 | 111 | |
gizmo69the2nd | 0:3984961a3725 | 112 | float getShuntRValue(void); |
gizmo69the2nd | 0:3984961a3725 | 113 | |
gizmo69the2nd | 0:3984961a3725 | 114 | /** Set the current LSB for maximum current in decimal |
gizmo69the2nd | 0:3984961a3725 | 115 | */ |
gizmo69the2nd | 0:3984961a3725 | 116 | void setCurrentLSB(float val); |
gizmo69the2nd | 0:3984961a3725 | 117 | |
gizmo69the2nd | 0:3984961a3725 | 118 | float getCurrentLSB(float val); |
gizmo69the2nd | 0:3984961a3725 | 119 | |
gizmo69the2nd | 0:3984961a3725 | 120 | protected: |
gizmo69the2nd | 0:3984961a3725 | 121 | |
gizmo69the2nd | 0:3984961a3725 | 122 | |
gizmo69the2nd | 0:3984961a3725 | 123 | private: |
gizmo69the2nd | 0:3984961a3725 | 124 | char _addr; |
gizmo69the2nd | 0:3984961a3725 | 125 | I2C *_i2c; |
gizmo69the2nd | 0:3984961a3725 | 126 | float ShuntR; |
gizmo69the2nd | 0:3984961a3725 | 127 | float CURR_LSB; |
gizmo69the2nd | 0:3984961a3725 | 128 | |
gizmo69the2nd | 0:3984961a3725 | 129 | |
gizmo69the2nd | 0:3984961a3725 | 130 | |
gizmo69the2nd | 0:3984961a3725 | 131 | }; |
gizmo69the2nd | 0:3984961a3725 | 132 | |
gizmo69the2nd | 0:3984961a3725 | 133 | #endif |