Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
LTC2449.cpp
Go to the documentation of this file.
1 
2 /*!
3 LTC2449: 24-Bit, 16-Channel Delta Sigma ADCs with Selectable Speed/Resolution.
4 LTC2442: 24-Bit, 4-Channel Delta Sigma ADC with Integrated Amplifier
5 LTC2448: 24-Bit, 8-/16-Channel Delta Sigma ADCs with Selectable Speed/Resolution
6 
7 @verbatim
8 
9 The LTC2444/LTC2445/LTC2448/LTC2449 are 8-/16-channel (4-/8-differential)
10 high speed 24-bit No Latency Delta Sigma ADCs. They use a proprietary
11 delta-sigma architecture enabling variable speed/resolution. Through a
12 simple 4-wire serial interface, ten speed/resolution combinations
13 6.9Hz/280nVRMS to 3.5kHz/25uVRMS (4kHz with external oscillator) can be
14 selected with no latency between conversion results or shift in DC accuracy
15 (offset, full-scale, linearity, drift). Additionally, a 2X speed mode can
16 be selected enabling output rates up to 7kHz (8kHz if an external
17 oscillator is used) with one cycle latency.
18 
19 @endverbatim
20 
21 http://www.linear.com/product/LTC2449
22 http://www.linear.com/product/LTC2442
23 http://www.linear.com/product/LTC2448
24 
25 http://www.linear.com/product/LTC2449#demoboards
26 http://www.linear.com/product/LTC2442#demoboards
27 http://www.linear.com/product/LTC2448#demoboards
28 
29 
30 Copyright 2018(c) Analog Devices, Inc.
31 
32 All rights reserved.
33 
34 Redistribution and use in source and binary forms, with or without
35 modification, are permitted provided that the following conditions are met:
36  - Redistributions of source code must retain the above copyright
37  notice, this list of conditions and the following disclaimer.
38  - Redistributions in binary form must reproduce the above copyright
39  notice, this list of conditions and the following disclaimer in
40  the documentation and/or other materials provided with the
41  distribution.
42  - Neither the name of Analog Devices, Inc. nor the names of its
43  contributors may be used to endorse or promote products derived
44  from this software without specific prior written permission.
45  - The use of this software may or may not infringe the patent rights
46  of one or more patent holders. This license does not release you
47  from the requirement that you obtain separate licenses from these
48  patent holders to use this software.
49  - Use of the software either in source or binary form, must be run
50  on or directly connected to an Analog Devices Inc. component.
51 
52 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
53 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
54 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
55 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
56 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
57 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
58 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
59 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
60 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
61 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62 */
63 
64 //! @ingroup Analog_to_Digital_Converters
65 //! @{
66 //! @defgroup LTC2449 LTC2449: 24-Bit, 16-Channel Delta Sigma ADCs with Selectable Speed/Resolution
67 //! @}
68 
69 /*! @file
70  @ingroup LTC2449
71  Library for LTC2449: 24-Bit, 16-Channel Delta Sigma ADCs with Selectable Speed/Resolution
72 */
73 
74 #include <stdint.h>
75 #include <Arduino.h>
76 #include "Linduino.h"
77 #include "LT_SPI.h"
78 #include "LTC2449.h"
79 #include <SPI.h>
80 
81 //! Define the SPI CS pin
82 #ifndef LTC2449_CS
83 #define LTC2449_CS QUIKEVAL_CS
84 #endif
85 
86 int8_t LTC2449_EOC_timeout(uint8_t cs, uint16_t miso_timeout)
87 // Checks for EOC with a specified timeout (ms)
88 {
89  uint16_t timer_count = 0; // Timer count for MISO
90  output_low(cs); //! 1) Pull CS low
91  while (1) //! 2) Wait for SDO (MISO) to go low
92  {
93  if (input(MISO) == 0) break; //! 3) If SDO is low, break loop
94  if (timer_count++>miso_timeout) // If timeout, return 1 (failure)
95  {
96  output_high(cs); // Pull CS high
97  return(1);
98  }
99  else
100  delay(1);
101  }
102  output_high(cs); // Pull CS high
103  return(0);
104 }
105 
106 // Reads from LTC2449.
107 void LTC2449_read(uint8_t cs, uint16_t adc_command, uint32_t *adc_code)
108 {
109  LT_union_int32_4bytes data, command; // LTC2449 data and command
110  LT_union_int16_2bytes temp_comm;
111  temp_comm.LT_int16 = adc_command;
112  command.LT_byte[3] = temp_comm.LT_byte[1];
113  command.LT_byte[2] = temp_comm.LT_byte[0];
114  command.LT_byte[1] = 0;
115  command.LT_byte[0] = 0;
116 
117  output_low(cs); //! 1) Pull CS low
118 
119  spi_transfer_block(cs, command.LT_byte, data.LT_byte, (uint8_t)4); //! 2) Transfer arrays
120 
121  output_high(cs); //! 3) Pull CS high
122  *adc_code = data.LT_int32;
123 }
124 
125 // Calculates the voltage corresponding to an adc code, given lsb weight (in volts) and the calibrated
126 // adc offset code (zero code that is subtracted from adc_code).
128 {
129  float adc_voltage;
130  adc_code -= 536870912; //! 1) Converts offset binary to binary
131  adc_voltage=(float)(adc_code+LTC2449_offset_code)*LTC2449_lsb; //! 2) Calculate voltage from ADC code, lsb, offset.
132  return(adc_voltage);
133 }
134 
135 // Calculate the lsb weight and offset code given a full-scale code and a measured zero-code.
136 void LTC2449_cal_voltage(int32_t zero_code, int32_t fs_code, float zero_voltage, float fs_voltage, float *LTC2449_lsb, int32_t *LTC2449_offset_code)
137 {
138  zero_code -= 536870912; //! 1) Converts zero code from offset binary to binary
139  fs_code -= 536870912; //! 2) Converts full scale code from offset binary to binary
140 
141  float temp_offset;
142  *LTC2449_lsb = (fs_voltage-zero_voltage)/((float)(fs_code - zero_code)); //! 3) Calculate the LSB
143 
144  temp_offset = (zero_voltage/ *LTC2449_lsb) - zero_code; //! 4) Calculate Unipolar offset
145  temp_offset = (temp_offset > (floor(temp_offset) + 0.5)) ? ceil(temp_offset) : floor(temp_offset); //! 5) Round
146  *LTC2449_offset_code = (int32_t)temp_offset; //! 6) Cast as int32_t
147 }
static uint8_t adc_command
Definition: DC2071AA.ino:111
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
#define output_high(pin)
Set "pin" high.
Definition: Linduino.h:75
Header File for Linduino Libraries and Demo Code.
void LTC2449_cal_voltage(int32_t zero_code, int32_t fs_code, float zero_voltage, float fs_voltage, float *LTC2449_lsb, int32_t *LTC2449_offset_code)
Calculate the lsb weight and offset code given a full-scale code and a measured zero-code.
Definition: LTC2449.cpp:136
static float adc_voltage
Definition: DC2071AA.ino:115
union LT_union_int32_4bytes data
Definition: DC2094A.ino:138
float LTC2449_code_to_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...
Definition: LTC2449.cpp:127
int16_t LT_int16
16-bit signed integer to be converted to two bytes
Definition: Linduino.h:101
#define output_low(pin)
Set "pin" low.
Definition: Linduino.h:72
#define input(pin)
Return the state of pin "pin".
Definition: Linduino.h:79
int32_t LT_int32
32-bit signed integer to be converted to four bytes
Definition: Linduino.h:110
LT_SPI: Routines to communicate with ATmega328P&#39;s hardware SPI port.
LTC2449: 24-Bit, 16-Channel Delta Sigma ADCs with Selectable Speed/Resolution.
This union splits one int32_t (32-bit signed integer) or uint32_t (32-bit unsigned integer) four uint...
Definition: Linduino.h:108
This union splits one int16_t (16-bit signed integer) or uint16_t (16-bit unsigned integer) into two ...
Definition: Linduino.h:99
static float LTC2449_lsb
The LTC2449 ideal reference voltage.
Definition: DC1410AB.ino:102
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
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 int32_t LTC2449_offset_code
Ideal offset for a perfect part.
Definition: DC742A.ino:127
int8_t LTC2449_EOC_timeout(uint8_t cs, uint16_t miso_timeout)
Define the SPI CS pin.
Definition: LTC2449.cpp:86
static uint32_t adc_code
Definition: DC2071AA.ino:113
void LTC2449_read(uint8_t cs, uint16_t adc_command, uint32_t *adc_code)
Reads from LTC2449.
Definition: LTC2449.cpp:107