| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

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