| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

DC941A.ino
Go to the documentation of this file.
1 /*!
2 Linear Technology DC941A Demonstration Board.
3 LTC2482: 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 The LTC2482 allows a wide common mode input range (0V to VCC) independent of the
9 reference voltage. The reference can be as low as 100mV or can be tied directly to
10 VCC. The noise level is 600nV RMS independent of VREF . This allows direct
11 digitization of low level signals with 16-bit accuracy. The LTC2482 includes an on-chip
12 trimmed oscillator, eliminating the need for external crystals or oscillators and
13 provides 87dB rejection of 50Hz and 60Hz line frequency noise. Absolute accuracy and low
14 drift are automatically maintained through continuous, transparent, offset and
15 full-scale calibration.
16
17 The voltage on the differential input pins can have any value between GND – 0.3V
18 and VCC + 0.3V. Within these limits the converter bipolar input range (VIN = IN+ – IN–)
19 extends from –0.5 • VREF to 0.5 • VREF. Outside this input range the converter
20 produces unique overrange and underrange output codes.
21
22 @endverbatim
23
24 http://www.linear.com/product/LTC2482
25
26 http://www.linear.com/product/LTC2482#demoboards
27
28
29 Copyright 2018(c) Analog Devices, Inc.
30
31 All rights reserved.
32
33 Redistribution and use in source and binary forms, with or without
34 modification, are permitted provided that the following conditions are met:
35 - Redistributions of source code must retain the above copyright
36 notice, this list of conditions and the following disclaimer.
37 - Redistributions in binary form must reproduce the above copyright
38 notice, this list of conditions and the following disclaimer in
39 the documentation and/or other materials provided with the
40 distribution.
41 - Neither the name of Analog Devices, Inc. nor the names of its
42 contributors may be used to endorse or promote products derived
43 from this software without specific prior written permission.
44 - The use of this software may or may not infringe the patent rights
45 of one or more patent holders. This license does not release you
46 from the requirement that you obtain separate licenses from these
47 patent holders to use this software.
48 - Use of the software either in source or binary form, must be run
49 on or directly connected to an Analog Devices Inc. component.
50
51 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
52 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
53 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
54 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
55 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
57 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
58 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
59 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 */
62
63 /*! @file
64 @ingroup LTC2482
65 */
66
67 #include <Arduino.h>
68 #include <stdint.h>
69 #include "Linduino.h"
70 #include "LT_SPI.h"
71 #include "UserInterface.h"
72 #include "LT_I2C.h"
73 #include "QuikEval_EEPROM.h"
74 #include "LTC24XX_general.h"
75 #include "LTC2482.h"
76 #include <SPI.h>
77
78 // Function Declaration
79 void print_title(); // Print the title block
80 void print_prompt(); // Prompt the user for an input command
81
82 void menu_1_read_input();
83 void menu_2_reference_voltage();
84
85 static uint8_t demo_board_connected; //!< Set to 1 if the board is connected
86
87 // Global variables
88 float LTC2482_vref = 5;
89 float LTC2482_range = LTC2482_vref/2;
90
91 //! Initialize Linduino
92 void setup()
93 {
94 char demo_name[]="DC941"; // Demo Board Name stored in QuikEval EEPROM
95
96 quikeval_I2C_init(); // Configure the EEPROM I2C port for 100kHz
97 quikeval_SPI_init(); // Configure the spi port for 4MHz SCK
98 quikeval_SPI_connect(); // Connect SPI to main data port
99
100 Serial.begin(115200); // Initialize the serial port to the PC
101 print_title();
102 demo_board_connected = discover_demo_board(demo_name);
103 if (demo_board_connected)
104 {
105 print_prompt();
106 }
107 }
108
109 //! Repeats Linduino loop
110 void loop()
111 {
112 uint16_t user_command;
113 {
114 if (Serial.available())
115 {
116 user_command = read_int(); // Read the user command
117 if (user_command != 'm')
118 Serial.println(user_command); // Prints the user command to com port
119 switch (user_command)
120 {
121 case 1:
122 menu_1_read_input();
123 break;
124 case 2:
125 menu_2_reference_voltage();
126 break;
127 default:
128 Serial.println(F("Invalid Option"));
129 break;
130 }
131 Serial.println();
132 print_prompt();
133 }
134 }
135 }
136
137 // Function Definitions
138 //! Read channel
139 //! @return void
140 void menu_1_read_input()
141 {
142 uint8_t user_command;
143 uint32_t adc_code; // The LTC2482 code
144 int32_t display_code = 0;
145 float adc_voltage; // The LTC2482 voltage
146
147 // Read and display
148 LTC2482_read(LTC2482_CS, &adc_code);
149 delay(200);
150 LTC2482_read(LTC2482_CS, &adc_code);
151
152 display_code = adc_code >> 4;
153 display_code = display_code & 0xFFFF;
154
155 Serial.print(F(" Received Code: 0x"));
156 Serial.println(display_code, HEX);
157
158 // Convert the received code to voltage
159 adc_voltage = LTC2482_code_to_voltage(display_code, LTC2482_range);
160
161 if (adc_code & 0x100000) // Checking sign bit
162 {
163 adc_voltage = LTC2482_range - adc_voltage;
164 adc_voltage = adc_voltage * (-1);
165 }
166
167 Serial.print(F(" Equivalent voltage: "));
168 Serial.print(adc_voltage, 4);
169 Serial.println(F(" V"));
170 }
171
172 void menu_2_reference_voltage()
173 {
174 Serial.print(F("\n Enter the reference voltage: "));
175 LTC2482_vref = read_float();
176 Serial.print(LTC2482_vref);
177 Serial.println(F(" V"));
178
179 LTC2482_range = LTC2482_vref/2;
180 }
181
182 //! Prints the title block when program first starts.
183 void print_title()
184 {
185 Serial.print(F("\n*****************************************************************\n"));
186 Serial.print(F("* DC941A Demonstration Program *\n"));
187 Serial.print(F("* *\n"));
188 Serial.print(F("* This program demonstrates how to send data and receive data *\n"));
189 Serial.print(F("* from the 16-bit ADC. *\n"));
190 Serial.print(F("* *\n"));
191 Serial.print(F("* *\n"));
192 Serial.print(F("* Set the baud rate to 115200 and select the newline terminator.*\n"));
193 Serial.print(F("* *\n"));
194 Serial.print(F("*****************************************************************\n"));
195 }
196
197 //! Prints main menu.
198 void print_prompt()
199 {
200 Serial.print(F("\n1-Read Input\n"));
201 Serial.print(F("2-Change reference voltage\n"));
202 Serial.print(F("\nEnter a Command: "));
203 }
setup
static void setup()
Initialize Linduino.
Definition: DC941A.ino:92
user_command
unsigned char user_command
Definition: Serial_EEPROM_Test.ino:75
Linduino.h
Header File for Linduino Libraries and Demo Code.
LTC2482.h
LTC2482: 16-Bit Delta-Sigma ADC with Easy Drive Input Current Cancellation.
adc_voltage
static float adc_voltage
Definition: DC2071AA.ino:115
LTC2482_CS
#define LTC2482_CS
Define the SPI CS pin.
Definition: LTC2482.h:80
LTC24XX_general.h
LTC24XX General Library: Functions and defines for all SINC4 Delta Sigma ADCs.
LTC2482_range
static float LTC2482_range
Definition: DC941A.ino:89
loop
static void loop()
Repeats Linduino loop.
Definition: DC941A.ino:110
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
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
demo_board_connected
static uint8_t demo_board_connected
Set to 1 if the board is connected.
Definition: DC941A.ino:85
LTC2482_code_to_voltage
float LTC2482_code_to_voltage(uint32_t adc_code, float vref)
Calculates the LTC2482 input voltage given the binary data, reference voltage and input gain...
Definition: LTC2482.cpp:84
print_title
static void print_title()
Prints the title block when program first starts.
Definition: DC941A.ino:183
LT_SPI.h
LT_SPI: Routines to communicate with ATmega328P&#39;s hardware SPI port.
LT_I2C.h
LT_I2C: Routines to communicate with ATmega328P&#39;s hardware I2C port.
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
menu_2_reference_voltage
static void menu_2_reference_voltage()
Definition: DC941A.ino:172
read_int
int32_t read_int()
Definition: UserInterface.cpp:93
display_code
static int32_t display_code
Definition: DC2071AA.ino:114
read_float
float read_float()
Definition: UserInterface.cpp:78
LTC2482_vref
static float LTC2482_vref
Definition: DC941A.ino:88
menu_1_read_input
static void menu_1_read_input()
Read channel.
Definition: DC941A.ino:140
quikeval_I2C_init
void quikeval_I2C_init(void)
Initializes Linduino I2C port.
Definition: LT_I2C.cpp:394
print_prompt
static void print_prompt()
Prints main menu.
Definition: DC941A.ino:198
LTC2482_read
void LTC2482_read(uint8_t cs, uint32_t *ptr_adc_code)
Reads the LTC2482 and returns 24-bit data.
Definition: LTC2482.cpp:72
adc_code
static uint32_t adc_code
Definition: DC2071AA.ino:113