Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
DC1490.ino
Go to the documentation of this file.
1 /*!
2 Linear Technology DC1490A-A Demonstration Board.
3 LTC2460: 24-Bit, 16-Channel Delta Sigma ADC with SPI interface
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 Single-Ended mode:
16  The voltage source should be connected to the ADC such that the negative lead is
17  connected to the COM(common) pin. The positive lead may be connected to any
18  channel input. Ensure voltage is within analog input voltage range -0.3 to 2.5V.
19 
20  How to test Differential Mode:
21  The voltage source should be connected with positive and negative leads to paired
22  channels. The voltage source negative output must also be connected to the COM
23  pin in order to provide a ground-referenced voltage. Ensure voltage is within
24  analog input voltage range -0.3V to +2.5V. Swapping input voltages results in a
25  reversed polarity reading.
26 
27  How to calibrate:
28  Apply 100mV CH0 with respect to COM. Next, measure this voltage with a precise
29  voltmeter and enter this value. (This takes the reading.) Now apply approximately
30  2.40 volts to CH0. Measure this voltage with a precise voltmeter and enter this
31  value. Calibration is now stored in EEPROM. Upon start-up the calibration values
32  will be restored.
33 
34 USER INPUT DATA FORMAT:
35  decimal : 1024
36  hex : 0x400
37  octal : 02000 (leading 0 "zero")
38  binary : B10000000000
39  float : 1024.0
40 
41 @endverbatim
42 
43 http://www.linear.com/product/LTC2460
44 
45 http://www.linear.com/product/LTC2460#demoboards
46 
47 
48 Copyright 2018(c) Analog Devices, Inc.
49 
50 All rights reserved.
51 
52 Redistribution and use in source and binary forms, with or without
53 modification, are permitted provided that the following conditions are met:
54  - Redistributions of source code must retain the above copyright
55  notice, this list of conditions and the following disclaimer.
56  - Redistributions in binary form must reproduce the above copyright
57  notice, this list of conditions and the following disclaimer in
58  the documentation and/or other materials provided with the
59  distribution.
60  - Neither the name of Analog Devices, Inc. nor the names of its
61  contributors may be used to endorse or promote products derived
62  from this software without specific prior written permission.
63  - The use of this software may or may not infringe the patent rights
64  of one or more patent holders. This license does not release you
65  from the requirement that you obtain separate licenses from these
66  patent holders to use this software.
67  - Use of the software either in source or binary form, must be run
68  on or directly connected to an Analog Devices Inc. component.
69 
70 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
71 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
72 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
73 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
74 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
75 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
76 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
77 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
78 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
79 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
80 
81  */
82 
83 /*! @file
84  @ingroup LTC2460
85 */
86 
87 #include <Arduino.h>
88 #include <stdint.h>
89 #include "Linduino.h"
90 #include "LT_SPI.h"
91 #include <SPI.h>
92 #include "UserInterface.h"
93 #include "LT_I2C.h"
94 #include "QuikEval_EEPROM.h"
95 #include "LTC24XX_general.h"
96 #include "LTC2460.h"
97 
98 // Function Declaration
99 void print_title(); // Print the title block
100 void print_prompt(); // Prompt the user for an input command
101 
103 void menu_2_set_1X2X();
104 
105 // Global variables
106 static uint8_t demo_board_connected; //!< Set to 1 if the board is connected
107 static int16_t two_x_mode = LTC2460_SPEED_1X; //!< The LTC2460 2X Mode settings
108 static float LTC2460_vref = 1.25;
109 static uint16_t eoc_timeout = 25;
110 // Constants
111 
112 //! Lookup table to build 1X / 2X bits
113 const uint16_t BUILD_1X_2X_COMMAND[2] = {LTC2460_SPEED_1X, LTC2460_SPEED_2X}; //!< Build the command for 1x or 2x mode
114 
115 
116 //! Initialize Linduino
117 void setup()
118 {
119  char demo_name[]="DC1490"; // Demo Board Name stored in QuikEval EEPROM
120  quikeval_SPI_init(); // Configure the spi port for 4MHz SCK
121  quikeval_SPI_connect(); // Connect SPI to main data port
122  quikeval_I2C_init(); // Configure the EEPROM I2C port for 100kHz
123  Serial.begin(115200); // Initialize the serial port to the PC
124  print_title();
125 
128  {
129  print_prompt();
130  }
131  else
132  {
133  Serial.println(F("EEPROM not detected, will attempt to proceed"));
135  print_prompt();
136  }
137  quikeval_SPI_connect(); //Initialize for SPI
138 }
139 
140 //! Repeats Linduino loop
141 void loop()
142 {
143  int16_t user_command; // The user input command
145  {
146  if (Serial.available()) // Check for user input
147  {
148  user_command = read_int(); // Read the user command
149  if (user_command != 'm')
150  Serial.println(user_command); // Prints the user command to com port
151  Serial.flush();
152  switch (user_command)
153  {
154  case 1:
156  break;
157  case 2:
158  menu_2_set_1X2X();
159  break;
160  case 3:
161  menu_3_sleep();
162  break;
163  default:
164  Serial.println(F("Incorrect Option"));
165  }
166  Serial.print(F("\n*************************\n"));
167  print_prompt();
168  }
169  }
170 }
171 
172 // Function Definitions
173 
174 //! Prints the title block when program first starts.
176 {
177  Serial.print(F("\n*****************************************************************\n"));
178  Serial.print(F("* DC1490A Demonstration Program *\n"));
179  Serial.print(F("* *\n"));
180  Serial.print(F("* This program demonstrates how to send data and receive data *\n"));
181  Serial.print(F("* from the 16-bit ADC. *\n"));
182  Serial.print(F("* *\n"));
183  Serial.print(F("* *\n"));
184  Serial.print(F("* Set the baud rate to 115200 and select the newline terminator.*\n"));
185  Serial.print(F("* *\n"));
186  Serial.print(F("*****************************************************************\n"));
187 }
188 
189 //! Prints main menu.
191 {
192  Serial.print(F("\n1-Read Single-Ended\n"));
193  Serial.print(F("2-2X Mode Settings\n"));
194  Serial.print(F("3-Sleep\n"));
195  Serial.print(F("Enter a Command: "));
196 }
197 
198 //! Read channels in single-ended mode
200 {
201  uint16_t adc_command; // The LTC2460 command word
202  int16_t user_command; // The user input command
203  int32_t adc_code = 0; // The LTC2460 code
204  float adc_voltage=0; // The LTC2460 voltage
205 
206  while (1)
207  {
208 
209  Serial.print(F("*************************\n\n"));
210  Serial.print(F("1-Read\n"));
211  Serial.print(F("m-Main Menu\n"));
212  Serial.print(F("Enter a Command: "));
213 
214  user_command = read_int(); // Read the single command
215  if (user_command == 'm')
216  {
217  break;
218  }
219 
220  else
221  {
222  Serial.println(user_command);
223  adc_command = two_x_mode;
224  Serial.print(F("ADC Command: 0x"));
225  Serial.println(adc_command, HEX);
226 
228  LTC2460_read(LTC2460_CS, adc_command, &adc_code); // Throws out last reading
229 
230  delay(50);
231 
232  LTC2460_read(LTC2460_CS, adc_command, &adc_code); // Now we're ready to read the desired data
233 
234  Serial.print(F("Received Code: 0x"));
235  Serial.println(((adc_code>>16) & 0x0000FFFF), HEX);
236  adc_voltage = LTC2460_code_to_voltage(adc_code, LTC2460_vref);
237  Serial.print(F(" ****"));
238  Serial.print(F("Voltage"));
239  Serial.print(F(": "));
240  Serial.print(adc_voltage, 4);
241  Serial.print(F("V\n\n"));
242  }
243 
244 
245  }
246 
247 
248 }
249 
250 //! Set 1X or 2X mode
252 {
253  int16_t user_command; // The user input command
254 
255  // 2X Mode
256  Serial.print(F("2X Mode Settings\n\n"));
257  Serial.print(F("0-Disable\n"));
258  Serial.print(F("1-Enable\n"));
259  Serial.print(F("Enter a Command: "));
260  user_command = read_int();
261  Serial.println(user_command);
262 
263  if (user_command == 0)
264  {
266  Serial.print(F("2X Mode Disabled, offset calibration enabled\n"));
267  }
268  else
269  {
271  Serial.print(F("2X Mode Enabled, offset calibration disabled\n"));
272  }
273 }
274 
276 {
277  int32_t adc_code = 0; // The LTC2460 code
278  Serial.print("Putting LTC2460 into sleep mode");
279  LTC2460_read(LTC2460_CS, 0x90, &adc_code); // Send sleep bit
280 }
#define LTC2460_CS
Define the SPI CS pin.
Definition: LTC2460.h:101
unsigned char user_command
static uint8_t adc_command
Definition: DC2071AA.ino:111
LTC2460 Ultra-Tiny, 16-bit delta sigma ADCs with 10ppm/degree C Max Precision Reference.
Header File for Linduino Libraries and Demo Code.
float LTC2460_code_to_voltage(int32_t adc_code, float vref)
Calculates the voltage corresponding to an adc code, given the reference (in volts) ...
Definition: LTC2460.cpp:86
static void print_title()
Prints the title block when program first starts.
Definition: DC1490.ino:175
static void print_prompt()
Prints main menu.
Definition: DC1490.ino:190
static float adc_voltage
Definition: DC2071AA.ino:115
LTC24XX General Library: Functions and defines for all SINC4 Delta Sigma ADCs.
QuikEval EEPROM Library.
void quikeval_SPI_init(void)
Configure the SPI port for 4Mhz SCK.
Definition: LT_SPI.cpp:151
int8_t discover_demo_board(char *demo_name)
Read the ID string from the EEPROM and determine if the correct board is connected.
static void setup()
Initialize Linduino.
Definition: DC1490.ino:117
LT_SPI: Routines to communicate with ATmega328P&#39;s hardware SPI port.
static void menu_1_read_single_ended()
Read channels in single-ended mode.
Definition: DC1490.ino:199
void LTC2460_read(uint8_t cs, uint8_t adc_command, int32_t *adc_code)
Definition: LTC2460.cpp:77
LT_I2C: Routines to communicate with ATmega328P&#39;s hardware I2C port.
const uint16_t BUILD_1X_2X_COMMAND[2]
Lookup table to build 1X / 2X bits.
Definition: DC1490.ino:113
static uint8_t demo_board_connected
Set to 1 if the board is connected.
Definition: DC1490.ino:106
char demo_name[]
Demo Board Name stored in QuikEval EEPROM.
Definition: DC1880A.ino:97
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 void menu_3_sleep()
Definition: DC1490.ino:275
static uint16_t eoc_timeout
Definition: DC1490.ino:109
static void loop()
Repeats Linduino loop.
Definition: DC1490.ino:141
void quikeval_I2C_init(void)
Initializes Linduino I2C port.
Definition: LT_I2C.cpp:394
static void menu_2_set_1X2X()
Set 1X or 2X mode.
Definition: DC1490.ino:251
static float LTC2460_vref
Definition: DC1490.ino:108
#define LTC2460_SPEED_2X
Definition: LTC2460.h:109
#define LTC2460_SPEED_1X
Definition: LTC2460.h:108
static int16_t two_x_mode
The LTC2460 2X Mode settings.
Definition: DC1490.ino:107
static uint32_t adc_code
Definition: DC2071AA.ino:113