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