Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
LTC2480.cpp
Go to the documentation of this file.
1 /*!
2 LTC2480: 16-Bit Delta-Sigma ADC with Easy Drive Input Current Cancellation.
3 
4 @verbatim
5 
6 The LTC2480 is a 16-Bit Delta-Sigma ADC with Easy Drive Input Current Cancellation.
7 It includes on-chip programmable gain and an oscillator. The LTC2480 can be
8 configured to provide a programmable gain from 1 to 256 in 8 steps, measure an
9 external signal or internal temperature sensor and reject line frequencies. 50Hz,
10 60Hz or simultaneous 50Hz/60Hz line frequency rejection can be selected as well
11 as a 2x speed-up mode.
12 
13 @endverbatim
14 
15 http://www.linear.com/product/LTC2480
16 
17 http://www.linear.com/product/LTC2480#demoboards
18 
19 
20 Copyright 2018(c) Analog Devices, Inc.
21 
22 All rights reserved.
23 
24 Redistribution and use in source and binary forms, with or without
25 modification, are permitted provided that the following conditions are met:
26  - Redistributions of source code must retain the above copyright
27  notice, this list of conditions and the following disclaimer.
28  - Redistributions in binary form must reproduce the above copyright
29  notice, this list of conditions and the following disclaimer in
30  the documentation and/or other materials provided with the
31  distribution.
32  - Neither the name of Analog Devices, Inc. nor the names of its
33  contributors may be used to endorse or promote products derived
34  from this software without specific prior written permission.
35  - The use of this software may or may not infringe the patent rights
36  of one or more patent holders. This license does not release you
37  from the requirement that you obtain separate licenses from these
38  patent holders to use this software.
39  - Use of the software either in source or binary form, must be run
40  on or directly connected to an Analog Devices Inc. component.
41 
42 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
43 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
44 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
45 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
46 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
47 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
48 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
49 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
50 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
51 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
52 */
53 
54 //! @ingroup Analog_to_Digital_Converters
55 //! @{
56 //! @defgroup LTC2480 LTC2480: 16-Bit Delta-Sigma ADC with Easy Drive Input Current Cancellation.
57 //! @}
58 
59 /*! @file
60  @ingroup LTC2480
61  Library for LTC2480: 16-Bit Delta-Sigma ADC with Easy Drive Input Current Cancellation.
62 */
63 
64 #include <stdint.h>
65 #include "Linduino.h"
66 #include "LT_SPI.h"
67 
68 // Function to set the input voltage gain and frequency rejection mode
69 void LTC2480_set_modes(uint8_t cs, uint8_t gain_selection, uint8_t rejection_mode)
70 {
71  uint8_t rx;
72  uint8_t mode = gain_selection | rejection_mode;
73  mode = mode | 0x80; // Enable
74  spi_transfer_byte(cs, mode, &rx);
75 }
76 
77 // Reads the LTC2480 and returns 24-bit data
78 void LTC2480_read(uint8_t cs, uint32_t *ptr_adc_code)
79 {
80  LT_union_int32_4bytes data, command; // LTC24XX data and command
81  command.LT_uint32 = 0;
82  data.LT_uint32 = 0;
83 
84  spi_transfer_block(cs, command.LT_byte, data.LT_byte, (uint8_t)3);
85 
86  *ptr_adc_code = data.LT_uint32;
87 }
88 
89 // Calculates the LTC2480 input voltage given the binary data, reference voltage and input gain.
90 float LTC2480_code_to_voltage(uint32_t adc_code, float vref, uint8_t gain)
91 {
92  float voltage;
93 
94  voltage = (float)adc_code;
95  voltage = voltage / (pow(2,16)-1); //! 2) This calculates the input as a fraction of the reference voltage (dimensionless)
96  voltage = voltage * vref; //! 3) Multiply fraction by Vref to get the actual voltage at the input (in volts)
97  voltage = voltage / gain; //! 4) Divide by input gain
98 
99  return(voltage);
100 }
static uint8_t rejection_mode
The LTC2498 rejection mode settings.
void LTC2480_read(uint8_t cs, uint32_t *ptr_adc_code)
Reads the LTC2480 and returns 24-bit data.
Definition: LTC2480.cpp:78
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
Header File for Linduino Libraries and Demo Code.
uint32_t LT_uint32
32-bit unsigned integer to be converted to four bytes
Definition: Linduino.h:111
union LT_union_int32_4bytes data
Definition: DC2094A.ino:138
void LTC2480_set_modes(uint8_t cs, uint8_t gain_selection, uint8_t rejection_mode)
Function to set the input voltage gain and frequency rejection mode.
Definition: LTC2480.cpp:69
LT_SPI: Routines to communicate with ATmega328P&#39;s hardware SPI port.
This union splits one int32_t (32-bit signed integer) or uint32_t (32-bit unsigned integer) four uint...
Definition: Linduino.h:108
float LTC2480_code_to_voltage(uint32_t adc_code, float vref, uint8_t gain)
Calculates the LTC2480 input voltage given the binary data, reference voltage and input gain...
Definition: LTC2480.cpp:90
void spi_transfer_byte(uint8_t cs_pin, uint8_t tx, uint8_t *rx)
Reads and sends a byte.
Definition: LT_SPI.cpp:87
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 voltage
Definition: DC2289AA.ino:71
static uint32_t adc_code
Definition: DC2071AA.ino:113