Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
LTC2422.cpp
Go to the documentation of this file.
1 /*!
2 LTC2422: 1-/2-Channel 20-Bit uPower No Latency Delta-Sigma ADC in MSOP-10
3 
4 @verbatim
5 
6 The LTC2421/LTC2422 are 1- and 2-channel 2.7V to 5.5V micropower 20-bit analog-
7 to-digital converters with an integrated oscillator, 8ppm INL and 1.2ppm RMS
8 noise. These ultrasmall devices use delta-sigma technology and a new digital
9 filter architecture that settles in a single cycle. This eliminates the latency
10 found in conventional delta-sigma converters and simplifies multiplexed
11 applications. Through a single pin, the LTC2421/LTC2422 can be configured for
12 better than 110dB rejection at 50Hz or 60Hz +/-2%, or can be driven by an
13 external oscillator for a user defined rejection frequency in the range 1Hz to
14 120Hz. The internal oscillator requires no external frequency setting
15 components.
16 
17 @endverbatim
18 
19 http://www.linear.com/product/LTC2422
20 
21 http://www.linear.com/product/LTC2422#demoboard
22 
23 
24 Copyright 2018(c) Analog Devices, Inc.
25 
26 All rights reserved.
27 
28 Redistribution and use in source and binary forms, with or without
29 modification, are permitted provided that the following conditions are met:
30  - Redistributions of source code must retain the above copyright
31  notice, this list of conditions and the following disclaimer.
32  - Redistributions in binary form must reproduce the above copyright
33  notice, this list of conditions and the following disclaimer in
34  the documentation and/or other materials provided with the
35  distribution.
36  - Neither the name of Analog Devices, Inc. nor the names of its
37  contributors may be used to endorse or promote products derived
38  from this software without specific prior written permission.
39  - The use of this software may or may not infringe the patent rights
40  of one or more patent holders. This license does not release you
41  from the requirement that you obtain separate licenses from these
42  patent holders to use this software.
43  - Use of the software either in source or binary form, must be run
44  on or directly connected to an Analog Devices Inc. component.
45 
46 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
47 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
48 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
49 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
50 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
51 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
52 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
53 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
54 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
55 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56 */
57 
58 //! @ingroup Analog_to_Digital_Converters
59 //! @{
60 //! @defgroup LTC2422 LTC2422: 1-/2-Channel 20-Bit uPower No Latency Delta-Sigma ADC in MSOP-10
61 //! @}
62 
63 /*! @file
64  @ingroup LTC2422
65  Library for LLTC2422: 1-/2-Channel 20-Bit uPower No Latency Delta-Sigma ADC in MSOP-10
66 */
67 
68 #include <stdint.h>
69 #include <Arduino.h>
70 #include "Linduino.h"
71 //#include "LT_I2C.h"
72 #include "LT_SPI.h"
73 #include "LTC2422.h"
74 #include <SPI.h>
75 
76 uint8_t LTC2422_EOC_timeout(uint8_t cs, uint16_t miso_timeout)
77 // Checks for EOC with a specified timeout (ms)
78 {
79  uint16_t timer_count = 0; // Timer count for MISO
80  output_low(cs); //! 1) Pull CS low
81  while (1) //! 2) Wait for SDO (MISO) to go low
82  {
83  if (input(MISO) == 0) break; //! 3) If SDO is low, break loop
84  if (timer_count++>miso_timeout) // If timeout, return 1 (failure)
85  {
86  output_high(cs); // Pull CS high
87  return(1);
88  }
89  else
90  delay(1);
91  }
92  output_high(cs); // Pull CS high
93  return(0);
94 }
95 
96 // Read ADC code from the LTC2422. Does not wait for end-of-conversion.
97 // To automatically wait for conversion to complete, use the LTC2422_EOC_timeout before this function..
98 void LTC2422_adc_read(uint8_t cs, uint8_t *adc_channel, int32_t *code)
99 {
100  LT_union_int32_4bytes data, command; // LTC2422 data
101 
102  command.LT_int32 = 0x00000000;
103 
104  spi_transfer_block(LTC2422_CS, command.LT_byte , data.LT_byte, (uint8_t)3);
105  if (data.LT_byte[2] & 0x40) // Obtains Channel Number
106  {
107  *adc_channel = 1;
108  }
109  else
110  {
111  *adc_channel = 0;
112  }
113  data.LT_byte[2] &= 0x3F; // Clear channel bit here so code to voltage function doesn't have to.
114  data.LT_byte[3] = 0x00; // Make sure MS Byte is zero, data is right-justified.
115  *code = data.LT_int32; // Return data
116 }
117 
118 // Calculates the voltage given the ADC code and lsb weight.
120 {
121  float adc_voltage;
122  adc_code -= 0x00200000; //! 1) Subtract offset
123  adc_voltage=((float)adc_code)*LTC2422_lsb; //! 2) Calculate voltage from ADC code and lsb
124  return(adc_voltage);
125 }
126 
127 // Calculates the lsb weight from the given reference voltage.
128 void LTC2422_calculate_lsb(float LTC2422_reference_voltage, float *LTC2422_lsb)
129 {
130  *LTC2422_lsb = LTC2422_reference_voltage/(1048575); //! 1) Calculate the LSB, ref_voltage /(2^20-1)
131 }
132 
133 
LTC2422: 1-/2-Channel 20-Bit uPower No Latency Delta-Sigma ADC in MSOP-10.
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
float LTC2422_code_to_voltage(int32_t adc_code, float LTC2422_lsb)
Calculates the voltage given the ADC code and lsb weight.
Definition: LTC2422.cpp:119
#define output_high(pin)
Set "pin" high.
Definition: Linduino.h:75
Header File for Linduino Libraries and Demo Code.
void LTC2422_adc_read(uint8_t cs, uint8_t *adc_channel, int32_t *code)
Read ADC code from the LTC2422.
Definition: LTC2422.cpp:98
static float adc_voltage
Definition: DC2071AA.ino:115
union LT_union_int32_4bytes data
Definition: DC2094A.ino:138
#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.
void LTC2422_calculate_lsb(float LTC2422_reference_voltage, float *LTC2422_lsb)
Calculates the lsb weight from the given reference voltage.
Definition: LTC2422.cpp:128
This union splits one int32_t (32-bit signed integer) or uint32_t (32-bit unsigned integer) four uint...
Definition: Linduino.h:108
#define LTC2422_CS
Define the SPI CS pin.
Definition: LTC2422.h:104
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
static float LTC2422_lsb
The LTC2422 least significant bit value with 5V full-scale.
Definition: DC934A.ino:135
uint8_t LTC2422_EOC_timeout(uint8_t cs, uint16_t miso_timeout)
Checks for EOC with a specified timeout.
Definition: LTC2422.cpp:76
static uint32_t adc_code
Definition: DC2071AA.ino:113