Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
DC1563A.ino
Go to the documentation of this file.
1 /*!
2 Linear Technology DC1563A Demonstration Board.
3 LTC2312-12: 12-Bit, 500Ksps ADC.
4 LTC2312-14: 14-Bit, 500Ksps ADC.
5 LTC2313-12: 12-Bit, 2.5Msps ADC
6 LTC2313-14: 14-Bit, 2.5Msps ADC
7 LTC2314-14: 14-Bit, 4.5Msps ADC
8 LTC2315-12: 12-Bit, 5Msps ADC
9 
10 @verbatim
11 
12 NOTES
13  Setup:
14  Set the terminal baud rate to 115200 and select the newline terminator. Equipment
15  required is a voltage source (preferably low-noise) and a precision voltmeter.
16  Ensure all jumpers on the demo board are installed in their default positions
17  from the factory. Refer to Demo Manual DC1563A.
18 
19  How to test:
20  The voltage source should be connected to input AIN. Ensure the input is within its
21  specified absolute input voltage range. (It is easiest
22  to tie the voltage source negative terminal to COM.) Ensure the voltage
23  source is set within the range of 0V to +2.048V for low range, or within 0V to +4.096V
24  for high range.
25 
26 USER INPUT DATA FORMAT:
27  decimal : 1024
28  hex : 0x400
29  octal : 02000 (leading 0 "zero")
30  binary : B10000000000
31  float : 1024.0
32 
33 @endverbatim
34 
35 http://www.linear.com/product/LTC2312-12
36 http://www.linear.com/product/LTC2312-14
37 http://www.linear.com/product/LTC2313-12
38 http://www.linear.com/product/LTC2313-14
39 http://www.linear.com/product/LTC2314-14
40 http://www.linear.com/product/LTC2315-12
41 
42 http://www.linear.com/product/LTC2312-12#demoboards
43 http://www.linear.com/product/LTC2312-14#demoboards
44 http://www.linear.com/product/LTC2313-12#demoboards
45 http://www.linear.com/product/LTC2313-14#demoboards
46 http://www.linear.com/product/LTC2314-14#demoboards
47 http://www.linear.com/product/LTC2315-12#demoboards
48 
49 
50 Copyright 2018(c) Analog Devices, Inc.
51 
52 All rights reserved.
53 
54 Redistribution and use in source and binary forms, with or without
55 modification, are permitted provided that the following conditions are met:
56  - Redistributions of source code must retain the above copyright
57  notice, this list of conditions and the following disclaimer.
58  - Redistributions in binary form must reproduce the above copyright
59  notice, this list of conditions and the following disclaimer in
60  the documentation and/or other materials provided with the
61  distribution.
62  - Neither the name of Analog Devices, Inc. nor the names of its
63  contributors may be used to endorse or promote products derived
64  from this software without specific prior written permission.
65  - The use of this software may or may not infringe the patent rights
66  of one or more patent holders. This license does not release you
67  from the requirement that you obtain separate licenses from these
68  patent holders to use this software.
69  - Use of the software either in source or binary form, must be run
70  on or directly connected to an Analog Devices Inc. component.
71 
72 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
73 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
74 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
75 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
76 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
77 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
78 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
79 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
80 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
81 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
82 */
83 
84 /*! @file
85  @ingroup LTC2315
86 */
87 
88 #include <Arduino.h>
89 #include <stdint.h>
90 #include "Linduino.h"
91 #include "LT_SPI.h"
92 #include "UserInterface.h"
93 #include "LT_I2C.h"
94 #include "QuikEval_EEPROM.h"
95 #include "LTC2315.h"
96 #include <SPI.h>
97 #include <Wire.h>
98 
99 // Function Declaration
100 void print_title(); // Print the title block
101 void print_prompt(); // Prompt the user for an input command
102 void print_user_command(uint8_t menu); // Display selected differential channels
103 
104 void menu_1_read_input();
105 void menu_2_select_bits();
106 void menu_3_select_vref();
107 void menu_4_select_part();
108 
109 // Global variables
110 static uint8_t LTC2315_bits = 12; //!< Default set for 12 bits
111 static uint8_t LTC2315_shift = 1;
112 float LTC2315_vref = 4.096;
113 static uint8_t LTC2315_JP3 = 1; //!< Default set for 4.096V (Vdd = 5V)
114 
115 
116 //! Initialize Linduino
117 void setup()
118 {
119  uint32_t adc_code;
120  quikeval_I2C_init(); // Configure the EEPROM I2C port for 100kHz
121  quikeval_SPI_init(); // Configure the spi port for 4MHz SCK
122  quikeval_SPI_connect(); // Connect SPI to main data port
123  Serial.begin(115200); // Initialize the serial port to the PC
124  print_title();
125  print_prompt();
126 }
127 
128 
129 //! Repeats Linduino loop
130 void loop()
131 {
132  uint16_t user_command;
133  {
134  if (Serial.available())
135  {
136  user_command = read_int(); // Read the user command
137  if (user_command != 'm')
138  Serial.println(user_command); // Prints the user command to com port
139  switch (user_command)
140  {
141  case 1:
143  break;
144  case 2:
146  break;
147  case 3:
149  break;
150  case 4:
152  break;
153  default:
154  Serial.println(" Invalid Option");
155  break;
156  }
157  Serial.println();
158  print_prompt();
159  }
160  }
161 }
162 
163 
164 // Function Definitions
165 //! Read channel
166 //! @return void
168 {
169  uint8_t user_command;
170  uint16_t adc_code; // The LTC2315 code
171  uint16_t display_code;
172  float adc_voltage; // The LTC2315 voltage
173 
174  // Read and display a selected channel
175  LTC2315_read(LTC2315_CS, &adc_code); //discard the first reading
176  delay(100);
177  LTC2315_read(LTC2315_CS, &adc_code);
178 
179  display_code = adc_code >> (16 - LTC2315_bits - LTC2315_shift); //the data is left justified to bit_14 of a 16 bit word for the LTC2314/2315, and left justified to bit_15 for the LTC2312/2313
180  if (LTC2315_bits == 12)
181  display_code = display_code & 0xFFF;
182  else
183  display_code = display_code & 0x3FFF;
184 
185  Serial.print(F(" Received Code: b"));
186  Serial.println(display_code, BIN);
187 
188  // Convert the received code to voltage
189  adc_voltage = LTC2315_code_to_voltage(adc_code, LTC2315_shift, LTC2315_vref);
190 
191  Serial.print(F(" Equivalent voltage: "));
192  Serial.print(adc_voltage, 4);
193  Serial.println(F("V"));
194 }
195 
196 
197 //! Select number of bits
198 //! @return void
200 {
201  uint8_t user_command;
202 
203  Serial.println(F(" 12 = 231X-12"));
204  Serial.println(F(" 14 = 231X-14"));
205  Serial.print(F(" Enter a Command, based upon the resolution of the part under test: "));
206 
207  user_command = read_int(); // Read user input
208  Serial.println(user_command); // Prints the user command to com port
209  switch (user_command)
210  {
211  case 12:
212  LTC2315_bits = 12;
213  Serial.println(F(" 12 bits selected"));
214  break;
215  case 14:
216  LTC2315_bits = 14;
217  Serial.println(F(" 14 bits selected"));
218  break;
219  default:
220  {
221  Serial.println(" Invalid Option");
222  return;
223  }
224  break;
225  }
226 }
227 
228 
229 //! Select vref
230 //! @return void
232 {
233  uint8_t user_command;
234 
235  Serial.println(F(" 0 = 2.048V Vref (Vdd = 3.3V)"));
236  Serial.println(F(" 1 = 4.096V Vref (Vdd = 5V)"));
237  Serial.print(F(" Enter a Command, based upon the position of JP3: "));
238 
239  user_command = read_int(); // Read user input
240  Serial.println(user_command); // Prints the user command to com port
241  switch (user_command)
242  {
243  case 0:
244  LTC2315_JP3 = 0;
245  LTC2315_vref = 2.048;
246  Serial.println(F(" 2.048V Vref selected"));
247  break;
248  case 1:
249  LTC2315_JP3 = 1;
250  LTC2315_vref = 4.096;
251  Serial.println(F(" 4.096V Vref selected"));
252  break;
253  default:
254  {
255  Serial.println(" Invalid Option");
256  return;
257  }
258  break;
259  }
260 }
261 
262 
263 //! Select part
264 //! @return void
266 {
267  uint8_t user_command;
268 
269  Serial.println(F(" 0 = LTC2314/2315"));
270  Serial.println(F(" 1 = LTC2312/2313"));
271  Serial.print(F(" Enter a Command: "));
272 
273  user_command = read_int(); // Read user input
274  Serial.println(user_command); // Prints the user command to com port
275  switch (user_command)
276  {
277  case 0:
278  LTC2315_shift = 1;
279  Serial.println(F(" LTC2314/2315 selected"));
280  break;
281  case 1:
282  LTC2315_shift = 0;
283  Serial.println(F(" LTC2312/2313 selected"));
284  break;
285  default:
286  Serial.println(" Invalid Option");
287  return;
288  break;
289  }
290 }
291 
292 
293 //! Prints the title block when program first starts.
295 {
296  Serial.println();
297  Serial.println(F("*****************************************************************"));
298  Serial.println(F("* DC1563A Demonstration Program *"));
299  Serial.println(F("* *"));
300  Serial.println(F("* This program demonstrates how to receive data *"));
301  Serial.println(F("* from the following ADCs: *"));
302  Serial.println(F("* LTC2312-12 *"));
303  Serial.println(F("* LTC2312-14 *"));
304  Serial.println(F("* LTC2313-12 *"));
305  Serial.println(F("* LTC2313-14 *"));
306  Serial.println(F("* LTC2314-14 *"));
307  Serial.println(F("* LTC2315-12 *"));
308  Serial.println(F("* *"));
309  Serial.println(F("* Set the baud rate to 115200 and select the newline terminator.*"));
310  Serial.println(F("* *"));
311  Serial.println(F("*****************************************************************"));
312 }
313 
314 
315 //! Prints main menu.
317 {
318  Serial.println(F("*************************"));
319  Serial.println(F("1-Read ADC Input"));
320  Serial.println(F("2-Select Number of bits (Default is 12 bits)"));
321  Serial.println(F("3-Select Vref (Default is 4.096V)"));
322  Serial.println(F("4-Select Part (Default is LTC2314/2315)\n"));
323  Serial.print(F("Enter a command: "));
324 }
325 
LTC2312-12: 12-Bit, 500Ksps ADC.
float LTC2315_code_to_voltage(uint16_t adc_code, uint8_t shift, float vref)
Calculates the LTC2315 input voltage given the binary data and lsb weight.
Definition: LTC2315.cpp:98
static void print_user_command(uint8_t menu)
unsigned char user_command
#define LTC2315_CS
Define the SPI CS pin.
Definition: LTC2315.h:92
static uint8_t LTC2315_JP3
Default set for 4.096V (Vdd = 5V)
Definition: DC1563A.ino:113
Header File for Linduino Libraries and Demo Code.
static uint8_t LTC2315_shift
Definition: DC1563A.ino:111
static void setup()
Initialize Linduino.
Definition: DC1563A.ino:117
void LTC2315_read(uint8_t cs, uint16_t *adc_code)
Reads the LTC2315 and returns 32-bit data in offset binary format.
Definition: LTC2315.cpp:89
static void menu_4_select_part()
Select part.
Definition: DC1563A.ino:265
static void print_prompt()
Prints main menu.
Definition: DC1563A.ino:316
static float adc_voltage
Definition: DC2071AA.ino:115
static void loop()
Repeats Linduino loop.
Definition: DC1563A.ino:130
static void menu_1_read_input()
Read channel.
Definition: DC1563A.ino:167
QuikEval EEPROM Library.
void quikeval_SPI_init(void)
Configure the SPI port for 4Mhz SCK.
Definition: LT_SPI.cpp:151
static void menu_3_select_vref()
Select vref.
Definition: DC1563A.ino:231
LT_SPI: Routines to communicate with ATmega328P&#39;s hardware SPI port.
LT_I2C: Routines to communicate with ATmega328P&#39;s hardware I2C port.
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()
static int32_t display_code
Definition: DC2071AA.ino:114
static float LTC2315_vref
Definition: DC1563A.ino:112
static void menu_2_select_bits()
Select number of bits.
Definition: DC1563A.ino:199
void quikeval_I2C_init(void)
Initializes Linduino I2C port.
Definition: LT_I2C.cpp:394
static void print_title()
Prints the title block when program first starts.
Definition: DC1563A.ino:294
static uint8_t LTC2315_bits
Default set for 12 bits.
Definition: DC1563A.ino:110
static uint32_t adc_code
Definition: DC2071AA.ino:113