| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

LTC2412.cpp
Go to the documentation of this file.
1 /*!
2 LTC2412: 2-Channel Differential Input 24-Bit No Latency Delta Sigma ADC
3 LTC2413: 24-Bit No Latency Delta Sigma ADC with Simultaneous 50Hz/60Hz Rejection ADC
4
5 @verbatim
6
7 The LTC2412 is a 2-channel differential input micropower 24-bit No Latency
8 Delta-Sigma analog-to-digital converter with an integrated oscillator. It
9 provides 2ppm INL and 0.16ppm RMS noise over the entire supply range. The two
10 differential channels are converted alternately with channel ID included in
11 the conversion results.
12
13 The converter accepts any external differential reference voltage from 0.1V to
14 VCC for flexible ratiometric and remote sensingmeasurement configurations. The
15 full-scale differential input range is from –0.5VREF to 0.5VREF. The LTC2412
16 communicates through a flexible 3-wire digital interface which is compatible
17 with SPI and MICROWIRE protocols.
18
19 @endverbatim
20
21 http://www.linear.com/product/LTC2412
22 http://www.linear.com/product/LTC2413
23
24 http://www.linear.com/product/LTC2412#demoboards
25 http://www.linear.com/product/LTC2413#demoboards
26
27
28 Copyright 2018(c) Analog Devices, Inc.
29
30 All rights reserved.
31
32 Redistribution and use in source and binary forms, with or without
33 modification, are permitted provided that the following conditions are met:
34 - Redistributions of source code must retain the above copyright
35 notice, this list of conditions and the following disclaimer.
36 - Redistributions in binary form must reproduce the above copyright
37 notice, this list of conditions and the following disclaimer in
38 the documentation and/or other materials provided with the
39 distribution.
40 - Neither the name of Analog Devices, Inc. nor the names of its
41 contributors may be used to endorse or promote products derived
42 from this software without specific prior written permission.
43 - The use of this software may or may not infringe the patent rights
44 of one or more patent holders. This license does not release you
45 from the requirement that you obtain separate licenses from these
46 patent holders to use this software.
47 - Use of the software either in source or binary form, must be run
48 on or directly connected to an Analog Devices Inc. component.
49
50 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
51 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
52 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
53 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
54 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
55 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
56 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
57 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
58 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
59 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
60 */
61
62 //! @ingroup Analog_to_Digital_Converters
63 //! @{
64 //! @defgroup LTC2412 LTC2412: 2-Channel Differential Input 24-Bit No Latency Delta Sigma ADC
65 //! @}
66
67 /*! @file
68 @ingroup LTC2412
69 Library for LTC2412: 2-Channel Differential Input 24-Bit No Latency Delta Sigma ADC
70 */
71
72 #include <stdint.h>
73 #include <Arduino.h>
74 #include "Linduino.h"
75 #include "LT_SPI.h"
76 #include "LTC2412.h"
77 #include <SPI.h>
78
79 int8_t LTC2412_EOC_timeout(uint8_t cs, uint16_t miso_timeout)
80 // Checks for EOC with a specified timeout
81 {
82 uint16_t timer_count = 0; // Timer count for MISO
83 output_low(cs); //! 1) Pull CS low
84 while (1) //! 2) Wait for SDO (MISO) to go low
85 {
86 if (input(MISO) == 0) break; //! 3) If SDO is low, break loop
87 if (timer_count++>miso_timeout) // If timeout, return 1 (failure)
88 {
89 output_high(cs); // Pull CS high
90 return(1);
91 }
92 else
93 delay(1);
94 }
95 return(0);
96 }
97
98 void LTC2412_read(uint8_t cs, uint32_t *adc_code)
99 // Reads the LTC2412 result
100 {
101 LT_union_int32_4bytes data, command;
102 command.LT_byte[3] = 0;
103 command.LT_byte[2] = 0;
104 command.LT_byte[1] = 0;
105 command.LT_byte[0] = 0;
106
107 output_low(cs); //! 1) Pull CS low
108 spi_transfer_block(cs, command.LT_byte, data.LT_byte, (uint8_t)4); //! 2) Transfer 4 bytes
109 output_high(cs); //! 3) Pull CS high
110 *adc_code = data.LT_int32;
111 }
112
113 float LTC2412_code_to_voltage(int32_t adc_code, float LTC2412_lsb , int32_t LTC2412_offset_code)
114 // Calculates the LTC2412 input voltage
115 {
116 float adc_voltage;
117 uint8_t sign;
118 sign = (uint8_t)(adc_code >> 29);
119 sign = sign & 1;
120 adc_code = adc_code>>5; //! 1) Bit-shift ADC code to the right 5 bits
121 adc_code = adc_code & 0xFFFFFF;
122 if (!sign)
123 adc_code -= 16777216; //! 2) Convert ADC code from offset binary to binary
124 adc_voltage=((float)adc_code+LTC2412_offset_code)*(LTC2412_lsb); //! 3) Calculate voltage from ADC code, lsb, offset.
125 return(adc_voltage);
126 }
sign
bool sign
Definition: Precision_Voltage_Source.ino:77
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
LTC2412_code_to_voltage
float LTC2412_code_to_voltage(int32_t adc_code, float LTC2412_lsb, int32_t LTC2412_offset_code)
Calculates the LTC2412 input voltage.
Definition: LTC2412.cpp:113
output_high
#define output_high(pin)
Set "pin" high.
Definition: Linduino.h:75
Linduino.h
Header File for Linduino Libraries and Demo Code.
adc_voltage
static float adc_voltage
Definition: DC2071AA.ino:115
LTC2412_EOC_timeout
int8_t LTC2412_EOC_timeout(uint8_t cs, uint16_t miso_timeout)
Checks for EOC with a specified timeout.
Definition: LTC2412.cpp:79
data
union LT_union_int32_4bytes data
Definition: DC2094A.ino:138
LTC2412_lsb
static float LTC2412_lsb
Ideal LSB voltage for a perfect part.
Definition: DC746A.ino:114
LTC2412_read
void LTC2412_read(uint8_t cs, uint32_t *adc_code)
Reads the LTC2412 result.
Definition: LTC2412.cpp:98
output_low
#define output_low(pin)
Set "pin" low.
Definition: Linduino.h:72
input
#define input(pin)
Return the state of pin "pin".
Definition: Linduino.h:79
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.
LTC2412.h
LTC2412: 2-Channel Differential Input 24-Bit No Latency Delta Sigma ADC LTC2413: 24-Bit No Latency De...
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
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
adc_code
static uint32_t adc_code
Definition: DC2071AA.ino:113
LTC2412_offset_code
static int32_t LTC2412_offset_code
Ideal offset for a perfect part.
Definition: DC746A.ino:115