| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

DC570A.ino
Go to the documentation of this file.
1 /*!
2 Linear Technology DC570A Demonstration Board.
3 LTC2440: 24-Bit, Differential Delta Sigma ADCs with Selectable Speed/Resolution
4
5 @verbatim
6
7 NOTES
8 Setup:
9 Set the terminal baud rate to 115200 and select the newline terminator. Equipment
10 required is a precision voltage source and a precision voltmeter. Additionally,
11 an external power supply is required to provide a negative voltage for Amp V-.
12 Set it to anywhere from -1V to -5V. Set Amp V+ to Vcc. Ensure the COM and REF-
13 pins are connected to ground. The REF+ pin should be connected to +5V.
14
15 How to test Differential Mode:
16 The voltage source should be connected with positive and negative leads to paired
17 channels. The voltage source negative output must also be connected to the COM
18 pin in order to provide a ground-referenced voltage. Ensure voltage is within
19 analog input voltage range -0.3V to +2.5V. Swapping input voltages results in a
20 reversed polarity reading.
21
22
23 USER INPUT DATA FORMAT:
24 decimal : 1024
25 hex : 0x400
26 octal : 02000 (leading 0 "zero")
27 binary : B10000000000
28 float : 1024.0
29
30 @endverbatim
31
32 http://www.linear.com/product/LTC2440
33
34 http://www.linear.com/product/LTC2440#demoboards
35
36
37 Copyright 2018(c) Analog Devices, Inc.
38
39 All rights reserved.
40
41 Redistribution and use in source and binary forms, with or without
42 modification, are permitted provided that the following conditions are met:
43 - Redistributions of source code must retain the above copyright
44 notice, this list of conditions and the following disclaimer.
45 - Redistributions in binary form must reproduce the above copyright
46 notice, this list of conditions and the following disclaimer in
47 the documentation and/or other materials provided with the
48 distribution.
49 - Neither the name of Analog Devices, Inc. nor the names of its
50 contributors may be used to endorse or promote products derived
51 from this software without specific prior written permission.
52 - The use of this software may or may not infringe the patent rights
53 of one or more patent holders. This license does not release you
54 from the requirement that you obtain separate licenses from these
55 patent holders to use this software.
56 - Use of the software either in source or binary form, must be run
57 on or directly connected to an Analog Devices Inc. component.
58
59 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
60 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
61 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
62 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
63 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
64 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
65 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
66 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
67 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
68 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
69 */
70
71 /*! @file
72 @ingroup LTC2440
73 */
74
75 #include <Arduino.h>
76 #include <stdint.h>
77 #include "Linduino.h"
78 #include "LT_SPI.h"
79 #include <SPI.h>
80 #include "UserInterface.h"
81 #include "LT_I2C.h"
82 #include "QuikEval_EEPROM.h"
83 #include "LTC24XX_general.h"
84 #include "LTC2440.h"
85
86 // Function Declaration
87 void print_title(); // Print the title block
88 void print_prompt(); // Prompt the user for an input command
89 void print_user_command(uint8_t menu); // Display selected differential channels
90
91 void menu_1_read_differential();
92 void menu_2_set_OSR();
93
94 // Global variables
95 static uint8_t demo_board_connected; //!< Set to 1 if the board is connected
96 static int16_t OSR_mode = LTC2440_OSR_32768; //!< The LTC2440 OSR mode settings
97 static float LTC2440_vref = 5.0;
98
99 //! Initialize Linduino
100 void setup()
101 {
102 char demo_name[]="DC570"; // Demo Board Name stored in QuikEval EEPROM
103 quikeval_SPI_init(); // Configure the spi port for 4MHz SCK
104 quikeval_SPI_connect(); // Connect SPI to main data port
105 quikeval_I2C_init(); // Configure the EEPROM I2C port for 100kHz
106 Serial.begin(115200); // Initialize the serial port to the PC
107 print_title();
108
109 demo_board_connected = discover_demo_board(demo_name);
110 if (demo_board_connected)
111 {
112 print_prompt();
113 }
114 else
115 {
116 Serial.println(F("EEPROM not detected, will attempt to proceed"));
117 demo_board_connected = 1;
118 print_prompt();
119 }
120 }
121
122 //! Repeats Linduino loop
123 void loop()
124 {
125 int16_t user_command; // The user input command
126 if (demo_board_connected)
127 {
128 if (Serial.available()) // Check for user input
129 {
130 user_command = read_int(); // Read the user command
131 if (user_command != 'm')
132 Serial.println(user_command); // Prints the user command to com port
133 Serial.flush();
134 switch (user_command)
135 {
136 case 1:
137 menu_1_read_differential();
138 break;
139 case 2:
140 menu_set_OSR();
141 break;
142 default:
143 Serial.println(F("Incorrect Option"));
144 }
145 Serial.print(F("\n*************************\n"));
146 print_prompt();
147 }
148 }
149 }
150
151 // Function Definitions
152
153 //! Prints the title block when program first starts.
154 void print_title()
155 {
156 Serial.print(F("\n*****************************************************************\n"));
157 Serial.print(F("* DC570A Demonstration Program *\n"));
158 Serial.print(F("* *\n"));
159 Serial.print(F("* This program demonstrates how to send data and receive data *\n"));
160 Serial.print(F("* from the 24-bit ADC. *\n"));
161 Serial.print(F("* *\n"));
162 Serial.print(F("* *\n"));
163 Serial.print(F("* Set the baud rate to 115200 and select the newline terminator.*\n"));
164 Serial.print(F("* *\n"));
165 Serial.print(F("*****************************************************************\n"));
166 }
167
168 //! Prints main menu.
169 void print_prompt()
170 {
171 Serial.print(F("\n1-Read Differential\n"));
172 Serial.print(F("2-OSR Mode Settings\n"));
173 Serial.print(F("Enter a Command: "));
174 }
175
176
177 //! Read channels in differential mode
178 void menu_1_read_differential()
179 {
180 uint8_t adc_command; // The LTC2440 command word
181 int32_t adc_code = 0; // The LTC2440 code
182 float adc_voltage; // The LTC2440 voltage
183 uint16_t miso_timeout = 1000; // Used to wait for EOC
184
185 adc_command = OSR_mode; // Build the OSR command code
186
187 if (!LTC2440_EOC_timeout(LTC2440_CS, miso_timeout)) // Check for EOC
188 LTC2440_read(LTC2440_CS, adc_command, &adc_code); // Throws out reading
189 else
190 {
191 Serial.println(F("\n ***SPI Error*** \n"));
192 return;
193 }
194
195 if (!LTC2440_EOC_timeout(LTC2440_CS, miso_timeout)) // Check for EOC
196 LTC2440_read(LTC2440_CS, adc_command, &adc_code);
197 else
198 {
199 Serial.println(F("\n ***SPI Error*** \n"));
200 return;
201 }
202
203 Serial.print(F("Received Code: 0x"));
204 Serial.println(adc_code, HEX);
205 adc_voltage = LTC2440_code_to_voltage(adc_code, LTC2440_vref);
206 Serial.print(F("\n ****"));
207 Serial.print(adc_voltage, 4);
208 Serial.print(F("V\n"));
209 }
210
211 //! Set the OSR
212 void menu_set_OSR()
213 {
214 int16_t user_command; // The user input command
215
216 // OSR Mode
217 Serial.print(F("OSR Settings\n\n"));
218 Serial.print(F("0-64\n"));
219 Serial.print(F("1-128\n"));
220 Serial.print(F("2-256\n"));
221 Serial.print(F("3-512\n"));
222 Serial.print(F("4-1024\n"));
223 Serial.print(F("5-2048\n"));
224 Serial.print(F("6-4096\n"));
225 Serial.print(F("7-8192\n"));
226 Serial.print(F("8-16384\n"));
227 Serial.print(F("9-32768\n"));
228 Serial.print(F("Enter a Command: "));
229 user_command = read_int();
230 Serial.println(user_command);
231
232 switch (user_command)
233 {
234 case 0:
235 OSR_mode = LTC2440_OSR_64;
236 break;
237 case 1:
238 OSR_mode = LTC2440_OSR_128;
239 break;
240 case 2:
241 OSR_mode = LTC2440_OSR_256;
242 break;
243 case 3:
244 OSR_mode = LTC2440_OSR_512;
245 break;
246 case 4:
247 OSR_mode = LTC2440_OSR_1024;
248 break;
249 case 5:
250 OSR_mode = LTC2440_OSR_2048;
251 break;
252 case 6:
253 OSR_mode = LTC2440_OSR_4096;
254 break;
255 case 7:
256 OSR_mode = LTC2440_OSR_8192;
257 break;
258 case 8:
259 OSR_mode = LTC2440_OSR_16384;
260 break;
261 case 9:
262 OSR_mode = LTC2440_OSR_32768;
263 break;
264 }
265 }
LTC2440_OSR_1024
#define LTC2440_OSR_1024
Definition: LTC2440.h:140
LTC2440_code_to_voltage
float LTC2440_code_to_voltage(int32_t adc_code, float vref)
Calculates the voltage corresponding to an adc code, given the reference (in volts) ...
Definition: LTC2440.cpp:92
LTC2440_vref
static float LTC2440_vref
Definition: DC570A.ino:97
user_command
unsigned char user_command
Definition: Serial_EEPROM_Test.ino:75
adc_command
static uint8_t adc_command
Definition: DC2071AA.ino:111
LTC2440_OSR_256
#define LTC2440_OSR_256
Definition: LTC2440.h:138
loop
static void loop()
Repeats Linduino loop.
Definition: DC570A.ino:123
LTC2440_EOC_timeout
int8_t LTC2440_EOC_timeout(uint8_t cs, uint16_t miso_timeout)
Checks for EOC with a specified timeout.
Definition: LTC2440.cpp:80
LTC2440_OSR_2048
#define LTC2440_OSR_2048
Definition: LTC2440.h:141
print_user_command
static void print_user_command(uint8_t menu)
Linduino.h
Header File for Linduino Libraries and Demo Code.
LTC2440.h
LTC2440: 24-Bit, Differential Delta Sigma ADCs with Selectable Speed/Resolution.
print_title
static void print_title()
Prints the title block when program first starts.
Definition: DC570A.ino:154
adc_voltage
static float adc_voltage
Definition: DC2071AA.ino:115
menu_1_read_differential
static void menu_1_read_differential()
Read channels in differential mode.
Definition: DC570A.ino:178
LTC24XX_general.h
LTC24XX General Library: Functions and defines for all SINC4 Delta Sigma ADCs.
OSR_mode
static int16_t OSR_mode
The LTC2440 OSR mode settings.
Definition: DC570A.ino:96
QuikEval_EEPROM.h
QuikEval EEPROM Library.
quikeval_SPI_init
void quikeval_SPI_init(void)
Configure the SPI port for 4Mhz SCK.
Definition: LT_SPI.cpp:151
LTC2440_OSR_16384
#define LTC2440_OSR_16384
Definition: LTC2440.h:144
discover_demo_board
int8_t discover_demo_board(char *demo_name)
Read the ID string from the EEPROM and determine if the correct board is connected.
Definition: QuikEval_EEPROM.cpp:141
LTC2440_CS
#define LTC2440_CS
Define the SPI CS pin.
Definition: LTC2440.h:130
LTC2440_OSR_4096
#define LTC2440_OSR_4096
Definition: LTC2440.h:142
LT_SPI.h
LT_SPI: Routines to communicate with ATmega328P&#39;s hardware SPI port.
LTC2440_OSR_512
#define LTC2440_OSR_512
Definition: LTC2440.h:139
LT_I2C.h
LT_I2C: Routines to communicate with ATmega328P&#39;s hardware I2C port.
menu_set_OSR
static void menu_set_OSR()
Set the OSR.
Definition: DC570A.ino:212
demo_name
char demo_name[]
Demo Board Name stored in QuikEval EEPROM.
Definition: DC1880A.ino:97
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
LTC2440_OSR_8192
#define LTC2440_OSR_8192
Definition: LTC2440.h:143
print_prompt
static void print_prompt()
Prints main menu.
Definition: DC570A.ino:169
quikeval_I2C_init
void quikeval_I2C_init(void)
Initializes Linduino I2C port.
Definition: LT_I2C.cpp:394
setup
static void setup()
Initialize Linduino.
Definition: DC570A.ino:100
demo_board_connected
static uint8_t demo_board_connected
Set to 1 if the board is connected.
Definition: DC570A.ino:95
LTC2440_read
void LTC2440_read(uint8_t cs, uint8_t adc_command, int32_t *adc_code)
Reads from LTC2440.
Definition: LTC2440.cpp:86
LTC2440_OSR_128
#define LTC2440_OSR_128
Definition: LTC2440.h:136
adc_code
static uint32_t adc_code
Definition: DC2071AA.ino:113
LTC2440_OSR_32768
#define LTC2440_OSR_32768
Definition: LTC2440.h:145
LTC2440_OSR_64
#define LTC2440_OSR_64
Definition: LTC2440.h:135
menu_2_set_OSR
static void menu_2_set_OSR()