| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

LTC1867.cpp
Go to the documentation of this file.
1
2 /*!
3 LTC1867: 16-Bit 8-Channel 200ksps ADC
4
5 @verbatim
6
7 The LTC1863/LTC1867 are pin-compatible, 8-channel 12-/16-bit A/D converters with
8 serial I/O, and an internal reference. The ADCs typically draw only 1.3mA from a
9 single 5V supply. The 8-channel input multiplexer can be configured for either
10 single-ended or differential inputs and unipolar or bipolar conversions (or
11 combinations thereof). The automatic nap and sleep modes benefit power sensitive
12 applications.
13
14 The LTC1867's DC performance is outstanding with a +/-2LSB INL specification and
15 no missing codes over temperature. The signal-to-noise ratio (SNR) for the
16 LTC1867 is typically 89dB, with the internal reference.
17
18 @endverbatim
19
20 http://www.linear.com/product/LTC1867
21
22 http://www.linear.com/product/LTC1867#demoboards
23
24
25 Copyright 2018(c) Analog Devices, Inc.
26
27 All rights reserved.
28
29 Redistribution and use in source and binary forms, with or without
30 modification, are permitted provided that the following conditions are met:
31 - Redistributions of source code must retain the above copyright
32 notice, this list of conditions and the following disclaimer.
33 - Redistributions in binary form must reproduce the above copyright
34 notice, this list of conditions and the following disclaimer in
35 the documentation and/or other materials provided with the
36 distribution.
37 - Neither the name of Analog Devices, Inc. nor the names of its
38 contributors may be used to endorse or promote products derived
39 from this software without specific prior written permission.
40 - The use of this software may or may not infringe the patent rights
41 of one or more patent holders. This license does not release you
42 from the requirement that you obtain separate licenses from these
43 patent holders to use this software.
44 - Use of the software either in source or binary form, must be run
45 on or directly connected to an Analog Devices Inc. component.
46
47 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
48 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
49 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
50 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
51 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
52 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
53 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
54 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
55 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
56 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57 */
58
59 //! @ingroup Analog_to_Digital_Converters
60 //! @{
61 //! @defgroup LTC1867 LTC1867: 16-Bit 8-Channel 200ksps ADC
62 //! @}
63
64 /*! @file
65 @ingroup LTC1867
66 Library for LTC1867: 16-Bit 8-Channel 200ksps ADC
67 */
68
69 #include <Arduino.h>
70 #include <stdint.h>
71 #include "Linduino.h"
72 #include "LT_SPI.h"
73 #include "LTC1867.h"
74 #include <SPI.h>
75
76
77 // Reads the ADC and returns 16-bit data
78 void LTC1867_read(uint8_t cs, uint8_t adc_command, uint16_t *adc_code)
79 {
80 spi_transfer_word(cs, (uint16_t)(adc_command<<8), adc_code);
81 }
82
83 // Calculates the LTC1867 input's unipolar voltage given the binary data and lsb weight.
84 float LTC1867_unipolar_code_to_voltage(uint16_t adc_code, float LTC1867_lsb, int32_t LTC1867_offset_unipolar_code)
85 {
86 float adc_voltage;
87 adc_voltage=((float)(adc_code+LTC1867_offset_unipolar_code))*LTC1867_lsb; //! 1) Calculate voltage from ADC code, lsb, offset.
88 return(adc_voltage);
89 }
90
91 // Calculates the LTC1867 input's bipolar voltage given the two's compliment data and lsb weight
92 float LTC1867_bipolar_code_to_voltage(uint16_t adc_code, float LTC1867_lsb, int32_t LTC1867_offset_bipolar_code)
93 {
94 float adc_voltage, sign = 1.0;
95 if (adc_code>>15)
96 {
97 adc_code = (adc_code ^ 0xFFFF)+1; //! 1) Convert ADC code from two's complement to binary
98 sign = -1;
99 }
100 adc_voltage=((float)(adc_code+LTC1867_offset_bipolar_code))*LTC1867_lsb*sign; //! 2) Calculate voltage from ADC code, lsb, offset.
101 return(adc_voltage);
102 }
103
104 // Calibrate the lsb
105 void LTC1867_cal_voltage(uint16_t zero_unipolar_code, uint16_t zero_bipolar_code, uint16_t fs_code, float zero_voltage, float fs_voltage, float *LTC1867_lsb, int32_t *LTC1867_offset_unipolar_code, int32_t *LTC1867_offset_bipolar_code)
106 {
107 float temp_offset;
108 *LTC1867_lsb = (fs_voltage-zero_voltage)/((float)(fs_code - zero_unipolar_code)); //! 1) Calculate the LSB
109
110 temp_offset = (zero_voltage/ *LTC1867_lsb) - zero_unipolar_code; //! 2) Calculate Unipolar offset
111 temp_offset = (temp_offset > (floor(temp_offset) + 0.5)) ? ceil(temp_offset) : floor(temp_offset); //! 3) Round
112 *LTC1867_offset_unipolar_code = (int32_t)temp_offset; //! 4) Cast as int32_t
113
114 temp_offset = (zero_voltage / *LTC1867_lsb) - zero_bipolar_code ; //! 5) Calculate Bipolar offset
115 temp_offset = (temp_offset > (floor(temp_offset) + 0.5)) ? ceil(temp_offset) : floor(temp_offset); //! 6) Round
116 *LTC1867_offset_bipolar_code = (int32_t)temp_offset; //! 7) cast as int32_t
117 }
adc_command
static uint8_t adc_command
Definition: DC2071AA.ino:111
sign
bool sign
Definition: Precision_Voltage_Source.ino:77
LTC1867_offset_unipolar_code
static int32_t LTC1867_offset_unipolar_code
Ideal unipolar offset for a perfect part.
Definition: DC806A.ino:129
Linduino.h
Header File for Linduino Libraries and Demo Code.
LTC1867_unipolar_code_to_voltage
float LTC1867_unipolar_code_to_voltage(uint16_t adc_code, float LTC1867_lsb, int32_t LTC1867_offset_unipolar_code)
Calculates the LTC1867 input&#39;s unipolar voltage given the binary data and lsb weight.
Definition: LTC1867.cpp:84
LTC1867_cal_voltage
void LTC1867_cal_voltage(uint16_t zero_unipolar_code, uint16_t zero_bipolar_code, uint16_t fs_code, float zero_voltage, float fs_voltage, float *LTC1867_lsb, int32_t *LTC1867_offset_unipolar_code, int32_t *LTC1867_offset_bipolar_code)
Calibrate the offset and LSB voltage given two measured offset codes, and a full-scale voltage with t...
Definition: LTC1867.cpp:105
LTC1867.h
LTC1867: 16-bit 8-channel 200ksps ADC.
adc_voltage
static float adc_voltage
Definition: DC2071AA.ino:115
LTC1867_bipolar_code_to_voltage
float LTC1867_bipolar_code_to_voltage(uint16_t adc_code, float LTC1867_lsb, int32_t LTC1867_offset_bipolar_code)
Calculates the LTC1867 input&#39;s bipolar voltage given the two&#39;s compliment data and lsb weight...
Definition: LTC1867.cpp:92
spi_transfer_word
void spi_transfer_word(uint8_t cs_pin, uint16_t tx, uint16_t *rx)
Reads and sends a word.
Definition: LT_SPI.cpp:98
LTC1867_read
void LTC1867_read(uint8_t cs, uint8_t adc_command, uint16_t *adc_code)
Reads the ADC and returns 16-bit data.
Definition: LTC1867.cpp:78
LT_SPI.h
LT_SPI: Routines to communicate with ATmega328P&#39;s hardware SPI port.
LTC1867_lsb
static float LTC1867_lsb
Ideal LSB voltage for a perfect part.
Definition: DC806A.ino:128
adc_code
static uint32_t adc_code
Definition: DC2071AA.ino:113
LTC1867_offset_bipolar_code
static int32_t LTC1867_offset_bipolar_code
Ideal bipolar offset for a perfect part.
Definition: DC806A.ino:130