Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
LTC2484.cpp
Go to the documentation of this file.
1 /*!
2 LTC2484: 24-Bit Delta Sigma ADC with Easy Drive Input Current Cancellation
3 
4 @verbatim
5 
6 The LTC2484 combines a 24-bit no latency delta-sigma analog-to-digital
7 converter with patented Easy Drive technology. The patented sampling scheme
8 eliminates dynamic input current errors and the shortcomings of on-chip
9 buffering through automatic cancellation of differential input current. This
10 allows large external source impedances and input signals with rail-to-rail
11 input range to be directly digitized while maintaining exceptional DC accuracy.
12 
13 The LTC2484 includes an on-chip oscillator. The LTC2484 can be configured to
14 reject line frequencies. 50Hz, 60Hz or simultaneous 50Hz/60Hz line frequency
15 rejection can be selected as well as a 2x speed-up mode.
16 
17 The LTC2484 allows a wide common mode input range (0V to VCC) independent of the
18 reference voltage. The reference can be as low as 100mV or can be tied directly
19 to VCC. The LTC2484 includes an on-chip trimmed oscillator, eliminating the need
20 for external crystals or oscillators. Absolute accuracy and low drift are
21 automatically maintained through continuous, transparent, offset and full-scale
22 calibration.
23 
24 @endverbatim
25 
26 http://www.linear.com/product/LTC2484
27 
28 http://www.linear.com/product/LTC2484#demoboards
29 
30 
31 Copyright 2018(c) Analog Devices, Inc.
32 
33 All rights reserved.
34 
35 Redistribution and use in source and binary forms, with or without
36 modification, are permitted provided that the following conditions are met:
37  - Redistributions of source code must retain the above copyright
38  notice, this list of conditions and the following disclaimer.
39  - Redistributions in binary form must reproduce the above copyright
40  notice, this list of conditions and the following disclaimer in
41  the documentation and/or other materials provided with the
42  distribution.
43  - Neither the name of Analog Devices, Inc. nor the names of its
44  contributors may be used to endorse or promote products derived
45  from this software without specific prior written permission.
46  - The use of this software may or may not infringe the patent rights
47  of one or more patent holders. This license does not release you
48  from the requirement that you obtain separate licenses from these
49  patent holders to use this software.
50  - Use of the software either in source or binary form, must be run
51  on or directly connected to an Analog Devices Inc. component.
52 
53 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
54 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
55 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
56 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
57 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
58 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
59 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
60 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
61 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
62 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63  */
64 
65 //! @ingroup Analog_to_Digital_Converters
66 //! @{
67 //! @defgroup LTC2484 LTC2484: 24-Bit Delta Sigma ADC with Easy Drive Input Current Cancellation
68 //! @}
69 
70 /*! @file
71  @ingroup LTC2484
72  Library for LTC2484: 24-Bit Delta Sigma ADC with Easy Drive Input Current Cancellation
73 */
74 
75 #include <stdint.h>
76 #include <Arduino.h>
77 #include "Linduino.h"
78 #include "LT_SPI.h"
79 #include "LTC2484.h"
80 #include "LTC24XX_general.h"
81 #include <SPI.h>
82 
83 // Checks for EOC with a specified timeout
84 int8_t LTC2484_EOC_timeout(uint8_t cs, uint16_t miso_timeout)
85 {
86 
87  return LTC24XX_EOC_timeout(cs, miso_timeout);
88 }
89 
90 void LTC2484_read(uint8_t cs, uint8_t adc_command, int32_t *adc_code)
91 // Reads the LTC2484
92 {
93  LTC24XX_SPI_8bit_command_32bit_data(cs, adc_command, adc_code);
94 }
95 
97 // Calculates the LTC2484 input bipolar voltage
98 {
99  return(LTC24XX_diff_code_to_calibrated_voltage(adc_code, LTC2484_lsb, LTC2484_offset_code));
100 }
101 
102 float LTC2484_temperature(int32_t adc_code, float LTC2484_t0, float LTC2484_r0)
103 // Calculate the LTC2484 temperature.
104 {
105  adc_code -= 0x20000000; // Converts offset binary to binary
106  return (((((float) adc_code) / LTC2484_r0) * (LTC2484_t0 + 273)) - 273); // Calculate temperature from ADC code, t0, r0.
107 }
108 
109 void LTC2484_cal_voltage(int32_t zero_code, int32_t fs_code, float zero_voltage, float fs_voltage, float *LTC2484_lsb, int32_t *LTC2484_offset_code)
110 // Calibrate the lsb
111 {
112  zero_code -= 0x20000000; // Converts zero code from offset binary to binary
113  fs_code -= 0x20000000; // Converts full scale from offset binary to binary
114 
115  float temp_offset;
116  *LTC2484_lsb = (fs_voltage-zero_voltage)/((float)(fs_code - zero_code)); // Calculate the LSB
117 
118  temp_offset = (zero_voltage/ *LTC2484_lsb) - zero_code; // Calculate Unipolar offset
119  temp_offset = (temp_offset > (floor(temp_offset) + 0.5)) ? ceil(temp_offset) : floor(temp_offset); // Round
120  *LTC2484_offset_code = (int32_t)temp_offset; // Cast as int32_t
121 }
122 
123 void LTC2484_cal_temperature(int32_t adc_code, float temperature, float *LTC2484_t0, float *LTC2484_r0)
124 // Calibrate temperature
125 {
126  adc_code -= 0x20000000; // Converts offset binary to binary
127  *LTC2484_r0 = (float) adc_code; // Convert the adc_code to a float value
128  *LTC2484_t0 = temperature; // Store the calibration temperature
129 }
LTC2484: 24-Bit Delta Sigma ADC with Easy Drive Input Current Cancellation.
static uint8_t adc_command
Definition: DC2071AA.ino:111
Header File for Linduino Libraries and Demo Code.
int8_t LTC24XX_EOC_timeout(uint8_t cs, uint16_t miso_timeout)
Checks for EOC with a specified timeout.
static float LTC2484_t0
Nominal temperature.
Definition: DC939A.ino:133
static int32_t LTC2484_offset_code
Ideal offset.
Definition: DC939A.ino:132
static float LTC2484_r0
ADC code at the nominal temperature (420mV default)
Definition: DC939A.ino:134
float LTC24XX_diff_code_to_calibrated_voltage(int32_t adc_code, float LTC2449_lsb, int32_t LTC2449_offset_code)
Calculates the voltage corresponding to an ADC code, given lsb weight (in volts) and the calibrated A...
void LTC24XX_SPI_8bit_command_32bit_data(uint8_t cs, uint8_t adc_command, int32_t *adc_code)
Reads from LTC24XX ADC that accepts an 8 bit configuration and returns a 32 bit result.
float LTC2484_code_to_voltage(int32_t adc_code, float LTC2484_lsb, int32_t LTC2484_offset_code)
Calculates the LTC2484 input bipolar voltage.
Definition: LTC2484.cpp:96
LTC24XX General Library: Functions and defines for all SINC4 Delta Sigma ADCs.
float LTC2484_temperature(int32_t adc_code, float LTC2484_t0, float LTC2484_r0)
Calculate the LTC2484 temperature.
Definition: LTC2484.cpp:102
void LTC2484_cal_voltage(int32_t zero_code, int32_t fs_code, float zero_voltage, float fs_voltage, float *LTC2484_lsb, int32_t *LTC2484_offset_code)
Calibrate the lsb.
Definition: LTC2484.cpp:109
void LTC2484_read(uint8_t cs, uint8_t adc_command, int32_t *adc_code)
Read LTC2484 result, program configuration for next conversion.
Definition: LTC2484.cpp:90
static float LTC2484_lsb
Ideal LSB size, 5V/(2^29) for a 5V reference.
Definition: DC939A.ino:131
void LTC2484_cal_temperature(int32_t adc_code, float temperature, float *LTC2484_t0, float *LTC2484_r0)
Calibrate temperature.
Definition: LTC2484.cpp:123
LT_SPI: Routines to communicate with ATmega328P&#39;s hardware SPI port.
int8_t LTC2484_EOC_timeout(uint8_t cs, uint16_t miso_timeout)
Checks for EOC with a specified timeout.
Definition: LTC2484.cpp:84
static uint32_t adc_code
Definition: DC2071AA.ino:113