| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

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