Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
LTC2508.cpp
Go to the documentation of this file.
1 /*!
2 LTC2508: 32-Bit Over-Sampling ADC with Configurable Digital Filter.
3 
4 @verbatim
5 
6 The LTC2508-32 is a low noise, low power, high performance 32-bit ADC
7 with an integrated configurable digital filter. Operating from a single
8 2.5V supply, the LTC2508-32 features a fully differential input range
9 up to ±VREF, with VREF ranging from 2.5V to 5.1V. The LTC2508-32 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/LTC2508
16 
17 http://www.linear.com/product/LTC2508#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 LTC2508 LTC2508 : 32-Bit Over-Sampling ADC with Configurable Digital Filter.
57 
58 //! @}
59 
60 /*! @file
61  @ingroup LTC2508
62  Library for LTC2508 32-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 LTC2508_code_to_voltage(int32_t code, float vref)
77 {
78  float voltage;
79  voltage = (float)code / 2147483648 * vref;
80  return voltage;
81 }
82 
83 // Send n num of pulses on pin given
84 void send_pulses(uint8_t pin, uint16_t num_of_pulses)
85 {
86  uint16_t i;
87  output_high(pin);
88 
89  for (i = 0; i < num_of_pulses; ++i)
90  {
91  output_low(pin); // Pull CS low
92  output_high(pin); // Pull CS high
93  }
94  output_low(pin); // Leave CS low
95 }
96 
97 // Reads 5 bytes of data on SPI - D31:D0 + W7:W0
98 uint32_t LTC2508_read_data(uint8_t QUIKEVAL_CS, uint16_t *DF)
99 {
100  uint8_t rx[5];
101  uint8_t tx[5] = {0,0,0,0,0};
102  uint32_t code = 0;
103 
104 
105  spi_transfer_block(QUIKEVAL_CS, tx, rx, 5); // Read 5 bytes on SPI port
106 
107  code = rx[4];
108  code = (code << 8) | rx[3];
109  code = (code << 8) | rx[2];
110  code = (code << 8) | rx[1];
111 
112  switch (rx[0])
113  {
114  case 0x85:
115  *DF = 256;
116  break;
117  case 0xA5:
118  *DF = 1024;
119  break;
120  case 0xC5:
121  *DF = 4096;
122  break;
123  case 0xE5:
124  *DF = 16384;
125  break;
126  default:
127  *DF = 0;
128  }
129  return code;
130 }
float LTC2508_code_to_voltage(int32_t code, float vref)
Calculates the output voltage from the given digital code and reference voltage.
Definition: LTC2508.cpp:76
#define output_high(pin)
Set "pin" high.
Definition: Linduino.h:75
uint32_t LTC2508_read_data(uint8_t QUIKEVAL_CS, uint16_t *DF)
Reads 5 bytes of data on SPI - D31:D0 + W7:W0.
Definition: LTC2508.cpp:98
Header File for Linduino Libraries and Demo Code.
#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.
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
void send_pulses(uint8_t pin, uint16_t num_of_pulses)
Send n num of pulses on pin given.
Definition: LTC2508.cpp:84