Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
LTC2990.h
Go to the documentation of this file.
1 /*!
2 LTC2990: 14-bit ADC Quad I2C voltage, current, and temperature monitor.
3 
4 @verbatim
5 
6 The LTC2990 is used to monitor system temperatures, voltages and currents.
7 Through the I2C serial interface, the four monitors can individually measure
8 supply voltages and can be paired for differential measurements of current sense
9 resistors or temperature sensing transistors. Additional measurements include
10 internal temperature and internal VCC. The internal 10ppm reference minimizes
11 the number of supporting components and area required. Selectable address and
12 configurable functionality give the LTC2990 flexibility to be incorporated in
13 various systems needing temperature, voltage or current data. The LTC2990 fits
14 well in systems needing sub-millivolt voltage resolution, 1% current measurement
15 and 1 degree Celsius temperature accuracy or any combination of the three.
16 
17 I2C DATA FORMAT (MSB FIRST);
18 
19 Data Out:
20 Byte #1 Byte #2 Byte #3
21 
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
23 
24 Data In:
25 Byte #1 Byte #2 Byte #3
26 
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
28 
29 Byte #4 Byte #5
30 MSB LSB
31 D15 D14 D13 D12 D11 D10 D9 D8 MACK D7 D6 D5 D4 D3 D2 D1 D0 MNACK STOP
32 
33 START : I2C Start
34 REPEAT Start : I2C Repeat Start
35 STOP : I2C Stop
36 SACK : I2C Slave Generated Acknowledge (Active Low)
37 MACK : I2C Master Generated Acknowledge (Active Low)
38 MNACK : I2C Master Generated Not Acknowledge
39 SAx : I2C Address
40 W : I2C Write (0)
41 R : I2C Read (1)
42 Cx : Command Code
43 Dx : Data Bits
44 X : Don't care
45 
46 
47 Example Code:
48 
49 Read single-ended voltage from V1.
50 
51  // Enable Single-Ended Mode
52  ack |= LTC2990_register_set_clear_bits(LTC2990_I2C_ADDRESS, LTC2990_CONTROL_REG, LTC2990_V1_V2_V3_V4, LTC2990_VOLTAGE_MODE_MASK);
53 
54  // Triggers a conversion by writing any value to the trigger register
55  ack |= LTC2990_register_write(LTC2990_I2C_ADDRESS, LTC2990_TRIGGER_REG, 0x00);
56 
57  // Flush one ADC reading in case it is stale. Then, take a new fresh reading.
58  ack |= LTC2990_adc_read_new_data(LTC2990_I2C_ADDRESS, LTC2990_V1_MSB_REG, &code, &data_valid, LTC2990_TIMEOUT);
59 
60  voltage = LTC2990_code_to_single_ended_voltage(code, LTC2990_SINGLE_ENDED_lsb);
61 
62 Read current from V3-V4.
63 
64  resistor = 1; // R_sense across V3-V4 in ohms
65 
66  // Enables differential mode.
67  ack |= LTC2990_register_set_clear_bits(LTC2990_I2C_ADDRESS, LTC2990_CONTROL_REG, LTC2990_V1V2_V3V4, LTC2990_VOLTAGE_MODE_MASK);
68 
69  // Triggers a conversion by writing any value to the trigger register
70  ack |= LTC2990_register_write(LTC2990_I2C_ADDRESS, LTC2990_TRIGGER_REG, 0x00);
71 
72  // Flush one ADC reading in case it is stale. Then, take a new fresh reading.
73  ack |= LTC2990_adc_read_new_data(LTC2990_I2C_ADDRESS, LTC2990_V2_MSB_REG, &code, &data_valid, LTC2990_TIMEOUT);
74 
75  voltage = LTC2990_code_to_differential_voltage(code, LTC2990_DIFFERENTIAL_lsb);
76 
77  current = voltage / resistor; // Calculates current
78 
79 Read temperature from diode connected to V1-V2.
80 
81  // Enables temperature mode
82  ack |= LTC2990_register_set_clear_bits(LTC2990_I2C_ADDRESS, LTC2990_CONTROL_REG, LTC2990_TR1_TR2, LTC2990_VOLTAGE_MODE_MASK);
83 
84  // Triggers a conversion by writing any value to the trigger register
85  ack |= LTC2990_register_write(LTC2990_I2C_ADDRESS, LTC2990_TRIGGER_REG, 0x00);
86 
87 
88  // Flush one ADC reading in case it is stale. Then, take a new fresh reading.
89  ack |= LTC2990_adc_read_new_data(LTC2990_I2C_ADDRESS, LTC2990_V1_MSB_REG, &adc_code, &data_valid, LTC2990_TIMEOUT);
90 
91  // Check which temperature mode the LTC2990 in currently in
92  ack |= LTC2990_register_read(LTC2990_I2C_ADDRESS, LTC2990_CONTROL_REG, &reg_data);
93  if (reg_data & LTC2990_KELVIN_ENABLE) isKelvin= true;
94  else isKelvin=false;
95 
96  temperature = LTC2990_temperature(adc_code, LTC2990_TEMPERATURE_lsb, isKelvin);
97 
98 @endverbatim
99 
100 http://www.linear.com/product/LTC2990
101 
102 http://www.linear.com/product/LTC2990#demoboards
103 
104 
105 Copyright 2018(c) Analog Devices, Inc.
106 
107 All rights reserved.
108 
109 Redistribution and use in source and binary forms, with or without
110 modification, are permitted provided that the following conditions are met:
111  - Redistributions of source code must retain the above copyright
112  notice, this list of conditions and the following disclaimer.
113  - Redistributions in binary form must reproduce the above copyright
114  notice, this list of conditions and the following disclaimer in
115  the documentation and/or other materials provided with the
116  distribution.
117  - Neither the name of Analog Devices, Inc. nor the names of its
118  contributors may be used to endorse or promote products derived
119  from this software without specific prior written permission.
120  - The use of this software may or may not infringe the patent rights
121  of one or more patent holders. This license does not release you
122  from the requirement that you obtain separate licenses from these
123  patent holders to use this software.
124  - Use of the software either in source or binary form, must be run
125  on or directly connected to an Analog Devices Inc. component.
126 
127 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
128 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
129 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
130 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
131 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
132 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
133 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
134 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
135 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
136 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
137 
138 */
139 /*! @file
140  @ingroup LTC2990
141  Library Header File for LTC2990: 14-bit Quad I2C Voltage, Current, and Temperature Monitor
142 */
143 
144 #ifndef LTC2990_H
145 #define LTC2990_H
146 
147 #include <Wire.h>
148 
149 /*! @name I2C_Addresses
150 @{ */
151 
152 //! I2C address of the LTC2990.
153 //! Configured by tying the ADR0, ADR1, and ADR2 pins high or low. See Table 1 of datasheet.
154 //! Uncomment LTC2990_I2C_ADDRESS to match demo board configuration.
155 // Address assignment
156 // LTC2990 I2C Address // AD1 AD0
157 #define LTC2990_I2C_ADDRESS 0x4C // Low Low
158 // #define LTC2990_I2C_ADDRESS 0x4D // Low High
159 // #define LTC2990_I2C_ADDRESS 0x4E // High Low
160 // #define LTC2990_I2C_ADDRESS 0x4F // High High
161 
162 
163 //! LTC2990 Global I2C Address.
164 #define LTC2990_I2C_GLOBAL_ADDRESS 0x77 // Global Address
165 
166 /*! @} */
167 /*! @name REGISTERS
168 @{ */
169 
170 #define LTC2990_STATUS_REG 0x00 //!< Indicates BUSY state and conversion status
171 #define LTC2990_CONTROL_REG 0x01 //!< Controls Mode, Single/Repeat, Celsius/Kelvin
172 #define LTC2990_TRIGGER_REG 0x02 //!< Triggers a conversion
173 #define LTC2990_TINT_MSB_REG 0x04 //!< Internal Temperature MSB
174 #define LTC2990_TINT_LSB_REG 0x05 //!< Internal Temperature LSB
175 #define LTC2990_V1_MSB_REG 0x06 //!< V1, V1-V2, or T_R1 T MSB
176 #define LTC2990_V1_LSB_REG 0x07 //!< V1, V1-V2, or T_R1 T LSB
177 #define LTC2990_V2_MSB_REG 0x08 //!< V2, V1-V2, or T_R2 Voltage MSB
178 #define LTC2990_V2_LSB_REG 0x09 //!< V2, V1-V2, or T_R2 Voltage LSB
179 #define LTC2990_V3_MSB_REG 0x0A //!< V3, V3-V4, or T_R2 T MSB
180 #define LTC2990_V3_LSB_REG 0x0B //!< V3, V3-V4, or T_R2 T LSB
181 #define LTC2990_V4_MSB_REG 0x0C //!< V4, V3-V4, or T_R2 Voltage MSB
182 #define LTC2990_V4_LSB_REG 0x0D //!< V4, V3-V4, or T_R2 Voltage LSB
183 #define LTC2990_VCC_MSB_REG 0x0E //!< Vcc MSB
184 #define LTC2990_VCC_LSB_REG 0x0F //!< Vcc LSB
185 
186 /*! @} */
187 /*! @name LTC2990_CONTROL_REG SETTINGS
188  Bitwise OR settings, and write to LTC2990_CONTROL_REG to configure settings.
189  Bitwise AND with value read from LTC2990_CONTROL_REG to determine present setting.
190 @{ */
191 
192 #define LTC2990_KELVIN_ENABLE 0x80 //!< Enable for Kelvin.
193 #define LTC2990_CELSIUS_ENABLE 0x00 //!< Enable for Celsius.
194 #define LTC2990_TEMP_FORMAT_MASK 0x80 //!< Use mask when changing temp formats
195 
196 #define LTC2990_SINGLE_ENABLE 0x40 //!< Enable for Single Acquisition
197 #define LTC2990_REPEATED_ENABLE 0x00 //!< Enable for Repeated Acquisition Mode
198 #define LTC2990_ACQUISITION_MASK 0x40 //!< Use mask when changing acquisition settings
199 
200 
201 /*! @} */
202 /*! @name LTC2990_CONTROL_REG ENABLE
203  Bitwise AND 0xE7 then Bitwise OR settings, and write to LTC2990_CONTROL_REG to configure enable settings.
204  Bitwise AND with value read from LTC2990_CONTROL_REG to determine present enable setting.
205 @{ */
206 
207 #define LTC2990_ENABLE_INT_TEMPERATURE 0x00 //!< Read only Internal Temperature
208 #define LTC2990_ENABLE_V1 0x08 //!< Tr1, V1 or V1-V2 per Mode are enabled
209 #define LTC2990_ENABLE_V2 0x10 //!< Tr2, V3 or V3-V4 per Mode are enabled
210 #define LTC2990_ENABLE_ALL 0x18 //!< All measurements per Mode are enabled
211 #define LTC2990_TEMP_MEAS_MODE_MASK 0x18 //!< Use mask when changing temp meas modes
212 
213 /*! @} */
214 /*! @name LTC2990_CONTROL_REG MODE
215  Bitwise AND 0xF8 then Bitwise OR settings, and write to LTC2990_CONTROL_REG to configure enable settings.
216  Bitwise AND with value read from LTC2990_CONTROL_REG to determine present enable setting.
217 @{ */
218 
219 #define LTC2990_V1_V2_TR2 0x00 //!< Read V1, V2 and TR2
220 #define LTC2990_V1V2_TR2 0x01 //!< Read V1-V2 and TR2
221 #define LTC2990_V1V2_V3_V4 0x02 //!< Read V1-V2, V3 and V4
222 #define LTC2990_TR1_V3_V4 0x03 //!< Read TR1, V3 and V4
223 #define LTC2990_TR1_V3V4 0x04 //!< Read TR1 and V3-V4
224 #define LTC2990_TR1_TR2 0x05 //!< Read TR1 and TR2
225 #define LTC2990_V1V2_V3V4 0x06 //!< Read V1-V2 and V3-V4
226 #define LTC2990_V1_V2_V3_V4 0x07 //!< Read V1, V2, V3 and V4
227 #define LTC2990_VOLTAGE_MODE_MASK 0x07 //!< Use mode mask when changing modes
228 
229 
230 
231 /*!@} */
232 
233 //! Reads a 14-bit adc_code from LTC2990.
234 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
235 int8_t LTC2990_adc_read(uint8_t i2c_address, //!< I2C address of the LTC2990. Configured by tying the ADR0, ADR1, and ADR2 pins high or low. See Table 1 of datasheet.
236  uint8_t msb_register_address, /*!< Address of the LTC2990 MSB register to be read. This is also known as the "command byte".
237  Two sequential 8-bit registers are read, starting with the msb_register_address.*/
238  int16_t *adc_code, //!< returns 14-bit value read from the ADC
239  int8_t *data_valid //!< returns the status of the DATA_VALID bit. *data_valid=0 indicates stale data
240  );
241 
242 //! Reads a 14-bit adc_code from the LTC2990 but enforces a maximum timeout.
243 //! Similar to LTC2990_adc_read except it repeats until the data_valid bit is set, it fails to receive an I2C acknowledge, or the timeout (in milliseconds)
244 //! expires. It keeps trying to read from the LTC2990 every millisecond until the data_valid bit is set (indicating new data since the previous
245 //! time this register was read) or until it fails to receive an I2C acknowledge (indicating an error on the I2C bus).
246 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
247 int8_t LTC2990_adc_read_timeout(uint8_t i2c_address, //!< I2C address of the LTC2990. Configured by tying the ADR0, ADR1, and ADR2 pins high or low. See Table 1 of datasheet.
248  uint8_t msb_register_address, /*!< Address of the LTC2990 MSB register to be read. This is also known as the "command byte".
249  Two sequential 8-bit registers will be read, starting with the msb_register_address.*/
250  int16_t *adc_code, //!< returns 14-bit value read from the ADC
251  int8_t *data_valid, //!< returns the status of the DATA_VALID bit. *data_valid=0 indicates stale data
252  uint16_t timeout, /*!< maximum timeout in milliseconds. If at any time a NACK is received the function aborts.*/
253  uint8_t status_bit //<!If the timeout is reached without valid data (*data_valid=1) the function exits.
254  );
255 
256 //! Reads new data (even after a mode change) by flushing old data and waiting for the data_valid bit to be set.
257 //! This function simplifies ADC reads when modes are changing. For example, if V1-V2 changes from temperature mode
258 //! to differential voltage mode, the data in the register may still correspond to the temperature reading immediately
259 //! after the mode change. Flushing one reading and waiting for a new reading guarantees fresh data is received.
260 //! If the timeout is reached without valid data (*data_valid=1) the function exits.
261 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
262 int8_t LTC2990_adc_read_new_data(uint8_t i2c_address, //!< I2C address of the LTC2990. Configured by tying the ADR0, ADR1, and ADR2 pins high or low. See Table 1 of datasheet.
263  uint8_t msb_register_address, /*!< Address of the LTC2990 MSB register to be read. This is also known as the "command byte".
264  Two sequential 8-bit registers will be read, starting with the msb_register_address.*/
265  int16_t *adc_code, //!< returns 14-bit value read from the ADC
266  int8_t *data_valid, //!< returns the status of the DATA_VALID bit. *data_valid=0 indicates stale data
267  uint16_t timeout /*!< maximum timeout in milliseconds. If at any time a NACK is received the function aborts.
268  If the timeout is reached without valid data (*data_valid=1) the function exits.*/
269  );
270 
271 //! Reads an 8-bit register from the LTC2990 using the standard repeated start format.
272 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
273 int8_t LTC2990_register_read(uint8_t i2c_address, //!< I2C address of the LTC2990. Configured by tying the ADR0, ADR1, and ADR2 pins high or low. See Table 1 of datasheet.
274  uint8_t register_address, //!< Address of the LTC2990 register to be read. This is also known as the "command byte".
275  uint8_t *register_data //!< returns 8-bit value read from the LTC2990 register.
276  );
277 
278 //! Write one byte to an LTC2990 register.
279 //! Writes to an 8-bit register inside the LTC2990 using the standard I2C repeated start format.
280 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
281 int8_t LTC2990_register_write(uint8_t i2c_address, //!< I2C address of the LTC2990. Configured by tying the ADR0, ADR1, and ADR2 pins high or low. See Table 1 of datasheet.
282  uint8_t register_address, //!< Address of the LTC2990 register to be overwritten. This is also known as the "command byte".
283  uint8_t register_data //!< Value that will be written to the register.
284  );
285 
286 
287 //! Used to set and clear bits in a control register. bits_to_set will be bitwise OR'd with the register.
288 //! 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.
289 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
290 int8_t LTC2990_register_set_clear_bits(uint8_t i2c_address, //!< I2C address of the LTC2990. Configured by tying the ADR0, ADR1, and ADR2 pins high or low. See Table 1 of datasheet.
291  uint8_t register_address, //!< Address of the LTC2990 register to be modified.
292  uint8_t bits_to_set, //!< bits_to_set will be bitwise OR'd with the register.
293  uint8_t bits_to_clear //!< bits_to_clear will be inverted and bitwise AND'd with the register
294  );
295 
296 
297 //! Calculates the LTC2990 single-ended input voltages
298 //! @return the single-ended voltage in volts
299 float LTC2990_code_to_single_ended_voltage(int16_t adc_code, //!< code read from the ADC (from a function such as LTC2990_adc_read)
300  float LTC2990_single_ended_lsb //!< single-ended LSB weight. If not calibrated, use LTC2990_SINGLE_ENDED_LSB
301  );
302 
303 //! Calculates the LTC2990 Vcc voltage
304 //! @return the Vcc voltage in volts
305 float LTC2990_code_to_vcc_voltage(int16_t adc_code, //!< code read from the ADC (from a function such as LTC2990_adc_read)
306  float LTC2990_single_ended_lsb //!< Vcc LSB weight. If not calibrated, use LTC2990_VCC_LSB
307  );
308 
309 //! Calculates the LTC2990 differential input voltage.
310 //! @return the differential voltage in volts
311 float LTC2990_code_to_differential_voltage(int16_t adc_code, //!< code read from the ADC (from a function such as LTC2990_adc_read)
312  float LTC2990_differential_lsb //!< differential LSB weight. If not calibrated, use LTC2990_DIFFERENTIAL_LSB
313  );
314 
315 //! Calculates the LTC2990 temperature
316 //! @return the temperature in degrees Celsius or degrees Kelvin (dependent on mode setting).
317 float LTC2990_temperature(int16_t adc_code, //!< code read from the ADC (from a function such as LTC2990_adc_read).
318  float LTC2990_temperature_lsb, //!< temperature LSB weight. If not calibrated, use LTC2990_TEMPERATURE_LSB
319  boolean unit //!< The temperature unit, true for Kelvin, false for Celsius
320  );
321 
322 //! Calculates the LTC2990 diode voltage
323 //! @return the diode voltage in volts.
324 float LTC2990_code_to_diode_voltage(int16_t adc_code, //!< code read from the ADC (from a function such as LTC2990_adc_read)
325  float LTC2990_diode_voltage_lsb //!< diode voltage LSB weight. If not calibrated, use LTC2990_DIODE_VOLTAGE_LSB
326  );
327 
328 #endif // LTC2990_H
uint8_t i2c_address
float LTC2990_code_to_vcc_voltage(int16_t adc_code, float LTC2990_single_ended_lsb)
Calculates the LTC2990 Vcc voltage.
Definition: LTC2990.cpp:185
float LTC2990_code_to_differential_voltage(int16_t adc_code, float LTC2990_differential_lsb)
Calculates the LTC2990 differential input voltage.
Definition: LTC2990.cpp:200
int8_t LTC2990_register_read(uint8_t i2c_address, uint8_t register_address, uint8_t *register_data)
Reads an 8-bit register from the LTC2990 using the standard repeated start format.
Definition: LTC2990.cpp:137
float LTC2990_code_to_single_ended_voltage(int16_t adc_code, float LTC2990_single_ended_lsb)
Calculates the LTC2990 single-ended input voltages.
Definition: LTC2990.cpp:170
long timeout
int8_t LTC2990_register_write(uint8_t i2c_address, uint8_t register_address, uint8_t register_data)
Write one byte to an LTC2990 register.
Definition: LTC2990.cpp:147
int8_t LTC2990_adc_read(uint8_t i2c_address, uint8_t msb_register_address, int16_t *adc_code, int8_t *data_valid)
Reads a 14-bit adc_code from LTC2990.
Definition: LTC2990.cpp:76
float LTC2990_code_to_diode_voltage(int16_t adc_code, float LTC2990_diode_voltage_lsb)
Calculates the LTC2990 diode voltage.
Definition: LTC2990.cpp:231
int8_t LTC2990_adc_read_new_data(uint8_t i2c_address, uint8_t msb_register_address, int16_t *adc_code, int8_t *data_valid, uint16_t timeout)
Reads new data (even after a mode change) by flushing old data and waiting for the data_valid bit to ...
Definition: LTC2990.cpp:124
int8_t LTC2990_register_set_clear_bits(uint8_t i2c_address, uint8_t register_address, uint8_t bits_to_set, uint8_t bits_to_clear)
Used to set and clear bits in a control register.
Definition: LTC2990.cpp:157
int8_t LTC2990_adc_read_timeout(uint8_t i2c_address, uint8_t msb_register_address, int16_t *adc_code, int8_t *data_valid, uint16_t timeout, uint8_t status_bit)
Reads a 14-bit adc_code from the LTC2990 but enforces a maximum timeout.
Definition: LTC2990.cpp:93
float LTC2990_temperature(int16_t adc_code, float LTC2990_temperature_lsb, boolean unit)
Calculates the LTC2990 temperature.
Definition: LTC2990.cpp:214
static uint32_t adc_code
Definition: DC2071AA.ino:113