Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
LTC2946.h
Go to the documentation of this file.
1 /*!
2  LTC2946: 12-Bit Wide Range Power, Charge and Energy Monitor
3 
4 @verbatim
5 
6 The LTC®2946 is a rail-to-rail system monitor that measures
7 current, voltage, power, charge and energy. It features an
8 operating range of 2.7V to 100V and includes a shunt regulator
9 for supplies above 100V. The current measurement common mode
10 range of 0V to 100V is independent of the input supply.
11 A 12-bit ADC measures load current, input voltage and an
12 auxiliary external voltage. Load current and internally
13 calculated power are integrated over an external clock or
14 crystal or internal oscillator time base for charge and energy.
15 An accurate time base allows the LTC2946 to provide measurement
16 accuracy of better than ±0.6% for charge and ±1% for power and
17 energy. Minimum and maximum values are stored and an overrange
18 alert with programmable thresholds minimizes the need for software
19 polling. Data is reported via a standard I2C interface.
20 Shutdown mode reduces power consumption to 15uA.
21 
22 
23 I2C DATA FORMAT (MSB FIRST):
24 
25 Data Out:
26 Byte #1 Byte #2 Byte #3
27 
28 START SA6 SA5 SA4 SA3 SA2 SA1 SA0 W SACK X X C5 C4 C3 C2 C1 C0 SACK D7 D6 D5 D4 D3 D2 D1 D0 SACK STOP
29 
30 Data In:
31 Byte #1 Byte #2 Byte #3
32 
33 START SA6 SA5 SA4 SA3 SA2 SA1 SA0 W SACK X X C5 C4 C3 C2 C1 C0 SACK Repeat Start SA6 SA5 SA4 SA3 SA2 SA1 SA0 R SACK
34 
35 Byte #4 Byte #5
36 MSB LSB
37 D15 D14 D13 D12 D11 D10 D9 D8 MACK D7 D6 D5 D4 D3 D2 D1 D0 MNACK STOP
38 
39 START : I2C Start
40 Repeat Start: I2c Repeat Start
41 STOP : I2C Stop
42 SAx : I2C Address
43 SACK : I2C Slave Generated Acknowledge (Active Low)
44 MACK : I2C Master Generated Acknowledge (Active Low)
45 MNACK : I2c Master Generated Not Acknowledge
46 W : I2C Write (0)
47 R : I2C Read (1)
48 Cx : Command Code
49 Dx : Data Bits
50 X : Don't care
51 
52 
53 
54 Example Code:
55 
56 Read power, current, voltage, charge and energy.
57 
58  CTRLA = LTC2946_CHANNEL_CONFIG_V_C_3|LTC2946_SENSE_PLUS|LTC2946_OFFSET_CAL_EVERY|LTC2946_ADIN_GND; //! Set Control A register to default value in continuous mode
59  ack |= LTC2946_write(LTC2946_I2C_ADDRESS, LTC2946_CTRLA_REG, CTRLA); //! Sets the LTC2946 to continuous mode
60 
61  resistor = .02; // Resistor Value On Demo Board
62 
63  ack |= LTC2946_read_24_bits(LTC2946_I2C_ADDRESS, LTC2946_POWER_MSB2_REG, &power_code); // Reads the ADC registers that contains V^2
64  power = LTC2946_code_to_power(power_code, resistor, LTC2946_Power_lsb); // Calculates power from power code, resistor value and power lsb
65 
66  ack |= LTC2946_read_12_bits(LTC2946_I2C_ADDRESS, LTC2946_DELTA_SENSE_MSB_REG, &current_code); // Reads the voltage code across sense resistor
67  current = LTC2946_code_to_current(current_code, resistor, LTC2946_DELTA_SENSE_lsb); // Calculates current from current code, resistor value and current lsb
68 
69  ack |= LTC2946_read_12_bits(LTC2946_I2C_ADDRESS, LTC2946_VIN_MSB_REG, &VIN_code); // Reads VIN voltage code
70  VIN = LTC2946_VIN_code_to_voltage(VIN_code, LTC2946_VIN_lsb); // Calculates VIN voltage from VIN code and lsb
71 
72  ack |= LTC2946_read_32_bits(LTC2946_I2C_ADDRESS, LTC2946_ENERGY_MSB3_REG, &energy_code); // Reads energy code
73  energy = LTC2946_code_to_energy(energy_code,resistor,LTC2946_Power_lsb, LTC2946_INTERNAL_TIME_lsb); //Calculates Energy in Joules from energy_code, resistor, power lsb and time lsb
74 
75  ack |= LTC2946_read_32_bits(LTC2946_I2C_ADDRESS, LTC2946_CHARGE_MSB3_REG, &charge_code); // Reads charge code
76  charge = LTC2946_code_to_coulombs(charge_code,resistor,LTC2946_DELTA_SENSE_lsb, LTC2946_INTERNAL_TIME_lsb); //Calculates charge in coulombs from charge_code, resistor, current lsb and time lsb
77 
78 
79 
80 @endverbatim
81 
82 http://www.linear.com/product/LTC2946
83 
84 http://www.linear.com/product/ltc2946#demoboards
85 
86 
87 Copyright 2018(c) Analog Devices, Inc.
88 
89 All rights reserved.
90 
91 Redistribution and use in source and binary forms, with or without
92 modification, are permitted provided that the following conditions are met:
93  - Redistributions of source code must retain the above copyright
94  notice, this list of conditions and the following disclaimer.
95  - Redistributions in binary form must reproduce the above copyright
96  notice, this list of conditions and the following disclaimer in
97  the documentation and/or other materials provided with the
98  distribution.
99  - Neither the name of Analog Devices, Inc. nor the names of its
100  contributors may be used to endorse or promote products derived
101  from this software without specific prior written permission.
102  - The use of this software may or may not infringe the patent rights
103  of one or more patent holders. This license does not release you
104  from the requirement that you obtain separate licenses from these
105  patent holders to use this software.
106  - Use of the software either in source or binary form, must be run
107  on or directly connected to an Analog Devices Inc. component.
108 
109 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
110 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
111 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
112 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
113 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
114 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
115 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
116 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
117 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
118 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
119 */
120 
121 /*! @file
122  @ingroup LTC2946
123  Header for LTC2946: 12-Bit Wide Range Power, Charge and Energy Monitor
124 */
125 
126 #ifndef LTC2946_H
127 #define LTC2946_H
128 
129 #include <Wire.h>
130 
131 //! Use table to select address
132 /*!
133 | LTC2946 I2C Address Assignment | Value | AD1 | AD2 |
134 | :-------------------------------- | :---: | :------: | :------: |
135 | LTC2946_I2C_ADDRESS | 0x67 | High | Low |
136 | LTC2946_I2C_ADDRESS | 0x68 | Float | High |
137 | LTC2946_I2C_ADDRESS | 0x69 | High | High |
138 | LTC2946_I2C_ADDRESS | 0x6A | Float | Float |
139 | LTC2946_I2C_ADDRESS | 0x6B | Float | Low |
140 | LTC2946_I2C_ADDRESS | 0x6C | Low | High |
141 | LTC2946_I2C_ADDRESS | 0x6D | High | Float |
142 | LTC2946_I2C_ADDRESS | 0x6E | Low | Float |
143 | LTC2946_I2C_ADDRESS | 0x6F | Low | Low |
144 | | | | |
145 | LTC2946_I2C_MASS_WRITE | 0xCC | X | X |
146 | LTC2946_I2C_ALERT_RESPONSE | 0x19 | X | X |
147 */
148 /*! @name LTC2946 I2C Address Assignments
149 @{ */
150 
151 // Address Choices:
152 // To choose an address, comment out all options except the
153 // configuration on the demo board.
154 
155 // Address assignment
156 // LTC2946 I2C Address // AD1 AD0
157 // #define LTC2946_I2C_ADDRESS 0x67 // High Low
158 // #define LTC2946_I2C_ADDRESS 0x68 // Float High
159 // #define LTC2946_I2C_ADDRESS 0x69 // High High
160 // #define LTC2946_I2C_ADDRESS 0x6A // Float Float
161 // #define LTC2946_I2C_ADDRESS 0x6B // Float Low
162 // #define LTC2946_I2C_ADDRESS 0x6C // Low High
163 // #define LTC2946_I2C_ADDRESS 0x6D // High Float
164 // #define LTC2946_I2C_ADDRESS 0x6E // Low Float
165 #define LTC2946_I2C_ADDRESS 0x6F // Low Low
166 
167 #define LTC2946_I2C_MASS_WRITE 0xCC
168 #define LTC2946_I2C_ALERT_RESPONSE 0x19
169 //! @}
170 
171 
172 /*!
173 | Name | Value |
174 | :------------------------------------------------ | :---: |
175 | LTC2946_CTRLA_REG | 0x00 |
176 | LTC2946_CTRLB_REG | 0x01 |
177 | LTC2946_ALERT1_REG | 0x02 |
178 | LTC2946_STATUS1_REG | 0x03 |
179 | LTC2946_FAULT1_REG | 0x04 |
180 | LTC2946_POWER_MSB2_REG | 0x05 |
181 | LTC2946_POWER_MSB1_REG | 0x06 |
182 | LTC2946_POWER_LSB_REG | 0x07 |
183 | LTC2946_MAX_POWER_MSB2_REG | 0x08 |
184 | LTC2946_MAX_POWER_MSB1_REG | 0x09 |
185 | LTC2946_MAX_POWER_LSB_REG | 0x0A |
186 | LTC2946_MIN_POWER_MSB2_REG | 0x0B |
187 | LTC2946_MIN_POWER_MSB1_REG | 0x0C |
188 | LTC2946_MIN_POWER_LSB_REG | 0x0D |
189 | LTC2946_MAX_POWER_THRESHOLD_MSB2_REG | 0x0E |
190 | LTC2946_MAX_POWER_THRESHOLD_MSB1_REG | 0x0F |
191 | LTC2946_MAX_POWER_THRESHOLD_LSB_REG | 0x10 |
192 | LTC2946_MIN_POWER_THRESHOLD_MSB2_REG | 0x11 |
193 | LTC2946_MIN_POWER_THRESHOLD_MSB1_REG | 0x12 |
194 | LTC2946_MIN_POWER_THRESHOLD_LSB_REG | 0x13 |
195 | LTC2946_DELTA_SENSE_MSB_REG | 0x14 |
196 | LTC2946_DELTA_SENSE_LSB_REG | 0x15 |
197 | LTC2946_MAX_DELTA_SENSE_MSB_REG | 0x16 |
198 | LTC2946_MAX_DELTA_SENSE_LSB_REG | 0x17 |
199 | LTC2946_MIN_DELTA_SENSE_MSB_REG | 0x18 |
200 | LTC2946_MIN_DELTA_SENSE_LSB_REG | 0x19 |
201 | LTC2946_MAX_DELTA_SENSE_THRESHOLD_MSB_REG | 0x1A |
202 | LTC2946_MAX_DELTA_SENSE_THRESHOLD_LSB_REG | 0x1B |
203 | LTC2946_MIN_DELTA_SENSE_THRESHOLD_MSB_REG | 0x1C |
204 | LTC2946_MIN_DELTA_SENSE_THRESHOLD_LSB_REG | 0x1D |
205 | LTC2946_VIN_MSB_REG | 0x1E |
206 | LTC2946_VIN_LSB_REG | 0x1F |
207 | LTC2946_MAX_VIN_MSB_REG | 0x20 |
208 | LTC2946_MAX_VIN_LSB_REG | 0x21 |
209 | LTC2946_MIN_VIN_MSB_REG | 0x22 |
210 | LTC2946_MIN_VIN_LSB_REG | 0x23 |
211 | LTC2946_MAX_VIN_THRESHOLD_MSB_REG | 0x24 |
212 | LTC2946_MAX_VIN_THRESHOLD_LSB_REG | 0x25 |
213 | LTC2946_MIN_VIN_THRESHOLD_MSB_REG | 0x26 |
214 | LTC2946_MIN_VIN_THRESHOLD_LSB_REG | 0x27 |
215 | LTC2946_ADIN_MSB_REG | 0x28 |
216 | LTC2946_ADIN_LSB_REG_REG | 0x29 |
217 | LTC2946_MAX_ADIN_MSB_REG | 0x2A |
218 | LTC2946_MAX_ADIN_LSB_REG | 0x2B |
219 | LTC2946_MIN_ADIN_MSB_REG | 0x2C |
220 | LTC2946_MIN_ADIN_LSB_REG | 0x2D |
221 | LTC2946_MAX_ADIN_THRESHOLD_MSB_REG | 0x2E |
222 | LTC2946_MAX_ADIN_THRESHOLD_LSB_REG | 0x2F |
223 | LTC2946_MIN_ADIN_THRESHOLD_MSB_REG | 0x30 |
224 | LTC2946_MIN_ADIN_THRESHOLD_LSB_REG | 0x31 |
225 | LTC2946_ALERT2_REG | 0x32 |
226 | LTC2946_GPIO_CFG_REG | 0x33 |
227 | LTC2946_TIME_COUNTER_MSB3_REG | 0x34 |
228 | LTC2946_TIME_COUNTER_MSB2_REG | 0x35 |
229 | LTC2946_TIME_COUNTER_MSB1_REG | 0x36 |
230 | LTC2946_TIME_COUNTER_LSB_REG | 0x37 |
231 | LTC2946_CHARGE_MSB3_REG | 0x38 |
232 | LTC2946_CHARGE_MSB2_REG | 0x39 |
233 | LTC2946_CHARGE_MSB1_REG | 0x3A |
234 | LTC2946_CHARGE_LSB_REG | 0x3B |
235 | LTC2946_ENERGY_MSB3_REG | 0x3C |
236 | LTC2946_ENERGY_MSB2_REG | 0x3D |
237 | LTC2946_ENERGY_MSB1_REG | 0x3E |
238 | LTC2946_ENERGY_LSB_REG | 0x3F |
239 | LTC2946_STATUS2_REG | 0x40 |
240 | LTC2946_FAULT2_REG | 0x41 |
241 | LTC2946_GPIO3_CTRL_REG | 0x42 |
242 | LTC2946_CLK_DIV_REG | 0x43 |
243 */
244 
245 
246 
247 /*! @name Registers
248 @{ */
249 // Registers
250 
251 #define LTC2946_CTRLA_REG 0x00
252 #define LTC2946_CTRLB_REG 0x01
253 #define LTC2946_ALERT1_REG 0x02
254 #define LTC2946_STATUS1_REG 0x03
255 #define LTC2946_FAULT1_REG 0x04
256 
257 #define LTC2946_POWER_MSB2_REG 0x05
258 #define LTC2946_POWER_MSB1_REG 0x06
259 #define LTC2946_POWER_LSB_REG 0x07
260 #define LTC2946_MAX_POWER_MSB2_REG 0x08
261 #define LTC2946_MAX_POWER_MSB1_REG 0x09
262 #define LTC2946_MAX_POWER_LSB_REG 0x0A
263 #define LTC2946_MIN_POWER_MSB2_REG 0x0B
264 #define LTC2946_MIN_POWER_MSB1_REG 0x0C
265 #define LTC2946_MIN_POWER_LSB_REG 0x0D
266 #define LTC2946_MAX_POWER_THRESHOLD_MSB2_REG 0x0E
267 #define LTC2946_MAX_POWER_THRESHOLD_MSB1_REG 0x0F
268 #define LTC2946_MAX_POWER_THRESHOLD_LSB_REG 0x10
269 #define LTC2946_MIN_POWER_THRESHOLD_MSB2_REG 0x11
270 #define LTC2946_MIN_POWER_THRESHOLD_MSB1_REG 0x12
271 #define LTC2946_MIN_POWER_THRESHOLD_LSB_REG 0x13
272 
273 #define LTC2946_DELTA_SENSE_MSB_REG 0x14
274 #define LTC2946_DELTA_SENSE_LSB_REG 0x15
275 #define LTC2946_MAX_DELTA_SENSE_MSB_REG 0x16
276 #define LTC2946_MAX_DELTA_SENSE_LSB_REG 0x17
277 #define LTC2946_MIN_DELTA_SENSE_MSB_REG 0x18
278 #define LTC2946_MIN_DELTA_SENSE_LSB_REG 0x19
279 #define LTC2946_MAX_DELTA_SENSE_THRESHOLD_MSB_REG 0x1A
280 #define LTC2946_MAX_DELTA_SENSE_THRESHOLD_LSB_REG 0x1B
281 #define LTC2946_MIN_DELTA_SENSE_THRESHOLD_MSB_REG 0x1C
282 #define LTC2946_MIN_DELTA_SENSE_THRESHOLD_LSB_REG 0x1D
283 
284 #define LTC2946_VIN_MSB_REG 0x1E
285 #define LTC2946_VIN_LSB_REG 0x1F
286 #define LTC2946_MAX_VIN_MSB_REG 0x20
287 #define LTC2946_MAX_VIN_LSB_REG 0x21
288 #define LTC2946_MIN_VIN_MSB_REG 0x22
289 #define LTC2946_MIN_VIN_LSB_REG 0x23
290 #define LTC2946_MAX_VIN_THRESHOLD_MSB_REG 0x24
291 #define LTC2946_MAX_VIN_THRESHOLD_LSB_REG 0x25
292 #define LTC2946_MIN_VIN_THRESHOLD_MSB_REG 0x26
293 #define LTC2946_MIN_VIN_THRESHOLD_LSB_REG 0x27
294 
295 #define LTC2946_ADIN_MSB_REG 0x28
296 #define LTC2946_ADIN_LSB_REG_REG 0x29
297 #define LTC2946_MAX_ADIN_MSB_REG 0x2A
298 #define LTC2946_MAX_ADIN_LSB_REG 0x2B
299 #define LTC2946_MIN_ADIN_MSB_REG 0x2C
300 #define LTC2946_MIN_ADIN_LSB_REG 0x2D
301 #define LTC2946_MAX_ADIN_THRESHOLD_MSB_REG 0x2E
302 #define LTC2946_MAX_ADIN_THRESHOLD_LSB_REG 0x2F
303 #define LTC2946_MIN_ADIN_THRESHOLD_MSB_REG 0x30
304 #define LTC2946_MIN_ADIN_THRESHOLD_LSB_REG 0x31
305 
306 #define LTC2946_ALERT2_REG 0x32
307 #define LTC2946_GPIO_CFG_REG 0x33
308 
309 #define LTC2946_TIME_COUNTER_MSB3_REG 0x34
310 #define LTC2946_TIME_COUNTER_MSB2_REG 0x35
311 #define LTC2946_TIME_COUNTER_MSB1_REG 0x36
312 #define LTC2946_TIME_COUNTER_LSB_REG 0x37
313 
314 #define LTC2946_CHARGE_MSB3_REG 0x38
315 #define LTC2946_CHARGE_MSB2_REG 0x39
316 #define LTC2946_CHARGE_MSB1_REG 0x3A
317 #define LTC2946_CHARGE_LSB_REG 0x3B
318 
319 #define LTC2946_ENERGY_MSB3_REG 0x3C
320 #define LTC2946_ENERGY_MSB2_REG 0x3D
321 #define LTC2946_ENERGY_MSB1_REG 0x3E
322 #define LTC2946_ENERGY_LSB_REG 0x3F
323 
324 #define LTC2946_STATUS2_REG 0x40
325 #define LTC2946_FAULT2_REG 0x41
326 #define LTC2946_GPIO3_CTRL_REG 0x42
327 #define LTC2946_CLK_DIV_REG 0x43
328 
329 //! @}
330 
331 /*!
332 | Voltage Selection Command | Value |
333 | :------------------------------------| :---: |
334 | LTC2946_DELTA_SENSE | 0x00 |
335 | LTC2946_VDD | 0x08 |
336 | LTC2946_ADIN | 0x10 |
337 | LTC2946_SENSE_PLUS | 0x18 |
338 */
339 
340 /*! @name Voltage Selection Command
341 @{ */
342 // Voltage Selection Command
343 #define LTC2946_DELTA_SENSE 0x00
344 #define LTC2946_VDD 0x08
345 #define LTC2946_ADIN 0x10
346 #define LTC2946_SENSE_PLUS 0x18
347 //! @}
348 
349 /*!
350 | Command Codes | Value |
351 | :-------------------------------------------- | :-------: |
352 | LTC2946_ADIN_INTVCC | 0x80 |
353 | LTC2946_ADIN_GND | 0x00 |
354 | LTC2946_OFFSET_CAL_LAST | 0x60 |
355 | LTC2946_OFFSET_CAL_128 | 0x40 |
356 | LTC2946_OFFSET_CAL_16 | 0x20 |
357 | LTC2946_OFFSET_CAL_EVERY | 0x00 |
358 | LTC2946_CHANNEL_CONFIG_SNAPSHOT | 0x07 |
359 | LTC2946_CHANNEL_CONFIG_V_C | 0x06 |
360 | LTC2946_CHANNEL_CONFIG_A_V_C_1 | 0x05 |
361 | LTC2946_CHANNEL_CONFIG_A_V_C_2 | 0x04 |
362 | LTC2946_CHANNEL_CONFIG_A_V_C_3 | 0x03 |
363 | LTC2946_CHANNEL_CONFIG_V_C_1 | 0x02 |
364 | LTC2946_CHANNEL_CONFIG_V_C_2 | 0x01 |
365 | LTC2946_CHANNEL_CONFIG_V_C_3 | 0x00 |
366 | LTC2946_ENABLE_ALERT_CLEAR | 0x80 |
367 | LTC2946_ENABLE_SHUTDOWN | 0x40 |
368 | LTC2946_ENABLE_CLEARED_ON_READ | 0x20 |
369 | LTC2946_ENABLE_STUCK_BUS_RECOVER | 0x10 |
370 | LTC2946_DISABLE_ALERT_CLEAR | 0x7F |
371 | LTC2946_DISABLE_SHUTDOWN | 0xBF |
372 | LTC2946_DISABLE_CLEARED_ON_READ | 0xDF |
373 | LTC2946_DISABLE_STUCK_BUS_RECOVER | 0xEF |
374 | LTC2946_ACC_PIN_CONTROL | 0x08 |
375 | LTC2946_DISABLE_ACC | 0x04 |
376 | LTC2946_ENABLE_ACC | 0x00 |
377 | LTC2946_RESET_ALL | 0x03 |
378 | LTC2946_RESET_ACC | 0x02 |
379 | LTC2946_ENABLE_AUTO_RESET | 0x01 |
380 | LTC2946_DISABLE_AUTO_RESET | 0x00 |
381 | LTC2946_MAX_POWER_MSB2_RESET | 0x00 |
382 | LTC2946_MIN_POWER_MSB2_RESET | 0xFF |
383 | LTC2946_MAX_DELTA_SENSE_MSB_RESET | 0x00 |
384 | LTC2946_MIN_DELTA_SENSE_MSB_RESET | 0xFF |
385 | LTC2946_MAX_VIN_MSB_RESET | 0x00 |
386 | LTC2946_MIN_VIN_MSB_RESET | 0xFF |
387 | LTC2946_MAX_ADIN_MSB_RESET | 0x00 |
388 | LTC2946_MIN_ADIN_MSB_RESET | 0xFF |
389 | LTC2946_ENABLE_MAX_POWER_ALERT | 0x80 |
390 | LTC2946_ENABLE_MIN_POWER_ALERT | 0x40 |
391 | LTC2946_DISABLE_MAX_POWER_ALERT | 0x7F |
392 | LTC2946_DISABLE_MIN_POWER_ALERT | 0xBF |
393 | LTC2946_ENABLE_MAX_I_SENSE_ALERT | 0x20 |
394 | LTC2946_ENABLE_MIN_I_SENSE_ALERT | 0x10 |
395 | LTC2946_DISABLE_MAX_I_SENSE_ALERT | 0xDF |
396 | LTC2946_DISABLE_MIN_I_SENSE_ALERT | 0xEF |
397 | LTC2946_ENABLE_MAX_VIN_ALERT | 0x08 |
398 | LTC2946_ENABLE_MIN_VIN_ALERT | 0x04 |
399 | LTC2946_DISABLE_MAX_VIN_ALERT | 0xF7 |
400 | LTC2946_DISABLE_MIN_VIN_ALERT | 0xFB |
401 | LTC2946_ENABLE_MAX_ADIN_ALERT | 0x02 |
402 | LTC2946_ENABLE_MIN_ADIN_ALERT | 0x01 |
403 | LTC2946_DISABLE_MAX_ADIN_ALERT | 0xFD |
404 | LTC2946_DISABLE_MIN_ADIN_ALERT | 0xFE |
405 | LTC2946_ENABLE_ADC_DONE_ALERT | 0x80 |
406 | LTC2946_DISABLE_ADC_DONE_ALERT | 0x7F |
407 | LTC2946_ENABLE_GPIO_1_ALERT | 0x40 |
408 | LTC2946_DISABLE_GPIO_1_ALERT | 0xBF |
409 | LTC2946_ENABLE_GPIO_2_ALERT | 0x20 |
410 | LTC2946_DISABLE_GPIO_2_ALERT | 0xDF |
411 | LTC2946_ENABLE_STUCK_BUS_WAKE_ALERT | 0x08 |
412 | LTC2946_DISABLE_STUCK_BUS_WAKE_ALERT | 0xF7 |
413 | LTC2946_ENABLE_ENERGY_OVERFLOW_ALERT | 0x04 |
414 | LTC2946_DISABLE_ENERGY_OVERFLOW_ALERT | 0xFB |
415 | LTC2946_ENABLE_CHARGE_OVERFLOW_ALERT | 0x02 |
416 | LTC2946_DISABLE_CHARGE_OVERFLOW_ALERT | 0xFD |
417 | LTC2946_ENABLE_COUNTER_OVERFLOW_ALERT | 0x01 |
418 | LTC2946_DISABLE_COUNTER_OVERFLOW_ALERT | 0xFE |
419 | LTC2946_GPIO1_IN_ACTIVE_HIGH | 0xC0 |
420 | LTC2946_GPIO1_IN_ACTIVE_LOW | 0x80 |
421 | LTC2946_GPIO1_OUT_HIGH_Z | 0x40 |
422 | LTC2946_GPIO1_OUT_LOW | 0x00 |
423 | LTC2946_GPIO2_IN_ACTIVE_HIGH | 0x30 |
424 | LTC2946_GPIO2_IN_ACTIVE_LOW | 0x20 |
425 | LTC2946_GPIO2_OUT_HIGH_Z | 0x10 |
426 | LTC2946_GPIO2_OUT_LOW | 0x12 |
427 | LTC2946_GPIO2_IN_ACC | 0x00 |
428 | LTC2946_GPIO3_IN_ACTIVE_HIGH | 0x18 |
429 | LTC2946_GPIO3_IN_ACTIVE_LOW | 0x10 |
430 | LTC2946_GPIO3_OUT_REG_42 | 0x04 |
431 | LTC2946_GPIO3_OUT_ALERT | 0x00 |
432 | LTC2946_GPIO3_OUT_LOW | 0x40 |
433 | LTC2946_GPIO3_OUT_HIGH_Z | 0x00 |
434 | LTC2946_GPIO_ALERT_CLEAR | 0x00 |
435 */
436 /*! @name Command Codes
437 @{ */
438 // Command Codes
439 
440 #define LTC2946_ADIN_INTVCC 0x80
441 #define LTC2946_ADIN_GND 0x00
442 
443 #define LTC2946_OFFSET_CAL_LAST 0x60
444 #define LTC2946_OFFSET_CAL_128 0x40
445 #define LTC2946_OFFSET_CAL_16 0x20
446 #define LTC2946_OFFSET_CAL_EVERY 0x00
447 
448 #define LTC2946_CHANNEL_CONFIG_SNAPSHOT 0x07
449 #define LTC2946_CHANNEL_CONFIG_V_C 0x06
450 #define LTC2946_CHANNEL_CONFIG_A_V_C_1 0x05
451 #define LTC2946_CHANNEL_CONFIG_A_V_C_2 0x04
452 #define LTC2946_CHANNEL_CONFIG_A_V_C_3 0x03
453 #define LTC2946_CHANNEL_CONFIG_V_C_1 0x02
454 #define LTC2946_CHANNEL_CONFIG_V_C_2 0x01
455 #define LTC2946_CHANNEL_CONFIG_V_C_3 0x00
456 
457 
458 #define LTC2946_ENABLE_ALERT_CLEAR 0x80
459 #define LTC2946_ENABLE_SHUTDOWN 0x40
460 #define LTC2946_ENABLE_CLEARED_ON_READ 0x20
461 #define LTC2946_ENABLE_STUCK_BUS_RECOVER 0x10
462 
463 #define LTC2946_DISABLE_ALERT_CLEAR 0x7F
464 #define LTC2946_DISABLE_SHUTDOWN 0xBF
465 #define LTC2946_DISABLE_CLEARED_ON_READ 0xDF
466 #define LTC2946_DISABLE_STUCK_BUS_RECOVER 0xEF
467 
468 #define LTC2946_ACC_PIN_CONTROL 0x08
469 #define LTC2946_DISABLE_ACC 0x04
470 #define LTC2946_ENABLE_ACC 0x00
471 
472 #define LTC2946_RESET_ALL 0x03
473 #define LTC2946_RESET_ACC 0x02
474 #define LTC2946_ENABLE_AUTO_RESET 0x01
475 #define LTC2946_DISABLE_AUTO_RESET 0x00
476 
477 
478 #define LTC2946_MAX_POWER_MSB2_RESET 0x00
479 #define LTC2946_MIN_POWER_MSB2_RESET 0xFF
480 #define LTC2946_MAX_DELTA_SENSE_MSB_RESET 0x00
481 #define LTC2946_MIN_DELTA_SENSE_MSB_RESET 0xFF
482 #define LTC2946_MAX_VIN_MSB_RESET 0x00
483 #define LTC2946_MIN_VIN_MSB_RESET 0xFF
484 #define LTC2946_MAX_ADIN_MSB_RESET 0x00
485 #define LTC2946_MIN_ADIN_MSB_RESET 0xFF
486 
487 #define LTC2946_ENABLE_MAX_POWER_ALERT 0x80
488 #define LTC2946_ENABLE_MIN_POWER_ALERT 0x40
489 #define LTC2946_DISABLE_MAX_POWER_ALERT 0x7F
490 #define LTC2946_DISABLE_MIN_POWER_ALERT 0xBF
491 
492 #define LTC2946_ENABLE_MAX_I_SENSE_ALERT 0x20
493 #define LTC2946_ENABLE_MIN_I_SENSE_ALERT 0x10
494 #define LTC2946_DISABLE_MAX_I_SENSE_ALERT 0xDF
495 #define LTC2946_DISABLE_MIN_I_SENSE_ALERT 0xEF
496 
497 #define LTC2946_ENABLE_MAX_VIN_ALERT 0x08
498 #define LTC2946_ENABLE_MIN_VIN_ALERT 0x04
499 #define LTC2946_DISABLE_MAX_VIN_ALERT 0xF7
500 #define LTC2946_DISABLE_MIN_VIN_ALERT 0xFB
501 
502 #define LTC2946_ENABLE_MAX_ADIN_ALERT 0x02
503 #define LTC2946_ENABLE_MIN_ADIN_ALERT 0x01
504 #define LTC2946_DISABLE_MAX_ADIN_ALERT 0xFD
505 #define LTC2946_DISABLE_MIN_ADIN_ALERT 0xFE
506 
507 #define LTC2946_ENABLE_ADC_DONE_ALERT 0x80
508 #define LTC2946_DISABLE_ADC_DONE_ALERT 0x7F
509 
510 #define LTC2946_ENABLE_GPIO_1_ALERT 0x40
511 #define LTC2946_DISABLE_GPIO_1_ALERT 0xBF
512 
513 #define LTC2946_ENABLE_GPIO_2_ALERT 0x20
514 #define LTC2946_DISABLE_GPIO_2_ALERT 0xDF
515 
516 #define LTC2946_ENABLE_STUCK_BUS_WAKE_ALERT 0x08
517 #define LTC2946_DISABLE_STUCK_BUS_WAKE_ALERT 0xF7
518 
519 #define LTC2946_ENABLE_ENERGY_OVERFLOW_ALERT 0x04
520 #define LTC2946_DISABLE_ENERGY_OVERFLOW_ALERT 0xFB
521 
522 #define LTC2946_ENABLE_CHARGE_OVERFLOW_ALERT 0x02
523 #define LTC2946_DISABLE_CHARGE_OVERFLOW_ALERT 0xFD
524 
525 #define LTC2946_ENABLE_COUNTER_OVERFLOW_ALERT 0x01
526 #define LTC2946_DISABLE_COUNTER_OVERFLOW_ALERT 0xFE
527 
528 #define LTC2946_GPIO1_IN_ACTIVE_HIGH 0xC0
529 #define LTC2946_GPIO1_IN_ACTIVE_LOW 0x80
530 #define LTC2946_GPIO1_OUT_HIGH_Z 0x40
531 #define LTC2946_GPIO1_OUT_LOW 0x00
532 
533 #define LTC2946_GPIO2_IN_ACTIVE_HIGH 0x30
534 #define LTC2946_GPIO2_IN_ACTIVE_LOW 0x20
535 #define LTC2946_GPIO2_OUT_HIGH_Z 0x10
536 #define LTC2946_GPIO2_OUT_LOW 0x12
537 #define LTC2946_GPIO2_IN_ACC 0x00
538 
539 
540 #define LTC2946_GPIO3_IN_ACTIVE_HIGH 0x0C
541 #define LTC2946_GPIO3_IN_ACTIVE_LOW 0x08
542 #define LTC2946_GPIO3_OUT_REG_42 0x04
543 #define LTC2946_GPIO3_OUT_ALERT 0x00
544 #define LTC2946_GPIO3_OUT_LOW 0x40
545 #define LTC2946_GPIO3_OUT_HIGH_Z 0x00
546 #define LTC2946_GPIO_ALERT_CLEAR 0x00
547 //! @}
548 
549 
550 /*!
551 | Register Mask Command | Value |
552 | :------------------------------------| :---: |
553 | LTC2946_CTRLA_ADIN_MASK | 0x7F |
554 | LTC2946_CTRLA_OFFSET_MASK | 0x9F |
555 | LTC2946_CTRLA_VOLTAGE_SEL_MASK | 0xE7 |
556 | LTC2946_CTRLA_CHANNEL_CONFIG_MASK | 0xF8 |
557 | LTC2946_CTRLB_ACC_MASK | 0xF3 |
558 | LTC2946_CTRLB_RESET_MASK | 0xFC |
559 | LTC2946_GPIOCFG_GPIO1_MASK | 0x3F |
560 | LTC2946_GPIOCFG_GPIO2_MASK | 0xCF |
561 | LTC2946_GPIOCFG_GPIO3_MASK | 0xF3 |
562 | LTC2946_GPIOCFG_GPIO2_OUT_MASK | 0xFD |
563 | LTC2946_GPIO3_CTRL_GPIO3_MASK | 0xBF |
564 
565 */
566 
567 /*! @name Register Mask Command
568 @{ */
569 // Register Mask Command
570 #define LTC2946_CTRLA_ADIN_MASK 0x7F
571 #define LTC2946_CTRLA_OFFSET_MASK 0x9F
572 #define LTC2946_CTRLA_VOLTAGE_SEL_MASK 0xE7
573 #define LTC2946_CTRLA_CHANNEL_CONFIG_MASK 0xF8
574 #define LTC2946_CTRLB_ACC_MASK 0xF3
575 #define LTC2946_CTRLB_RESET_MASK 0xFC
576 #define LTC2946_GPIOCFG_GPIO1_MASK 0x3F
577 #define LTC2946_GPIOCFG_GPIO2_MASK 0xCF
578 #define LTC2946_GPIOCFG_GPIO3_MASK 0xF3
579 #define LTC2946_GPIOCFG_GPIO2_OUT_MASK 0xFD
580 #define LTC2946_GPIO3_CTRL_GPIO3_MASK 0xBF
581 //! @}
582 
583 
584 //! Write an 8-bit code to the LTC2946.
585 //! @return The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
586 int8_t LTC2946_write(uint8_t i2c_address, //!< Register address for the LTC2946
587  uint8_t adc_command, //!< The "command byte" for the LTC2946
588  uint8_t code //!< Value that will be written to the register.
589  );
590 //! Write a 16-bit code to the LTC2946.
591 //! @return The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
592 int8_t LTC2946_write_16_bits(uint8_t i2c_address, //!< Register address for the LTC2946
593  uint8_t adc_command, //!< The "command byte" for the LTC2946
594  uint16_t code //!< Value that will be written to the register.
595  );
596 
597 //! Write a 24-bit code to the LTC2946.
598 //! @return The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
599 int8_t LTC2946_write_24_bits(uint8_t i2c_address, //!< Register address for the LTC2946
600  uint8_t adc_command, //!< The "command byte" for the LTC2946
601  uint32_t code //!< Value that will be written to the register.
602  );
603 //! Write a 32-bit code to the LTC2946.
604 //! @return The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
605 int8_t LTC2946_write_32_bits(uint8_t i2c_address, //!< Register address for the LTC2946
606  uint8_t adc_command, //!< The "command byte" for the LTC2946
607  uint32_t code //!< Value that will be written to the register.
608  );
609 
610 //! Reads an 8-bit adc_code from LTC2946
611 //! @return The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
612 int8_t LTC2946_read(uint8_t i2c_address, //!< Register address for the LTC2946
613  uint8_t adc_command, //!< The "command byte" for the LTC2946
614  uint8_t *adc_code //!< Value that will be read from the register.
615  );
616 //! Reads a 12-bit adc_code from LTC2946
617 //! @return The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
618 int8_t LTC2946_read_12_bits(uint8_t i2c_address, //!< Register address for the LTC2946
619  uint8_t adc_command, //!< The "command byte" for the LTC2946
620  uint16_t *adc_code //!< Value that will be read from the register.
621  );
622 //! Reads a 16-bit adc_code from LTC2946
623 //! @return The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
624 int8_t LTC2946_read_16_bits(uint8_t i2c_address, //!< Register address for the LTC2946
625  uint8_t adc_command, //!< The "command byte" for the LTC2946
626  uint16_t *adc_code //!< Value that will be read from the register.
627  );
628 //! Reads a 24-bit adc_code from LTC2946
629 //! @return The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
630 int8_t LTC2946_read_24_bits(uint8_t i2c_address, //!< Register address for the LTC2946
631  uint8_t adc_command, //!< The "command byte" for the LTC2946
632  uint32_t *adc_code //!< Value that will be read from the register.
633  );
634 //! Reads a 32-bit adc_code from LTC2946
635 //! @return The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
636 int8_t LTC2946_read_32_bits(uint8_t i2c_address, //!< Register address for the LTC2946
637  uint8_t adc_command, //!< The "command byte" for the LTC2946
638  uint32_t *adc_code //!< Value that will be read from the register.
639  );
640 
641 //! Calculate the LTC2946 VIN voltage
642 //! @return Returns the VIN Voltage in Volts
643 float LTC2946_VIN_code_to_voltage(uint16_t adc_code, //!< The ADC value
644  float LTC2946_VIN_lsb //!< VIN lsb weight
645  );
646 //! Calculate the LTC2946 ADIN voltage
647 //! @return Returns the ADIN Voltage in Volts
648 float LTC2946_ADIN_code_to_voltage(uint16_t adc_code, //!< The ADC value
649  float LTC2946_ADIN_lsb //!< ADIN lsb weight
650  );
651 //! Calculate the LTC2946 current with a sense resistor
652 //! @return The LTC2946 current in Amps
653 float LTC2946_code_to_current(uint16_t adc_code, //!< The ADC value
654  float resistor, //!< The resistor value
655  float LTC2946_DELTA_SENSE_lsb //!< Delta sense lsb weight
656  );
657 //! Calculate the LTC2946 power
658 //! @return The LTC2946 power in Watts
659 float LTC2946_code_to_power(int32_t adc_code, //!< The ADC value
660  float resistor, //!< The resistor value
661  float LTC2946_Power_lsb); //!< Power lsb weight
662 
663 //! Calculate the LTC2946 energy
664 //! @return The LTC2946 energy in Joules
665 float LTC2946_code_to_energy(int32_t adc_code, //!< The ADC value
666  float resistor, //!< The resistor value
667  float LTC2946_Power_lsb, //!< Power lsb weight
668  float LTC2946_TIME_lsb //!< Time lsb weight
669  );
670 
671 //! Calculate the LTC2946 coulombs
672 //! @return The LTC2946 charge in coulombs
673 float LTC2946_code_to_coulombs(int32_t adc_code, //!< The ADC value
674  float resistor, //!< The resistor value
675  float LTC2946_DELTA_SENSE_lsb, //!< Delta sense lsb weight
676  float LTC2946_Time_lsb //!< Time lsb weight
677  );
678 //! Calculate the LTC2946 internal time base
679 //! @return The internal time base in seconds.
680 float LTC2946_code_to_time(float time_code, //!< Time adc code
681  float LTC2946_Time_lsb //!< Time lsb weight
682  );
683 
684 
685 #endif // LTC2946_H
uint8_t i2c_address
static uint8_t adc_command
Definition: DC2071AA.ino:111
int8_t LTC2946_read(uint8_t i2c_address, uint8_t adc_command, uint8_t *adc_code)
Reads an 8-bit adc_code from LTC2946.
Definition: LTC2946.cpp:130
const float LTC2946_ADIN_lsb
Typical ADIN lsb weight in volts.
Definition: DC2156.ino:127
const float resistor
resistor value on demo board
Definition: DC1496BB.ino:116
int8_t LTC2946_write_24_bits(uint8_t i2c_address, uint8_t adc_command, uint32_t code)
Write a 24-bit code to the LTC2946.
Definition: LTC2946.cpp:103
const float LTC2946_VIN_lsb
Typical VIN lsb weight in volts.
Definition: DC2156.ino:129
int8_t LTC2946_write_32_bits(uint8_t i2c_address, uint8_t adc_command, uint32_t code)
Write a 32-bit code to the LTC2946.
Definition: LTC2946.cpp:116
float LTC2946_code_to_current(uint16_t adc_code, float resistor, float LTC2946_DELTA_SENSE_lsb)
Calculate the LTC2946 current with a sense resistor.
Definition: LTC2946.cpp:212
static float LTC2946_TIME_lsb
Static variable which is based off of the default clk frequency of 250KHz.
Definition: DC2156.ino:134
float LTC2946_code_to_power(int32_t adc_code, float resistor, float LTC2946_Power_lsb)
Calculate the LTC2946 power.
Definition: LTC2946.cpp:222
float LTC2946_code_to_energy(int32_t adc_code, float resistor, float LTC2946_Power_lsb, float LTC2946_TIME_lsb)
Calculate the LTC2946 energy.
Definition: LTC2946.cpp:233
int8_t LTC2946_write(uint8_t i2c_address, uint8_t adc_command, uint8_t code)
Write an 8-bit code to the LTC2946.
Definition: LTC2946.cpp:81
float LTC2946_code_to_coulombs(int32_t adc_code, float resistor, float LTC2946_DELTA_SENSE_lsb, float LTC2946_Time_lsb)
Calculate the LTC2946 coulombs.
Definition: LTC2946.cpp:243
int8_t LTC2946_read_12_bits(uint8_t i2c_address, uint8_t adc_command, uint16_t *adc_code)
Reads a 12-bit adc_code from LTC2946.
Definition: LTC2946.cpp:141
float LTC2946_code_to_time(float time_code, float LTC2946_Time_lsb)
Calculate the LTC2946 internal time base.
Definition: LTC2946.cpp:253
int8_t LTC2946_read_16_bits(uint8_t i2c_address, uint8_t adc_command, uint16_t *adc_code)
Reads a 16-bit adc_code from LTC2946.
Definition: LTC2946.cpp:155
int8_t LTC2946_write_16_bits(uint8_t i2c_address, uint8_t adc_command, uint16_t code)
Write a 16-bit code to the LTC2946.
Definition: LTC2946.cpp:93
float LTC2946_ADIN_code_to_voltage(uint16_t adc_code, float LTC2946_ADIN_lsb)
Calculate the LTC2946 ADIN voltage.
Definition: LTC2946.cpp:203
const float LTC2946_Power_lsb
Typical POWER lsb weight in V^2 VIN_lsb * DELTA_SENSE_lsb.
Definition: DC2156.ino:130
int8_t LTC2946_read_24_bits(uint8_t i2c_address, uint8_t adc_command, uint32_t *adc_code)
Reads a 24-bit adc_code from LTC2946.
Definition: LTC2946.cpp:166
static uint32_t adc_code
Definition: DC2071AA.ino:113
int8_t LTC2946_read_32_bits(uint8_t i2c_address, uint8_t adc_command, uint32_t *adc_code)
Reads a 32-bit adc_code from LTC2946.
Definition: LTC2946.cpp:180
float LTC2946_VIN_code_to_voltage(uint16_t adc_code, float LTC2946_VIN_lsb)
Calculate the LTC2946 VIN voltage.
Definition: LTC2946.cpp:194
const float LTC2946_DELTA_SENSE_lsb
Typical Delta lsb weight in volts.
Definition: DC2156.ino:128