| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

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