| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

LTC2485.cpp
Go to the documentation of this file.
1 /*!
2 LTC2485: 24-Bit Delta Sigma ADC with Easy Drive Input Current Cancellation and
3 I2C Interface
4
5 @verbatim
6
7 The LTC2485 combines a 24-bit plus sign No Latency Delta Sigma analog-to-digital
8 converter with patented Easy Drive technology and I2C digital interface. The
9 patented sampling scheme eliminates dynamic input current errors and the
10 shortcomings of on-chip buffering through automatic cancellation of differential
11 input current. This allows large external source impedances and input signals,
12 with rail-to-rail input range to be directly digitized while maintaining
13 exceptional DC accuracy.
14
15 @endverbatim
16
17
18 Copyright 2018(c) Analog Devices, Inc.
19
20 All rights reserved.
21
22 Redistribution and use in source and binary forms, with or without
23 modification, are permitted provided that the following conditions are met:
24 - Redistributions of source code must retain the above copyright
25 notice, this list of conditions and the following disclaimer.
26 - Redistributions in binary form must reproduce the above copyright
27 notice, this list of conditions and the following disclaimer in
28 the documentation and/or other materials provided with the
29 distribution.
30 - Neither the name of Analog Devices, Inc. nor the names of its
31 contributors may be used to endorse or promote products derived
32 from this software without specific prior written permission.
33 - The use of this software may or may not infringe the patent rights
34 of one or more patent holders. This license does not release you
35 from the requirement that you obtain separate licenses from these
36 patent holders to use this software.
37 - Use of the software either in source or binary form, must be run
38 on or directly connected to an Analog Devices Inc. component.
39
40 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
41 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
42 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
43 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
44 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
45 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
46 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
47 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
48 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
49 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50 */
51
52 //! @ingroup Analog_to_Digital_Converters
53 //! @{
54 //! @defgroup LTC2485 LTC2485: 24-Bit Delta Sigma ADC with Easy Drive Input Current Cancellation and I2C Interface
55 //! @}
56
57 /*! @file
58 @ingroup LTC2485
59 Library for LTC2485: 24-Bit Delta Sigma ADC with Easy Drive Input Current Cancellation and I2C Interface
60 */
61
62
63 #include <stdint.h>
64 #include <Arduino.h>
65 #include "Linduino.h"
66 #include "LT_I2C.h"
67 #include "LTC2485.h"
68
69 // Reads from LTC2485
70 int8_t LTC2485_read(uint8_t i2c_address, uint8_t adc_command, int32_t *adc_code, uint16_t eoc_timeout)
71 {
72 int8_t ack;
73 uint16_t timer_count = 0; // Timer count to wait for ACK
74 LT_union_int32_4bytes data;
75
76 while (1)
77 {
78 ack = i2c_read_block_data(i2c_address, adc_command, 4, data.LT_byte);
79 if (!ack)
80 break; // !ack indicates success
81 if (timer_count++>eoc_timeout) // If timeout, return 1 (failure)
82 return (1);
83 else
84 delay(1);
85 }
86
87 if (data.LT_byte[3]==0xC0)
88 {
89
90 *adc_code= 2147483647; //Positive Overflow
91 return (ack);
92 }
93
94 if (data.LT_byte[3]==0x3F)
95 {
96 *adc_code=-2147483648; //Negative Overflow
97 return (ack);
98 }
99
100 data.LT_byte[3]=data.LT_byte[3] & 0x7F; //Remove sign bit
101
102 data.LT_int32 = data.LT_int32 << 1; //shift left by one bit to restore two's complement
103
104 data.LT_int32/=256; //Convert back to 24 bit value from 32 bits.
105 *adc_code=data.LT_int32;
106
107 return (ack); // Success
108 }
i2c_address
uint8_t i2c_address
adc_command
static uint8_t adc_command
Definition: DC2071AA.ino:111
i2c_read_block_data
int8_t i2c_read_block_data(uint8_t address, uint8_t command, uint8_t length, uint8_t *values)
Read a block of data, starting at register specified by "command" and ending at (command + length - 1...
Definition: LT_I2C.cpp:244
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
LTC2485.h
LTC2485: 24-Bit Delta Sigma ADC with Easy Drive Input Current Cancellation and I2C Interface...
Linduino.h
Header File for Linduino Libraries and Demo Code.
data
union LT_union_int32_4bytes data
Definition: DC2094A.ino:138
eoc_timeout
static uint16_t eoc_timeout
timeout in ms
Definition: LTC2492_Panel_Meter.ino:135
LTC2485_read
int8_t LTC2485_read(uint8_t i2c_address, uint8_t adc_command, int32_t *adc_code, uint16_t eoc_timeout)
Reads from LTC2485 ADC that accepts an 8 bit configuration and returns a 24 bit result.
Definition: LTC2485.cpp:70
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_I2C.h
LT_I2C: Routines to communicate with ATmega328P&#39;s hardware I2C 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
adc_code
static uint32_t adc_code
Definition: DC2071AA.ino:113