Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
DC1716A.ino
Go to the documentation of this file.
1 /*!
2 Linear Technology DC1716A Demonstration Board.
3 LTC2473: 16-Bit, Delta Sigma ADC with I2C 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 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 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/LTC2473
32 
33 http://www.linear.com/product/LTC2473#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 LTC2473
72 */
73 
74 #include <Arduino.h>
75 #include <stdint.h>
76 #include "Linduino.h"
77 #include "LT_SPI.h"
78 #include <SPI.h>
79 #include "UserInterface.h"
80 #include "LT_I2C.h"
81 #include "QuikEval_EEPROM.h"
82 #include "LTC2473.h"
83 #include "LTC24XX_general.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 
91 int8_t menu_2_set_sps();
92 uint8_t menu_3_sleep();
93 void menu_4_set_address();
94 
95 // Global variables
96 static float LTC2473_vref = 1.25; //!< The nominal reference voltage
97 static uint8_t i2c_address = LTC2473_I2C_ADDRESS; //!< I2C address in 7 bit format for part
98 static uint16_t timeout = 300; //!< The timeout in microseconds
99 
100 //! Initialize Linduino
101 void setup()
102 {
103  uint8_t demo_board_connected; // Set to 1 if the board is connected
104  char demo_name[]="DC1716"; // Demo Board Name stored in QuikEval EEPROM
105  quikeval_I2C_init(); // Configure the EEPROM I2C port for 100kHz
106  quikeval_I2C_connect(); // Connect I2C to main data port
107  Serial.begin(115200); // Initialize the serial port to the PC
108  print_title();
109 
110  demo_board_connected = discover_demo_board(demo_name);
111  if (demo_board_connected)
112  {
113  print_prompt();
114  }
115  else
116  {
117  Serial.println(F("EEPROM not detected, will attempt to proceed"));
118  print_prompt();
119  }
120 }
121 
122 //! Repeats Linduino loop
123 void loop()
124 {
125  int16_t user_command; // The user input command
126  uint8_t acknowledge = 0;
127  if (Serial.available()) // Check for user input
128  {
129  user_command = read_int(); // Read the user command
130  if (user_command != 'm')
131  Serial.println(user_command); // Prints the user command to com port
132  Serial.flush();
133  switch (user_command)
134  {
135  case 1:
136  acknowledge |= menu_1_read_differential();
137  break;
138  case 2:
139  acknowledge |= menu_2_set_sps();
140  break;
141  case 3:
142  acknowledge |= menu_3_sleep();
143  break;
144  case 4:
146  break;
147  default:
148  Serial.println(F("Incorrect Option"));
149  }
150  if (acknowledge)
151  Serial.println(F("***** I2C ERROR *****"));
152  Serial.print(F("\n*************************\n"));
153  print_prompt();
154  }
155 }
156 
157 // Function Definitions
158 
159 //! Prints the title block when program first starts.
161 {
162  Serial.print(F("\n*****************************************************************\n"));
163  Serial.print(F("* DC1716A Demonstration Program *\n"));
164  Serial.print(F("* *\n"));
165  Serial.print(F("* This program demonstrates how to send data and receive data *\n"));
166  Serial.print(F("* from the 16-bit ADC. *\n"));
167  Serial.print(F("* *\n"));
168  Serial.print(F("* *\n"));
169  Serial.print(F("* Set the baud rate to 115200 and select the newline terminator.*\n"));
170  Serial.print(F("* *\n"));
171  Serial.print(F("*****************************************************************\n"));
172 }
173 
174 //! Prints main menu.
176 {
177  Serial.print(F("\n1-Read Differential\n"));
178  Serial.print(F("2-Set SPS\n"));
179  Serial.print(F("3-Sleep Mode\n"));
180  Serial.print(F("4-Set I2C Address\n"));
181  Serial.print(F("Enter a Command: "));
182 }
183 
184 //! Read the ADC
185 //! @return 0 if successful, 1 is failure
187 {
188  int32_t adc_code = 0; // The LTC2473 code
189  float adc_voltage; // The LTC2473 voltage
190  uint8_t ack = 0; // Acknowledge bit
191  int16_t user_command; // The user input command
192 
193  ack |= LTC2473_read(i2c_address, &adc_code, timeout); // Throws out reading
194  delay(100);
195  ack |= LTC2473_read(i2c_address, &adc_code, timeout); // Reads the ADC
196 
197  if (!ack)
198  {
199  Serial.print(F("Received Code: 0x"));
200  Serial.println(adc_code >> 14, HEX);
201  adc_voltage = LTC2473_code_to_voltage(adc_code, LTC2473_vref);
202  Serial.print(F("\n ****"));
203  Serial.print(adc_voltage, 4);
204  Serial.print(F("V\n"));
205  }
206  else
207  {
208  Serial.println(F("Device NAK'd, please check I2C address"));
209  return 1;
210  }
211  return(0);
212 }
213 
214 //! Set the SPS
216 {
217  uint8_t ack = 0;
218  uint8_t adc_command; // The LTC2473 command byte
219  int16_t user_command; // The user input command
220 
221  Serial.print(F("Samples Per Second Mode Settings\n\n"));
222  Serial.print(F("0-208 SPS\n"));
223  Serial.print(F("1-833 SPS\n"));
224  Serial.print(F("Enter a Command: "));
225  user_command = read_int();
226 
227  if (user_command == 0)
228  {
230  Serial.print(F("208 SPS Mode \n"));
231  }
232  else
233  {
235  Serial.print(F("833 SPS Mode \n"));
236  }
237  return(ack);
238 }
239 
240 
241 //! Set LTC2473 to sleep mode
242 uint8_t menu_3_sleep()
243 {
244  uint8_t ack = 0;
246 
247  Serial.println(F("\nThe LTC2473 is in sleep mode"));
248  return(ack);
249 }
250 
251 //! Set the I2C 7 bit address
253 {
254  int16_t user_command;
255  Serial.print(F("What is the I2C address of the part?\n"));
256  Serial.print(F("Please enter in 7-bit format, decimal\n"));
257 
258  user_command =read_int();
259  Serial.println(user_command);
260  i2c_address = user_command&0x7F;
261 }
static int8_t menu_2_set_sps()
Set the SPS.
Definition: DC1716A.ino:215
static uint16_t timeout
The timeout in microseconds.
Definition: DC1716A.ino:98
static uint8_t i2c_address
I2C address in 7 bit format for part.
Definition: DC1716A.ino:97
unsigned char user_command
#define LTC2473_I2C_ADDRESS
I2C address of the LTC2473.
Definition: LTC2473.h:116
static uint8_t adc_command
Definition: DC2071AA.ino:111
static uint8_t menu_3_sleep()
Set LTC2473 to sleep mode.
Definition: DC1716A.ino:242
uint8_t LTC2473_read(uint8_t i2c_address, int32_t *adc_code, uint16_t timeout)
Reads from LTC2473.
Definition: LTC2473.cpp:77
Header File for Linduino Libraries and Demo Code.
#define LTC2473_ENABLE_PROGRAMMING
Definition: LTC2473.h:125
float LTC2473_code_to_voltage(int32_t adc_code, float vref)
Calculates the voltage corresponding to an ADC code, given the reference (in volts) ...
Definition: LTC2473.cpp:94
static int8_t menu_1_read_differential()
Read the ADC.
Definition: DC1716A.ino:186
static void print_user_command(uint8_t menu)
static float adc_voltage
Definition: DC2071AA.ino:115
LTC24XX General Library: Functions and defines for all SINC4 Delta Sigma ADCs.
#define LTC2473_SPS_833
Definition: LTC2473.h:127
QuikEval EEPROM Library.
uint8_t LTC2473_write(uint8_t i2c_address, uint8_t adc_command)
Writes to the LTC2473.
Definition: LTC2473.cpp:85
static void loop()
Repeats Linduino loop.
Definition: DC1716A.ino:123
LTC2473: 16-Bit, Delta Sigma ADC with I2C interface.
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.
static void print_title()
Prints the title block when program first starts.
Definition: DC1716A.ino:160
static float LTC2473_vref
The nominal reference voltage.
Definition: DC1716A.ino:96
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
int32_t read_int()
static void setup()
Initialize Linduino.
Definition: DC1716A.ino:101
#define LTC2473_SPS_208
Definition: LTC2473.h:126
void quikeval_I2C_init(void)
Initializes Linduino I2C port.
Definition: LT_I2C.cpp:394
void quikeval_I2C_connect(void)
Switch MUX to connect I2C pins to QuikEval connector.
Definition: LT_I2C.cpp:401
static void print_prompt()
Prints main menu.
Definition: DC1716A.ino:175
#define LTC2473_SLEEP
Definition: LTC2473.h:128
static uint32_t adc_code
Definition: DC2071AA.ino:113
static void menu_4_set_address()
Set the I2C 7 bit address.
Definition: DC1716A.ino:252
static uint8_t demo_board_connected
Set to 1 if the board is connected.