| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

LTC2449_Datalogger.ino
Go to the documentation of this file.
1 /*!
2 LTC2449: 24-Bit High Speed 16-Channel Delta Sigma ADCs with Selectable Speed/Resolution
3
4 @verbatim
5
6 The LTC2449 is a 16-channel (8-differential) high speed 24-bit No Latency Delta Sigma ADCs.
7 They use a proprietary delta-sigma architecture enabling variable speed/resolution. Through
8 a simple 4-wire serial interface, ten speed/resolution combinations 6.9Hz/280nVRMS to
9 3.5kHz/25uVRMS (4kHz with external oscillator) can be selected with no latency between
10 conversion results or shift in DC accuracy (offset, full-scale, linearity, drift).
11 Additionally, a 2X speed mode can be selected enabling output rates up to 7kHz (8kHz if an
12 external oscillator is used) with one cycle latency.
13
14 @endverbatim
15
16 http://www.linear.com/product/LTC2449
17
18 http://www.linear.com/product/LTC2449#demoboards
19
20
21 Copyright 2018(c) Analog Devices, Inc.
22
23 All rights reserved.
24
25 Redistribution and use in source and binary forms, with or without
26 modification, are permitted provided that the following conditions are met:
27 - Redistributions of source code must retain the above copyright
28 notice, this list of conditions and the following disclaimer.
29 - Redistributions in binary form must reproduce the above copyright
30 notice, this list of conditions and the following disclaimer in
31 the documentation and/or other materials provided with the
32 distribution.
33 - Neither the name of Analog Devices, Inc. nor the names of its
34 contributors may be used to endorse or promote products derived
35 from this software without specific prior written permission.
36 - The use of this software may or may not infringe the patent rights
37 of one or more patent holders. This license does not release you
38 from the requirement that you obtain separate licenses from these
39 patent holders to use this software.
40 - Use of the software either in source or binary form, must be run
41 on or directly connected to an Analog Devices Inc. component.
42
43 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
44 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
45 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
46 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
47 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
48 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
49 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
50 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
51 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
52 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53 */
54
55 #include <stdint.h>
56 #include <Arduino.h>
57 #include "Linduino.h"
58 #include "QuikEval_EEPROM.h"
59 #include "UserInterface.h"
60 #include <SPI.h>
61 #include "LT_SPI.h"
62 #include <Wire.h>
63 #include "LT_I2C.h"
64 #include "LTC24XX_general.h"
65
66 #define CS QUIKEVAL_CS //!< The chip select
67
68 // Constants
69
70 //! Lookup table to build the command for single-ended mode
71 const uint8_t SINGLE_ENDED_CONFIG_ARRAY[16] = {LTC24XX_MULTI_CH_CH0, LTC24XX_MULTI_CH_CH1, LTC24XX_MULTI_CH_CH2, LTC24XX_MULTI_CH_CH3,
72 LTC24XX_MULTI_CH_CH4, LTC24XX_MULTI_CH_CH5, LTC24XX_MULTI_CH_CH6, LTC24XX_MULTI_CH_CH7,
73 LTC24XX_MULTI_CH_CH8, LTC24XX_MULTI_CH_CH9, LTC24XX_MULTI_CH_CH10, LTC24XX_MULTI_CH_CH11,
74 LTC24XX_MULTI_CH_CH12, LTC24XX_MULTI_CH_CH13, LTC24XX_MULTI_CH_CH14, LTC24XX_MULTI_CH_CH15
75 }; //!< Builds the command for single-ended mode
76
77 //! Lookup table to build the command for differential mode
78 const uint8_t DIFF_CONFIG_ARRAY[16] = {LTC24XX_MULTI_CH_P0_N1, LTC24XX_MULTI_CH_P2_N3, LTC24XX_MULTI_CH_P4_N5, LTC24XX_MULTI_CH_P6_N7,
79 LTC24XX_MULTI_CH_P8_N9, LTC24XX_MULTI_CH_P10_N11, LTC24XX_MULTI_CH_P12_N13, LTC24XX_MULTI_CH_P14_N15,
80 LTC24XX_MULTI_CH_P1_N0, LTC24XX_MULTI_CH_P3_N2, LTC24XX_MULTI_CH_P5_N4, LTC24XX_MULTI_CH_P7_N6,
81 LTC24XX_MULTI_CH_P9_N8, LTC24XX_MULTI_CH_P11_N10, LTC24XX_MULTI_CH_P13_N12, LTC24XX_MULTI_CH_P15_N14
82 }; //!< Build the command for differential mode
83
84
85 //! Lookup table to build the OSR command
86 const uint8_t OSR_CONFIG_ARRAY[10] = {LTC24XX_MULTI_CH_OSR_32768, LTC24XX_MULTI_CH_OSR_16384, LTC24XX_MULTI_CH_OSR_8192,
87 LTC24XX_MULTI_CH_OSR_4096, LTC24XX_MULTI_CH_OSR_2048, LTC24XX_MULTI_CH_OSR_1024, LTC24XX_MULTI_CH_OSR_512, LTC24XX_MULTI_CH_OSR_256,
88 LTC24XX_MULTI_CH_OSR_128, LTC24XX_MULTI_CH_OSR_64
89 }; //!< Build the command for different OSR modes
90
91 // Prototypes
92 void read_LTC2449(float vref, uint16_t eoc_timeout, uint16_t channel_delay);
93 void print_all(float *results);
94 void print_prompt();
95 void print_all(float *results);
96
97 //! Initialize Linduino
98 void setup()
99 {
100 char demo_name[] = "DC742"; // Demo Board Name stored in QuikEval EEPROM
101 int8_t demo_board_connected; // Set to 1 if the board is connected
102
103 Serial.begin(115200); // Initialize the serial port to the PC
104 Serial.println(F("Welcome to the LTC2499 Test Program\n"));
105 delay(200);
106
107 quikeval_I2C_init(); // Enable the I2C port
108 quikeval_SPI_init(); // Configure the spi port for 4volts SCK
109 quikeval_SPI_connect(); // Connect SPI to main data port
110
111 demo_board_connected = discover_demo_board(demo_name);
112
113 // If demo board is not connected loop forever
114 if (!demo_board_connected)
115 Serial.println(F("Standard demo board not detected, verify hardware connections to your circuit."));
116
117 } // End of setup()
118
119
120 //! Repeats Linduino loop
121 void loop()
122 {
123 static float LTC2499_vref = 5.0; // Reference voltage
124 static uint16_t EOC_timout = 250; // End of conversion timeout
125 static uint16_t loop_delay = 500; // the delay between loops
126 static uint16_t channel_read_delay = 20; // The delay between channel readings
127 static char user_command; // The user input command
128
129 print_prompt(); // Prints the prompt
130
131 user_command = read_char(); // Reads the users input
132 Serial.println(user_command); // Displays the user input
133
134 switch (user_command)
135 {
136 case 'S':
137 case 's':
138 // Single loop
139 read_LTC2449(LTC2499_vref, EOC_timout, channel_read_delay); // Read all the channels
140 break;
141 case 'C':
142 case 'c':
143 // Continous loop
144 do
145 {
146 read_LTC2449(LTC2499_vref, EOC_timout, channel_read_delay); // Read all the channels
147 delay(loop_delay); // Delay before repeating the loop
148 }
149 while (Serial.available() == false); // Check to see is anything was entered
150 read_int(); // Clears the Serial.available
151 break;
152 default:
153 Serial.println(F("Incorrect Option"));
154 break;
155 }
156 }
157
158 //! Print the Prompt
159 void print_prompt()
160 {
161 Serial.println();
162 Serial.println(F("S-Single Loop"));
163 Serial.println(F("C-Continuous Loop"));
164 Serial.println(F(" Enter any character to exit Continuous Loop"));
165
166 Serial.print(F("Enter a command: "));
167 }
168
169 //! Reads the LTC2449 and displays the results
170 void read_LTC2449(float vref, uint16_t eoc_timeout, uint16_t channel_delay)
171 {
172 float results[16];
173 int32_t adc_code = 0;
174 uint8_t i;
175
176 LTC24XX_EOC_timeout(CS, eoc_timeout); // Wait for end of conversion
177 LTC24XX_SPI_16bit_command_32bit_data(CS, SINGLE_ENDED_CONFIG_ARRAY[0], OSR_CONFIG_ARRAY[7], &adc_code); // Prime with CH0
178
179 for (i=0; i<=15; i++)
180 {
181 delay(channel_delay);
182 LTC24XX_EOC_timeout(CS, eoc_timeout); // Wait for end of conversion
183 LTC24XX_SPI_16bit_command_32bit_data(CS, SINGLE_ENDED_CONFIG_ARRAY[(i+1)%16], OSR_CONFIG_ARRAY[7], &adc_code); // Read the ADC
184 results[i%16] = LTC24XX_diff_code_to_voltage(adc_code, vref); // Convert ADC code to voltage
185 }
186
187 print_all(results); // Display results
188 }
189
190 //! Displays the the data in the array
191 void print_all(float *results)
192 {
193 uint8_t i;
194 for (i=0; i<=15; i++)
195 {
196 Serial.print(results[i], 8);
197 if (!((i+1)%16)) Serial.println();
198 else Serial.print(F(" , "));
199 }
200 }
LTC24XX_MULTI_CH_OSR_32768
#define LTC24XX_MULTI_CH_OSR_32768
Definition: LTC24XX_general.h:251
LTC24XX_MULTI_CH_CH3
#define LTC24XX_MULTI_CH_CH3
Definition: LTC24XX_general.h:185
print_prompt
static void print_prompt()
Print the Prompt.
Definition: LTC2449_Datalogger.ino:159
LTC24XX_MULTI_CH_CH14
#define LTC24XX_MULTI_CH_CH14
Definition: LTC24XX_general.h:196
LTC24XX_MULTI_CH_OSR_8192
#define LTC24XX_MULTI_CH_OSR_8192
Definition: LTC24XX_general.h:249
user_command
unsigned char user_command
Definition: Serial_EEPROM_Test.ino:75
LTC24XX_MULTI_CH_CH8
#define LTC24XX_MULTI_CH_CH8
Definition: LTC24XX_general.h:190
LTC24XX_MULTI_CH_CH15
#define LTC24XX_MULTI_CH_CH15
Definition: LTC24XX_general.h:197
loop_delay
static uint16_t loop_delay
Definition: LTC2442_Datalogger.ino:98
LTC24XX_MULTI_CH_CH13
#define LTC24XX_MULTI_CH_CH13
Definition: LTC24XX_general.h:195
LTC24XX_MULTI_CH_CH1
#define LTC24XX_MULTI_CH_CH1
Definition: LTC24XX_general.h:183
LTC24XX_MULTI_CH_OSR_256
#define LTC24XX_MULTI_CH_OSR_256
Definition: LTC24XX_general.h:244
LTC24XX_MULTI_CH_CH6
#define LTC24XX_MULTI_CH_CH6
Definition: LTC24XX_general.h:188
LTC24XX_MULTI_CH_P13_N12
#define LTC24XX_MULTI_CH_P13_N12
Definition: LTC24XX_general.h:225
LTC24XX_MULTI_CH_OSR_1024
#define LTC24XX_MULTI_CH_OSR_1024
Definition: LTC24XX_general.h:246
LTC24XX_MULTI_CH_P1_N0
#define LTC24XX_MULTI_CH_P1_N0
Definition: LTC24XX_general.h:207
Linduino.h
Header File for Linduino Libraries and Demo Code.
LTC24XX_EOC_timeout
int8_t LTC24XX_EOC_timeout(uint8_t cs, uint16_t miso_timeout)
Checks for EOC with a specified timeout.
Definition: LTC24XX_general.cpp:82
LTC24XX_MULTI_CH_CH5
#define LTC24XX_MULTI_CH_CH5
Definition: LTC24XX_general.h:187
setup
static void setup()
Initialize Linduino.
Definition: LTC2449_Datalogger.ino:98
LTC24XX_MULTI_CH_P4_N5
#define LTC24XX_MULTI_CH_P4_N5
Definition: LTC24XX_general.h:212
LTC24XX_MULTI_CH_CH0
#define LTC24XX_MULTI_CH_CH0
Definition: LTC24XX_general.h:182
LTC24XX_MULTI_CH_CH11
#define LTC24XX_MULTI_CH_CH11
Definition: LTC24XX_general.h:193
loop
static void loop()
Repeats Linduino loop.
Definition: LTC2449_Datalogger.ino:121
DIFF_CONFIG_ARRAY
const uint8_t DIFF_CONFIG_ARRAY[16]
Lookup table to build the command for differential mode.
Definition: LTC2449_Datalogger.ino:78
LTC2499_vref
static float LTC2499_vref
The LTC2499 reference voltage.
Definition: DC1012AA.ino:112
LTC24XX_general.h
LTC24XX General Library: Functions and defines for all SINC4 Delta Sigma ADCs.
LTC24XX_MULTI_CH_P9_N8
#define LTC24XX_MULTI_CH_P9_N8
Definition: LTC24XX_general.h:219
LTC24XX_MULTI_CH_P14_N15
#define LTC24XX_MULTI_CH_P14_N15
Definition: LTC24XX_general.h:227
LTC24XX_SPI_16bit_command_32bit_data
void LTC24XX_SPI_16bit_command_32bit_data(uint8_t cs, uint8_t adc_command_high, uint8_t adc_command_low, int32_t *adc_code)
Reads from LTC24XX ADC that accepts a 16 bit configuration and returns a 32 bit result.
Definition: LTC24XX_general.cpp:136
LTC24XX_MULTI_CH_OSR_64
#define LTC24XX_MULTI_CH_OSR_64
Definition: LTC24XX_general.h:242
LTC24XX_MULTI_CH_CH2
#define LTC24XX_MULTI_CH_CH2
Definition: LTC24XX_general.h:184
SINGLE_ENDED_CONFIG_ARRAY
const uint8_t SINGLE_ENDED_CONFIG_ARRAY[16]
Lookup table to build the command for single-ended mode.
Definition: LTC2449_Datalogger.ino:71
eoc_timeout
static uint16_t eoc_timeout
timeout in ms
Definition: LTC2492_Panel_Meter.ino:135
LTC24XX_MULTI_CH_P3_N2
#define LTC24XX_MULTI_CH_P3_N2
Definition: LTC24XX_general.h:210
QuikEval_EEPROM.h
QuikEval EEPROM Library.
LTC24XX_MULTI_CH_OSR_4096
#define LTC24XX_MULTI_CH_OSR_4096
Definition: LTC24XX_general.h:248
LTC24XX_MULTI_CH_P2_N3
#define LTC24XX_MULTI_CH_P2_N3
Definition: LTC24XX_general.h:209
LTC24XX_MULTI_CH_OSR_16384
#define LTC24XX_MULTI_CH_OSR_16384
Definition: LTC24XX_general.h:250
LTC24XX_MULTI_CH_OSR_128
#define LTC24XX_MULTI_CH_OSR_128
Definition: LTC24XX_general.h:243
quikeval_SPI_init
void quikeval_SPI_init(void)
Configure the SPI port for 4Mhz SCK.
Definition: LT_SPI.cpp:151
read_LTC2449
static void read_LTC2449(float vref, uint16_t eoc_timeout, uint16_t channel_delay)
Reads the LTC2449 and displays the results.
Definition: LTC2449_Datalogger.ino:170
discover_demo_board
int8_t discover_demo_board(char *demo_name)
Read the ID string from the EEPROM and determine if the correct board is connected.
Definition: QuikEval_EEPROM.cpp:141
LTC24XX_MULTI_CH_P10_N11
#define LTC24XX_MULTI_CH_P10_N11
Definition: LTC24XX_general.h:221
LTC24XX_MULTI_CH_CH12
#define LTC24XX_MULTI_CH_CH12
Definition: LTC24XX_general.h:194
LTC24XX_MULTI_CH_OSR_512
#define LTC24XX_MULTI_CH_OSR_512
Definition: LTC24XX_general.h:245
LTC24XX_MULTI_CH_P12_N13
#define LTC24XX_MULTI_CH_P12_N13
Definition: LTC24XX_general.h:224
LT_SPI.h
LT_SPI: Routines to communicate with ATmega328P&#39;s hardware SPI port.
LTC24XX_MULTI_CH_CH7
#define LTC24XX_MULTI_CH_CH7
Definition: LTC24XX_general.h:189
LTC24XX_MULTI_CH_P5_N4
#define LTC24XX_MULTI_CH_P5_N4
Definition: LTC24XX_general.h:213
print_all
static void print_all(float *results)
Displays the the data in the array.
Definition: LTC2449_Datalogger.ino:191
OSR_CONFIG_ARRAY
const uint8_t OSR_CONFIG_ARRAY[10]
Lookup table to build the OSR command.
Definition: LTC2449_Datalogger.ino:86
LT_I2C.h
LT_I2C: Routines to communicate with ATmega328P&#39;s hardware I2C port.
CS
#define CS
LTC2449: 24-Bit High Speed 16-Channel Delta Sigma ADCs with Selectable Speed/Resolution.
Definition: LTC2449_Datalogger.ino:66
LTC24XX_MULTI_CH_P8_N9
#define LTC24XX_MULTI_CH_P8_N9
Definition: LTC24XX_general.h:218
LTC24XX_MULTI_CH_P7_N6
#define LTC24XX_MULTI_CH_P7_N6
Definition: LTC24XX_general.h:216
LTC24XX_diff_code_to_voltage
float LTC24XX_diff_code_to_voltage(int32_t adc_code, float vref)
Calculates the voltage corresponding to an ADC code, given the reference voltage. ...
Definition: LTC24XX_general.cpp:389
demo_name
char demo_name[]
Demo Board Name stored in QuikEval EEPROM.
Definition: DC1880A.ino:97
quikeval_SPI_connect
void quikeval_SPI_connect()
Connect SPI pins to QuikEval connector through the Linduino MUX. This will disconnect I2C...
Definition: LT_SPI.cpp:138
UserInterface.h
read_int
int32_t read_int()
Definition: UserInterface.cpp:93
LTC24XX_MULTI_CH_CH10
#define LTC24XX_MULTI_CH_CH10
Definition: LTC24XX_general.h:192
EOC_timout
static uint16_t EOC_timout
Definition: LTC2442_Datalogger.ino:97
LTC24XX_MULTI_CH_CH9
#define LTC24XX_MULTI_CH_CH9
Definition: LTC24XX_general.h:191
LTC24XX_MULTI_CH_P15_N14
#define LTC24XX_MULTI_CH_P15_N14
Definition: LTC24XX_general.h:228
quikeval_I2C_init
void quikeval_I2C_init(void)
Initializes Linduino I2C port.
Definition: LT_I2C.cpp:394
i
static int i
Definition: DC2430A.ino:184
LTC24XX_MULTI_CH_P11_N10
#define LTC24XX_MULTI_CH_P11_N10
Definition: LTC24XX_general.h:222
LTC24XX_MULTI_CH_OSR_2048
#define LTC24XX_MULTI_CH_OSR_2048
Definition: LTC24XX_general.h:247
vref
float vref
Definition: LTC2492_Thermocouple_Meter.ino:129
LTC24XX_MULTI_CH_P0_N1
#define LTC24XX_MULTI_CH_P0_N1
Definition: LTC24XX_general.h:206
LTC24XX_MULTI_CH_CH4
#define LTC24XX_MULTI_CH_CH4
Definition: LTC24XX_general.h:186
channel_read_delay
static uint16_t channel_read_delay
Definition: LTC2442_Datalogger.ino:99
read_char
int8_t read_char()
Definition: UserInterface.cpp:116
adc_code
static uint32_t adc_code
Definition: DC2071AA.ino:113
LTC24XX_MULTI_CH_P6_N7
#define LTC24XX_MULTI_CH_P6_N7
Definition: LTC24XX_general.h:215
demo_board_connected
static uint8_t demo_board_connected
Set to 1 if the board is connected.
Definition: _24xx_iso_spi_delay.ino:71