| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

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