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