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