| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

LTC2348.cpp
Go to the documentation of this file.
1 /*!
2 LTC2348-18: Octal, 18-Bit, 200ksps Differential ±10.24V Input SoftSpan ADC with Wide Input Common Mode Range.
3 LTC2348-16: Octal, 16-Bit, 200ksps Differential ±10.24V Input SoftSpan ADC with Wide Input Common Mode Range.
4 LTC2344-18: Quad, 18-Bit, 400ksps/ch Differential SoftSpan ADC with Wide Input Common Mode Range.
5 LTC2344-16: Quad, 16-Bit, 400ksps/ch Differential SoftSpan ADC with Wide Input Common Mode Range.
6 LTC2333-18: Buffered 8-Channel, 18-Bit, 800ksps Differential ±10.24V ADC with 30VP-P Common Mode Range.
7 LTC2333-16: Buffered 8-Channel, 16-Bit, 800ksps Differential ±10.24V ADC with 30VP-P Common Mode Range.
8 LTC2357-18: Buffered Quad, 18-Bit, 350ksps/Ch Differential ±10.24V ADC with 30VP-P Common Mode Range.
9 LTC2357-16: Buffered Quad, 16-Bit, 350ksps/Ch Differential ±10.24V ADC with 30VP-P Common Mode Range.
10 LTC2358-18: Buffered Octal, 18-Bit, 200ksps/Ch Differential ±10.24V ADC with 30VP-P Common Mode Range.
11 LTC2358-16: Buffered Octal, 16-Bit, 200ksps/Ch Differential ±10.24V ADC with 30VP-P Common Mode Range.
12 LTC2353-18: Buffered Dual, 18-Bit, 550ksps/Ch Differential ±10.24V ADC with 30VP-P Common Mode Range.
13 LTC2353-16: Buffered Dual, 16-Bit, 550ksps/Ch Differential ±10.24V ADC with 30VP-P Common Mode Range.
14
15
16 @verbatim
17
18 The LTC2348 is an 18-bit,low noise 8-channel simultaneous sampling successive
19 approximation register(SAR) ADC with differential,wide common mode range
20 inputs. Operating from a 5V low voltage supply, flexible high voltage supplies,
21 and using the internal reference and buffer, each channel of this SoftSpan ADC
22 can be independently configured on a conversion-by-conversion basis to accept
23 ±10.24V, 0V to 10.24V, ±5.12V,or 0V to 5.12V signals.
24
25 @endverbatim
26
27 http://www.linear.com/product/LTC2348-18
28 http://www.linear.com/product/LTC2348-16
29 http://www.linear.com/product/LTC2344-18
30 http://www.linear.com/product/LTC2344-16
31 http://www.linear.com/product/LTC2333-18
32 http://www.linear.com/product/LTC2333-16
33 http://www.linear.com/product/LTC2357-18
34 http://www.linear.com/product/LTC2357-16
35 http://www.linear.com/product/LTC2358-18
36 http://www.linear.com/product/LTC2358-16
37 http://www.linear.com/product/LTC2353-18
38 http://www.linear.com/product/LTC2353-16
39
40 http://www.linear.com/product/LTC2348-18#demoboards
41 http://www.linear.com/product/LTC2348-16#demoboards
42 http://www.linear.com/product/LTC2344-18#demoboards
43 http://www.linear.com/product/LTC2344-16#demoboards
44 http://www.linear.com/product/LTC2333-18#demoboards
45 http://www.linear.com/product/LTC2333-16#demoboards
46 http://www.linear.com/product/LTC2357-18#demoboards
47 http://www.linear.com/product/LTC2357-16#demoboards
48 http://www.linear.com/product/LTC2358-18#demoboards
49 http://www.linear.com/product/LTC2358-16#demoboards
50 http://www.linear.com/product/LTC2353-18#demoboards
51 http://www.linear.com/product/LTC2353-16#demoboards
52
53
54 Copyright 2018(c) Analog Devices, Inc.
55
56 All rights reserved.
57
58 Redistribution and use in source and binary forms, with or without
59 modification, are permitted provided that the following conditions are met:
60 - Redistributions of source code must retain the above copyright
61 notice, this list of conditions and the following disclaimer.
62 - Redistributions in binary form must reproduce the above copyright
63 notice, this list of conditions and the following disclaimer in
64 the documentation and/or other materials provided with the
65 distribution.
66 - Neither the name of Analog Devices, Inc. nor the names of its
67 contributors may be used to endorse or promote products derived
68 from this software without specific prior written permission.
69 - The use of this software may or may not infringe the patent rights
70 of one or more patent holders. This license does not release you
71 from the requirement that you obtain separate licenses from these
72 patent holders to use this software.
73 - Use of the software either in source or binary form, must be run
74 on or directly connected to an Analog Devices Inc. component.
75
76 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
77 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
78 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
79 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
80 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
81 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
82 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
83 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
84 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
85 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
86 */
87
88 //! @ingroup Analog_to_Digital_Converters
89 //! @{
90 //! @defgroup LTC23XX LTC23XX: 16/18-Bit Differential Input SoftSpan ADC with Wide Input Common Mode Range.
91 //! @}
92
93 /*! @file
94 @ingroup LTC23XX
95 Library for LTC23XX: 16/18-Bit Differential Input SoftSpan ADC with Wide Input Common Mode Range.
96 */
97 #include <Arduino.h>
98 #include <stdint.h>
99 #include <SPI.h>
100 #include "Linduino.h"
101 #include "UserInterface.h"
102 #include "QuikEval_EEPROM.h"
103 #include "LTC2348.h"
104 #include "LT_SPI.h"
105
106 void LTC23XX_create_config_word(uint8_t channel, uint8_t config_number, uint32_t *config_word)
107 {
108 *config_word = *config_word | (uint32_t(config_number & 0x07) << (channel * 3));
109 }
110
111 // Transmits 24 bits (3 bytes) of configuration information and
112 // reads back 24 bytes of data (3 bytes/ 24 bits for each channel)
113 // 24 bits: 18 bit data + 3 bit config + 3 bit channel number
114 // Read back is done in a new cycle
115 void LTC23XX_read(uint8_t cs_pin, uint32_t config_word, uint8_t data_array[24])
116 {
117 int i, j;
118 uint8_t tx_array[24];
119
120 tx_array[23] = (uint8_t)(config_word >> 16);
121 tx_array[22] = (uint8_t)(config_word >> 8);
122 tx_array[21] = (uint8_t)(config_word);
123 for (i = 20; i >= 0; --i)
124 {
125 tx_array[i] = 0;
126 }
127 spi_transfer_block(cs_pin, tx_array, data_array, 24);
128 }
129
130 int32_t sign_extend_17(uint32_t data)
131 {
132 uint8_t sign;
133 uint32_t mask = 0x20000;
134 int32_t data_signed = data;
135 sign = (data & mask) >> 17;
136 if (sign)
137 data_signed = data_signed | 0xFFFC0000;
138 return data_signed;
139 }
140
141 // Calculates the voltage from ADC output data depending on the channel configuration
142 float LTC23XX_voltage_calculator(uint32_t data, uint8_t channel_configuration)
143 {
144 float voltage;
145 int32_t data_signed;
146 switch (channel_configuration)
147 {
148 case 0:
149 voltage = 0;
150 break; // Disable Channel
151 case 1:
152 voltage = (float)data * (1.25 * VREF / 1.000) / POW2_18;
153 break;
154 case 2:
155 data_signed = sign_extend_17(data);
156 voltage = (float)data_signed * (1.25 * VREF / 1.024) / POW2_17;
157 break;
158 case 3:
159 data_signed = sign_extend_17(data);
160 voltage = (float)data_signed * (1.25 * VREF / 1.000) / POW2_17;
161 break;
162 case 4:
163 voltage = (float)data * (2.50 * VREF / 1.024) / POW2_18;
164 break;
165 case 5:
166 voltage = (float)data * (2.50 * VREF / 1.000) / POW2_18;
167 break;
168 case 6:
169 data_signed = sign_extend_17(data);
170 voltage = (float)data_signed * (2.50 * VREF / 1.024) / POW2_17;
171 break;
172 case 7:
173 data_signed = sign_extend_17(data);
174 voltage = (float)data_signed * (2.50 * VREF ) / POW2_17;
175 break;
176 }
177 return voltage;
178 }
179
sign
bool sign
Definition: Precision_Voltage_Source.ino:77
Linduino.h
Header File for Linduino Libraries and Demo Code.
POW2_18
#define POW2_18
Definition: LTC2348.h:110
channel
static uint8_t channel
LTC2305 Channel selection.
Definition: DC1444A.ino:127
LTC23XX_create_config_word
void LTC23XX_create_config_word(uint8_t channel, uint8_t config_number, uint32_t *config_word)
Creates 24-bit configuration word for the 8 channels.
Definition: LTC2348.cpp:106
VREF
#define VREF
Definition: LTC2348.h:109
sign_extend_17
int32_t sign_extend_17(uint32_t data)
Definition: LTC2348.cpp:130
LTC23XX_voltage_calculator
float LTC23XX_voltage_calculator(uint32_t data, uint8_t channel_configuration)
Calculates the voltage from ADC output data depending on the channel configuration.
Definition: LTC2348.cpp:142
data
union LT_union_int32_4bytes data
Definition: DC2094A.ino:138
LTC23XX_read
void LTC23XX_read(uint8_t cs_pin, uint32_t config_word, uint8_t data_array[24])
Transmits 24 bits (3 bytes) of configuration information and reads back 24 bytes of data (3 bytes/ 24...
Definition: LTC2348.cpp:115
QuikEval_EEPROM.h
QuikEval EEPROM Library.
LT_SPI.h
LT_SPI: Routines to communicate with ATmega328P&#39;s hardware SPI port.
LTC2348.h
LTC2348-18: Octal, 18-Bit, 200ksps Differential ±10.24V Input SoftSpan ADC with Wide Input Common Mod...
UserInterface.h
i
static int i
Definition: DC2430A.ino:184
spi_transfer_block
void spi_transfer_block(uint8_t cs_pin, uint8_t *tx, uint8_t *rx, uint8_t length)
Reads and sends a byte array.
Definition: LT_SPI.cpp:125
voltage
static float voltage
Definition: DC2289AA.ino:71
POW2_17
#define POW2_17
Definition: LTC2348.h:111