| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

LTC4261.cpp
Go to the documentation of this file.
1 /*!
2 LTC4261: Negative Voltage Hot Swap Controller with ADC and I2C Monitoring
3
4 @verbatim
5
6 The LTC4261/LTC4261-2 negative voltage Hot SwapTM controller allows a board
7 to be safely inserted and removed from a live backplane. Using an external
8 N-channel pass transistor, the board supply voltage can be ramped at an
9 adjustable rate. The devices feature independently adjustable inrush current
10 and overcurrent limits to minimize stresses on the pass transistor during
11 start-up, input step and output short conditions. The LTC4261 defaults
12 to latch-off while the LTC4261-2 defaults to auto-retry on overcurrent faults.
13
14 @endverbatim
15
16 http://www.linear.com/product/LTC4261
17
18 http://www.linear.com/product/LTC4261#demoboards
19
20
21 Copyright 2018(c) Analog Devices, Inc.
22
23 All rights reserved.
24
25 Redistribution and use in source and binary forms, with or without
26 modification, are permitted provided that the following conditions are met:
27 - Redistributions of source code must retain the above copyright
28 notice, this list of conditions and the following disclaimer.
29 - Redistributions in binary form must reproduce the above copyright
30 notice, this list of conditions and the following disclaimer in
31 the documentation and/or other materials provided with the
32 distribution.
33 - Neither the name of Analog Devices, Inc. nor the names of its
34 contributors may be used to endorse or promote products derived
35 from this software without specific prior written permission.
36 - The use of this software may or may not infringe the patent rights
37 of one or more patent holders. This license does not release you
38 from the requirement that you obtain separate licenses from these
39 patent holders to use this software.
40 - Use of the software either in source or binary form, must be run
41 on or directly connected to an Analog Devices Inc. component.
42
43 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
44 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
45 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
46 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
47 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
48 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
49 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
50 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
51 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
52 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53 */
54
55 //! @ingroup Hot_Swap
56 //! @{
57 //! @defgroup LTC4261 LTC4261: Negative Voltage Hot Swap Controllers with ADC and I2C Monitoring
58 //! @}
59
60 /*! @file
61 @ingroup LTC4261
62 Library for LTC4261: Negative Voltage Hot Swap Controllers with ADC and I2C Monitoring
63 */
64
65 #include <Arduino.h>
66 #include <stdint.h>
67 #include "Linduino.h"
68 #include "LT_I2C.h"
69 #include "LTC4261.h"
70 #include <Wire.h>
71
72 // Writes an 8-bit code to the LTC4261
73 int8_t LTC4261_write(uint8_t i2c_address, uint8_t command, uint8_t code)
74 // The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge
75 {
76 int8_t ack;
77 ack = i2c_write_byte_data(i2c_address,command,code);
78 return ack;
79 }
80
81 // Reads an 8-bit code from the LTC4261
82 int8_t LTC4261_read(uint8_t i2c_address, uint8_t command, uint8_t *code)
83 // The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge
84 {
85 int8_t ack;
86 ack = i2c_read_byte_data(i2c_address,command,code);
87 return ack;
88 }
89
90 // Reads a 10-bit adc_code from LTC4261
91 int8_t LTC4261_read_10_bits(uint8_t i2c_address, uint8_t adc_command, uint16_t *adc_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 uint8_t values[2];
96 ack = i2c_read_block_data(i2c_address,adc_command, 2,values);
97 *adc_code = (uint16_t)(values[0]) <<2 | values[1]>>6;
98 return ack;
99 }
100
101 // SMBus Alert Response Protocol: Sends an alert response command and releases /ALERT pin. LTC4261 responds with its address
102 int8_t LTC4261_ARA(uint8_t alert_response_address, uint8_t *i2c_address)
103 // The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge
104 {
105 int8_t ack;
106 ack = i2c_read_byte(alert_response_address, i2c_address);
107 return ack;
108 }
109 // Calculates the LTC4261 ADIN voltage
110 float LTC4261_ADIN_code_to_voltage(uint16_t adc_code, float LTC4261_ADIN_lsb, float resistor_divider_ratio)
111 // Returns the ADIN Voltage in Volts
112 {
113 float adc_voltage;
114 adc_voltage = (float)adc_code*LTC4261_ADIN_lsb; //! 1) Calculate voltage from code and ADIN lsb
115 return(adc_voltage*resistor_divider_ratio);
116 }
117
118 // Calculates the LTC4261 current with a sense resistor
119 float LTC4261_code_to_current(uint16_t adc_code, float resistor, float LTC4261_DELTA_SENSE_lsb)
120 // Returns the LTC4261 sense current
121 {
122 float voltage, current;
123 voltage = (float)adc_code*LTC4261_DELTA_SENSE_lsb; //! 1) Calculate voltage from ADC code and delta sense lsb
124 current = voltage/resistor; //! 2) Calculate current, I = V/R
125 return(current);
126 }
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
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
LTC4261_write
int8_t LTC4261_write(uint8_t i2c_address, uint8_t command, uint8_t code)
Write an 8-bit code to the LTC4261.
Definition: LTC4261.cpp:73
resistor
const float resistor
resistor value on demo board
Definition: DC1496BB.ino:116
Linduino.h
Header File for Linduino Libraries and Demo Code.
LTC4261.h
LTC4261: Negative Voltage Hot Swap Controller with ADC and I2C Monitoring.
LTC4261_read_10_bits
int8_t LTC4261_read_10_bits(uint8_t i2c_address, uint8_t adc_command, uint16_t *adc_code)
Reads a 10-bit adc_code from LTC4261.
Definition: LTC4261.cpp:91
adc_voltage
static float adc_voltage
Definition: DC2071AA.ino:115
LTC4261_ARA
int8_t LTC4261_ARA(uint8_t alert_response_address, uint8_t *i2c_address)
SMBus Alert Response Protocol: Sends an alert response command and releases /ALERT pin...
Definition: LTC4261.cpp:102
LTC4261_read
int8_t LTC4261_read(uint8_t i2c_address, uint8_t command, uint8_t *code)
Reads an 8-bit adc_code from LTC4261.
Definition: LTC4261.cpp:82
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
LT_I2C.h
LT_I2C: Routines to communicate with ATmega328P&#39;s hardware I2C port.
LTC4261_code_to_current
float LTC4261_code_to_current(uint16_t adc_code, float resistor, float LTC4261_DELTA_SENSE_lsb)
Calculate the LTC4261 current with a sense resistor.
Definition: LTC4261.cpp:119
voltage
static float voltage
Definition: DC2289AA.ino:71
current
static uint16_t current
the current measurement from the LTC3335&#39;s counter test mode.
Definition: DC2343A.ino:114
LTC4261_ADIN_code_to_voltage
float LTC4261_ADIN_code_to_voltage(uint16_t adc_code, float LTC4261_ADIN_lsb, float resistor_divider_ratio)
Calculate the LTC4261 ADIN voltage.
Definition: LTC4261.cpp:110
adc_code
static uint32_t adc_code
Definition: DC2071AA.ino:113
i2c_read_byte
int8_t i2c_read_byte(uint8_t address, uint8_t *value)
Read a byte, store in "value".
Definition: LT_I2C.cpp:93
values
static uint8_t values[4]
Definition: DC2218A.ino:117