Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
LTC4151.h
Go to the documentation of this file.
1 /*!
2 LTC4151: High Voltage I2C Current and Voltage Monitor
3 
4 @verbatim
5 
6 The LTC4151 is a high side power monitor that operates over a wide voltage
7 range of 7V to 80V. In default operation mode, the onboard 12-bit ADC
8 continuously measures high side current, input voltage and an external voltage.
9 Data is reported through the I2C interface when polled by a host. The LTC4151
10 can also perform on-demand measurement in a snapshot mode. The LTC4151 features
11 a dedicated shutdown pin to reduce power consumption. The LTC4151-1/LTC4151-2
12 feature split I2C data pins to drive opto-isolators. The data out on the
13 LTC4151-1 is inverted while that on the LTC4151-2 is not.
14 
15 I2C DATA FORMAT (MSB FIRST);
16 
17 Data Out:
18 
19 Byte #1 Byte #2 Byte #3
20 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
21 
22 Data In:
23 
24 Byte #1 Byte #2 Byte #3 MSB LSB
25 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
26 
27 Byte #4 Byte #5
28 D15 D14 D13 D12 D11 D10 D0 D8 MACK D7 D6 D5 D4 D3 D2 D1 D0 MNACK STOP
29 
30 START : I2C Start
31 REPEAT START : I2C Repeat Start
32 STOP : I2C Stop
33 SACK : I2C Slave Generated Acknowledge (Active Low)
34 MACK : I2C Master Generated Acknowledge (Active Low)
35 MNACK : I2C Master Generated Not Acknowledge
36 SAx : I2C Address
37 W : I2C Write (0)
38 R : I2C Read (1)
39 Cx : Command Code
40 Dx : Data Bits
41 X : Don't care
42 
43 
44 
45 Example Code:
46 
47 
48 @endverbatim
49 
50 http://www.linear.com/product/LTC4151
51 
52 http://www.linear.com/product/LTC4151#demoboards
53 
54 
55 Copyright 2018(c) Analog Devices, Inc.
56 
57 All rights reserved.
58 
59 Redistribution and use in source and binary forms, with or without
60 modification, are permitted provided that the following conditions are met:
61  - Redistributions of source code must retain the above copyright
62  notice, this list of conditions and the following disclaimer.
63  - Redistributions in binary form must reproduce the above copyright
64  notice, this list of conditions and the following disclaimer in
65  the documentation and/or other materials provided with the
66  distribution.
67  - Neither the name of Analog Devices, Inc. nor the names of its
68  contributors may be used to endorse or promote products derived
69  from this software without specific prior written permission.
70  - The use of this software may or may not infringe the patent rights
71  of one or more patent holders. This license does not release you
72  from the requirement that you obtain separate licenses from these
73  patent holders to use this software.
74  - Use of the software either in source or binary form, must be run
75  on or directly connected to an Analog Devices Inc. component.
76 
77 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
78 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
79 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
80 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
81 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
82 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
83 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
84 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
85 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
86 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
87 */
88 
89 /*! @file
90  @ingroup LTC4151
91  Library Header File for LTC4151: High Voltage I2C Current and Voltage Monitor
92 */
93 
94 #ifndef LTC4151_H
95 #define LTC4151_H
96 
97 #include <Wire.h>
98 
99 //! Address Choices:
100 //! To choose an address, comment out all options except the
101 //! configuration on the demo board.
102 
103 /*!
104 | LTC4151 I2C Address | Value | AD1 | AD2 |
105 | :------------------ | :------: | :------: | :------: |
106 | LTC4151_I2C_ADDRESS | 0x67 | High | Low |
107 | LTC4151_I2C_ADDRESS | 0x68 | Float | High |
108 | LTC4151_I2C_ADDRESS | 0x69 | High | High |
109 | LTC4151_I2C_ADDRESS | 0x6A | Float | Float |
110 | LTC4151_I2C_ADDRESS | 0x6B | Float | Low |
111 | LTC4151_I2C_ADDRESS | 0x6C | Low | High |
112 | LTC4151_I2C_ADDRESS | 0x6D | High | Float |
113 | LTC4151_I2C_ADDRESS | 0x6E | Low | Float |
114 | LTC4151_I2C_ADDRESS | 0x6F | Low | Low |
115 | LTC4151_I2C_GLOBAL_ADDRESS | 0x66 | X | X |
116 */
117 
118 /*! @name I2C_Addresses
119 @{ */
120 
121 // Address assignment
122 // LTC4151 I2C Address // AD1 AD0
123 // #define LTC4151_I2C_ADDRESS 0x67 // High Low
124 // #define LTC4151_I2C_ADDRESS 0x68 // Float High
125 // #define LTC4151_I2C_ADDRESS 0x69 // High High
126 // #define LTC4151_I2C_ADDRESS 0x6A // Float Float
127 // #define LTC4151_I2C_ADDRESS 0x6B // Float Low
128 // #define LTC4151_I2C_ADDRESS 0x6C // Low High
129 // #define LTC4151_I2C_ADDRESS 0x6D // High Float
130 // #define LTC4151_I2C_ADDRESS 0x6E // Low Float
131 #define LTC4151_I2C_ADDRESS 0x6F // Low Low
132 
133 // LTC4151 Global I2C Address.
134 // #define LTC4151_I2C_GLOBAL_ADDRESS 0x66 // Global Address
135 
136 //! @} */
137 
138 //! Note: Register 0x07 is Reserved.
139 /*!
140 | Registers | Location | Descrition |
141 | :------------------------ | :-----------: | :---------------------------------------- |
142 | LTC4151_SENSE_MSB_REG | 0x00 | ADC Current Sense Voltage Data (8 MSB) |
143 | LTC4151_SENSE_LSB_REG | 0x01 | ADC Current Sense Voltage Data (4 LSB) |
144 | LTC4151_VIN_MSB_REG | 0x02 | ADC V_IN Voltage Data (8 MSB) |
145 | LTC4151_VIN_LSB_REG | 0x03 | ADC V_IN Voltage Data (4 LSB) |
146 | LTC4151_ADIN_MSB_REG | 0x04 | ADC ADIN Voltage Data (8 MSB) |
147 | LTC4151_ADIN_LSB_REG | 0x05 | ADC ADIN Voltage Data (4 LSB) |
148 | LTC4151_CONTROL_REG | 0x06 | Controls ADC Operation Mode and Test Mode |
149 
150 */
151 
152 /*! @name REGISTERS
153 @{ */
154 // Registers
155 #define LTC4151_SENSE_MSB_REG 0x00 // ADC Current Sense Voltage Data (8 MSB)
156 #define LTC4151_SENSE_LSB_REG 0x01 // ADC Current Sense Voltage Data (4 LSB)
157 #define LTC4151_VIN_MSB_REG 0x02 // ADC V_IN Voltage Data (8 MSB)
158 #define LTC4151_VIN_LSB_REG 0x03 // ADC V_IN Voltage Data (4 LSB)
159 #define LTC4151_ADIN_MSB_REG 0x04 // ADC ADIN Voltage Data (8 MSB)
160 #define LTC4151_ADIN_LSB_REG 0x05 // ADC ADIN Voltage Data (4 LSB)
161 #define LTC4151_CONTROL_REG 0x06 // Controls ADC Operation Mode and Test Mode
162 //!@} */
163 
164 //! Bitwise AND with channel register, and write to LTC4151_CONTROL_REG.
165 /*!
166 | Commands and Channel Registers | Value | Descrition |
167 | :---------------------------- | :---: | :--------- |
168 | LTC4151_CONTINUOUS_MODE | 0x00 | Sets LTC4151 in Continuous Mode |
169 | LTC4151_SNAPSHOT_MODE | 0x80 | Sets LTC4151 in Snapshot Mode |
170 | LTC4151_SENSE_CHANNEL_REG | 0x00 | ADC Sense Channel For Snapshot Mode |
171 | LTC4151_VIN_CHANNEL_REG | 0x20 | DC V_IN Channel For Snapshot Mode |
172 | LTC4151_ADIN_CHANNEL_REG | 0x40 | ADC ADIN Channel For Snapshot Mode |
173 */
174 
175 /*! @name LTC4151 Commands
176 @{ */
177 
178 #define LTC4151_SENSE_CHANNEL_REG 0x00 // ADC Sense Channel For Snapshot Mode
179 #define LTC4151_VIN_CHANNEL_REG 0x20 // ADC V_IN Channel For Snapshot Mode
180 #define LTC4151_ADIN_CHANNEL_REG 0x40 // ADC ADIN Channel For Snapshot Mode
181 
182 #define LTC4151_CONTINUOUS_MODE 0x00
183 #define LTC4151_SNAPSHOT_MODE 0x80
184 //! @} */
185 
186 //! Write one byte to an LTC4151 register.
187 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
188 int8_t LTC4151_write(uint8_t i2c_address, //!< I2C address of the LTC4151. Configured by tying the ADR0 and ADR1 pins high or low. See Table 1 of datasheet.
189  uint8_t adc_command, //!< The "command byte" for the LTC4151.
190  uint8_t code //!< Value that will be written to the register.
191  );
192 
193 //! Reads a 12-bit value from LTC4151
194 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
195 int8_t LTC4151_read_12_bits(uint8_t i2c_address, //!< I2C address of the LTC4151. Configured by tying the ADR0 and ADR1 pins high or low. See Table 1 of datasheet.
196  uint8_t adc_command, //!< The "command byte" for the LTC4151.
197  uint16_t *adc_code //!< Returns 12-bit value read from the adc
198  );
199 
200 //! Calculates the LTC4151 sense current in Amps given "resistor" value in ohms and "LTC4151_sense_lsb" LSB weight in volts.
201 //! @return Returns the current in Amperes.
202 float LTC4151_code_to_sense_current(uint16_t adc_code, //!< Code read from the adc (from a function such as LTC4151_read_12_bits)
203  float resistor, //!< The sense resistor value
204  float LTC4151_sense_lsb //!< Current LSB weight.
205  );
206 
207 //! Calculates the LTC4151 V_IN voltage given "LTC_vin_lsb" LSB weight in volts
208 //! @return the V_IN voltage in volts.
209 float LTC4151_code_to_vin_voltage(uint16_t adc_code, //!< Code read from the adc (from a function such as LTC4151_read_12_bits)
210  float LTC4151_vin_lsb //!< Voltage LSB weight.
211  );
212 
213 //! Calculates the LTC4151 ADIN voltage in mV given "LTC4151_adin_lsb" LSB weight in mV
214 //! @return the ADIN voltage in volts.
215 float LTC4151_code_to_ADIN_voltage(uint16_t adc_code, //!< Code read from the adc (from a function such as LTC4151_read_12_bits)
216  float LTC4151_adin_lsb //!< ADIN voltage LSB weight.
217  );
218 
219 #endif // LTC4151_H
uint8_t i2c_address
int8_t LTC4151_write(uint8_t i2c_address, uint8_t adc_command, uint8_t code)
Write one byte to an LTC4151 register.
Definition: LTC4151.cpp:73
static uint8_t adc_command
Definition: DC2071AA.ino:111
const float LTC4151_adin_lsb
Typical ADIN lsb weight in mV.
Definition: DC1208A.ino:110
const float resistor
resistor value on demo board
Definition: DC1496BB.ino:116
float LTC4151_code_to_sense_current(uint16_t adc_code, float resistor, float LTC4151_sense_lsb)
Calculates the LTC4151 sense current in Amps given "resistor" value in ohms and "LTC4151_sense_lsb" L...
Definition: LTC4151.cpp:100
const float LTC4151_sense_lsb
Typical sense lsb weight in volts.
Definition: DC1208A.ino:108
float LTC4151_code_to_ADIN_voltage(uint16_t adc_code, float LTC4151_adin_lsb)
Calculates the LTC4151 ADIN voltage in mV given "LTC4151_adin_lsb" LSB weight in mV.
Definition: LTC4151.cpp:117
int8_t LTC4151_read_12_bits(uint8_t i2c_address, uint8_t adc_command, uint16_t *adc_code)
Reads a 12-bit value from LTC4151.
Definition: LTC4151.cpp:83
float LTC4151_code_to_vin_voltage(uint16_t adc_code, float LTC4151_vin_lsb)
Calculates the LTC4151 V_IN voltage given "LTC_vin_lsb" LSB weight in volts.
Definition: LTC4151.cpp:109
const float LTC4151_vin_lsb
Typical Vin lsb weight in volts.
Definition: DC1208A.ino:109
static uint32_t adc_code
Definition: DC2071AA.ino:113