Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
LTC2380.cpp
Go to the documentation of this file.
1 /*!
2 LTC2376-16: 16-Bit, 250Ksps ADC
3 LTC2376-18: 18-Bit, 250Ksps ADC
4 LTC2376-20: 20-Bit, 250Ksps ADC
5 LTC2377-16: 16-Bit, 500Ksps ADC
6 LTC2377-18: 18-Bit, 500Ksps ADC
7 LTC2377-20: 20-Bit, 500Ksps ADC
8 LTC2378-16: 16-Bit, 1Msps ADC
9 LTC2378-18: 18-Bit, 1Msps ADC
10 LTC2378-20: 20-Bit, 1Msps ADC
11 LTC2379-18: 18-Bit, 1.6Msps ADC
12 LTC2380-16: 16-Bit, 2Msps ADC
13 
14 @verbatim
15 
16 The following parts (DUT) are pin-compatible, 16/18/20-bit A/D converters with serial I/O, and an internal reference:
17 LTC2376-16: 16-Bit, 250Ksps ADC
18 LTC2376-18: 18-Bit, 250Ksps ADC
19 LTC2376-20: 20-Bit, 250Ksps ADC
20 LTC2377-16: 16-Bit, 500Ksps ADC
21 LTC2377-18: 18-Bit, 500Ksps ADC
22 LTC2377-20: 20-Bit, 500Ksps ADC
23 LTC2378-16: 16-Bit, 1Msps ADC
24 LTC2378-18: 18-Bit, 1Msps ADC
25 LTC2378-20: 20-Bit, 1Msps ADC
26 LTC2379-18: 18-Bit, 1.6Msps ADC
27 LTC2380-16: 16-Bit, 2Msps ADC
28 
29 The DUTs typically draw only 8.4 mA from a single 2.5V supply. The automatic nap and sleep modes benefit power sensitive applications.
30 
31 The DUTs DC performance is outstanding with a +/-0.5 ppm INL specification and
32 no missing codes over temperature. The signal-to-noise ratio (SNR) for the LTC2380 is typically 104 dB, with the internal reference.
33 
34 @endverbatim
35 
36 http://www.linear.com/product/LTC2376-16
37 http://www.linear.com/product/LTC2376-18
38 http://www.linear.com/product/LTC2376-20
39 http://www.linear.com/product/LTC2377-16
40 http://www.linear.com/product/LTC2377-18
41 http://www.linear.com/product/LTC2377-20
42 http://www.linear.com/product/LTC2378-16
43 http://www.linear.com/product/LTC2378-18
44 http://www.linear.com/product/LTC2378-20
45 http://www.linear.com/product/LTC2379-18
46 http://www.linear.com/product/LTC2380-16
47 
48 http://www.linear.com/product/LTC2376-16#demoboards
49 http://www.linear.com/product/LTC2376-18#demoboards
50 http://www.linear.com/product/LTC2376-20#demoboards
51 http://www.linear.com/product/LTC2377-16#demoboards
52 http://www.linear.com/product/LTC2377-18#demoboards
53 http://www.linear.com/product/LTC2377-20#demoboards
54 http://www.linear.com/product/LTC2378-16#demoboards
55 http://www.linear.com/product/LTC2378-18#demoboards
56 http://www.linear.com/product/LTC2378-20#demoboards
57 http://www.linear.com/product/LTC2379-18#demoboards
58 http://www.linear.com/product/LTC2380-16#demoboards
59 
60 
61 Copyright 2018(c) Analog Devices, Inc.
62 
63 All rights reserved.
64 
65 Redistribution and use in source and binary forms, with or without
66 modification, are permitted provided that the following conditions are met:
67  - Redistributions of source code must retain the above copyright
68  notice, this list of conditions and the following disclaimer.
69  - Redistributions in binary form must reproduce the above copyright
70  notice, this list of conditions and the following disclaimer in
71  the documentation and/or other materials provided with the
72  distribution.
73  - Neither the name of Analog Devices, Inc. nor the names of its
74  contributors may be used to endorse or promote products derived
75  from this software without specific prior written permission.
76  - The use of this software may or may not infringe the patent rights
77  of one or more patent holders. This license does not release you
78  from the requirement that you obtain separate licenses from these
79  patent holders to use this software.
80  - Use of the software either in source or binary form, must be run
81  on or directly connected to an Analog Devices Inc. component.
82 
83 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
84 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
85 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
86 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
87 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
88 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
89 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
90 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
91 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
92 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
93 */
94 
95 //! @ingroup Analog_to_Digital_Converters
96 //! @{
97 //! @defgroup LTC2380 LTC2380: 16/18/20-Bit 1Msps ADC
98 //! @}
99 
100 /*! @file
101  @ingroup LTC2380
102  Library for LTC2380: 16/18/20-Bit 1Msps ADC
103 */
104 
105 #include <Arduino.h>
106 #include <stdint.h>
107 #include "Linduino.h"
108 #include "LT_SPI.h"
109 #include "LTC2380.h"
110 #include <SPI.h>
111 
112 
113 // Reads from a SPI LTC2380-XX device that has no configuration word and a 32 bit output word in 2's complement format.
114 void LTC2380_read(uint8_t cs, int32_t *ptr_adc_code)
115 {
116  LT_union_int16_2bytes command; // LTC2380 data and command
117  command.LT_uint16 = 0; // Set to zero, not necessary but avoids
118  // random data in scope shots.
119 
120 //Form a four byte object to hold four bytes of data
121  LT_union_int32_4bytes data; //instantiate the union
122  data.LT_byte[3] = 0;
123  data.LT_byte[2] = 0;
124  data.LT_byte[1] = 0;
125  data.LT_byte[0] = 0;
126 
127  spi_transfer_block(cs,command.LT_byte,data.LT_byte,4);
128 
129  *ptr_adc_code = data.LT_int32;
130 
131  return;
132 }
133 
134 
135 // Calculates the voltage corresponding to an adc code in 2's complement, given the reference voltage (in volts)
136 float LTC2380_code_to_voltage(int32_t adc_code, uint8_t gain_compression, float vref)
137 {
138  float voltage;
139 
140  if (gain_compression == 1)
141  vref = 0.8*vref;
142 
143  voltage = (float)adc_code;
144  voltage = voltage / (pow(2,31)-1); //! 2) This calculates the input as a fraction of the reference voltage (dimensionless)
145  voltage = voltage * vref + 0.1; //! 3) Multiply fraction by Vref to get the actual voltage at the input (in volts)
146 
147  return(voltage);
148 }
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
Header File for Linduino Libraries and Demo Code.
union LT_union_int32_4bytes data
Definition: DC2094A.ino:138
void LTC2380_read(uint8_t cs, int32_t *ptr_adc_code)
Reads the LTC2380 and returns 32-bit data in 2&#39;s complement format.
Definition: LTC2380.cpp:114
uint16_t LT_uint16
16-bit unsigned integer to be converted to two bytes
Definition: Linduino.h:102
int32_t LT_int32
32-bit signed integer to be converted to four bytes
Definition: Linduino.h:110
LT_SPI: Routines to communicate with ATmega328P&#39;s hardware SPI port.
float LTC2380_code_to_voltage(int32_t adc_code, uint8_t gain_compression, float vref)
Calculates the LTC2380 input voltage given the binary data and lsb weight.
Definition: LTC2380.cpp:136
This union splits one int32_t (32-bit signed integer) or uint32_t (32-bit unsigned integer) four uint...
Definition: Linduino.h:108
This union splits one int16_t (16-bit signed integer) or uint16_t (16-bit unsigned integer) into two ...
Definition: Linduino.h:99
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
static float voltage
Definition: DC2289AA.ino:71
uint8_t LT_byte[2]
2 bytes (unsigned 8-bit integers) to be converted to a 16-bit signed or unsigned integer ...
Definition: Linduino.h:103
LTC2376-16: 16-Bit, 250Ksps ADC LTC2376-18: 18-Bit, 250Ksps ADC LTC2376-20: 20-Bit, 250Ksps ADC LTC2377-16: 16-Bit, 500Ksps ADC LTC2377-18: 18-Bit, 500Ksps ADC LTC2377-20: 20-Bit, 500Ksps ADC LTC2378-16: 16-Bit, 1Msps ADC LTC2378-18: 18-Bit, 1Msps ADC LTC2378-20: 20-Bit, 1Msps ADC LTC2379-18: 18-Bit, 1.6Msps ADC LTC2380-16: 16-Bit, 2Msps ADC.
static uint32_t adc_code
Definition: DC2071AA.ino:113