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