Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
DC1011AB.ino
Go to the documentation of this file.
1 /*!
2 Linear Technology DC1011A-B Demonstration Board.
3 LTC2496: 16-Bit 8-/16-Channel Delta Sigma ADC with Easy Drive Input Current Cancellation
4 
5 @verbatim
6 
7 NOTES
8  Setup:
9  Set the terminal baud rate to 115200 and select the newline terminator.
10  Equipment required is a precision voltage source and a precision
11  voltmeter. No external power supply is required. Ensure all jumpers on
12  the demo board are installed in their default positions from the
13  factory.
14 
15  How to test Single-Ended mode:
16  The voltage source should be connected to the ADC such that the negative
17  lead is connected to COM. The positive lead may be connected to any
18  channel input. Ensure voltage is within analog input voltage range -2.5V to
19  +2.5V.
20 
21  How to test Differential Mode:
22  The voltage source should be connected with positive and negative leads to
23  paired channels. The voltage source negative output must also be connected to
24  the COM pin in order to provide a ground-referenced voltage. Ensure voltage is
25  within analog input voltage range -2.5V to +2.5V. Swapping input voltages
26  results in a reversed polarity reading.
27 
28 USER INPUT DATA FORMAT:
29  decimal : 1024
30  hex : 0x400
31  octal : 02000 (leading 0 "zero")
32  binary : B10000000000
33  float : 1024.0
34 
35 
36 @endverbatim
37 
38 http://www.linear.com/product/LTC2496
39 
40 http://www.linear.com/product/LTC2496#demoboards
41 
42 
43 
44 Copyright 2018(c) Analog Devices, Inc.
45 
46 All rights reserved.
47 
48 Redistribution and use in source and binary forms, with or without
49 modification, are permitted provided that the following conditions are met:
50  - Redistributions of source code must retain the above copyright
51  notice, this list of conditions and the following disclaimer.
52  - Redistributions in binary form must reproduce the above copyright
53  notice, this list of conditions and the following disclaimer in
54  the documentation and/or other materials provided with the
55  distribution.
56  - Neither the name of Analog Devices, Inc. nor the names of its
57  contributors may be used to endorse or promote products derived
58  from this software without specific prior written permission.
59  - The use of this software may or may not infringe the patent rights
60  of one or more patent holders. This license does not release you
61  from the requirement that you obtain separate licenses from these
62  patent holders to use this software.
63  - Use of the software either in source or binary form, must be run
64  on or directly connected to an Analog Devices Inc. component.
65 
66 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
67 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
68 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
69 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
70 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
71 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
72 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
73 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
74 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
75 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
76 */
77 
78 /*! @file
79  @ingroup LTC2496
80 */
81 
82 #include <Arduino.h>
83 #include <stdint.h>
84 #include "Linduino.h"
85 #include "LT_SPI.h"
86 #include "UserInterface.h"
87 #include "QuikEval_EEPROM.h"
88 #include "LTC2496.h"
89 #include "LTC24XX_general.h"
90 #include <SPI.h>
91 #include <Wire.h>
92 #include "LT_I2C.h"
93 
94 // Function Declaration
95 void print_title(); // Print the title block
96 void print_prompt(); // Prompt the user for an input command
97 void print_user_command(uint8_t menu); // Display selected differential channels
98 
99 uint8_t menu_1_read_single_ended();
100 uint8_t menu_2_read_differential();
101 
102 // Global variables
103 static uint8_t demo_board_connected; //!< Set to 1 if the board is connected
104 static float reference_voltage = 5; //!< The reference voltage range, set to 5v through JP2 and JP3 by default
105 
106 //Constants
107 const uint16_t MISO_TIMEOUT = 1000; //!< The MISO timeout (ms)
108 // Build the command for single-ended mode
110  LTC2496_CH1,
111  LTC2496_CH2,
112  LTC2496_CH3,
113  LTC2496_CH4,
114  LTC2496_CH5,
115  LTC2496_CH6,
116  LTC2496_CH7,
117  LTC2496_CH8,
118  LTC2496_CH9,
119  LTC2496_CH10,
120  LTC2496_CH11,
121  LTC2496_CH12,
122  LTC2496_CH13,
123  LTC2496_CH14,
125  }; //!< Builds the command for single-ended mode
126 
127 // Build the command for differential mode
128 const uint8_t BUILD_COMMAND_DIFF[16] = { LTC2496_P0_N1,
144  };
145 
146 
147 //! Initialize Linduino
148 void setup()
149 // Setup the program
150 {
151  char demo_name[] = "DC1011"; // Demo Board Name stored in QuikEval EEPROM
152 
153  quikeval_SPI_init(); // Configure the spi port for 4MHz SCK
154  quikeval_SPI_connect(); // Connect SPI to main data port
155  quikeval_I2C_init(); // Configure the EEPROM I2C port for 100kHz
156  Serial.begin(115200); // Initialize the serial port to the PC
157  print_title();
160  {
161  print_prompt();
162  }
163 }
164 
165 //! Repeats Linduino loop
166 void loop()
167 {
168  uint8_t user_command; // The user input command
169  uint8_t ack = 0;
171  {
172  if (Serial.available()) // Check for user input
173  {
174  user_command = read_int(); // Read the user command
175  if (user_command == 'm');
176  else
177  Serial.println(user_command);
178  delay(50); // Allow the print to finish
179  switch (user_command)
180  {
181  case 1:
182  ack |= menu_1_read_single_ended();
183  break;
184  case 2:
185  ack |= menu_2_read_differential();
186  break;
187  default:
188  Serial.println("Incorrect Option");
189  break;
190  }
191  if (ack)
192  Serial.println(F("***** SPI ERROR *****"));
193  Serial.println(F("*****************************************************************"));
194  print_prompt();
195  }
196  }
197 }
198 
199 //Function Definitions
200 
201 //! Prints the title block when program first starts.
203 {
204  Serial.println();
205  Serial.println(F("*****************************************************************"));
206  Serial.println(F("* DC1011A-B Demonstration Program *"));
207  Serial.println(F("* *"));
208  Serial.println(F("* This program demonstrates how to send data and receive data *"));
209  Serial.println(F("* from the 24-bit delta-sigma ADC. *"));
210  Serial.println(F("* *"));
211  Serial.println(F("* *"));
212  Serial.println(F("* Set the baud rate to 115200 select the newline terminator. *"));
213  Serial.println(F("* *"));
214  Serial.println(F("*****************************************************************"));
215 }
216 
217 //! Prints main menu.
219 {
220 
221  Serial.println(F("1-Read Single-Ended"));
222  Serial.println(F("2-Read Differential"));
223  Serial.println();
224  Serial.print(F("Enter a command:"));
225 }
226 
227 //! read from ADC single-ended
228 //! @return 0 if successful, 1 if failure
229 //! @return 0 when m is entered into menu, 1 if timeout for EOC
231 {
232  uint8_t adc_command; // The LTC2496 command byte
233  int16_t user_command; // The user input command
234  int32_t adc_code=0; // The LTC2496 code
235  float adc_voltage; // The LTC2496 voltage
236 
237  while (1)
238  {
239  Serial.print(F("*************************\n\n")); // Display single-ended menu
240  Serial.print(F("0-CH0 8-CH8\n"));
241  Serial.print(F("1-CH1 9-CH9\n"));
242  Serial.print(F("2-CH2 10-CH10\n"));
243  Serial.print(F("3-CH3 11-CH11\n"));
244  Serial.print(F("4-CH4 12-CH12\n"));
245  Serial.print(F("5-CH5 13-CH13\n"));
246  Serial.print(F("6-CH6 14-CH14\n"));
247  Serial.print(F("7-CH7 15-CH15\n"));
248  Serial.print(F("16-ALL\n"));
249  Serial.print(F("m-Main Menu\n"));
250  Serial.print(F("\nEnter a Command: "));
251  user_command = read_int(); // Read the single command
252  if (user_command == 'm')
253  return(0);
254  else
255  Serial.println(user_command);
256  Serial.println();
257 
258  if (user_command == 16)
259  {
260  Serial.print(F("ALL\n"));
261  adc_command = LTC2496_ENABLE | BUILD_COMMAND_SINGLE_ENDED[0]; // Build ADC command for channel 0
262 
263  if (LTC2496_EOC_timeout(LTC2496_CS, MISO_TIMEOUT)) // Check for EOC
264  return(1);
265  LTC2496_read(LTC2496_CS, adc_command, &adc_code); // Throws out last reading
266 
267  for (int8_t x = 0; x < 15; x++)
268  {
269  adc_command = LTC2496_ENABLE | BUILD_COMMAND_SINGLE_ENDED[(x + 1) % 16]; // Read all channels in single-ended mode
270  if (LTC2496_EOC_timeout(LTC2496_CS, MISO_TIMEOUT)) // Check for EOC
271  return(1);
272  LTC2496_read(LTC2496_CS, adc_command, &adc_code);
273  adc_voltage = LTC2496_code_to_voltage(adc_code, reference_voltage);
274  Serial.print(F(" ****"));
275  Serial.print(F("CH"));
276  Serial.print(x);
277  Serial.print(F(": "));
278  Serial.print(adc_voltage, 4);
279  Serial.print(F("V\n"));
280  }
281  }
282  else if (user_command<16 && user_command >=0) // Read selected channel
283  {
285  Serial.print(F("\nADC Command: B"));
286  Serial.println(adc_command, BIN);
287  if (LTC2496_EOC_timeout(LTC2496_CS, MISO_TIMEOUT)) // Check for EOC
288  return(1);
289  LTC2496_read(LTC2496_CS, adc_command, &adc_code); // Throws out last reading
290  if (LTC2496_EOC_timeout(LTC2496_CS, MISO_TIMEOUT)) // Check for EOC
291  return(1);
292  LTC2496_read(LTC2496_CS, adc_command, &adc_code);
293  Serial.print(F("Received Code: 0x"));
294  Serial.println(adc_code, HEX);
295  adc_voltage = LTC2496_code_to_voltage(adc_code, reference_voltage);
296  Serial.print(F(" ****"));
297  Serial.print(F("CH"));
298  Serial.print(user_command);
299  Serial.print(F(": "));
300  Serial.print(adc_voltage, 4);
301  Serial.print(F("V\n"));
302  }
303  }
304 }
305 
306 //! Read channels in differential mode
307 //! @return 0 when m is entered into menu, 1 if timeout for EOC
309 {
310  int8_t y; // Offset into differential channel array to select polarity
311  uint8_t adc_command; // The LTC2496 command byte
312  int16_t user_command; // The user input command
313  int32_t adc_code=1; // The LTC2496 code
314  float adc_voltage; // The LTC2496 voltage
315 
316  while (1)
317  {
318  // Display differential menu
319  Serial.print(F("\n*************************\n\n"));
320  Serial.print(F("0-0P-1N 8-1P-0N\n"));
321  Serial.print(F("1-2P-3N 9-3P-2N\n"));
322  Serial.print(F("2-4P-5N 10-5P-4N\n"));
323  Serial.print(F("3-6P-7N 11-7P-6N\n"));
324  Serial.print(F("4-8P-9N 12-9P-8N\n"));
325  Serial.print(F("5-10P-11N 13-11P-10N\n"));
326  Serial.print(F("6-12P_13N 14-13P-12N\n"));
327  Serial.print(F("7-14P-15N 15-15P-14N\n"));
328  Serial.print(F("16-ALL Even_P-Odd_N\n"));
329  Serial.print(F("17-ALL Odd_P-Even_N\n"));
330  Serial.print(F("m-Main Menu\n"));
331  Serial.print(F("\nEnter a Command: "));
332  user_command = read_int();
333  if (user_command == 'm')
334  return(0);
335  Serial.println(user_command);
336  Serial.println();
337 
338  if ((user_command == 16) || (user_command == 17))
339  {
340  if (user_command == 16)
341  {
342  Serial.print(F("ALL Even_P-Odd_N\n")); // Cycles through options 0-7
343  y = 0;
344  }
345  if (user_command == 17)
346  {
347  Serial.print(F("ALL Odd_P-Even_N\n")); // Cycles through options 8-15
348  y = 8;
349  }
350  adc_command = LTC2496_ENABLE | BUILD_COMMAND_DIFF[y]; // Set up first channel
351  if (LTC2496_EOC_timeout(LTC2496_CS, MISO_TIMEOUT)) // check for EOC
352  return(1);
353  LTC2496_read(LTC2496_CS, adc_command, &adc_code); // Throws out last reading
354  for (int8_t x = 0; x <= 7; x++) // Read all channels. All even channels are positive and odd channels are negative
355  {
356  adc_command = LTC2496_ENABLE | BUILD_COMMAND_DIFF[((x+1) % 8) + y];
357  if (LTC2496_EOC_timeout(LTC2496_CS, MISO_TIMEOUT)) // Check for EOC
358  return(1);
359  LTC2496_read(LTC2496_CS, adc_command, &adc_code);
360  adc_voltage = LTC2496_code_to_voltage(adc_code, reference_voltage);
361  Serial.println();
362  Serial.print(F("**** "));
363  print_user_command(x + y);
364  Serial.print(F(": "));
365  Serial.print(adc_voltage, 4);
366  Serial.print(F("V\n"));
367  }
368  }
369  else // Read selected channels
370  {
371  // Reads and displays a selected channel
373  Serial.print(F("ADC Command: 0b"));
374  Serial.println(adc_command, BIN);
375  if (LTC2496_EOC_timeout(LTC2496_CS, MISO_TIMEOUT)) // Check for EOC
376  return(1);
377  LTC2496_read(LTC2496_CS, adc_command, &adc_code); // Throws out last reading
378  if (LTC2496_EOC_timeout(LTC2496_CS, MISO_TIMEOUT)) // Check for EOC
379  return(1);
380  LTC2496_read(LTC2496_CS, adc_command, &adc_code);
381  Serial.print(F("Received Code: 0x"));
382  Serial.println(adc_code, HEX);
383  adc_voltage = LTC2496_code_to_voltage(adc_code, reference_voltage);
384  Serial.println();
385  Serial.print(F("**** "));
386  Serial.print(F("CH"));
387  print_user_command(user_command);
388  Serial.print(F(": "));
389  Serial.print(adc_voltage, 4);
390  Serial.print(F("V"));
391  Serial.println();
392  }
393  }
394 }
395 
396 //! Display selected differential channels. Displaying Single-Ended channels is
397 //! straightforward; not so with differential because the inputs can take either polarity.
398 void print_user_command(uint8_t menu) //!< the selected channels
399 {
400  switch (menu)
401  {
402  case 0:
403  Serial.print("0P-1N");
404  break;
405  case 1:
406  Serial.print("2P-3N");
407  break;
408  case 2:
409  Serial.print("4P-5N");
410  break;
411  case 3:
412  Serial.print("6P-7N");
413  break;
414  case 4:
415  Serial.print("8P-9N");
416  break;
417  case 5:
418  Serial.print("10P-11N");
419  break;
420  case 6:
421  Serial.print("12P-13N");
422  break;
423  case 7:
424  Serial.print("14P-15N");
425  break;
426  case 8:
427  Serial.print("1P-0N");
428  break;
429  case 9:
430  Serial.print("3P-2N");
431  break;
432  case 10:
433  Serial.print("5P-4N");
434  break;
435  case 11:
436  Serial.print("7P-6N");
437  break;
438  case 12:
439  Serial.print("9P-8N");
440  break;
441  case 13:
442  Serial.print("11P-10N");
443  break;
444  case 14:
445  Serial.print("13P-12N");
446  break;
447  case 15:
448  Serial.print("15P-14N");
449  break;
450  }
451  Serial.print(": ");
452 }
const uint8_t BUILD_COMMAND_DIFF[16]
Definition: DC1011AB.ino:128
#define LTC2496_CH13
Definition: LTC2496.h:215
static uint8_t menu_1_read_single_ended()
read from ADC single-ended
Definition: DC1011AB.ino:230
LTC2496: 16-Bit 8-/16-Channel Delta Sigma ADC with Easy Drive Input Current Cancellation.
unsigned char user_command
static uint8_t adc_command
Definition: DC2071AA.ino:111
#define LTC2496_P15_N14
Definition: LTC2496.h:177
#define LTC2496_CH14
Definition: LTC2496.h:216
#define LTC2496_CH4
Definition: LTC2496.h:206
Header File for Linduino Libraries and Demo Code.
static void setup()
Initialize Linduino.
Definition: DC1011AB.ino:148
#define LTC2496_CH3
Definition: LTC2496.h:205
static uint8_t demo_board_connected
Set to 1 if the board is connected.
Definition: DC1011AB.ino:103
#define LTC2496_P10_N11
Definition: LTC2496.h:170
#define LTC2496_CH11
Definition: LTC2496.h:213
#define LTC2496_CH10
Definition: LTC2496.h:212
static void loop()
Repeats Linduino loop.
Definition: DC1011AB.ino:166
#define LTC2496_P13_N12
Definition: LTC2496.h:174
#define LTC2496_P0_N1
Definition: LTC2496.h:155
#define LTC2496_CS
define the SPI CS pin
Definition: LTC2496.h:112
#define LTC2496_CH7
Definition: LTC2496.h:209
static float adc_voltage
Definition: DC2071AA.ino:115
static void print_prompt()
Prints main menu.
Definition: DC1011AB.ino:218
#define LTC2496_ENABLE
Definition: LTC2496.h:119
#define LTC2496_P5_N4
Definition: LTC2496.h:162
#define LTC2496_P9_N8
Definition: LTC2496.h:168
LTC24XX General Library: Functions and defines for all SINC4 Delta Sigma ADCs.
const uint8_t BUILD_COMMAND_SINGLE_ENDED[16]
Builds the command for single-ended mode.
Definition: DC1011AB.ino:109
#define LTC2496_CH15
Definition: LTC2496.h:217
static float reference_voltage
The reference voltage range, set to 5v through JP2 and JP3 by default.
Definition: DC1011AB.ino:104
QuikEval EEPROM Library.
#define LTC2496_P4_N5
Definition: LTC2496.h:161
#define LTC2496_P11_N10
Definition: LTC2496.h:171
void quikeval_SPI_init(void)
Configure the SPI port for 4Mhz SCK.
Definition: LT_SPI.cpp:151
#define LTC2496_P7_N6
Definition: LTC2496.h:165
int8_t discover_demo_board(char *demo_name)
Read the ID string from the EEPROM and determine if the correct board is connected.
LT_SPI: Routines to communicate with ATmega328P&#39;s hardware SPI port.
#define LTC2496_P2_N3
Definition: LTC2496.h:158
#define LTC2496_P6_N7
Definition: LTC2496.h:164
#define LTC2496_CH8
Definition: LTC2496.h:210
LT_I2C: Routines to communicate with ATmega328P&#39;s hardware I2C port.
#define LTC2496_CH5
Definition: LTC2496.h:207
void LTC2496_read(uint8_t cs, uint8_t adc_command, int32_t *adc_code)
Read LTC2496 result, program configuration for next conversion.
Definition: LTC2496.cpp:86
const uint16_t MISO_TIMEOUT
The MISO timeout (ms)
Definition: DC1011AB.ino:107
char demo_name[]
Demo Board Name stored in QuikEval EEPROM.
Definition: DC1880A.ino:97
#define LTC2496_P8_N9
Definition: LTC2496.h:167
float LTC2496_code_to_voltage(int32_t adc_code, float vref)
Calculates the LTC2496 input voltage.
Definition: LTC2496.cpp:93
void quikeval_SPI_connect()
Connect SPI pins to QuikEval connector through the Linduino MUX. This will disconnect I2C...
Definition: LT_SPI.cpp:138
int32_t read_int()
#define LTC2496_P3_N2
Definition: LTC2496.h:159
#define LTC2496_CH1
Definition: LTC2496.h:203
#define LTC2496_CH6
Definition: LTC2496.h:208
void quikeval_I2C_init(void)
Initializes Linduino I2C port.
Definition: LT_I2C.cpp:394
#define LTC2496_CH12
Definition: LTC2496.h:214
#define LTC2496_CH9
Definition: LTC2496.h:211
static void print_user_command(uint8_t menu)
Display selected differential channels.
Definition: DC1011AB.ino:398
int8_t LTC2496_EOC_timeout(uint8_t cs, uint16_t miso_timeout)
Checks for EOC with a specified timeout.
Definition: LTC2496.cpp:79
#define LTC2496_P12_N13
Definition: LTC2496.h:173
#define LTC2496_P14_N15
Definition: LTC2496.h:176
#define LTC2496_CH2
Definition: LTC2496.h:204
#define LTC2496_CH0
Definition: LTC2496.h:202
static uint32_t adc_code
Definition: DC2071AA.ino:113
static void print_title()
Prints the title block when program first starts.
Definition: DC1011AB.ino:202
static uint8_t menu_2_read_differential()
Read channels in differential mode.
Definition: DC1011AB.ino:308
#define LTC2496_P1_N0
Definition: LTC2496.h:156