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