Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
LTC2308.cpp
Go to the documentation of this file.
1 /*!
2 LTC2308: 12-Bit 8-Channel 200ksps ADC
3 
4 @verbatim
5 
6 The LTC2308 is an 8-channel 12-bit A/D converter with
7 serial I/O, and an internal reference. The ADCs typically draw only 1.3mA from a
8 single 5V supply. The 8-channel input multiplexer can be configured for either
9 single-ended or differential inputs and unipolar or bipolar conversions (or
10 combinations thereof). The automatic nap and sleep modes benefit power sensitive
11 applications.
12 
13 The LTC2308's DC performance is outstanding with a +/-2LSB INL specification and
14 no missing codes over temperature. The signal-to-noise ratio (SNR) for the
15 LTC2308 is typically 89dB, with the internal reference.
16 
17 @endverbatim
18 
19 http://www.linear.com/product/LTC2308
20 
21 http://www.linear.com/product/LTC2308#demoboards
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 LTC2308 LTC2308: 12-Bit 8-Channel 200ksps ADC
61 //! @}
62 
63 /*! @file
64  @ingroup LTC2308
65  Library for LTC2308: 12-Bit 8-Channel 200ksps ADC
66 */
67 
68 #include <Arduino.h>
69 #include <stdint.h>
70 #include "Linduino.h"
71 #include "LT_SPI.h"
72 #include "LTC2308.h"
73 #include <SPI.h>
74 
75 
76 // Reads the ADC and returns 16-bit data
77 void LTC2308_read(uint8_t cs, uint8_t adc_command, uint16_t *adc_code)
78 {
79  spi_transfer_word(cs, (uint16_t)(adc_command<<8), adc_code);
80 }
81 
82 
83 // Calculates the LTC2308 input voltage given the data, range, and unipolar/bipolar status.
84 float LTC2308_code_to_voltage(uint16_t adc_code, float vref, uint8_t uni_bipolar)
85 {
86  float voltage;
87  float sign = 1;
88 
89  if (uni_bipolar == LTC2308_UNIPOLAR_MODE)
90  {
91  voltage = (float)adc_code;
92  voltage = voltage / (pow(2,16)-1); //! 2) This calculates the input as a fraction of the reference voltage (dimensionless)
93  }
94  else
95  {
96  vref = vref/2;
97  if ((adc_code & 0x8000) == 0x8000) //adc code is < 0
98  {
99  adc_code = (adc_code ^ 0xFFFF)+1; //! Convert ADC code from two's complement to binary
100  sign = -1;
101  }
102  voltage = sign*(float)adc_code;
103  voltage = voltage / (pow(2,15)-1); //! 2) This calculates the input as a fraction of the reference voltage (dimensionless)
104  }
105  voltage = voltage * vref; //! 3) Multiply fraction by Vref to get the actual voltage at the input (in volts)
106 
107  return(voltage);
108 }
void LTC2308_read(uint8_t cs, uint8_t adc_command, uint16_t *adc_code)
Reads the ADC and returns 16-bit data.
Definition: LTC2308.cpp:77
static uint8_t adc_command
Definition: DC2071AA.ino:111
static uint8_t uni_bipolar
Default set for unipolar mode.
Definition: DC682A.ino:121
Header File for Linduino Libraries and Demo Code.
#define LTC2308_UNIPOLAR_MODE
Definition: LTC2308.h:133
void spi_transfer_word(uint8_t cs_pin, uint16_t tx, uint16_t *rx)
Reads and sends a word.
Definition: LT_SPI.cpp:98
LT_SPI: Routines to communicate with ATmega328P&#39;s hardware SPI port.
float LTC2308_code_to_voltage(uint16_t adc_code, float vref, uint8_t uni_bipolar)
Calculates the LTC2308 input&#39;s unipolar voltage given the binary data and lsb weight.
Definition: LTC2308.cpp:84
static float voltage
Definition: DC2289AA.ino:71
static uint32_t adc_code
Definition: DC2071AA.ino:113
LTC2308: 16-bit 8-channel 100ksps ADC.