Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
DC798B.ino
Go to the documentation of this file.
1 /*!
2 Linear Technology DC798B Demonstration Board.
3 LTC2480: 16-Bit Delta-Sigma ADC with Easy Drive Input Current Cancellation.
4 
5 @verbatim
6 
7 The LTC2480 is a 16-Bit Delta-Sigma ADC with Easy Drive Input Current Cancellation.
8 It includes on-chip programmable gain and an oscillator. The LTC2480 can be
9 configured to provide a programmable gain from 1 to 256 in 8 steps, measure an
10 external signal or internal temperature sensor and reject line frequencies. 50Hz,
11 60Hz or simultaneous 50Hz/60Hz line frequency rejection can be selected as well
12 as a 2x speed-up mode.
13 
14 The voltage on the input pins can have any value between GND – 0.3V and VCC + 0.3V.
15 Within these limits the converter bipolar input range (VIN = IN+ – IN–) extends
16 from –0.5 • VREF/GAIN to 0.5 • VREF/GAIN. Outside this input range the converter
17 produces unique overrange and underrange output codes.
18 
19 @endverbatim
20 
21 http://www.linear.com/product/LTC2480
22 
23 http://www.linear.com/product/LTC2480#demoboards
24 
25 
26 Copyright 2018(c) Analog Devices, Inc.
27 
28 All rights reserved.
29 
30 Redistribution and use in source and binary forms, with or without
31 modification, are permitted provided that the following conditions are met:
32  - Redistributions of source code must retain the above copyright
33  notice, this list of conditions and the following disclaimer.
34  - Redistributions in binary form must reproduce the above copyright
35  notice, this list of conditions and the following disclaimer in
36  the documentation and/or other materials provided with the
37  distribution.
38  - Neither the name of Analog Devices, Inc. nor the names of its
39  contributors may be used to endorse or promote products derived
40  from this software without specific prior written permission.
41  - The use of this software may or may not infringe the patent rights
42  of one or more patent holders. This license does not release you
43  from the requirement that you obtain separate licenses from these
44  patent holders to use this software.
45  - Use of the software either in source or binary form, must be run
46  on or directly connected to an Analog Devices Inc. component.
47 
48 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
49 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
50 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
51 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
52 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
53 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
54 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
55 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
56 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
57 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
58 */
59 
60 /*! @file
61  @ingroup LTC2480
62 */
63 
64 #include <Arduino.h>
65 #include <stdint.h>
66 #include "Linduino.h"
67 #include "LT_SPI.h"
68 #include "UserInterface.h"
69 #include "LT_I2C.h"
70 #include "QuikEval_EEPROM.h"
71 #include "LTC24XX_general.h"
72 #include "LTC2480.h"
73 #include <SPI.h>
74 
75 // Function Declaration
76 void print_title(); // Print the title block
77 void print_prompt(); // Prompt the user for an input command
78 
79 void menu_1_read_input();
80 void menu_2_select_gain();
83 
84 static uint8_t demo_board_connected; //!< Set to 1 if the board is connected
85 
86 // Global variables
87 float LTC2480_vref = 5;
90 uint8_t LTC2480_gain = 1;
91 uint8_t LTC2480_rejection_mode = 0; // Simultaneous 50Hz/60Hz Rejection
92 
93 //! Initialize Linduino
94 void setup()
95 {
96  char demo_name[]="DC798"; // Demo Board Name stored in QuikEval EEPROM
97 
98  quikeval_I2C_init(); // Configure the EEPROM I2C port for 100kHz
99  quikeval_SPI_init(); // Configure the spi port for 4MHz SCK
100  quikeval_SPI_connect(); // Connect SPI to main data port
101 
102  Serial.begin(115200); // Initialize the serial port to the PC
103  print_title();
106  {
107  print_prompt();
108  }
110 }
111 
112 //! Repeats Linduino loop
113 void loop()
114 {
115  uint16_t user_command;
116  {
117  if (Serial.available())
118  {
119  user_command = read_int(); // Read the user command
120  if (user_command != 'm')
121  Serial.println(user_command); // Prints the user command to com port
122  switch (user_command)
123  {
124  case 1:
126  break;
127  case 2:
129  break;
130  case 3:
132  break;
133  case 4:
135  break;
136  default:
137  Serial.println(F("Invalid Option"));
138  break;
139  }
140  Serial.println();
141  print_prompt();
142  }
143  }
144 }
145 
146 // Function Definitions
147 //! Read channel
148 //! @return void
150 {
151  uint8_t user_command;
152  uint32_t adc_code; // The LTC2480 code
153  int32_t display_code = 0;
154  float adc_voltage; // The LTC2480 voltage
155 
156  // Read and display
157  LTC2480_read(LTC2480_CS, &adc_code); // discard the first reading
158  delay(200);
159  LTC2480_read(LTC2480_CS, &adc_code);
160 
161  display_code = adc_code >> 4;
162  display_code = display_code & 0xFFFF;
163 
164  Serial.print(F(" Received Code: 0x"));
165  Serial.println(display_code, HEX);
166 
167  // Convert the received code to voltage
168  adc_voltage = LTC2480_code_to_voltage(display_code, LTC2480_range, LTC2480_gain);
169 
170  if (adc_code & 0x100000) // Checking sign bit
171  {
172  adc_voltage = LTC2480_range - adc_voltage;
173  adc_voltage = adc_voltage * (-1);
174  }
175 
176  Serial.print(F(" Equivalent voltage: "));
177  Serial.print(adc_voltage, 4);
178  Serial.println(F(" V"));
179 }
180 
181 //! Select number of bits
182 //! @return void
184 {
185  uint16_t user_command;
186 
187  Serial.println();
188  Serial.print(F(" Select a gain (1, 4, 8, 16, 32, 64, 128, 256): "));
189 
190  user_command = read_int(); // Read user input
191  Serial.println(user_command); // Prints the user command to com port
192  switch (user_command)
193  {
194  case 1:
196  LTC2480_gain = 1;
197  Serial.println(F(" Gain = 1"));
198  break;
199  case 4:
201  LTC2480_gain = 4;
202  Serial.println(F(" Gain = 4"));
203  break;
204  case 8:
206  LTC2480_gain = 8;
207  Serial.println(F(" Gain = 8"));
208  break;
209  case 16:
211  LTC2480_gain = 16;
212  Serial.println(F(" Gain = 16"));
213  break;
214  case 32:
216  LTC2480_gain = 32;
217  Serial.println(F(" Gain = 32"));
218  break;
219  case 64:
221  LTC2480_gain = 64;
222  Serial.println(F(" Gain = 64"));
223  break;
224  case 128:
226  LTC2480_gain = 128;
227  Serial.println(F(" Gain = 128"));
228  break;
229  case 256:
231  LTC2480_gain = 256;
232  Serial.println(F(" Gain = 256"));
233  break;
234  default:
235  {
236  Serial.println(F(" Invalid Option"));
237  return;
238  }
239  break;
240  }
242 }
243 
244 //! Select frequency rejection
245 //! @return void
247 {
248  uint8_t user_command;
249 
250  Serial.println(F(" 0: Simultaneous 50Hz/60Hz rejection"));
251  Serial.println(F(" 1: 50Hz Rejection"));
252  Serial.println(F(" 2: 60Hz Rejection"));
253  Serial.print(F(" Enter the required rejection mode: "));
254 
255  user_command = read_int(); // Read user input
256  Serial.println(user_command); // Prints the user command to com port
257 
258  switch (user_command)
259  {
260  case 0:
261  Serial.println(F("Selected simultaneous 50Hz/60Hz rejection"));
262  LTC2480_rejection_mode = 0x00;
263  break;
264  case 1:
265  Serial.println(F("Selected 50Hz Rejection"));
266  LTC2480_rejection_mode = 0x02;
267  break;
268  case 2:
269  Serial.println(F("Selected 60Hz rejection"));
270  LTC2480_rejection_mode = 0x04;
271  break;
272  default:
273  {
274  Serial.println(F(" Invalid Option"));
275  return;
276  }
277  break;
278  }
280 }
281 
283 {
284  Serial.print(F("\n Enter the reference voltage: "));
286  Serial.print(LTC2480_vref);
287  Serial.println(F(" V"));
288 
290 }
291 
292 //! Prints the title block when program first starts.
294 {
295  Serial.print(F("\n*****************************************************************\n"));
296  Serial.print(F("* DC798B Demonstration Program *\n"));
297  Serial.print(F("* *\n"));
298  Serial.print(F("* This program demonstrates how to send data and receive data *\n"));
299  Serial.print(F("* from the 16-bit ADC. *\n"));
300  Serial.print(F("* *\n"));
301  Serial.print(F("* *\n"));
302  Serial.print(F("* Set the baud rate to 115200 and select the newline terminator.*\n"));
303  Serial.print(F("* *\n"));
304  Serial.print(F("*****************************************************************\n"));
305 }
306 
307 //! Prints main menu.
309 {
310  Serial.print(F("\n1-Read Input\n"));
311  Serial.print(F("2-Select Gain\n"));
312  Serial.print(F("3-Select Rejection\n"));
313  Serial.print(F("4-Change reference voltage\n"));
314  Serial.print(F("\nEnter a Command: "));
315 }
static void print_title()
Prints the title block when program first starts.
Definition: DC798B.ino:293
static void loop()
Repeats Linduino loop.
Definition: DC798B.ino:113
unsigned char user_command
void LTC2480_read(uint8_t cs, uint32_t *ptr_adc_code)
Reads the LTC2480 and returns 24-bit data.
Definition: LTC2480.cpp:78
static float LTC2480_range
Definition: DC798B.ino:88
Header File for Linduino Libraries and Demo Code.
#define LTC2480_CS
Define the SPI CS pin.
Definition: LTC2480.h:77
static float LTC2480_vref
Definition: DC798B.ino:87
#define LTC2480_GAIN_16
Definition: LTC2480.h:86
static void setup()
Initialize Linduino.
Definition: DC798B.ino:94
LTC2480: 16-Bit Delta-Sigma ADC with Easy Drive Input Current Cancellation.
static float adc_voltage
Definition: DC2071AA.ino:115
static uint8_t LTC2480_gain_selection
Definition: DC798B.ino:89
LTC24XX General Library: Functions and defines for all SINC4 Delta Sigma ADCs.
static void menu_3_select_rejection()
Select frequency rejection.
Definition: DC798B.ino:246
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 menu_2_select_gain()
Select number of bits.
Definition: DC798B.ino:183
void LTC2480_set_modes(uint8_t cs, uint8_t gain_selection, uint8_t rejection_mode)
Function to set the input voltage gain and frequency rejection mode.
Definition: LTC2480.cpp:69
LT_SPI: Routines to communicate with ATmega328P&#39;s hardware SPI port.
static void menu_4_reference_voltage()
Definition: DC798B.ino:282
LT_I2C: Routines to communicate with ATmega328P&#39;s hardware I2C port.
static uint8_t LTC2480_rejection_mode
Definition: DC798B.ino:91
static void print_prompt()
Prints main menu.
Definition: DC798B.ino:308
static void menu_1_read_input()
Read channel.
Definition: DC798B.ino:149
#define LTC2480_GAIN_32
Definition: LTC2480.h:87
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 int32_t display_code
Definition: DC2071AA.ino:114
float read_float()
float LTC2480_code_to_voltage(uint32_t adc_code, float vref, uint8_t gain)
Calculates the LTC2480 input voltage given the binary data, reference voltage and input gain...
Definition: LTC2480.cpp:90
#define LTC2480_GAIN_4
Definition: LTC2480.h:84
void quikeval_I2C_init(void)
Initializes Linduino I2C port.
Definition: LT_I2C.cpp:394
#define LTC2480_GAIN_256
Definition: LTC2480.h:90
#define LTC2480_GAIN_8
Definition: LTC2480.h:85
static uint8_t demo_board_connected
Set to 1 if the board is connected.
Definition: DC798B.ino:84
#define LTC2480_GAIN_1
Definition: LTC2480.h:83
#define LTC2480_GAIN_64
Definition: LTC2480.h:88
static uint32_t adc_code
Definition: DC2071AA.ino:113
#define LTC2480_GAIN_128
Definition: LTC2480.h:89
static uint8_t LTC2480_gain
Definition: DC798B.ino:90