![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
I2C not yet integrated
Tested working with single and differential voltages.
Connect SCL (pin 11) to D15 Connect SDA (pin 10) to D14 Connect pin 16 to +5v Connect pin 9 to gnd
LTC2991.h@5:8aa0f4e6788c, 2016-12-08 (annotated)
- Committer:
- lrdawg99
- Date:
- Thu Dec 08 21:48:29 2016 +0000
- Revision:
- 5:8aa0f4e6788c
- Parent:
- 2:c9e727dcd00e
scl sda switch
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lrdawg99 | 0:1473318f27b6 | 1 | /*! |
lrdawg99 | 0:1473318f27b6 | 2 | LTC2991: 14-bit ADC octal I2C voltage, current, and temperature monitor. |
lrdawg99 | 0:1473318f27b6 | 3 | |
lrdawg99 | 0:1473318f27b6 | 4 | @verbatim |
lrdawg99 | 0:1473318f27b6 | 5 | |
lrdawg99 | 0:1473318f27b6 | 6 | The LTC2991 is used to monitor system temperatures, voltages and currents. |
lrdawg99 | 0:1473318f27b6 | 7 | Through the I2C serial interface, the eight monitors can individually measure |
lrdawg99 | 0:1473318f27b6 | 8 | supply voltages and can be paired for differential measurements of current sense |
lrdawg99 | 0:1473318f27b6 | 9 | resistors or temperature sensing transistors. Additional measurements include |
lrdawg99 | 0:1473318f27b6 | 10 | internal temperature and internal VCC. The internal 10ppm reference minimizes |
lrdawg99 | 0:1473318f27b6 | 11 | the number of supporting components and area required. Selectable address and |
lrdawg99 | 0:1473318f27b6 | 12 | configurable functionality give the LTC2991 flexibility to be incorporated in |
lrdawg99 | 0:1473318f27b6 | 13 | various systems needing temperature, voltage or current data. The LTC2991 fits |
lrdawg99 | 0:1473318f27b6 | 14 | well in systems needing submillivolt voltage resolution, 1% current measurement |
lrdawg99 | 0:1473318f27b6 | 15 | and 1 degree Celsius temperature accuracy or any combination of the three. |
lrdawg99 | 0:1473318f27b6 | 16 | |
lrdawg99 | 0:1473318f27b6 | 17 | I2C DATA FORMAT (MSB FIRST); |
lrdawg99 | 0:1473318f27b6 | 18 | |
lrdawg99 | 0:1473318f27b6 | 19 | Data Out: |
lrdawg99 | 0:1473318f27b6 | 20 | Byte #1 Byte #2 Byte #3 |
lrdawg99 | 0:1473318f27b6 | 21 | |
lrdawg99 | 0:1473318f27b6 | 22 | START SA6 SA5 SA4 SA3 SA2 SA1 SA0 W SACK X X X X C3 C2 C1 C0 SACK D7 D6 D5 D4 D3 D2 D1 D0 SACK STOP |
lrdawg99 | 0:1473318f27b6 | 23 | |
lrdawg99 | 0:1473318f27b6 | 24 | Data In: |
lrdawg99 | 0:1473318f27b6 | 25 | Byte #1 Byte #2 Byte #3 |
lrdawg99 | 0:1473318f27b6 | 26 | |
lrdawg99 | 0:1473318f27b6 | 27 | START SA6 SA5 SA4 SA3 SA2 SA1 SA0 W SACK X X X X C3 C2 C1 C0 SACK REPEAT START SA6 SA5 SA4 SA3 SA2 SA1 SA0 R SACK |
lrdawg99 | 0:1473318f27b6 | 28 | |
lrdawg99 | 0:1473318f27b6 | 29 | Byte #4 Byte #5 |
lrdawg99 | 0:1473318f27b6 | 30 | MSB LSB |
lrdawg99 | 0:1473318f27b6 | 31 | D15 D14 D13 D12 D11 D10 D9 D8 MACK D7 D6 D5 D4 D3 D2 D1 D0 MNACK STOP |
lrdawg99 | 0:1473318f27b6 | 32 | |
lrdawg99 | 0:1473318f27b6 | 33 | START : I2C Start |
lrdawg99 | 0:1473318f27b6 | 34 | REPEAT Start : I2C Repeat Start |
lrdawg99 | 0:1473318f27b6 | 35 | STOP : I2C Stop |
lrdawg99 | 0:1473318f27b6 | 36 | SACK : I2C Slave Generated Acknowledge (Active Low) |
lrdawg99 | 0:1473318f27b6 | 37 | MACK : I2C Master Generated Acknowledge (Active Low) |
lrdawg99 | 0:1473318f27b6 | 38 | MNACK : I2C Master Generated Not Acknowledge |
lrdawg99 | 0:1473318f27b6 | 39 | SAx : I2C Address |
lrdawg99 | 0:1473318f27b6 | 40 | W : I2C Write (0) |
lrdawg99 | 0:1473318f27b6 | 41 | R : I2C Read (1) |
lrdawg99 | 0:1473318f27b6 | 42 | Cx : Command Code |
lrdawg99 | 0:1473318f27b6 | 43 | Dx : Data Bits |
lrdawg99 | 0:1473318f27b6 | 44 | X : Don't care |
lrdawg99 | 0:1473318f27b6 | 45 | |
lrdawg99 | 0:1473318f27b6 | 46 | |
lrdawg99 | 0:1473318f27b6 | 47 | Example Code: |
lrdawg99 | 0:1473318f27b6 | 48 | |
lrdawg99 | 0:1473318f27b6 | 49 | Read single-ended voltage from V1. |
lrdawg99 | 0:1473318f27b6 | 50 | |
lrdawg99 | 0:1473318f27b6 | 51 | // Enable Single-Ended Mode |
lrdawg99 | 0:1473318f27b6 | 52 | ack |= LTC2991_register_set_clear_bits(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V1234_REG, 0x00, LTC2991_V1_V2_DIFFERENTIAL_ENABLE | LTC2991_V1_V2_TEMP_ENABLE); |
lrdawg99 | 0:1473318f27b6 | 53 | |
lrdawg99 | 0:1473318f27b6 | 54 | // Flush one ADC reading in case it is stale. Then, take a new fresh reading. |
lrdawg99 | 0:1473318f27b6 | 55 | ack |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V1_MSB_REG, &code, &data_valid, LTC2991_TIMEOUT); |
lrdawg99 | 0:1473318f27b6 | 56 | |
lrdawg99 | 0:1473318f27b6 | 57 | voltage = LTC2991_code_to_single_ended_voltage(code, LTC2991_SINGLE_ENDED_lsb); // Converts code to voltage from single-ended lsb |
lrdawg99 | 0:1473318f27b6 | 58 | |
lrdawg99 | 0:1473318f27b6 | 59 | Read current from V3-V4. |
lrdawg99 | 0:1473318f27b6 | 60 | |
lrdawg99 | 0:1473318f27b6 | 61 | resistor = 1; // R_sense across V3-V4 in ohms |
lrdawg99 | 0:1473318f27b6 | 62 | |
lrdawg99 | 0:1473318f27b6 | 63 | // Enable Differential Mode |
lrdawg99 | 0:1473318f27b6 | 64 | ack |= LTC2991_register_set_clear_bits(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V1234_REG, LTC2991_V3_V4_DIFFERENTIAL_ENABLE, LTC2991_V3_V4_TEMP_ENABLE); |
lrdawg99 | 0:1473318f27b6 | 65 | |
lrdawg99 | 0:1473318f27b6 | 66 | // Flush one ADC reading in case it is stale. Then, take a new fresh reading. |
lrdawg99 | 0:1473318f27b6 | 67 | ack |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V4_MSB_REG, &code, &data_valid, LTC2991_TIMEOUT); |
lrdawg99 | 0:1473318f27b6 | 68 | |
lrdawg99 | 0:1473318f27b6 | 69 | voltage = LTC2991_code_to_differential_voltage(code, LTC2991_DIFFERENTIAL_lsb); // Converts code to voltage from differential lsb |
lrdawg99 | 0:1473318f27b6 | 70 | current = voltage / resistor; // Calculates current |
lrdawg99 | 0:1473318f27b6 | 71 | |
lrdawg99 | 0:1473318f27b6 | 72 | Read temperature from diode connected to V7-V8. |
lrdawg99 | 0:1473318f27b6 | 73 | |
lrdawg99 | 0:1473318f27b6 | 74 | // Enable temperature mode. |
lrdawg99 | 0:1473318f27b6 | 75 | ack |= LTC2991_register_set_clear_bits(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V5678_REG, LTC2991_V7_V8_TEMP_ENABLE, 0x00); |
lrdawg99 | 0:1473318f27b6 | 76 | |
lrdawg99 | 0:1473318f27b6 | 77 | // Flush one ADC reading in case it is stale. Then, take a new fresh reading. |
lrdawg99 | 0:1473318f27b6 | 78 | ack |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V7_MSB_REG, &adc_code, &data_valid, LTC2991_TIMEOUT); |
lrdawg99 | 0:1473318f27b6 | 79 | |
lrdawg99 | 0:1473318f27b6 | 80 | // Converts code to temperature from adc code and temperature lsb |
lrdawg99 | 0:1473318f27b6 | 81 | temperature = LTC2991_temperature(adc_code, LTC2991_TEMPERATURE_lsb); |
lrdawg99 | 0:1473318f27b6 | 82 | |
lrdawg99 | 0:1473318f27b6 | 83 | @endverbatim |
lrdawg99 | 0:1473318f27b6 | 84 | |
lrdawg99 | 0:1473318f27b6 | 85 | http://www.linear.com/product/LTC2991 |
lrdawg99 | 0:1473318f27b6 | 86 | |
lrdawg99 | 0:1473318f27b6 | 87 | http://www.linear.com/product/LTC2991#demoboards |
lrdawg99 | 0:1473318f27b6 | 88 | |
lrdawg99 | 0:1473318f27b6 | 89 | REVISION HISTORY |
lrdawg99 | 0:1473318f27b6 | 90 | $Revision: 3659 $ |
lrdawg99 | 0:1473318f27b6 | 91 | $Date: 2015-07-01 10:19:20 -0700 (Wed, 01 Jul 2015) $ |
lrdawg99 | 0:1473318f27b6 | 92 | |
lrdawg99 | 0:1473318f27b6 | 93 | Copyright (c) 2013, Linear Technology Corp.(LTC) |
lrdawg99 | 0:1473318f27b6 | 94 | All rights reserved. |
lrdawg99 | 0:1473318f27b6 | 95 | |
lrdawg99 | 0:1473318f27b6 | 96 | Redistribution and use in source and binary forms, with or without |
lrdawg99 | 0:1473318f27b6 | 97 | modification, are permitted provided that the following conditions are met: |
lrdawg99 | 0:1473318f27b6 | 98 | |
lrdawg99 | 0:1473318f27b6 | 99 | 1. Redistributions of source code must retain the above copyright notice, this |
lrdawg99 | 0:1473318f27b6 | 100 | list of conditions and the following disclaimer. |
lrdawg99 | 0:1473318f27b6 | 101 | 2. Redistributions in binary form must reproduce the above copyright notice, |
lrdawg99 | 0:1473318f27b6 | 102 | this list of conditions and the following disclaimer in the documentation |
lrdawg99 | 0:1473318f27b6 | 103 | and/or other materials provided with the distribution. |
lrdawg99 | 0:1473318f27b6 | 104 | |
lrdawg99 | 0:1473318f27b6 | 105 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
lrdawg99 | 0:1473318f27b6 | 106 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
lrdawg99 | 0:1473318f27b6 | 107 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
lrdawg99 | 0:1473318f27b6 | 108 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR |
lrdawg99 | 0:1473318f27b6 | 109 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
lrdawg99 | 0:1473318f27b6 | 110 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
lrdawg99 | 0:1473318f27b6 | 111 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
lrdawg99 | 0:1473318f27b6 | 112 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
lrdawg99 | 0:1473318f27b6 | 113 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
lrdawg99 | 0:1473318f27b6 | 114 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
lrdawg99 | 0:1473318f27b6 | 115 | |
lrdawg99 | 0:1473318f27b6 | 116 | The views and conclusions contained in the software and documentation are those |
lrdawg99 | 0:1473318f27b6 | 117 | of the authors and should not be interpreted as representing official policies, |
lrdawg99 | 0:1473318f27b6 | 118 | either expressed or implied, of Linear Technology Corp. |
lrdawg99 | 0:1473318f27b6 | 119 | |
lrdawg99 | 0:1473318f27b6 | 120 | The Linear Technology Linduino is not affiliated with the official Arduino team. |
lrdawg99 | 0:1473318f27b6 | 121 | However, the Linduino is only possible because of the Arduino team's commitment |
lrdawg99 | 0:1473318f27b6 | 122 | to the open-source community. Please, visit http://www.arduino.cc and |
lrdawg99 | 0:1473318f27b6 | 123 | http://store.arduino.cc , and consider a purchase that will help fund their |
lrdawg99 | 0:1473318f27b6 | 124 | ongoing work. |
lrdawg99 | 0:1473318f27b6 | 125 | |
lrdawg99 | 0:1473318f27b6 | 126 | */ |
lrdawg99 | 0:1473318f27b6 | 127 | /*! @file |
lrdawg99 | 0:1473318f27b6 | 128 | @ingroup LTC2991 |
lrdawg99 | 0:1473318f27b6 | 129 | Library Header File for LTC2991: 14-bit Octal I2C Voltage, Current, and Temperature Monitor |
lrdawg99 | 0:1473318f27b6 | 130 | */ |
lrdawg99 | 0:1473318f27b6 | 131 | |
lrdawg99 | 0:1473318f27b6 | 132 | #ifndef LTC2991_H |
lrdawg99 | 0:1473318f27b6 | 133 | #define LTC2991_H |
lrdawg99 | 0:1473318f27b6 | 134 | |
lrdawg99 | 0:1473318f27b6 | 135 | typedef bool boolean; |
lrdawg99 | 0:1473318f27b6 | 136 | //#include <Wire.h> |
lrdawg99 | 0:1473318f27b6 | 137 | |
lrdawg99 | 0:1473318f27b6 | 138 | // Calibration Variables |
lrdawg99 | 0:1473318f27b6 | 139 | //! Typical single-ended LSB weight in volts |
lrdawg99 | 0:1473318f27b6 | 140 | const float LTC2991_SINGLE_ENDED_lsb = 3.05176E-04; |
lrdawg99 | 0:1473318f27b6 | 141 | //! Typical differential LSB weight in volts |
lrdawg99 | 0:1473318f27b6 | 142 | const float LTC2991_DIFFERENTIAL_lsb = 1.90735E-05; |
lrdawg99 | 0:1473318f27b6 | 143 | //! Typical VCC LSB weight in volts |
lrdawg99 | 0:1473318f27b6 | 144 | const float LTC2991_VCC_lsb = 3.05176E-04; |
lrdawg99 | 0:1473318f27b6 | 145 | //! Typical temperature LSB weight in degrees Celsius (and Kelvin). |
lrdawg99 | 0:1473318f27b6 | 146 | //! Used for internal temperature as well as remote diode temperature measurements. |
lrdawg99 | 0:1473318f27b6 | 147 | const float LTC2991_TEMPERATURE_lsb = 0.0625; |
lrdawg99 | 0:1473318f27b6 | 148 | //! Typical remote diode LSB weight in volts. |
lrdawg99 | 0:1473318f27b6 | 149 | //! Used to readback diode voltage when in temperature measurement mode. |
lrdawg99 | 0:1473318f27b6 | 150 | const float LTC2991_DIODE_VOLTAGE_lsb = 3.815E-05; |
lrdawg99 | 0:1473318f27b6 | 151 | |
lrdawg99 | 0:1473318f27b6 | 152 | /*! @name I2C_Addresses |
lrdawg99 | 0:1473318f27b6 | 153 | @{ */ |
lrdawg99 | 0:1473318f27b6 | 154 | |
lrdawg99 | 0:1473318f27b6 | 155 | //! I2C address of the LTC2991. |
lrdawg99 | 0:1473318f27b6 | 156 | //! Configured by tying the ADR0, ADR1, and ADR2 pins high or low. See Table 1 of datasheet. |
lrdawg99 | 0:1473318f27b6 | 157 | //! Uncomment LTC2991_I2C_ADDRESS to match demo board configuration. |
lrdawg99 | 0:1473318f27b6 | 158 | // Address assignment |
lrdawg99 | 0:1473318f27b6 | 159 | // LTC2991 I2C Address // AD2 AD1 AD0 |
lrdawg99 | 1:4e4194db7cd6 | 160 | #define LTC2991_I2C_ADDRESS 0x48 // Low Low Low |
lrdawg99 | 0:1473318f27b6 | 161 | // #define LTC2991_I2C_ADDRESS 0x49 // Low Low High |
lrdawg99 | 0:1473318f27b6 | 162 | // #define LTC2991_I2C_ADDRESS 0x4A // Low High Low |
lrdawg99 | 0:1473318f27b6 | 163 | // #define LTC2991_I2C_ADDRESS 0x4B // Low High High |
lrdawg99 | 0:1473318f27b6 | 164 | // #define LTC2991_I2C_ADDRESS 0x4C // High Low Low |
lrdawg99 | 0:1473318f27b6 | 165 | // #define LTC2991_I2C_ADDRESS 0x4D // High Low High |
lrdawg99 | 0:1473318f27b6 | 166 | // #define LTC2991_I2C_ADDRESS 0x4E // High High Low |
lrdawg99 | 1:4e4194db7cd6 | 167 | //#define LTC2991_I2C_ADDRESS 0x4F // High High High |
lrdawg99 | 0:1473318f27b6 | 168 | |
lrdawg99 | 0:1473318f27b6 | 169 | //! LTC2991 Global I2C Address. |
lrdawg99 | 0:1473318f27b6 | 170 | #define LTC2991_I2C_GLOBAL_ADDRESS 0x77 // Global Address |
lrdawg99 | 0:1473318f27b6 | 171 | |
lrdawg99 | 0:1473318f27b6 | 172 | /*! @} */ |
lrdawg99 | 0:1473318f27b6 | 173 | /*! @name REGISTERS |
lrdawg99 | 0:1473318f27b6 | 174 | @{ */ |
lrdawg99 | 0:1473318f27b6 | 175 | |
lrdawg99 | 0:1473318f27b6 | 176 | #define LTC2991_STATUS_LOW_REG 0x00 //!< Data_Valid Bits(V1 Through V8) |
lrdawg99 | 0:1473318f27b6 | 177 | #define LTC2991_STATUS_HIGH_REG 0x01 //!< Data_valid bits |
lrdawg99 | 0:1473318f27b6 | 178 | #define LTC2991_CHANNEL_ENABLE_REG 0x01 //!< Channel Enable, Vcc, T_internal Conversion Status, Trigger |
lrdawg99 | 0:1473318f27b6 | 179 | #define LTC2991_CONTROL_V1234_REG 0x06 //!< V1, V2, V3, and V4 Control Register |
lrdawg99 | 0:1473318f27b6 | 180 | #define LTC2991_CONTROL_V5678_REG 0x07 //!< V5, V6, V7, AND V8 Control Register |
lrdawg99 | 0:1473318f27b6 | 181 | #define LTC2991_CONTROL_PWM_Tinternal_REG 0x08 //!< PWM Threshold and T_internal Control Register |
lrdawg99 | 0:1473318f27b6 | 182 | #define LTC2991_PWM_THRESHOLD_MSB_REG 0x09 //!< PWM Threshold |
lrdawg99 | 0:1473318f27b6 | 183 | #define LTC2991_V1_MSB_REG 0x0A //!< V1, or T_R1 T MSB |
lrdawg99 | 0:1473318f27b6 | 184 | #define LTC2991_V1_LSB_REG 0x0B //!< V1, or T_R1 T LSB |
lrdawg99 | 0:1473318f27b6 | 185 | #define LTC2991_V2_MSB_REG 0x0C //!< V2, V1-V2, or T_R2 Voltage MSB |
lrdawg99 | 0:1473318f27b6 | 186 | #define LTC2991_V2_LSB_REG 0x0D //!< V2, V1-V2, or T_R2 Voltage LSB |
lrdawg99 | 0:1473318f27b6 | 187 | #define LTC2991_V3_MSB_REG 0x0E //!< V3, or T_R2 T MSB |
lrdawg99 | 0:1473318f27b6 | 188 | #define LTC2991_V3_LSB_REG 0x0F //!< V3, or T_R2 T LSB |
lrdawg99 | 0:1473318f27b6 | 189 | #define LTC2991_V4_MSB_REG 0x10 //!< V4, V3-V4, or T_R2 Voltage MSB |
lrdawg99 | 0:1473318f27b6 | 190 | #define LTC2991_V4_LSB_REG 0x11 //!< V4, V3-V4, or T_R2 Voltage LSB |
lrdawg99 | 0:1473318f27b6 | 191 | #define LTC2991_V5_MSB_REG 0x12 //!< V5, or T_R3 T MSB |
lrdawg99 | 0:1473318f27b6 | 192 | #define LTC2991_V5_LSB_REG 0x13 //!< V5, or T_R3 T LSB |
lrdawg99 | 0:1473318f27b6 | 193 | #define LTC2991_V6_MSB_REG 0x14 //!< V6, V5-V6, or T_R3 Voltage MSB |
lrdawg99 | 0:1473318f27b6 | 194 | #define LTC2991_V6_LSB_REG 0x15 //!< V6, V5-V6, or T_R3 Voltage LSB |
lrdawg99 | 0:1473318f27b6 | 195 | #define LTC2991_V7_MSB_REG 0x16 //!< V7, or T_R4 T MSB |
lrdawg99 | 0:1473318f27b6 | 196 | #define LTC2991_V7_LSB_REG 0x17 //!< V7, or T_R4 T LSB |
lrdawg99 | 0:1473318f27b6 | 197 | #define LTC2991_V8_MSB_REG 0x18 //!< V8, V7-V8, or T_R4 Voltage MSB |
lrdawg99 | 0:1473318f27b6 | 198 | #define LTC2991_V8_LSB_REG 0x19 //!< V8, V7-V8, or T_R4 Voltage LSB |
lrdawg99 | 0:1473318f27b6 | 199 | #define LTC2991_T_Internal_MSB_REG 0x1A //!< T_Internal MSB |
lrdawg99 | 0:1473318f27b6 | 200 | #define LTC2991_T_Internal_LSB_REG 0x1B //!< T_Internal LSB |
lrdawg99 | 0:1473318f27b6 | 201 | #define LTC2991_Vcc_MSB_REG 0x1C //!< Vcc MSB |
lrdawg99 | 0:1473318f27b6 | 202 | #define LTC2991_Vcc_LSB_REG 0x1D //!< Vcc LSB |
lrdawg99 | 0:1473318f27b6 | 203 | |
lrdawg99 | 0:1473318f27b6 | 204 | /*! @} */ |
lrdawg99 | 0:1473318f27b6 | 205 | /*! @name LTC2991_CHANNEL_ENABLE_REG SETTINGS |
lrdawg99 | 0:1473318f27b6 | 206 | Bitwise OR settings, and write to LTC2991_CHANNEL_ENABLE_REG to configure settings. |
lrdawg99 | 0:1473318f27b6 | 207 | Bitwise AND with value read from LTC2991_CHANNEL_ENABLE_REG to determine present setting. |
lrdawg99 | 0:1473318f27b6 | 208 | @{ */ |
lrdawg99 | 0:1473318f27b6 | 209 | |
lrdawg99 | 0:1473318f27b6 | 210 | #define LTC2991_V7_V8_TR4_ENABLE 0x80 //!< Enable V7-V8 measurements, including TR4 temperature |
lrdawg99 | 0:1473318f27b6 | 211 | #define LTC2991_V5_V6_TR3_ENABLE 0x40 //!< Enable V5-V6 measurements, including TR3 temperature |
lrdawg99 | 0:1473318f27b6 | 212 | #define LTC2991_V3_V4_TR2_ENABLE 0x20 //!< Enable V3-V4 measurements, including TR2 temperature |
lrdawg99 | 0:1473318f27b6 | 213 | #define LTC2991_V1_V2_TR1_ENABLE 0x10 //!< Enable V1-V2 measurements, including TR1 temperature |
lrdawg99 | 0:1473318f27b6 | 214 | #define LTC2991_VCC_TINTERNAL_ENABLE 0x08 //!< Enable Vcc internal voltage measurement |
lrdawg99 | 0:1473318f27b6 | 215 | #define LTC2991_ENABLE_ALL_CHANNELS 0xF8 //!< Use to enable all LTC2991 channels. Equivalent to bitwise OR'ing all channel enables. |
lrdawg99 | 0:1473318f27b6 | 216 | #define LTC2991_BUSY 0x04 //!< LTC2991 Busy Bit |
lrdawg99 | 0:1473318f27b6 | 217 | |
lrdawg99 | 0:1473318f27b6 | 218 | /*! @} */ |
lrdawg99 | 0:1473318f27b6 | 219 | /*! @name LTC2991_CONTROL_V1234_REG SETTINGS |
lrdawg99 | 0:1473318f27b6 | 220 | Bitwise OR settings, and write to LTC2991_CONTROL_V1234_REG to configure settings. |
lrdawg99 | 0:1473318f27b6 | 221 | Bitwise AND with value read from LTC2991_CONTROL_V1234_REG to determine present setting. |
lrdawg99 | 0:1473318f27b6 | 222 | @{ */ |
lrdawg99 | 0:1473318f27b6 | 223 | |
lrdawg99 | 0:1473318f27b6 | 224 | #define LTC2991_V3_V4_FILTER_ENABLE 0x80 //!< Enable filters on V3-V4 |
lrdawg99 | 0:1473318f27b6 | 225 | #define LTC2991_V3_V4_KELVIN_ENABLE 0x40 //!< Enable V3-V4 for Kelvin. Otherwise, Celsius. |
lrdawg99 | 0:1473318f27b6 | 226 | #define LTC2991_V3_V4_TEMP_ENABLE 0x20 //!< Enable V3-V4 temperature mode. |
lrdawg99 | 0:1473318f27b6 | 227 | #define LTC2991_V3_V4_DIFFERENTIAL_ENABLE 0x10 //!< Enable V3-V4 differential mode. Otherwise, single-ended. |
lrdawg99 | 0:1473318f27b6 | 228 | #define LTC2991_V1_V2_FILTER_ENABLE 0x08 //!< Enable filters on V1-V2 |
lrdawg99 | 0:1473318f27b6 | 229 | #define LTC2991_V1_V2_KELVIN_ENABLE 0x04 //!< Enable V1-V2 for Kelvin. Otherwise, Celsius. |
lrdawg99 | 0:1473318f27b6 | 230 | #define LTC2991_V1_V2_TEMP_ENABLE 0x02 //!< Enable V1-V2 temperature mode. |
lrdawg99 | 0:1473318f27b6 | 231 | #define LTC2991_V1_V2_DIFFERENTIAL_ENABLE 0x01 //!< Enable V1-V2 differential mode. Otherwise, single-ended. |
lrdawg99 | 0:1473318f27b6 | 232 | |
lrdawg99 | 0:1473318f27b6 | 233 | /*! @} */ |
lrdawg99 | 0:1473318f27b6 | 234 | /*! @name LTC2991_CONTROL_V5678_REG SETTINGS |
lrdawg99 | 0:1473318f27b6 | 235 | Bitwise OR settings, and write to LTC2991_CONTROL_V5678_REG to configure settings. |
lrdawg99 | 0:1473318f27b6 | 236 | Bitwise AND with value read from LTC2991_CONTROL_V5678_REG to determine present setting. |
lrdawg99 | 0:1473318f27b6 | 237 | @{ */ |
lrdawg99 | 0:1473318f27b6 | 238 | |
lrdawg99 | 0:1473318f27b6 | 239 | #define LTC2991_V7_V8_FILTER_ENABLE 0x80 //!< Enable filters on V7-V8 |
lrdawg99 | 0:1473318f27b6 | 240 | #define LTC2991_V7_V8_KELVIN_ENABLE 0x40 //!< Enable V7-V8 for Kelvin. Otherwise, Celsius. |
lrdawg99 | 0:1473318f27b6 | 241 | #define LTC2991_V7_V8_TEMP_ENABLE 0x20 //!< Enable V7-V8 temperature mode. |
lrdawg99 | 0:1473318f27b6 | 242 | #define LTC2991_V7_V8_DIFFERENTIAL_ENABLE 0x10 //!< Enable V7-V8 differential mode. Otherwise, single-ended. |
lrdawg99 | 0:1473318f27b6 | 243 | #define LTC2991_V5_V6_FILTER_ENABLE 0x08 //!< Enable filters on V5-V6 |
lrdawg99 | 0:1473318f27b6 | 244 | #define LTC2991_V5_V6_KELVIN_ENABLE 0x04 //!< Enable V5-V6 for Kelvin. Otherwise, Celsius. |
lrdawg99 | 0:1473318f27b6 | 245 | #define LTC2991_V5_V6_TEMP_ENABLE 0x02 //!< Enable V5-V6 temperature mode. |
lrdawg99 | 0:1473318f27b6 | 246 | #define LTC2991_V5_V6_DIFFERENTIAL_ENABLE 0x01 //!< Enable V5-V6 differential mode. Otherwise, single-ended. |
lrdawg99 | 0:1473318f27b6 | 247 | |
lrdawg99 | 0:1473318f27b6 | 248 | /*! @} */ |
lrdawg99 | 0:1473318f27b6 | 249 | /*! @name LTC2991_CONTROL_PWM_Tinternal_REG SETTINGS |
lrdawg99 | 0:1473318f27b6 | 250 | Bitwise OR settings, and write to LTC2991_CONTROL_PWM_Tinternal_REG to configure settings. |
lrdawg99 | 0:1473318f27b6 | 251 | Bitwise AND with value read from LTC2991_CONTROL_PWM_Tinternal_REG to determine present setting. |
lrdawg99 | 0:1473318f27b6 | 252 | @{ */ |
lrdawg99 | 0:1473318f27b6 | 253 | |
lrdawg99 | 0:1473318f27b6 | 254 | #define LTC2991_PWM_0 0x80 //!< PWM threshold Least Significant Bit |
lrdawg99 | 0:1473318f27b6 | 255 | #define LTC2991_PWM_INVERT 0x40 //!< Invert PWM |
lrdawg99 | 0:1473318f27b6 | 256 | #define LTC2991_PWM_ENABLE 0x20 //!< Enable PWM |
lrdawg99 | 0:1473318f27b6 | 257 | #define LTC2991_REPEAT_MODE 0x10 //!< Enable Repeated Aquisition Mode |
lrdawg99 | 0:1473318f27b6 | 258 | #define LTC2991_INT_FILTER_ENABLE 0x08 //!< Enable Internal Temperature Filter |
lrdawg99 | 0:1473318f27b6 | 259 | #define LTC2991_INT_KELVIN_ENABLE 0x04 //!< Enable internal temperature for Kelvin. Otherwise, Celsius. |
lrdawg99 | 0:1473318f27b6 | 260 | /*!@} */ |
lrdawg99 | 0:1473318f27b6 | 261 | |
lrdawg99 | 2:c9e727dcd00e | 262 | #include "LT_I2C.h" |
lrdawg99 | 2:c9e727dcd00e | 263 | |
lrdawg99 | 2:c9e727dcd00e | 264 | |
lrdawg99 | 2:c9e727dcd00e | 265 | class LTC2991 { |
lrdawg99 | 2:c9e727dcd00e | 266 | |
lrdawg99 | 2:c9e727dcd00e | 267 | private: |
lrdawg99 | 2:c9e727dcd00e | 268 | LT_I2C *lti2c; |
lrdawg99 | 2:c9e727dcd00e | 269 | |
lrdawg99 | 2:c9e727dcd00e | 270 | |
lrdawg99 | 2:c9e727dcd00e | 271 | public: |
lrdawg99 | 2:c9e727dcd00e | 272 | LTC2991(); |
lrdawg99 | 2:c9e727dcd00e | 273 | LTC2991(PinName i2c_scl_, PinName i2c_sda_); |
lrdawg99 | 2:c9e727dcd00e | 274 | |
lrdawg99 | 0:1473318f27b6 | 275 | //! Reads a 14-bit adc_code from LTC2991. |
lrdawg99 | 0:1473318f27b6 | 276 | //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge. |
lrdawg99 | 0:1473318f27b6 | 277 | int8_t LTC2991_adc_read(uint8_t i2c_address, //!< I2C address of the LTC2991. Configured by tying the ADR0, ADR1, and ADR2 pins high or low. See Table 1 of datasheet. |
lrdawg99 | 0:1473318f27b6 | 278 | uint8_t msb_register_address, /*!< Address of the LTC2991 MSB register to be read. This is also known as the "command byte". |
lrdawg99 | 0:1473318f27b6 | 279 | Two sequential 8-bit registers are read, starting with the msb_register_address.*/ |
lrdawg99 | 0:1473318f27b6 | 280 | int16_t *adc_code, //!< returns 14-bit value read from the adc |
lrdawg99 | 0:1473318f27b6 | 281 | int8_t *data_valid //!< returns the status of the DATA_VALID bit. *data_valid=0 indicates stale data |
lrdawg99 | 0:1473318f27b6 | 282 | ); |
lrdawg99 | 0:1473318f27b6 | 283 | |
lrdawg99 | 0:1473318f27b6 | 284 | //! Reads a 14-bit adc_code from the LTC2991 but enforces a maximum timeout. |
lrdawg99 | 0:1473318f27b6 | 285 | //! Similar to LTC2991_adc_read except it repeats until the data_valid bit is set, it fails to receive an I2C acknowledge, or the timeout (in milliseconds) |
lrdawg99 | 0:1473318f27b6 | 286 | //! expires. It keeps trying to read from the LTC2991 every millisecond until the data_valid bit is set (indicating new data since the previous |
lrdawg99 | 0:1473318f27b6 | 287 | //! time this register was read) or until it fails to receive an I2C acknowledge (indicating an error on the I2C bus). |
lrdawg99 | 0:1473318f27b6 | 288 | //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge. |
lrdawg99 | 0:1473318f27b6 | 289 | int8_t LTC2991_adc_read_timeout(uint8_t i2c_address, //!< I2C address of the LTC2991. Configured by tying the ADR0, ADR1, and ADR2 pins high or low. See Table 1 of datasheet. |
lrdawg99 | 0:1473318f27b6 | 290 | uint8_t msb_register_address, /*!< Address of the LTC2991 MSB register to be read. This is also known as the "command byte". |
lrdawg99 | 0:1473318f27b6 | 291 | Two sequential 8-bit registers will be read, starting with the msb_register_address.*/ |
lrdawg99 | 0:1473318f27b6 | 292 | int16_t *adc_code, //!< returns 14-bit value read from the adc |
lrdawg99 | 0:1473318f27b6 | 293 | int8_t *data_valid, //!< returns the status of the DATA_VALID bit. *data_valid=0 indicates stale data |
lrdawg99 | 0:1473318f27b6 | 294 | uint16_t timeout, //!< maximum timeout in millisceonds. If at any time a NACK is received the function aborts. |
lrdawg99 | 0:1473318f27b6 | 295 | uint8_t status_bit //!< If the timeout is reached without valid data (*data_valid=1) the function exits.*/ |
lrdawg99 | 0:1473318f27b6 | 296 | ); |
lrdawg99 | 0:1473318f27b6 | 297 | |
lrdawg99 | 0:1473318f27b6 | 298 | //! Reads new data (even after a mode change) by flushing old data and waiting for the data_valid bit to be set. |
lrdawg99 | 0:1473318f27b6 | 299 | //! This function simplifies adc reads when modes are changing. For example, if V1-V2 changes from temperature mode |
lrdawg99 | 0:1473318f27b6 | 300 | //! to differential voltage mode, the data in the register may still correspond to the temperature reading immediately |
lrdawg99 | 0:1473318f27b6 | 301 | //! after the mode change. Flushing one reading and waiting for a new reading guarantees fresh data is received. |
lrdawg99 | 0:1473318f27b6 | 302 | //! If the timeout is reached without valid data (*data_valid=1) the function exits. |
lrdawg99 | 0:1473318f27b6 | 303 | //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge. |
lrdawg99 | 0:1473318f27b6 | 304 | int8_t LTC2991_adc_read_new_data(uint8_t i2c_address, //!< I2C address of the LTC2991. Configured by tying the ADR0, ADR1, and ADR2 pins high or low. See Table 1 of datasheet. |
lrdawg99 | 0:1473318f27b6 | 305 | uint8_t msb_register_address, /*!< Address of the LTC2991 MSB register to be read. This is also known as the "command byte". |
lrdawg99 | 0:1473318f27b6 | 306 | Two sequential 8-bit registers will be read, starting with the msb_register_address.*/ |
lrdawg99 | 0:1473318f27b6 | 307 | int16_t *adc_code, //!< returns 14-bit value read from the adc |
lrdawg99 | 0:1473318f27b6 | 308 | int8_t *data_valid, //!< returns the status of the DATA_VALID bit. *data_valid=0 indicates stale data |
lrdawg99 | 0:1473318f27b6 | 309 | uint16_t timeout /*!< maximum timeout in millisceonds. If at any time a NACK is received the function aborts. |
lrdawg99 | 0:1473318f27b6 | 310 | If the timeout is reached without valid data (*data_valid=1) the function exits.*/ |
lrdawg99 | 0:1473318f27b6 | 311 | ); |
lrdawg99 | 0:1473318f27b6 | 312 | |
lrdawg99 | 0:1473318f27b6 | 313 | //! Reads an 8-bit register from the LTC2991 using the standard repeated start format. |
lrdawg99 | 0:1473318f27b6 | 314 | //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge. |
lrdawg99 | 0:1473318f27b6 | 315 | int8_t LTC2991_register_read(uint8_t i2c_address, //!< I2C address of the LTC2991. Configured by tying the ADR0, ADR1, and ADR2 pins high or low. See Table 1 of datasheet. |
lrdawg99 | 0:1473318f27b6 | 316 | uint8_t register_address, //!< Address of the LTC2991 register to be read. This is also known as the "command byte". |
lrdawg99 | 0:1473318f27b6 | 317 | uint8_t *register_data //!< returns 8-bit value read from the LTC2991 register. |
lrdawg99 | 0:1473318f27b6 | 318 | ); |
lrdawg99 | 0:1473318f27b6 | 319 | |
lrdawg99 | 0:1473318f27b6 | 320 | //! Write one byte to an LTC2991 register. |
lrdawg99 | 0:1473318f27b6 | 321 | //! Writes to an 8-bit register inside the LTC2991 using the standard I2C repeated start format. |
lrdawg99 | 0:1473318f27b6 | 322 | //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge. |
lrdawg99 | 0:1473318f27b6 | 323 | int8_t LTC2991_register_write(uint8_t i2c_address, //!< I2C address of the LTC2991. Configured by tying the ADR0, ADR1, and ADR2 pins high or low. See Table 1 of datasheet. |
lrdawg99 | 0:1473318f27b6 | 324 | uint8_t register_address, //!< Address of the LTC2991 register to be overwritten. This is also known as the "command byte". |
lrdawg99 | 0:1473318f27b6 | 325 | uint8_t register_data //!< Value that will be written to the register. |
lrdawg99 | 0:1473318f27b6 | 326 | ); |
lrdawg99 | 0:1473318f27b6 | 327 | |
lrdawg99 | 0:1473318f27b6 | 328 | |
lrdawg99 | 0:1473318f27b6 | 329 | //! Used to set and clear bits in a control register. bits_to_set will be bitwise OR'd with the register. |
lrdawg99 | 0:1473318f27b6 | 330 | //! bits_to_clear will be inverted and bitwise AND'd with the register so that every location with a 1 will result in a 0 in the register. |
lrdawg99 | 0:1473318f27b6 | 331 | //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge. |
lrdawg99 | 0:1473318f27b6 | 332 | int8_t LTC2991_register_set_clear_bits(uint8_t i2c_address, //!< I2C address of the LTC2991. Configured by tying the ADR0, ADR1, and ADR2 pins high or low. See Table 1 of datasheet. |
lrdawg99 | 0:1473318f27b6 | 333 | uint8_t register_address, //!< Address of the LTC2991 register to be modified. |
lrdawg99 | 0:1473318f27b6 | 334 | uint8_t bits_to_set, //!< bits_to_set will be bitwise OR'd with the register. |
lrdawg99 | 0:1473318f27b6 | 335 | uint8_t bits_to_clear //!< bits_to_clear will be inverted and bitwise AND'd with the register |
lrdawg99 | 0:1473318f27b6 | 336 | ); |
lrdawg99 | 0:1473318f27b6 | 337 | |
lrdawg99 | 0:1473318f27b6 | 338 | //! Calculates the LTC2991 single-ended input voltages |
lrdawg99 | 0:1473318f27b6 | 339 | //! @return the single-ended voCalculatesltage in volts |
lrdawg99 | 0:1473318f27b6 | 340 | float LTC2991_code_to_single_ended_voltage(int16_t adc_code, //!< code read from the adc (from a function such as LTC2991_adc_read) |
lrdawg99 | 0:1473318f27b6 | 341 | float LTC2991_single_ended_lsb //!< single-ended LSB weight. If not calibrated, use LTC2991_SINGLE_ENDED_LSB |
lrdawg99 | 0:1473318f27b6 | 342 | ); |
lrdawg99 | 0:1473318f27b6 | 343 | |
lrdawg99 | 0:1473318f27b6 | 344 | //! Calculates the LTC2991 Vcc voltage |
lrdawg99 | 0:1473318f27b6 | 345 | //! @return the Vcc voltage in volts |
lrdawg99 | 0:1473318f27b6 | 346 | float LTC2991_code_to_vcc_voltage(int16_t adc_code, //!< code read from the adc (from a function such as LTC2991_adc_read) |
lrdawg99 | 0:1473318f27b6 | 347 | float LTC2991_single_ended_lsb //!< Vcc LSB weight. If not calibrated, use LTC2991_VCC_LSB |
lrdawg99 | 0:1473318f27b6 | 348 | ); |
lrdawg99 | 0:1473318f27b6 | 349 | |
lrdawg99 | 0:1473318f27b6 | 350 | //! Calculates the LTC2991 differential input voltage. |
lrdawg99 | 0:1473318f27b6 | 351 | //! @return the differential voltage in volts |
lrdawg99 | 0:1473318f27b6 | 352 | float LTC2991_code_to_differential_voltage(int16_t adc_code, //!< code read from the adc (from a function such as LTC2991_adc_read) |
lrdawg99 | 0:1473318f27b6 | 353 | float LTC2991_differential_lsb //!< differential LSB weight. If not calibrated, use LTC2991_DIFFERENTIAL_LSB |
lrdawg99 | 0:1473318f27b6 | 354 | ); |
lrdawg99 | 0:1473318f27b6 | 355 | |
lrdawg99 | 0:1473318f27b6 | 356 | //! Calculates the LTC2991 temperature |
lrdawg99 | 0:1473318f27b6 | 357 | //! @return the temperature in degrees Celsius or degrees Kevlin (dependent on mode setting). |
lrdawg99 | 0:1473318f27b6 | 358 | float LTC2991_temperature(int16_t adc_code, //!< code read from the adc (from a function such as LTC2991_adc_read). |
lrdawg99 | 0:1473318f27b6 | 359 | float LTC2991_temperature_lsb, //!< temperature LSB weight. If not calibrated, use LTC2991_TEMPERATURE_LSB |
lrdawg99 | 0:1473318f27b6 | 360 | boolean unit //!< The temperature unit, true for Kelvin, false for Celsius |
lrdawg99 | 0:1473318f27b6 | 361 | ); |
lrdawg99 | 0:1473318f27b6 | 362 | |
lrdawg99 | 0:1473318f27b6 | 363 | //! Calcultates the LTC2991 diode voltage |
lrdawg99 | 0:1473318f27b6 | 364 | //! @return the diode voltage in volts. |
lrdawg99 | 0:1473318f27b6 | 365 | float LTC2991_code_to_diode_voltage(int16_t adc_code, //!< code read from the adc (from a function such as LTC2991_adc_read) |
lrdawg99 | 0:1473318f27b6 | 366 | float LTC2991_diode_voltage_lsb //!< diode voltage LSB weight. If not calibrated, use LTC2991_DIODE_VOLTAGE_LSB |
lrdawg99 | 0:1473318f27b6 | 367 | ); |
lrdawg99 | 2:c9e727dcd00e | 368 | }; |
lrdawg99 | 0:1473318f27b6 | 369 | #endif // LTC2991_H |