| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

LTC6115.cpp
Go to the documentation of this file.
1 /*!
2 LTC6115 High Voltage High Side Current and Voltage Sense
3
4 @verbatim
5
6 The LTC6115 is a versatile combination of a high voltage, high side current
7 sense amplifier and a voltage sense amplifier.
8
9 @endverbatim
10
11 https://www.analog.com/en/products/ltc6115.html
12
13
14 Copyright 2018(c) Analog Devices, Inc.
15
16 All rights reserved.
17
18 Redistribution and use in source and binary forms, with or without
19 modification, are permitted provided that the following conditions are met:
20 - Redistributions of source code must retain the above copyright
21 notice, this list of conditions and the following disclaimer.
22 - Redistributions in binary form must reproduce the above copyright
23 notice, this list of conditions and the following disclaimer in
24 the documentation and/or other materials provided with the
25 distribution.
26 - Neither the name of Analog Devices, Inc. nor the names of its
27 contributors may be used to endorse or promote products derived
28 from this software without specific prior written permission.
29 - The use of this software may or may not infringe the patent rights
30 of one or more patent holders. This license does not release you
31 from the requirement that you obtain separate licenses from these
32 patent holders to use this software.
33 - Use of the software either in source or binary form, must be run
34 on or directly connected to an Analog Devices Inc. component.
35
36 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
37 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
38 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
39 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
40 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
42 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
43 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46
47 The views and conclusions contained in the software and documentation are those
48 of the authors and should not be interpreted as representing official policies,
49 either expressed or implied, of Analog Devices Inc.
50
51 The Analog Devices Linduino is not affiliated with the official Arduino team.
52 However, the Linduino is only possible because of the Arduino team's commitment
53 to the open-source community. Please, visit http://www.arduino.cc and
54 http://store.arduino.cc , and consider a purchase that will help fund their
55 ongoing work.
56
57 Copyright 2018 Analog Devices Inc. (ADI)
58
59 */
60
61
62 //! @ingroup Power_Monitors
63 //! @{
64 //! @defgroup LTC6115 LTC6115: High-Voltage High Side Current and Voltage Sense
65 //! @}
66
67 /*! @file
68 @ingroup LTC6115
69 Library for LTC6115 High-Voltage High Side Current and Voltage Sense
70 */
71
72
73 #include <stdint.h>
74 #include <Arduino.h>
75 #include "Linduino.h"
76 #include "LT_SPI.h"
77 #include "LTC6115.h"
78 #include <SPI.h>
79
80
81 /*!
82 6115 Primary Variables
83 */
84 float LTC6115_VGain = 0;
85 float LTC6115_IGain = 0;
86
87
88 // Function Definitions
89
90 //! This function will initialize 6115 variables.
91 //! @return void
92 void LTC6115_initialize()
93 {
94 LTC6115_VGain = 2; // 2.0 V/V default
95 LTC6115_IGain = 2.5; // 2.5 V/A default, equiv to 50 V/V with Rsense = 50mOhm
96 }
97
98 //! This function returns the voltage gain (V/V).
99 //! @return float
100 float getVGain()
101 {
102 float temp;
103 temp = LTC6115_VGain;
104 return temp;
105 }
106
107 //! This function returns the current gain (V/A).
108 //! @return float
109 float getIGain()
110 {
111 float temp;
112 temp = LTC6115_IGain;
113 return temp;
114 }
115
116 //! This function converts ADC code to Voltage.
117 //! @return float
118 float LTC6115ConvertToVolts(uint32_t val)
119 {
120 float temp;
121
122 temp = (float)val / (float)MAXADCVAL * (float) AREF;
123 return temp / (float) LTC6115_VGain * float(40); /* 6115 Vsense fixed input divider 1:40 */
124 }
125
126 //! This function converts ADC code to Voltage without the converted voltage print statement.
127 //! @return float
128 float LTC6115ToVolts(uint32_t val)
129 {
130 float temp;
131 temp = (float)val / (float)MAXADCVAL * (float) AREF;
132 return temp / (float) LTC6115_VGain * float(40); /* 6115 Vsense fixed input divider 1:40 */
133 }
134
135 //! This function converts ADC code to Current.
136 //! @return float
137 float LTC6115ConvertToAmps(uint32_t val)
138 {
139 float temp;
140 temp = (float)val / (float)MAXADCVAL * (float) AREF;
141 return temp / (float) LTC6115_IGain;
142 }
143
144 //! This function converts ADC code to Current without the converted current print statement.
145 //! @return float
146 float LTC6115ToAmps(uint32_t val)
147 {
148 float temp;
149 temp = (float)val / (float)MAXADCVAL * (float) AREF;
150 return temp / (float) LTC6115_IGain;
151 }
152
153 //! This function changes the Voltage gain.
154 //! @return void
155 void LTC6115ChangeVGain(float val)
156 {
157 LTC6115_VGain = val;
158 }
159
160 //! This function changes the Current gain.
161 //! @return float
162 void LTC6115ChangeIGain(float val)
163 {
164 LTC6115_IGain = val;
165 }
166
167 //! This function converts milliseconds to frequency (Hz).
168 //! @return uint32_t
169 uint32_t millsToHz(uint32_t val)
170 {
171 float temp;
172 float seconds;
173 uint32_t fr;
174
175 seconds = (float) val / 1000.0;
176 temp = 1 / seconds;
177 fr = (uint32_t) round(temp);
178 return fr;
179 }
180
181
182
183
184
MAXADCVAL
#define MAXADCVAL
Definition: LTC6115.h:70
LTC6115ChangeIGain
void LTC6115ChangeIGain(float val)
This function changes the Current gain.
Definition: LTC6115.cpp:162
Linduino.h
Header File for Linduino Libraries and Demo Code.
LTC6115ToVolts
float LTC6115ToVolts(uint32_t val)
This function converts ADC code to Voltage without the converted voltage print statement.
Definition: LTC6115.cpp:128
LTC6115ConvertToVolts
float LTC6115ConvertToVolts(uint32_t val)
This function converts ADC code to Voltage.
Definition: LTC6115.cpp:118
LTC6115_initialize
void LTC6115_initialize()
This function will initialize 6115 variables.
Definition: LTC6115.cpp:92
LTC6115ToAmps
float LTC6115ToAmps(uint32_t val)
This function converts ADC code to Current without the converted current print statement.
Definition: LTC6115.cpp:146
getIGain
float getIGain()
This function returns the current gain (V/A).
Definition: LTC6115.cpp:109
AREF
#define AREF
Definition: LTC6115.h:71
LT_SPI.h
LT_SPI: Routines to communicate with ATmega328P&#39;s hardware SPI port.
millsToHz
uint32_t millsToHz(uint32_t val)
This function converts milliseconds to frequency (Hz).
Definition: LTC6115.cpp:169
LTC6115_IGain
float LTC6115_IGain
Definition: LTC6115.cpp:85
getVGain
float getVGain()
This function returns the voltage gain (V/V).
Definition: LTC6115.cpp:100
LTC6115ChangeVGain
void LTC6115ChangeVGain(float val)
This function changes the Voltage gain.
Definition: LTC6115.cpp:155
LTC6115.h
LTC6115 High Voltage High Side Current and Voltage Sense.
LTC6115_VGain
float LTC6115_VGain
6115 Primary Variables
Definition: LTC6115.cpp:84
LTC6115ConvertToAmps
float LTC6115ConvertToAmps(uint32_t val)
This function converts ADC code to Current.
Definition: LTC6115.cpp:137