| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

DC742A.ino
Go to the documentation of this file.
1 /*!
2 Linear Technology DC742A Demonstration Board.
3 LTC2449: 24-Bit, 16-Channel Delta Sigma ADC with Selectable Speed/Resolution.
4
5 Linear Technology DC979A Demonstration Board.
6 LTC2442: 24-Bit, 4-Channel Delta Sigma ADC with Integrated Amplifier
7
8 Linear Technology DC845A Demonstration Board.
9 LTC2448: 24-Bit, 8-/16-Channel Delta Sigma ADCs with Selectable Speed/Resolution
10
11 @verbatim
12
13 NOTES
14 Setup:
15 Set the terminal baud rate to 115200 and select the newline terminator. Equipment
16 required is a precision voltage source and a precision voltmeter. Additionally,
17 an external power supply is required to provide a negative voltage for Amp V-.
18 Set it to anywhere from -1V to -5V. Set Amp V+ to Vcc. Ensure the COM and REF-
19 pins are connected to ground. The REF+ pin should be connected to +5V.
20
21 How to test Single-Ended mode:
22 The voltage source should be connected to the ADC such that the negative lead is
23 connected to the COM(common) pin. The positive lead may be connected to any
24 channel input. Ensure voltage is within analog input voltage range -0.3 to 2.5V.
25
26 How to test Differential Mode:
27 The voltage source should be connected with positive and negative leads to paired
28 channels. The voltage source negative output must also be connected to the COM
29 pin in order to provide a ground-referenced voltage. Ensure voltage is within
30 analog input voltage range -0.3V to +2.5V. Swapping input voltages results in a
31 reversed polarity reading.
32
33 How to calibrate:
34 Apply 100mV CH0 with respect to COM. Next, measure this voltage with a precise
35 voltmeter and enter this value. (This takes the reading.) Now apply approximately
36 2.40 volts to CH0. Measure this voltage with a precise voltmeter and enter this
37 value. Calibration is now stored in EEPROM. Upon start-up the calibration values
38 will be restored.
39
40 USER INPUT DATA FORMAT:
41 decimal : 1024
42 hex : 0x400
43 octal : 02000 (leading 0 "zero")
44 binary : B10000000000
45 float : 1024.0
46
47 @endverbatim
48
49 http://www.linear.com/product/LTC2449
50 http://www.linear.com/product/LTC2442
51 http://www.linear.com/product/LTC2448
52
53 http://www.linear.com/product/LTC2449#demoboards
54 http://www.linear.com/product/LTC2442#demoboards
55 http://www.linear.com/product/LTC2448#demoboards
56
57
58 Copyright 2018(c) Analog Devices, Inc.
59
60 All rights reserved.
61
62 Redistribution and use in source and binary forms, with or without
63 modification, are permitted provided that the following conditions are met:
64 - Redistributions of source code must retain the above copyright
65 notice, this list of conditions and the following disclaimer.
66 - Redistributions in binary form must reproduce the above copyright
67 notice, this list of conditions and the following disclaimer in
68 the documentation and/or other materials provided with the
69 distribution.
70 - Neither the name of Analog Devices, Inc. nor the names of its
71 contributors may be used to endorse or promote products derived
72 from this software without specific prior written permission.
73 - The use of this software may or may not infringe the patent rights
74 of one or more patent holders. This license does not release you
75 from the requirement that you obtain separate licenses from these
76 patent holders to use this software.
77 - Use of the software either in source or binary form, must be run
78 on or directly connected to an Analog Devices Inc. component.
79
80 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
81 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
82 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
83 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
84 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
85 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
86 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
87 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
88 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
89 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
90
91 */
92
93 /*! @file
94 @ingroup LTC2449
95 */
96
97 #include <Arduino.h>
98 #include <stdint.h>
99 #include "Linduino.h"
100 #include "LT_SPI.h"
101 #include "UserInterface.h"
102 #include "LT_I2C.h"
103 #include "QuikEval_EEPROM.h"
104 #include "LTC2449.h"
105 #include <SPI.h>
106 #include <Wire.h>
107
108 // Function Declaration
109 void print_title(); // Print the title block
110 void print_prompt(); // Prompt the user for an input command
111 void print_user_command(uint8_t menu); // Display selected differential channels
112 void store_calibration(); // Store the ADC calibration to the EEPROM
113 int8_t restore_calibration(); // Read the calibration from EEPROM, return 1 if successful, 0 if not
114
115 int8_t menu_1_read_single_ended();
116 int8_t menu_2_read_differential();
117 int8_t menu_3_calibrate();
118 void menu_4_set_OSR();
119 void menu_5_set_1X2X();
120 void menu_6_en_dis_cal();
121
122 // Global variables
123 static uint8_t demo_board_connected; //!< Set to 1 if the board is connected
124 static int16_t OSR_mode = LTC2449_OSR_32768; //!< The LTC2449 OSR setting
125 static int16_t two_x_mode = LTC2449_SPEED_1X; //!< The LTC2449 2X Mode settings
126 static float LTC2449_lsb = 9.3132258E-9; //!< Ideal LSB voltage for a perfect part
127 static int32_t LTC2449_offset_code = 0; //!< Ideal offset for a perfect part
128
129 // Constants
130
131 //! Lookup table to build the command for single-ended mode
132 const uint16_t BUILD_COMMAND_SINGLE_ENDED[16] = {LTC2449_CH0, LTC2449_CH1, LTC2449_CH2, LTC2449_CH3,
133 LTC2449_CH4, LTC2449_CH5, LTC2449_CH6, LTC2449_CH7,
134 LTC2449_CH8, LTC2449_CH9, LTC2449_CH10, LTC2449_CH11,
135 LTC2449_CH12, LTC2449_CH13, LTC2449_CH14, LTC2449_CH15
136 }; //!< Builds the command for single-ended mode
137
138 //! Lookup table to build the command for differential mode
139 const uint16_t BUILD_COMMAND_DIFF[16] = {LTC2449_P0_N1, LTC2449_P2_N3, LTC2449_P4_N5, LTC2449_P6_N7,
140 LTC2449_P8_N9, LTC2449_P10_N11, LTC2449_P12_N13, LTC2449_P14_N15,
141 LTC2449_P1_N0, LTC2449_P3_N2, LTC2449_P5_N4, LTC2449_P7_N6,
142 LTC2449_P9_N8, LTC2449_P11_N10, LTC2449_P13_N12, LTC2449_P15_N14
143 }; //!< Build the command for differential mode
144
145 //! Lookup table to build the command for OSR
146 const uint16_t BUILD_OSR_COMMAND[10] = {LTC2449_OSR_32768, LTC2449_OSR_64, LTC2449_OSR_128, LTC2449_OSR_256, LTC2449_OSR_512,
147 LTC2449_OSR_1024, LTC2449_OSR_2048, LTC2449_OSR_4096, LTC2449_OSR_8192, LTC2449_OSR_16384
148 }; //!< Build the command for OSR
149
150 //! Lookup table to build 1X / 2X bits
151 const uint16_t BUILD_1X_2X_COMMAND[2] = {LTC2449_SPEED_1X, LTC2449_SPEED_2X}; //!< Build the command for 1x or 2x mode
152
153 //! MISO timeout constant
154 const uint16_t MISO_TIMEOUT = 1000;
155
156 //! Initialize Linduino
157 void setup()
158 {
159 char demo_name[]="DC742"; // Demo Board Name stored in QuikEval EEPROM
160
161 quikeval_SPI_init(); // Configure the spi port for 4MHz SCK
162 quikeval_SPI_connect(); // Connect SPI to main data port
163 quikeval_I2C_init(); // Configure the EEPROM I2C port for 100kHz
164 Serial.begin(115200); // Initialize the serial port to the PC
165 print_title();
166 demo_board_connected = discover_demo_board(demo_name);
167 if (demo_board_connected)
168 {
169 restore_calibration();
170 print_prompt();
171 }
172 }
173
174 //! Repeats Linduino loop
175 void loop()
176 {
177 int16_t user_command; // The user input command
178 uint8_t acknowledge = 0;
179 if (demo_board_connected)
180 {
181 if (Serial.available()) // Check for user input
182 {
183 user_command = read_int(); // Read the user command
184 if (user_command != 'm')
185 Serial.println(user_command); // Prints the user command to com port
186 Serial.flush();
187 switch (user_command)
188 {
189 case 1:
190 acknowledge |= menu_1_read_single_ended();
191 break;
192 case 2:
193 acknowledge |= menu_2_read_differential();
194 break;
195 case 3:
196 acknowledge |= menu_3_calibrate();
197 break;
198 case 4:
199 menu_4_set_OSR();
200 break;
201 case 5:
202 menu_5_set_1X2X();
203 break;
204 case 6:
205 menu_6_en_dis_cal();
206 break;
207 default:
208 Serial.println("Incorrect Option");
209 }
210 if (acknowledge)
211 Serial.println("***** SPI ERROR *****");
212 Serial.print(F("\n*************************\n"));
213 print_prompt();
214 }
215 }
216 }
217
218 // Function Definitions
219
220 //! Prints the title block when program first starts.
221 void print_title()
222 {
223 Serial.print(F("\n*****************************************************************\n"));
224 Serial.print(F("* DC742A Demonstration Program *\n"));
225 Serial.print(F("* *\n"));
226 Serial.print(F("* This program demonstrates how to send data and receive data *\n"));
227 Serial.print(F("* from the 24-bit ADC. *\n"));
228 Serial.print(F("* *\n"));
229 Serial.print(F("* *\n"));
230 Serial.print(F("* Set the baud rate to 115200 and select the newline terminator.*\n"));
231 Serial.print(F("* *\n"));
232 Serial.print(F("*****************************************************************\n"));
233 }
234
235 //! Prints main menu.
236 void print_prompt()
237 {
238 Serial.print(F("\n1-Read Single-Ended\n"));
239 Serial.print(F("2-Read Differential\n"));
240 Serial.print(F("3-Calibration\n"));
241 Serial.print(F("4-Oversample Ratio Settings\n"));
242 Serial.print(F("5-2X Mode Settings\n"));
243 Serial.print(F("6-Enable / Disable Calibration Key\n\n"));
244 Serial.print(F("Enter a Command: "));
245 }
246
247 //! Display selected differential channels. Displaying single-ended channels is
248 //! straightforward; not so with differential because the inputs can take either polarity.
249 void print_user_command(uint8_t menu)
250 {
251 switch (menu)
252 {
253 case 0:
254 Serial.print("0P-1N");
255 break;
256 case 1:
257 Serial.print("2P-3N");
258 break;
259 case 2:
260 Serial.print("4P-5N");
261 break;
262 case 3:
263 Serial.print("6P-7N");
264 break;
265 case 4:
266 Serial.print("8P-9N");
267 break;
268 case 5:
269 Serial.print("10P-11N");
270 break;
271 case 6:
272 Serial.print("12P-13N");
273 break;
274 case 7:
275 Serial.print("14P-15N");
276 break;
277 case 8:
278 Serial.print("1P-0N");
279 break;
280 case 9:
281 Serial.print("3P-2N");
282 break;
283 case 10:
284 Serial.print("5P-4N");
285 break;
286 case 11:
287 Serial.print("7P-6N");
288 break;
289 case 12:
290 Serial.print("9P-8N");
291 break;
292 case 13:
293 Serial.print("11P-10N");
294 break;
295 case 14:
296 Serial.print("13P-12N");
297 break;
298 case 15:
299 Serial.print("15P-14N");
300 break;
301 }
302 Serial.print(": ");
303 }
304
305 //! Read channels in single-ended mode
306 //! @return 0 if successful, 1 is failure
307 int8_t menu_1_read_single_ended()
308 {
309 uint16_t adc_command; // The LTC2449 command word
310 int16_t user_command; // The user input command
311 uint32_t adc_code = 0; // The LTC2449 code
312 float adc_voltage; // The LTC2449 voltage
313
314 while (1)
315 {
316 Serial.print(F("*************************\n\n"));
317 Serial.print(F("0-CH0 8-CH8\n"));
318 Serial.print(F("1-CH1 9-CH9\n"));
319 Serial.print(F("2-CH2 10-CH10\n"));
320 Serial.print(F("3-CH3 11-CH11\n"));
321 Serial.print(F("4-CH4 12-CH12\n"));
322 Serial.print(F("5-CH5 13-CH13\n"));
323 Serial.print(F("6-CH6 14-CH14\n"));
324 Serial.print(F("7-CH7 15-CH15\n"));
325 Serial.print(F("16-ALL\n"));
326 Serial.print(F("m-Main Menu\n"));
327 Serial.print("Enter a Command: ");
328
329 user_command = read_int(); // Read the single command
330 if (user_command == 'm')
331 return(0);
332 Serial.println(user_command);
333
334 if (user_command == 16)
335 {
336 Serial.print(F("ALL\n"));
337 adc_command = BUILD_COMMAND_SINGLE_ENDED[0] | OSR_mode | two_x_mode; // Build ADC command for channel 0
338 if (LTC2449_EOC_timeout(LTC2449_CS, MISO_TIMEOUT)) // Checks for EOC with a timeout
339 return(1);
340 LTC2449_read(LTC2449_CS, adc_command, &adc_code); // Throws out last reading
341
342 for (int8_t x = 0; x <= 15; x++) // Read all channels in single-ended mode
343 {
344 if (two_x_mode)
345 {
346 LTC2449_read(LTC2449_CS, adc_command, &adc_code); // Throws out an extra reading in 2x mode
347 if (LTC2449_EOC_timeout(LTC2449_CS, MISO_TIMEOUT)) // Checks for EOC with a timeout
348 return(1);
349 }
350 adc_command = BUILD_COMMAND_SINGLE_ENDED[(x + 1) % 16] | OSR_mode | two_x_mode;
351 if (LTC2449_EOC_timeout(LTC2449_CS, MISO_TIMEOUT)) // Checks for EOC with a timeout
352 return(1);
353 LTC2449_read(LTC2449_CS, adc_command, &adc_code);
354 adc_voltage = LTC2449_code_to_voltage(adc_code, LTC2449_lsb, LTC2449_offset_code);
355 Serial.print(" ****");
356 Serial.print("CH");
357 Serial.print(x);
358 Serial.print(": ");
359 Serial.print(adc_voltage, 4);
360 Serial.print(F("V\n\n"));
361 }
362 }
363 else
364 {
365 adc_command = BUILD_COMMAND_SINGLE_ENDED[user_command] | OSR_mode | two_x_mode;
366 Serial.print("\nADC Command: B");
367 Serial.println(adc_command, BIN);
368 if (LTC2449_EOC_timeout(LTC2449_CS, MISO_TIMEOUT)) // Checks for EOC with a timeout
369 return(1);
370 LTC2449_read(LTC2449_CS, adc_command, &adc_code); // Throws out last reading
371 if (two_x_mode)
372 {
373 LTC2449_read(LTC2449_CS, adc_command, &adc_code); // Throws out an extra reading in 2x mode
374 if (LTC2449_EOC_timeout(LTC2449_CS, MISO_TIMEOUT)) // Checks for EOC with a timeout
375 return(1);
376 }
377 if (LTC2449_EOC_timeout(LTC2449_CS, MISO_TIMEOUT)) // Checks for EOC with a timeout
378 return(1);
379 LTC2449_read(LTC2449_CS, adc_command, &adc_code); // Now we're ready to read the desired data
380 Serial.print("Received Code: 0x");
381 Serial.println(adc_code, HEX);
382 adc_voltage = LTC2449_code_to_voltage(adc_code, LTC2449_lsb, LTC2449_offset_code);
383 Serial.print(" ****");
384 Serial.print("CH");
385 Serial.print(user_command);
386 Serial.print(": ");
387 Serial.print(adc_voltage, 4);
388 Serial.print(F("V\n\n"));
389 }
390 }
391 return(0);
392 }
393
394 //! Read channels in differential mode
395 //! @return 0 if successful, 1 is failure
396 int8_t menu_2_read_differential()
397 {
398 int8_t y; // Offset into differential channel array to select polarity
399 uint16_t adc_command; // The LTC2449 command word
400 int16_t user_command; // The user input command
401 uint32_t adc_code = 0; // The LTC2449 code
402 float adc_voltage; // The LTC2449 voltage
403
404 while (1)
405 {
406 Serial.print(F("\n*************************\n\n")); // Display differential menu
407 Serial.print(F("0-0P-1N 8-1P-0N\n"));
408 Serial.print(F("1-2P-3N 9-3P-2N\n"));
409 Serial.print(F("2-4P-5N 10-5P-4N\n"));
410 Serial.print(F("3-6P-7N 11-7P-6N\n"));
411 Serial.print(F("4-8P-9N 12-9P-8N\n"));
412 Serial.print(F("5-10P-11N 13-11P-10N\n"));
413 Serial.print(F("6-12P_13N 14-13P-12N\n"));
414 Serial.print(F("7-14P-15N 15-15P-14N\n"));
415 Serial.print(F("16-ALL Even_P-Odd_N\n"));
416 Serial.print(F("17-ALL Odd_P-Even_N\n"));
417 Serial.print(F("m-Main Menu\n"));
418
419 user_command = read_int(); // Read the single command
420 if (user_command == 'm')
421 return(0);
422 Serial.println(user_command);
423 if ((user_command == 16) || (user_command == 17))
424 {
425 if (user_command == 16)
426 {
427 Serial.print(F("ALL Even_P-Odd_N\n")); // Cycles through options 0-7
428 y = 0;
429 }
430 if (user_command == 17)
431 {
432 Serial.print(F("ALL Odd_P-Even_N\n")); // Cycles through options 8-15
433 y = 8;
434 }
435
436 adc_command = BUILD_COMMAND_DIFF[y] | OSR_mode | two_x_mode; // Build the channel 0 and 1 for differential mode
437 if (LTC2449_EOC_timeout(LTC2449_CS, MISO_TIMEOUT)) // Checks for EOC with a timeout
438 return(1);
439 LTC2449_read(LTC2449_CS, adc_command, &adc_code); // Throws out reading
440 for (int8_t x = 0; x < 7; x++) // Read all channels in differential mode. All even channels are positive and odd channels are negative
441 {
442 if (two_x_mode)
443 {
444 LTC2449_read(LTC2449_CS, adc_command, &adc_code); // Throws out an extra reading in 2x mode
445 if (LTC2449_EOC_timeout(LTC2449_CS, MISO_TIMEOUT)) // Checks for EOC with a timeout
446 return(1);
447 }
448 adc_command = BUILD_COMMAND_DIFF[((x + 1) % 8) + y] | OSR_mode | two_x_mode;
449 if (LTC2449_EOC_timeout(LTC2449_CS, MISO_TIMEOUT)) // Checks for EOC with a timeout
450 return(1);
451 LTC2449_read(LTC2449_CS, adc_command, &adc_code);
452 Serial.print("Received Code: 0x");
453 Serial.println(adc_code, HEX);
454 adc_voltage = LTC2449_code_to_voltage(adc_code, LTC2449_lsb, LTC2449_offset_code);
455 Serial.print("\n ****");
456 print_user_command(x + y);
457 Serial.print(": ");
458 Serial.print(adc_voltage, 4);
459 Serial.print(F("V\n"));
460 }
461 }
462 else
463 {
464 // Reads and displays a selected channel
465 adc_command = BUILD_COMMAND_DIFF[user_command] | OSR_mode | two_x_mode;
466 Serial.print("ADC Command: B");
467 Serial.println(adc_command, BIN);
468 if (LTC2449_EOC_timeout(LTC2449_CS, MISO_TIMEOUT)) // Checks for EOC with a timeout
469 return(1);
470 LTC2449_read(LTC2449_CS, adc_command, &adc_code); // Throws out last reading
471 if (two_x_mode)
472 {
473 if (LTC2449_EOC_timeout(LTC2449_CS, MISO_TIMEOUT)) // Checks for EOC with a timeout
474 return(1);
475 LTC2449_read(LTC2449_CS, adc_command, &adc_code); // Throws out an extra reading in 2x mode
476 }
477 if (LTC2449_EOC_timeout(LTC2449_CS, MISO_TIMEOUT)) // Checks for EOC with a timeout
478 return(1);
479 LTC2449_read(LTC2449_CS, adc_command, &adc_code);
480 Serial.print("Received Code: 0x");
481 Serial.println(adc_code, HEX);
482 adc_voltage = LTC2449_code_to_voltage(adc_code, LTC2449_lsb, LTC2449_offset_code);
483 Serial.print("\n ****");
484 print_user_command(user_command);
485 Serial.print(adc_voltage, 4);
486 Serial.print(F("V\n"));
487 }
488 }
489 return(0);
490 }
491
492 //! Calibrate ADC given two known inputs
493 //! @return 0 if successful, 1 is failure
494 int8_t menu_3_calibrate()
495 {
496 uint16_t adc_command; // The LTC2449 command word
497 int16_t user_command; // The user input command
498 uint32_t adc_code = 0; // The LTC2449 code
499 float zero_voltage; // Measured cal voltage
500 float fs_voltage; // Measured cal voltage
501 uint32_t zero_code; // Cal zero code
502 uint32_t fs_code; // Cal full scale code
503
504 // Calibration
505 Serial.println("Apply 100mV to CH0 with respect to COM");
506 Serial.println("or apply a voltage for the lower point in two point calibration");
507 Serial.print("Enter the measured input voltage:");
508 zero_voltage = read_float();
509 Serial.println(zero_voltage, 6);
510
511 // Set OSR to 32768
512 adc_command = BUILD_OSR_COMMAND[9]; // Build OSR command
513 if (LTC2449_EOC_timeout(LTC2449_CS, MISO_TIMEOUT)) // Checks for EOC with a timeout
514 return(1);
515 LTC2449_read(LTC2449_CS, adc_command, &adc_code); // Send OSR command
516
517 adc_command = BUILD_COMMAND_SINGLE_ENDED[0] | LTC2449_OSR_32768 | LTC2449_SPEED_1X; // Build ADC command byte for voltage input
518 if (LTC2449_EOC_timeout(LTC2449_CS, MISO_TIMEOUT)) // Checks for EOC with a timeout
519 return(1);
520 LTC2449_read(LTC2449_CS, adc_command, &adc_code); // Throw away previous reading
521 delay(100);
522 if (LTC2449_EOC_timeout(LTC2449_CS, MISO_TIMEOUT)) // Checks for EOC with a timeout
523 return(1);
524 LTC2449_read(LTC2449_CS, adc_command, &zero_code); // Measure zero
525
526 Serial.println("Apply ~2.40V input voltage to CH0.");
527 Serial.println("Enter the measured input voltage:");
528
529 fs_voltage = read_float();
530 if (LTC2449_EOC_timeout(LTC2449_CS, MISO_TIMEOUT)) // Checks for EOC with a timeout
531 return(1);
532 LTC2449_read(LTC2449_CS, adc_command, &adc_code); // Throw away previous reading
533 delay(100);
534 if (LTC2449_EOC_timeout(LTC2449_CS, MISO_TIMEOUT)) // Checks for EOC with a timeout
535 return(1);
536 LTC2449_read(LTC2449_CS, adc_command, &fs_code); // Measure full scale
537 LTC2449_cal_voltage(zero_code, fs_code, zero_voltage, fs_voltage, &LTC2449_lsb, &LTC2449_offset_code);
538
539 Serial.print("ADC offset : ");
540 Serial.println(LTC2449_offset_code);
541 Serial.print(" ADC lsb : ");
542 Serial.print(LTC2449_lsb*1.0e9, 4);
543 Serial.println("nV (32-bits)");
544 store_calibration();
545 return(0);
546 }
547
548 //! Set Oversample Ratio (OSR)
549 //! @return void
550 void menu_4_set_OSR()
551 {
552 int16_t user_command; // The user input command
553
554 // Oversample Ratio Settings
555 Serial.print(F("Oversample Ratio Settings\n")); // Display OSR menu
556 Serial.print(F("1-64\n"));
557 Serial.print(F("2-128\n"));
558 Serial.print(F("3-256\n"));
559 Serial.print(F("4-512\n"));
560 Serial.print(F("5-1024\n"));
561 Serial.print(F("6-2048\n"));
562 Serial.print(F("7-4096\n"));
563 Serial.print(F("8-8192\n"));
564 Serial.print(F("9-16384\n"));
565 Serial.print(F("10-32768\n"));
566 Serial.print("\nEnter a Command: ");
567
568 user_command = read_int();
569 Serial.println(user_command);
570
571 OSR_mode = BUILD_OSR_COMMAND[user_command]; // Build OSR command
572
573 Serial.print("\nADC OSR Command: B");
574 Serial.println(OSR_mode, BIN);
575 }
576
577 //! Set 1X or 2X mode
578 //! @return void
579 void menu_5_set_1X2X()
580 {
581 int16_t user_command; // The user input command
582
583 // 2X Mode
584 Serial.print(F("2X Mode Settings\n\n"));
585 Serial.print(F("0-Disable\n"));
586 Serial.print(F("1-Enable\n"));
587 Serial.print(F("Enter a Command: "));
588 user_command = read_int();
589 Serial.println(user_command);
590
591 if (user_command == 0)
592 {
593 two_x_mode = LTC2449_SPEED_1X;
594 Serial.print(F("2X Mode Disabled\n"));
595 }
596 else
597 {
598 two_x_mode = LTC2449_SPEED_2X;
599 Serial.print(F("2X Mode Enabled\n"));
600 }
601 }
602
603 //! Store measured calibration parameters to nonvolatile EEPROM on demo board
604 //! @return void
605 void store_calibration()
606 // store the ADC calibration to the EEPROM
607 {
608 eeprom_write_int16(EEPROM_I2C_ADDRESS, EEPROM_CAL_KEY, EEPROM_CAL_STATUS_ADDRESS); // Cal key
609 eeprom_write_int32(EEPROM_I2C_ADDRESS, LTC2449_offset_code, EEPROM_CAL_STATUS_ADDRESS+2); // Offset
610 eeprom_write_float(EEPROM_I2C_ADDRESS, LTC2449_lsb, EEPROM_CAL_STATUS_ADDRESS+6); // LSB
611 Serial.println("Calibration Stored to EEPROM");
612 }
613
614 //! Enable / Disable calibration without actually touching stored calibration values
615 //! @return void
616 void menu_6_en_dis_cal()
617 {
618 int16_t user_command; // The user input command
619
620 Serial.println(F("Enable / Disable calibration key"));
621 Serial.println(F("0-Disable\n"));
622 Serial.println(F("1-Enable - use ONLY if you know a calibration has been performed previously\n"));
623 Serial.println(F("Enter a Command: "));
624 user_command = read_int();
625
626 if (user_command == 0)
627 {
628 eeprom_write_int16(EEPROM_I2C_ADDRESS, 0xFFFF, EEPROM_CAL_STATUS_ADDRESS); // Reset cal key
629 Serial.print(F("Calibration Disabled\n"));
630 }
631 else
632 {
633 eeprom_write_int16(EEPROM_I2C_ADDRESS, EEPROM_CAL_KEY, EEPROM_CAL_STATUS_ADDRESS); // Set cal key
634 Serial.print(F("Calibration Enabled\n"));
635 }
636 restore_calibration();
637 }
638
639 //! Read stored calibration parameters from nonvolatile EEPROM on demo board
640 //! @return return 1 if successful, 0 if not
641 int8_t restore_calibration()
642 // read the calibration from EEPROM
643 {
644 int16_t cal_key;
645 // read the cal key from the EEPROM
646 eeprom_read_int16(EEPROM_I2C_ADDRESS, &cal_key, EEPROM_CAL_STATUS_ADDRESS);
647 if (cal_key == EEPROM_CAL_KEY)
648 {
649 // calibration has been stored, read offset and lsb
650 eeprom_read_int32(EEPROM_I2C_ADDRESS, &LTC2449_offset_code, EEPROM_CAL_STATUS_ADDRESS+2); // offset
651 eeprom_read_float(EEPROM_I2C_ADDRESS, &LTC2449_lsb, EEPROM_CAL_STATUS_ADDRESS+6); // lsb
652 Serial.println("Calibration Restored");
653 return(1);
654 }
655 else
656 {
657 Serial.println("Calibration not found");
658 return(0);
659 }
660 }
LTC2449_lsb
static float LTC2449_lsb
Ideal LSB voltage for a perfect part.
Definition: DC742A.ino:126
LTC2449_P10_N11
#define LTC2449_P10_N11
Definition: LTC2449.h:191
setup
static void setup()
Initialize Linduino.
Definition: DC742A.ino:157
eeprom_read_int16
uint8_t eeprom_read_int16(uint8_t i2c_address, int16_t *read_data, uint16_t address)
Read the two byte integer data from the EEPROM starting at address.
Definition: QuikEval_EEPROM.cpp:395
menu_1_read_single_ended
static int8_t menu_1_read_single_ended()
Read channels in single-ended mode.
Definition: DC742A.ino:307
menu_5_set_1X2X
static void menu_5_set_1X2X()
Set 1X or 2X mode.
Definition: DC742A.ino:579
LTC2449_P3_N2
#define LTC2449_P3_N2
Definition: LTC2449.h:180
user_command
unsigned char user_command
Definition: Serial_EEPROM_Test.ino:75
adc_command
static uint8_t adc_command
Definition: DC2071AA.ino:111
LTC2449_P14_N15
#define LTC2449_P14_N15
Definition: LTC2449.h:197
EEPROM_I2C_ADDRESS
#define EEPROM_I2C_ADDRESS
Definition: QuikEval_EEPROM.h:60
LTC2449_CS
#define LTC2449_CS
Define the SPI CS pin.
Definition: LTC2449.h:140
LTC2449_CH0
#define LTC2449_CH0
Definition: LTC2449.h:156
LTC2449_P11_N10
#define LTC2449_P11_N10
Definition: LTC2449.h:192
LTC2449_CH12
#define LTC2449_CH12
Definition: LTC2449.h:168
LTC2449_OSR_2048
#define LTC2449_OSR_2048
Definition: LTC2449.h:217
LTC2449_P6_N7
#define LTC2449_P6_N7
Definition: LTC2449.h:185
BUILD_1X_2X_COMMAND
const uint16_t BUILD_1X_2X_COMMAND[2]
Lookup table to build 1X / 2X bits.
Definition: DC742A.ino:151
LTC2449_OSR_32768
#define LTC2449_OSR_32768
Definition: LTC2449.h:221
menu_3_calibrate
static int8_t menu_3_calibrate()
Calibrate ADC given two known inputs.
Definition: DC742A.ino:494
demo_board_connected
static uint8_t demo_board_connected
Set to 1 if the board is connected.
Definition: DC742A.ino:123
LTC2449_OSR_8192
#define LTC2449_OSR_8192
Definition: LTC2449.h:219
Linduino.h
Header File for Linduino Libraries and Demo Code.
eeprom_read_float
uint8_t eeprom_read_float(uint8_t i2c_address, float *read_data, uint16_t address)
Read the four byte float data from the EEPROM starting at address.
Definition: QuikEval_EEPROM.cpp:435
eeprom_write_int32
uint8_t eeprom_write_int32(uint8_t i2c_address, int32_t write_data, uint16_t address)
Write the 4 byte long data to the EEPROM starting at address.
Definition: QuikEval_EEPROM.cpp:455
store_calibration
static void store_calibration()
Store measured calibration parameters to nonvolatile EEPROM on demo board.
Definition: DC742A.ino:605
LTC2449_cal_voltage
void LTC2449_cal_voltage(int32_t zero_code, int32_t fs_code, float zero_voltage, float fs_voltage, float *LTC2449_lsb, int32_t *LTC2449_offset_code)
Calculate the lsb weight and offset code given a full-scale code and a measured zero-code.
Definition: LTC2449.cpp:136
LTC2449_OSR_16384
#define LTC2449_OSR_16384
Definition: LTC2449.h:220
LTC2449_CH14
#define LTC2449_CH14
Definition: LTC2449.h:170
MISO_TIMEOUT
const uint16_t MISO_TIMEOUT
MISO timeout constant.
Definition: DC742A.ino:154
menu_4_set_OSR
static void menu_4_set_OSR()
Set Oversample Ratio (OSR)
Definition: DC742A.ino:550
print_user_command
static void print_user_command(uint8_t menu)
Display selected differential channels.
Definition: DC742A.ino:249
OSR_mode
static int16_t OSR_mode
The LTC2449 OSR setting.
Definition: DC742A.ino:124
adc_voltage
static float adc_voltage
Definition: DC2071AA.ino:115
LTC2449_CH3
#define LTC2449_CH3
Definition: LTC2449.h:159
LTC2449_code_to_voltage
float LTC2449_code_to_voltage(int32_t adc_code, float LTC2449_lsb, int32_t LTC2449_offset_code)
Calculates the voltage corresponding to an adc code, given lsb weight (in volts) and the calibrated A...
Definition: LTC2449.cpp:127
LTC2449_P0_N1
#define LTC2449_P0_N1
Definition: LTC2449.h:176
LTC2449_P12_N13
#define LTC2449_P12_N13
Definition: LTC2449.h:194
eeprom_write_float
uint8_t eeprom_write_float(uint8_t i2c_address, float write_data, uint16_t address)
Write the 4 byte float data to the EEPROM starting at address.
Definition: QuikEval_EEPROM.cpp:412
BUILD_COMMAND_SINGLE_ENDED
const uint16_t BUILD_COMMAND_SINGLE_ENDED[16]
Lookup table to build the command for single-ended mode.
Definition: DC742A.ino:132
eeprom_write_int16
uint8_t eeprom_write_int16(uint8_t i2c_address, int16_t write_data, uint16_t address)
Write the 2 byte integer data to the EEPROM starting at address.
Definition: QuikEval_EEPROM.cpp:377
LTC2449_CH5
#define LTC2449_CH5
Definition: LTC2449.h:161
LTC2449_CH1
#define LTC2449_CH1
Definition: LTC2449.h:157
LTC2449_P5_N4
#define LTC2449_P5_N4
Definition: LTC2449.h:183
QuikEval_EEPROM.h
QuikEval EEPROM Library.
LTC2449_CH11
#define LTC2449_CH11
Definition: LTC2449.h:167
quikeval_SPI_init
void quikeval_SPI_init(void)
Configure the SPI port for 4Mhz SCK.
Definition: LT_SPI.cpp:151
LTC2449_OSR_512
#define LTC2449_OSR_512
Definition: LTC2449.h:215
LTC2449_CH13
#define LTC2449_CH13
Definition: LTC2449.h:169
EEPROM_CAL_STATUS_ADDRESS
#define EEPROM_CAL_STATUS_ADDRESS
Definition: QuikEval_EEPROM.h:58
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
LTC2449_CH8
#define LTC2449_CH8
Definition: LTC2449.h:164
LT_SPI.h
LT_SPI: Routines to communicate with ATmega328P&#39;s hardware SPI port.
LTC2449_CH6
#define LTC2449_CH6
Definition: LTC2449.h:162
LTC2449_P4_N5
#define LTC2449_P4_N5
Definition: LTC2449.h:182
LTC2449_CH9
#define LTC2449_CH9
Definition: LTC2449.h:165
LT_I2C.h
LT_I2C: Routines to communicate with ATmega328P&#39;s hardware I2C port.
BUILD_COMMAND_DIFF
const uint16_t BUILD_COMMAND_DIFF[16]
Lookup table to build the command for differential mode.
Definition: DC742A.ino:139
BUILD_OSR_COMMAND
const uint16_t BUILD_OSR_COMMAND[10]
Lookup table to build the command for OSR.
Definition: DC742A.ino:146
LTC2449_P13_N12
#define LTC2449_P13_N12
Definition: LTC2449.h:195
LTC2449_P2_N3
#define LTC2449_P2_N3
Definition: LTC2449.h:179
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
eeprom_read_int32
uint8_t eeprom_read_int32(uint8_t i2c_address, int32_t *read_data, uint16_t address)
Read the four byte long data from the EEPROM starting at address.
Definition: QuikEval_EEPROM.cpp:478
UserInterface.h
read_int
int32_t read_int()
Definition: UserInterface.cpp:93
LTC2449_P9_N8
#define LTC2449_P9_N8
Definition: LTC2449.h:189
LTC2449.h
LTC2449: 24-Bit, 16-Channel Delta Sigma ADCs with Selectable Speed/Resolution.
LTC2449_CH10
#define LTC2449_CH10
Definition: LTC2449.h:166
LTC2449_OSR_64
#define LTC2449_OSR_64
Definition: LTC2449.h:212
read_float
float read_float()
Definition: UserInterface.cpp:78
menu_2_read_differential
static int8_t menu_2_read_differential()
Read channels in differential mode.
Definition: DC742A.ino:396
x
int32_t x
Definition: LTC2492_Thermocouple_Meter.ino:119
LTC2449_OSR_128
#define LTC2449_OSR_128
Definition: LTC2449.h:213
print_title
static void print_title()
Prints the title block when program first starts.
Definition: DC742A.ino:221
two_x_mode
static int16_t two_x_mode
The LTC2449 2X Mode settings.
Definition: DC742A.ino:125
LTC2449_OSR_1024
#define LTC2449_OSR_1024
Definition: LTC2449.h:216
LTC2449_CH15
#define LTC2449_CH15
Definition: LTC2449.h:171
LTC2449_SPEED_1X
#define LTC2449_SPEED_1X
Definition: LTC2449.h:148
LTC2449_CH2
#define LTC2449_CH2
Definition: LTC2449.h:158
LTC2449_OSR_256
#define LTC2449_OSR_256
Definition: LTC2449.h:214
LTC2449_OSR_4096
#define LTC2449_OSR_4096
Definition: LTC2449.h:218
LTC2449_CH7
#define LTC2449_CH7
Definition: LTC2449.h:163
quikeval_I2C_init
void quikeval_I2C_init(void)
Initializes Linduino I2C port.
Definition: LT_I2C.cpp:394
restore_calibration
static int8_t restore_calibration()
Read stored calibration parameters from nonvolatile EEPROM on demo board.
Definition: DC742A.ino:641
print_prompt
static void print_prompt()
Prints main menu.
Definition: DC742A.ino:236
LTC2449_CH4
#define LTC2449_CH4
Definition: LTC2449.h:160
LTC2449_P8_N9
#define LTC2449_P8_N9
Definition: LTC2449.h:188
LTC2449_P1_N0
#define LTC2449_P1_N0
Definition: LTC2449.h:177
LTC2449_P7_N6
#define LTC2449_P7_N6
Definition: LTC2449.h:186
LTC2449_SPEED_2X
#define LTC2449_SPEED_2X
Definition: LTC2449.h:149
LTC2449_offset_code
static int32_t LTC2449_offset_code
Ideal offset for a perfect part.
Definition: DC742A.ino:127
LTC2449_EOC_timeout
int8_t LTC2449_EOC_timeout(uint8_t cs, uint16_t miso_timeout)
Define the SPI CS pin.
Definition: LTC2449.cpp:86
EEPROM_CAL_KEY
#define EEPROM_CAL_KEY
Definition: QuikEval_EEPROM.h:59
loop
static void loop()
Repeats Linduino loop.
Definition: DC742A.ino:175
menu_6_en_dis_cal
static void menu_6_en_dis_cal()
Enable / Disable calibration without actually touching stored calibration values. ...
Definition: DC742A.ino:616
adc_code
static uint32_t adc_code
Definition: DC2071AA.ino:113
LTC2449_P15_N14
#define LTC2449_P15_N14
Definition: LTC2449.h:198
LTC2449_read
void LTC2449_read(uint8_t cs, uint16_t adc_command, uint32_t *adc_code)
Reads from LTC2449.
Definition: LTC2449.cpp:107