| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

LTC4282.cpp
Go to the documentation of this file.
1 /*!
2 LTC4282: High Current Hot Swap Controller with I2C Compatible Monitoring and EEPROM
3
4 @verbatim
5
6 The LTC4282 Hot Swap controller allows a board to be safely inserted and removed from a live backplane.
7 Using one or more external N-channel pass transistors, board supply voltage and inrush current is ramped up at an adjustable rate.
8 An I2C interface and onboard ADC allows for monitoring of board current, voltage, power, energy and fault status.
9
10 @endverbatim
11
12 http://www.linear.com/product/LTC4282
13
14 http://www.linear.com/product/LTC4282#demoboards
15
16
17 Copyright 2018(c) Analog Devices, Inc.
18
19 All rights reserved.
20
21 Redistribution and use in source and binary forms, with or without
22 modification, are permitted provided that the following conditions are met:
23 - Redistributions of source code must retain the above copyright
24 notice, this list of conditions and the following disclaimer.
25 - Redistributions in binary form must reproduce the above copyright
26 notice, this list of conditions and the following disclaimer in
27 the documentation and/or other materials provided with the
28 distribution.
29 - Neither the name of Analog Devices, Inc. nor the names of its
30 contributors may be used to endorse or promote products derived
31 from this software without specific prior written permission.
32 - The use of this software may or may not infringe the patent rights
33 of one or more patent holders. This license does not release you
34 from the requirement that you obtain separate licenses from these
35 patent holders to use this software.
36 - Use of the software either in source or binary form, must be run
37 on or directly connected to an Analog Devices Inc. component.
38
39 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
40 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
41 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
42 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
43 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
44 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
45 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
46 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
47 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
48 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49 */
50
51 //! @ingroup Hot_Swap
52 //! @{
53 //! @defgroup LTC4282 LTC4282: High Current Hot Swap Controller with I2C Compatible Monitoring and EEPROM
54 //! @}
55
56 /*! @file
57 @ingroup LTC4282
58 Library for LTC4282: High Current Hot Swap Controller with I2C Compatible Monitoring and EEPROM
59 */
60
61 #include <Arduino.h>
62 #include <stdint.h>
63 #include <Linduino.h>
64 #include <LT_I2C.h>
65 #include "LTC4282.h"
66
67
68 // Write an 8-bit code to the LTC4282.
69 int8_t LTC4282_write(uint8_t i2c_address, uint8_t adc_command, uint8_t code)
70 // The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
71 {
72 int32_t ack;
73
74 ack = i2c_write_byte_data(i2c_address, adc_command, code);
75
76 return ack;
77
78 }
79
80 // Write a 16-bit code to the LTC4282.
81 int8_t LTC4282_write_16_bits(uint8_t i2c_address, uint8_t adc_command, uint16_t code)
82 // The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
83 {
84 int8_t ack;
85
86 ack = i2c_write_word_data(i2c_address, adc_command, code);
87 return(ack);
88 }
89
90 // Write a 32-bit code to the LTC4282.
91 int8_t LTC4282_write_32_bits(uint8_t i2c_address, uint8_t adc_command, uint32_t code)
92 // The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
93 {
94 int8_t ack;
95
96 LT_union_int32_4bytes data;
97 data.LT_int32 = code;
98
99 ack = i2c_write_block_data(i2c_address, adc_command, (uint8_t) 4, data.LT_byte);
100
101 return(ack);
102 }
103
104 // Write a 48-bit code to the LTC4282.
105 int8_t LTC4282_write_48_bits(uint8_t i2c_address, uint8_t adc_command, uint64_t code)
106 // The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
107 {
108 int8_t ack;
109
110 LT_union_int64_8bytes data;
111 data.LT_uint64 = code;
112
113 ack = i2c_write_block_data(i2c_address, adc_command, (uint8_t) 6, data.LT_byte);
114
115 return(ack);
116 }
117
118
119 // Reads an 8-bit adc_code from LTC4282
120 int8_t LTC4282_read(uint8_t i2c_address, uint8_t adc_command, uint8_t *adc_code)
121 // The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
122 {
123 int8_t ack;
124 ack = i2c_read_byte_data(i2c_address, adc_command, adc_code);
125 return ack;
126 }
127
128 // Reads a 16-bit adc_code from LTC4282
129 int8_t LTC4282_read_16_bits(uint8_t i2c_address, uint8_t adc_command, uint16_t *adc_code)
130 // The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
131 {
132 int32_t ack;
133
134 ack = i2c_read_word_data(i2c_address, adc_command, adc_code);
135
136 return ack;
137 }
138
139 // Reads a 32-bit adc_code from LTC4282
140 int8_t LTC4282_read_32_bits(uint8_t i2c_address, uint8_t adc_command, uint32_t *adc_code)
141 // The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
142 {
143 int8_t ack;
144
145 LT_union_int32_4bytes data;
146
147 ack = i2c_read_block_data(i2c_address, adc_command, (uint8_t) 4, data.LT_byte);
148
149 *adc_code = 0xFFFFFFFF & data.LT_int32;
150 return(ack);
151 }
152
153 // Reads a 48-bit adc_code from LTC4282
154 int8_t LTC4282_read_48_bits(uint8_t i2c_address, uint8_t adc_command, uint64_t *adc_code)
155 // The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
156 {
157 int8_t ack;
158
159 LT_union_int64_8bytes data;
160
161 ack = i2c_read_block_data(i2c_address, adc_command, (uint8_t) 6, data.LT_byte);
162
163 *adc_code = 0xFFFFFFFFFFFFLL &data.LT_uint64;
164 return(ack);
165 }
166
167 // Convert ADC code to VGPIO
168 float LTC4282_code_to_VGPIO(uint16_t code)
169 // Returns floating point value of GPIO Voltage
170 {
171 float value = (code*1.28)/(65535);
172 return value;
173
174 }
175
176 // Convert ADC code to voltage
177 float LTC4282_code_to_voltage(uint16_t code, float fullscaleVoltage)
178 // Returns floating point value of voltage
179 {
180 float value = (code*fullscaleVoltage)/((65536)-1);
181 return value;
182 }
183
184 // Convert ADC code to current
185 float LTC4282_code_to_current(uint16_t code, float resistor)
186 // Returns floating point value of current
187 {
188 float value = (code*.04)/(((65536)-1)*resistor);
189 return value;
190 }
191
192 // Convert ADC code to power
193 float LTC4282_code_to_power(uint16_t code, float fullscaleVoltage, float resistor)
194 // Returns floating point value of power
195 {
196 float value = (code*.04*fullscaleVoltage*65536.0)/(65535.0*65535.0*resistor);
197 return value;
198 }
199 // Convert ADC code to energy
200 float LTC4282_code_to_energy(uint64_t code, float fullscaleVoltage, float resistor, float tConv)
201 // Returns floating point value of power
202 {
203 float value = (code*.04*fullscaleVoltage*tConv*256.0)/(65535.0*65535.0*resistor);
204 return value;
205 }
206
207 // Convert ADC code to coulombs
208 float LTC4282_code_to_coulombs(uint64_t code, float resistor, float tConv)
209 // Returns floating point value of coulombs
210 {
211 float value = (code*.04*tConv)/(((65536)-1)*resistor);
212 return value;
213 }
214
215 // Convert ADC code to average power
216 float LTC4282_code_to_avg_power(uint64_t code, float energy, float tConv)
217 // Returns floating point value of average power
218 {
219 float value = energy/(tConv*code);
220 return value;
221 }
222
223 // Convert ADC code to average current
224 float LTC4282_code_to_avg_current(uint64_t code, float coulombs, float tConv)
225 // Returns floating point value of average power
226 {
227 float value = coulombs/(tConv*code);
228 return value;
229 }
230
231 // Convert ADC code to GPIO alarm voltage
232 float LTC4282_code_to_GPIO_alarm(uint8_t code)
233 // Returns floating point value of GPIO alarm voltage
234 {
235 float value = code*1.280/255;
236 return value;
237 }
238
239 // Convert ADC code to alarm voltage
240 float LTC4282_code_to_volt_alarm(uint8_t code, float fullscaleVoltage)
241 // Returns floating point value of alarm voltage
242 {
243 float value = code*fullscaleVoltage/255;
244 return value;
245 }
246
247 // Convert ADC code to alarm current
248 float LTC4282_code_to_current_alarm(uint8_t code, float resistor)
249 // Returns floating point value of alarm current
250 {
251 float value = (code*.04)/(255*resistor);
252 return value;
253 }
254
255 // Convert ADC code to alarm power
256 float LTC4282_code_to_power_alarm(uint8_t code, float fullscaleVoltage, float resistor)
257 // Returns floating point value of alarm power
258 {
259 float value = (code*fullscaleVoltage*.04*256)/(255.0*255.0*resistor);
260 return value;
261 }
262
263 // Convert GPIO voltage to alarm code
264 uint8_t LTC4282_VGPIO_to_code_alarm(float vgpio)
265 // Returns the ADC code of the floating point value parameter
266 {
267 uint8_t code = (int)(vgpio*255.0/1.280);
268 return code;
269 }
270
271 // Convert voltage to alarm code
272 uint8_t LTC4282_volt_to_code_alarm(float volt, float fullscaleVoltage)
273 // Returns the ADC code of the floating point value parameter
274 {
275 uint8_t code = (int)(volt*255.0/fullscaleVoltage);
276 return code;
277 }
278
279 // Convert current to alarm code
280 uint8_t LTC4282_current_to_code_alarm(float current, float resistor)
281 // Returns the ADC code of the floating point value parameter
282 {
283 uint8_t code = (current*255.0*resistor)/(.04);
284 return code;
285 }
286
287 // Convert power to alarm code
288 uint8_t LTC4282_power_to_code_alarm(float power, float resistor, float fullscaleVoltage)
289 // Returns the ADC code of the floating point value parameter
290 {
291 uint8_t code = (power*255.0*255.0*resistor/(256*.04*fullscaleVoltage));
292 return code;
293 }
LTC4282_code_to_avg_power
float LTC4282_code_to_avg_power(uint64_t code, float energy, float tConv)
Convert ADC code to average power.
Definition: LTC4282.cpp:216
LTC4282_code_to_voltage
float LTC4282_code_to_voltage(uint16_t code, float fullscaleVoltage)
Convert ADC code to voltage.
Definition: LTC4282.cpp:177
LTC4282_VGPIO_to_code_alarm
uint8_t LTC4282_VGPIO_to_code_alarm(float vgpio)
Convert GPIO voltage to alarm code.
Definition: LTC4282.cpp:264
LTC4282_code_to_coulombs
float LTC4282_code_to_coulombs(uint64_t code, float resistor, float tConv)
Convert ADC code to coulombs.
Definition: LTC4282.cpp:208
i2c_address
uint8_t i2c_address
adc_command
static uint8_t adc_command
Definition: DC2071AA.ino:111
i2c_read_block_data
int8_t i2c_read_block_data(uint8_t address, uint8_t command, uint8_t length, uint8_t *values)
Read a block of data, starting at register specified by "command" and ending at (command + length - 1...
Definition: LT_I2C.cpp:244
LT_union_int32_4bytes::LT_byte
uint8_t LT_byte[4]
4 bytes (unsigned 8-bit integers) to be converted to a 32-bit signed or unsigned integer ...
Definition: Linduino.h:112
LTC4282_read_32_bits
int8_t LTC4282_read_32_bits(uint8_t i2c_address, uint8_t adc_command, uint32_t *adc_code)
Read a 32-bit code from the LTC4282.
Definition: LTC4282.cpp:140
i2c_read_byte_data
int8_t i2c_read_byte_data(uint8_t address, uint8_t command, uint8_t *value)
Read a byte of data at register specified by "command", store in "value".
Definition: LT_I2C.cpp:124
resistor
const float resistor
resistor value on demo board
Definition: DC1496BB.ino:116
LTC4282_code_to_power
float LTC4282_code_to_power(uint16_t code, float fullscaleVoltage, float resistor)
Convert ADC code to power.
Definition: LTC4282.cpp:193
Linduino.h
Header File for Linduino Libraries and Demo Code.
LTC4282_code_to_VGPIO
float LTC4282_code_to_VGPIO(uint16_t code)
Convert ADC code to VGPIO.
Definition: LTC4282.cpp:168
LT_union_int64_8bytes::LT_uint64
uint64_t LT_uint64
32-bit unsigned integer to be converted to four bytes
Definition: LTC4282.h:577
LTC4282_power_to_code_alarm
uint8_t LTC4282_power_to_code_alarm(float power, float resistor, float fullscaleVoltage)
Convert power to alarm code.
Definition: LTC4282.cpp:288
LTC4282_code_to_current
float LTC4282_code_to_current(uint16_t code, float resistor)
Convert ADC code to current.
Definition: LTC4282.cpp:185
LTC4282_current_to_code_alarm
uint8_t LTC4282_current_to_code_alarm(float current, float resistor)
Convert current to alarm code.
Definition: LTC4282.cpp:280
LTC4282_read_48_bits
int8_t LTC4282_read_48_bits(uint8_t i2c_address, uint8_t adc_command, uint64_t *adc_code)
Read a 48-bit code from the LTC4282.
Definition: LTC4282.cpp:154
data
union LT_union_int32_4bytes data
Definition: DC2094A.ino:138
i2c_write_word_data
int8_t i2c_write_word_data(uint8_t address, uint8_t command, uint16_t value)
Write a 16-bit word of data to register specified by "command".
Definition: LT_I2C.cpp:216
LTC4282_code_to_energy
float LTC4282_code_to_energy(uint64_t code, float fullscaleVoltage, float resistor, float tConv)
Convert ADC code to energy.
Definition: LTC4282.cpp:200
LTC4282_code_to_GPIO_alarm
float LTC4282_code_to_GPIO_alarm(uint8_t code)
Convert ADC code to GPIO alarm voltage.
Definition: LTC4282.cpp:232
LTC4282_volt_to_code_alarm
uint8_t LTC4282_volt_to_code_alarm(float volt, float fullscaleVoltage)
Convert voltage to alarm code.
Definition: LTC4282.cpp:272
i2c_write_byte_data
int8_t i2c_write_byte_data(uint8_t address, uint8_t command, uint8_t value)
Write a byte of data to register specified by "command".
Definition: LT_I2C.cpp:155
LTC4282_write
int8_t LTC4282_write(uint8_t i2c_address, uint8_t adc_command, uint8_t code)
Write an 8-bit code to the LTC4282.
Definition: LTC4282.cpp:69
LTC4282_write_16_bits
int8_t LTC4282_write_16_bits(uint8_t i2c_address, uint8_t adc_command, uint16_t code)
Write an 16-bit code to the LTC4282.
Definition: LTC4282.cpp:81
LT_union_int32_4bytes::LT_int32
int32_t LT_int32
32-bit signed integer to be converted to four bytes
Definition: Linduino.h:110
LTC4282_code_to_volt_alarm
float LTC4282_code_to_volt_alarm(uint8_t code, float fullscaleVoltage)
Convert ADC code to alarm voltage.
Definition: LTC4282.cpp:240
LT_union_int64_8bytes
Definition: LTC4282.h:574
LTC4282_write_32_bits
int8_t LTC4282_write_32_bits(uint8_t i2c_address, uint8_t adc_command, uint32_t code)
Write an 32-bit code to the LTC4282.
Definition: LTC4282.cpp:91
i2c_read_word_data
int8_t i2c_read_word_data(uint8_t address, uint8_t command, uint16_t *value)
Read a 16-bit word of data from register specified by "command".
Definition: LT_I2C.cpp:172
LT_I2C.h
LT_I2C: Routines to communicate with ATmega328P&#39;s hardware I2C port.
i2c_write_block_data
int8_t i2c_write_block_data(uint8_t address, uint8_t command, uint8_t length, uint8_t *values)
Write a block of data, starting at register specified by "command" and ending at (command + length - ...
Definition: LT_I2C.cpp:321
LT_union_int64_8bytes::LT_byte
uint8_t LT_byte[8]
4 bytes (unsigned 8-bit integers) to be converted to a 32-bit signed or unsigned integer ...
Definition: LTC4282.h:578
LT_union_int32_4bytes
This union splits one int32_t (32-bit signed integer) or uint32_t (32-bit unsigned integer) four uint...
Definition: Linduino.h:108
LTC4282_read_16_bits
int8_t LTC4282_read_16_bits(uint8_t i2c_address, uint8_t adc_command, uint16_t *adc_code)
Read a 16-bit code from the LTC4282.
Definition: LTC4282.cpp:129
LTC4282.h
LTC4282: High Current Hot Swap Controller with I2C Compatible Monitoring and EEPROM.
LTC4282_read
int8_t LTC4282_read(uint8_t i2c_address, uint8_t adc_command, uint8_t *adc_code)
Read an 8-bit code from the LTC4282.
Definition: LTC4282.cpp:120
current
static uint16_t current
the current measurement from the LTC3335&#39;s counter test mode.
Definition: DC2343A.ino:114
LTC4282_write_48_bits
int8_t LTC4282_write_48_bits(uint8_t i2c_address, uint8_t adc_command, uint64_t code)
Write an 48-bit code to the LTC4282.
Definition: LTC4282.cpp:105
LTC4282_code_to_current_alarm
float LTC4282_code_to_current_alarm(uint8_t code, float resistor)
Convert ADC code to alarm current.
Definition: LTC4282.cpp:248
LTC4282_code_to_avg_current
float LTC4282_code_to_avg_current(uint64_t code, float coulombs, float tConv)
Convert ADC code to average current.
Definition: LTC4282.cpp:224
adc_code
static uint32_t adc_code
Definition: DC2071AA.ino:113
LTC4282_code_to_power_alarm
float LTC4282_code_to_power_alarm(uint8_t code, float fullscaleVoltage, float resistor)
Convert ADC code to alarm power.
Definition: LTC4282.cpp:256