Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
LTC2512.cpp
Go to the documentation of this file.
1 /*!
2 LTC2512: 24-Bit Over-Sampling ADC with Configurable Digital Filter.
3 
4 @verbatim
5 
6 The LTC2512 is a low noise, low power, high performance 24-bit ADC
7 with an integrated configurable digital filter. Operating from a single
8 2.5V supply, the LTC2512 features a fully differential input range
9 up to ±VREF, with VREF ranging from 2.5V to 5.1V. The LTC2512 supports
10 a wide common mode range from 0V to VREF simplifying analog signal
11 conditioning requirements.
12 
13 @endverbatim
14 
15 http://www.linear.com/product/LTC2512-24
16 
17 http://www.linear.com/product/LTC2512-24#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 LTC2512 LTC2512 : 24-Bit Over-Sampling ADC with Configurable Digital Filter.
57 
58 //! @}
59 
60 /*! @file
61  @ingroup LTC2512
62  Library for LTC2512 24-Bit Over-Sampling ADC with Configurable Digital Filter.
63 */
64 
65 #include <Arduino.h>
66 #include "LT_I2C.h"
67 #include "LT_SPI.h"
68 #include "UserInterface.h"
69 #include "QuikEval_EEPROM.h"
70 #include "Linduino.h"
71 #include <Wire.h>
72 #include <stdint.h>
73 #include <SPI.h>
74 
75 // Calculates the output voltage from the given digital code and reference voltage
76 float LTC2512_code_to_voltage(int32_t code, float vref)
77 {
78  float voltage;
79  int sign;
80  if (code & 0x800000)
81  code = code | 0xFF000000;
82  voltage = (float)code / 8388608 * vref;
83  return voltage;
84 }
85 
86 // Send n num of pulses on pin given
87 void send_pulses(uint8_t pin, uint16_t num_of_pulses)
88 {
89  uint16_t i;
90  output_high(pin);
91 
92  for (i = 0; i < num_of_pulses; ++i)
93  {
94  output_low(pin); // Pull CS low
95  output_high(pin); // Pull CS high
96  }
97  output_low(pin); // Leave CS low
98 }
99 
100 // Reads 4 bytes of data on SPI - D23:D0 + W7:W0
101 uint32_t LTC2512_read_data(uint8_t QUIKEVAL_CS, uint16_t *DF)
102 {
103  uint8_t rx[4];
104  uint8_t tx[4] = {0,0,0,0};
105  uint32_t code=0;
106 
107 
108  spi_transfer_block(QUIKEVAL_CS, tx, rx, 4); // Read 5 bytes on SPI port
109 
110  code = rx[3] & 0xFF;
111  code = (code << 8) | rx[2];
112  code = (code << 8) | rx[1];
113  code = code & 0xFFFFFF;
114  switch (rx[0])
115  {
116  case 0x26:
117  *DF = 4;
118  break;
119  case 0x36:
120  *DF = 8;
121  break;
122  case 0x46:
123  *DF = 16;
124  break;
125  case 0x56:
126  *DF = 32;
127  break;
128  default:
129  *DF = 0;
130  }
131  return code;
132 }
void send_pulses(uint8_t pin, uint16_t num_of_pulses)
Send n num of pulses on pin given.
Definition: LTC2512.cpp:87
#define output_high(pin)
Set "pin" high.
Definition: Linduino.h:75
Header File for Linduino Libraries and Demo Code.
float LTC2512_code_to_voltage(int32_t code, float vref)
Calculates the output voltage from the given digital code and reference voltage.
Definition: LTC2512.cpp:76
#define output_low(pin)
Set "pin" low.
Definition: Linduino.h:72
QuikEval EEPROM Library.
LT_SPI: Routines to communicate with ATmega328P&#39;s hardware SPI port.
LT_I2C: Routines to communicate with ATmega328P&#39;s hardware I2C port.
uint32_t LTC2512_read_data(uint8_t QUIKEVAL_CS, uint16_t *DF)
Reads 4 bytes of data on SPI - D23:D0 + W7:W0.
Definition: LTC2512.cpp:101
static int i
Definition: DC2430A.ino:184
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
#define QUIKEVAL_CS
QuikEval CS pin (SPI chip select on QuikEval connector pin 6) connects to Arduino SS pin...
Definition: Linduino.h:57