Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
DC746A.ino
Go to the documentation of this file.
1 /*!
2 Linear Technology DC571A Demonstration Board.
3 LTC2412: 2-Channel Differential Input 24-Bit No Latency Delta Sigma ADC
4 
5 Linear Technology DC346A Demonstration Board.
6 LTC2413: 24-Bit No Latency Delta Sigma ADC with Simultaneous 50Hz/60Hz Rejection ADC
7 
8 @verbatim
9 
10 NOTES
11  Setup:
12  Set the terminal baud rate to 115200 and select the newline terminator.
13  Equipment required is a precision voltage source and a precision
14  voltmeter. No external power supply is required. Ensure all jumpers on
15  the demo board are installed in their default positions from the
16  factory.
17 
18  How to test Single-Ended mode:
19  The voltage source should be connected to the ADC such that the negative
20  lead is connected to ground. The positive lead may be connected to any
21  channel input. Ensure voltage is within analog input voltage range -0.3V to
22  +2.5V.
23 
24  How to test Differential Mode:
25  The voltage source should be connected with positive and negative leads to
26  paired channels. The voltage source negative output must also be connected to
27  the COM pin in order to provide a ground-referenced voltage. Ensure voltage is
28  within analog input voltage range -0.3V to +2.5V. Swapping input voltages
29  results in a reversed polarity reading.
30 
31  How to calibrate:
32  Apply 100mV to CH0 with respect to COM pin. Next, Measure this voltage with a
33  precise voltmeter and enter this value. (This takes the reading.) Apply a higher
34  voltage than the first voltage or approximately 2.40 volts to CH0. Anything
35  above 2.40 is not reccomened. It is very likely to reach the ADC's full-scale
36  and poduce invalide lsb and offset. Measure this voltage with a precise
37  voltmeter and enter this value. Calibration is now stored in EEPROM. Upon
38  startup the calibration values will be restored.
39 
40 USER INPUT DATA FORMAT:
41  decimal : 1024
42  hex : 0x400
43  octal : 02000 (leading 0 "zero")
44  binary : B10000000000
45  float : 1024.0
46 
47 @endverbatim
48 
49 http://www.linear.com/product/LTC2412
50 http://www.linear.com/product/LTC2413
51 
52 http://www.linear.com/product/LTC2412#demoboards
53 http://www.linear.com/product/LTC2413#demoboards
54 
55 
56 Copyright 2018(c) Analog Devices, Inc.
57 
58 All rights reserved.
59 
60 Redistribution and use in source and binary forms, with or without
61 modification, are permitted provided that the following conditions are met:
62  - Redistributions of source code must retain the above copyright
63  notice, this list of conditions and the following disclaimer.
64  - Redistributions in binary form must reproduce the above copyright
65  notice, this list of conditions and the following disclaimer in
66  the documentation and/or other materials provided with the
67  distribution.
68  - Neither the name of Analog Devices, Inc. nor the names of its
69  contributors may be used to endorse or promote products derived
70  from this software without specific prior written permission.
71  - The use of this software may or may not infringe the patent rights
72  of one or more patent holders. This license does not release you
73  from the requirement that you obtain separate licenses from these
74  patent holders to use this software.
75  - Use of the software either in source or binary form, must be run
76  on or directly connected to an Analog Devices Inc. component.
77 
78 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
79 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
80 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
81 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
82 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
83 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
84 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
85 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
86 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
87 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
88  */
89 
90 /*! @file
91  @ingroup LTC2412
92 */
93 
94 #include <Arduino.h>
95 #include <stdint.h>
96 #include "Linduino.h"
97 #include "LT_SPI.h"
98 #include "LT_I2C.h"
99 #include "UserInterface.h"
100 #include "QuikEval_EEPROM.h"
101 #include "LTC2412.h"
102 #include <SPI.h>
103 #include <Wire.h>
104 
105 // Function Declaration
106 void print_title(); // Print the title block
107 void print_prompt(); // Prompt the user for an input command
108 
109 int8_t menu_1_read_single_ended();
111 
112 // Global variables
113 static uint8_t demo_board_connected; //!< Set to 1 if the board is connected
114 static float LTC2412_lsb = 2.98023241E-7; //!< Ideal LSB voltage for a perfect part
115 static int32_t LTC2412_offset_code = 0; //!< Ideal offset for a perfect part
116 static float reference_voltage = 5.0;
117 
118 //Constants
119 
120 const uint16_t MISO_TIMEOUT = 1000; //!< The MISO timeout (ms)
121 
122 //! Initialize Linduino
123 void setup()
124 {
125  char demo_name[6]="DC746"; // Demo Board Name stored in QuikEval EEPROM
126  quikeval_SPI_init(); // Configure the spi port for 4MHz SCK
127  quikeval_SPI_connect(); // Connect SPI to main data port
128  quikeval_I2C_init(); // Configure the EEPROM I2C port for 100kHz
129  Serial.begin(115200); // Initialize the serial port to the PC
130  print_title();
133  {
134  print_prompt();
135  }
136 }
137 
138 //! Repeats Linduino loop
139 void loop()
140 {
141  int16_t user_command; // The user input command
142  uint8_t acknowledge = 0;
144  {
145  if (Serial.available()) // Check for user input
146  {
147  user_command = read_int(); // Read the user command
148  Serial.println(user_command);
149  switch (user_command)
150  {
151  case 1:
153  break;
154  case 2:
156  break;
157  default:
158  Serial.println("Incorrect Option");
159  break;
160  }
161  if (acknowledge)
162  Serial.println(F("***** SPI ERROR ******"));
163  Serial.print(F("\n*************************\n"));
164  print_prompt();
165  }
166  }
167 }
168 
169 //! Repeats Linduino loop
171 {
172  int16_t user_command; // The user input command
173  uint32_t adc_code; // The LTC2418 code
174  float adc_voltage; // The LTC2418 voltage
175  uint8_t channel;
176 
177  if (LTC2412_EOC_timeout(LTC2412_CS, MISO_TIMEOUT)) // Check for EOC
178  return(1);
179  LTC2412_read(LTC2412_CS, &adc_code);
180  Serial.print(F("Received Code: 0x"));
181  Serial.println(adc_code, HEX);
182  adc_voltage = LTC2412_code_to_voltage(adc_code, LTC2412_lsb , LTC2412_offset_code);
183  channel = adc_code >> 30;
184  channel = channel & 1;
185  Serial.print(F("CH"));
186  Serial.print(channel);
187  Serial.print(F(": "));
188  Serial.print(adc_voltage, 4);
189  Serial.print(F("V\n"));
190 
191  if (LTC2412_EOC_timeout(LTC2412_CS, MISO_TIMEOUT)) // Check for EOC
192  return(1);
193  LTC2412_read(LTC2412_CS, &adc_code);
194  Serial.print(F("Received Code: 0x"));
195  Serial.println(adc_code, HEX);
196  adc_voltage = LTC2412_code_to_voltage(adc_code, LTC2412_lsb , LTC2412_offset_code);
197  channel = adc_code >> 30;
198  channel = channel & 1;
199  Serial.print(F("CH"));
200  Serial.print(channel);
201  Serial.print(F(": "));
202  Serial.print(adc_voltage, 4);
203  Serial.print(F("V\n"));
204  return(0);
205 }
206 
208 {
209  float refp, refn;
210  Serial.print(F("Enter REF+ : "));
211  refp = read_float();
212  Serial.print(refp);
213  Serial.println(F(" V"));
214  Serial.print(F("Enter REF- : "));
215  refn = read_float();
216  Serial.print(refn);
217  Serial.println(F(" V"));
218  reference_voltage = refp - refn;
219  LTC2412_lsb = reference_voltage / 16777216;
220 }
221 
222 //! Prints the title block when program first starts.
224 {
225  Serial.print(F("\n*****************************************************************\n"));
226  Serial.print(F("* DC746A Demonstration Program *\n"));
227  Serial.print(F("* *\n"));
228  Serial.print(F("* This program demonstrates how to send data and receive data *\n"));
229  Serial.print(F("* from the 24-bit ADC. *\n"));
230  Serial.print(F("* *\n"));
231  Serial.print(F("* Set the baud rate to 115200 and select the newline terminator.*\n"));
232  Serial.print(F("* *\n"));
233  Serial.print(F("*****************************************************************\n"));
234 }
235 
236 //! Prints main menu.
238 {
239  Serial.print(F("\nReference voltage: "));
240  Serial.print(reference_voltage);
241  Serial.println(F("V"));
242  Serial.print(F("Input Voltage Range: "));
243  Serial.print((-1) * reference_voltage/2);
244  Serial.print(" - ");
245  Serial.print(reference_voltage/2);
246  Serial.println(F(" V"));
247  Serial.println(F("Please Verify!"));
248 
249  Serial.print(F("\n1-Read Both Channels\n"));
250  Serial.print(F("2-Change Reference Voltage\n"));
251  Serial.println();
252  Serial.print(F("Enter a command:"));
253 }
unsigned char user_command
float LTC2412_code_to_voltage(int32_t adc_code, float LTC2412_lsb, int32_t LTC2412_offset_code)
Calculates the LTC2412 input voltage.
Definition: LTC2412.cpp:113
Header File for Linduino Libraries and Demo Code.
const uint16_t MISO_TIMEOUT
The MISO timeout (ms)
Definition: DC746A.ino:120
static uint8_t channel
LTC2305 Channel selection.
Definition: DC1444A.ino:127
static float adc_voltage
Definition: DC2071AA.ino:115
int8_t LTC2412_EOC_timeout(uint8_t cs, uint16_t miso_timeout)
Checks for EOC with a specified timeout.
Definition: LTC2412.cpp:79
static float LTC2412_lsb
Ideal LSB voltage for a perfect part.
Definition: DC746A.ino:114
static void print_title()
Prints the title block when program first starts.
Definition: DC746A.ino:223
#define LTC2412_CS
Define the SPI CS pin.
Definition: LTC2412.h:99
void LTC2412_read(uint8_t cs, uint32_t *adc_code)
Reads the LTC2412 result.
Definition: LTC2412.cpp:98
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.
LT_SPI: Routines to communicate with ATmega328P&#39;s hardware SPI port.
LTC2412: 2-Channel Differential Input 24-Bit No Latency Delta Sigma ADC LTC2413: 24-Bit No Latency De...
static float reference_voltage
Definition: DC746A.ino:116
static void setup()
Initialize Linduino.
Definition: DC746A.ino:123
LT_I2C: Routines to communicate with ATmega328P&#39;s hardware I2C port.
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_2_change_ref_voltage()
Definition: DC746A.ino:207
static void print_prompt()
Prints main menu.
Definition: DC746A.ino:237
float read_float()
static uint8_t demo_board_connected
Set to 1 if the board is connected.
Definition: DC746A.ino:113
void quikeval_I2C_init(void)
Initializes Linduino I2C port.
Definition: LT_I2C.cpp:394
static void loop()
Repeats Linduino loop.
Definition: DC746A.ino:139
static uint32_t adc_code
Definition: DC2071AA.ino:113
static int8_t menu_1_read_single_ended()
Repeats Linduino loop.
Definition: DC746A.ino:170
static int32_t LTC2412_offset_code
Ideal offset for a perfect part.
Definition: DC746A.ino:115