| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

DC1304A_B.ino
Go to the documentation of this file.
1
2
3 /*!
4 Linear Technology DC1304A-B Demonstration Board.
5 LTC6603: Dual Matched, High Frequency Bandpass/Lowpass Filters
6
7 @verbatim
8 NOTES
9 Setup:
10 Set the terminal baud rate to 115200 and select the newline terminator.
11 Equipment required is a precision voltage source and a precision
12 voltmeter. No external power supply is required. Ensure all jumpers on
13 the demo board are installed in their default positions from the
14 factory.
15
16 USER INPUT DATA FORMAT:
17 decimal : 1024
18 hex : 0x400
19 octal : 02000 (leading 0 "zero")
20 binary : B10000000000
21 float : 1024.0
22
23 @endverbatim
24
25 http://www.analog.com/en/products/amplifiers/adc-drivers/fully-differential-amplifiers/ltc6603.html
26
27 http://www.analog.com/en/design-center/evaluation-hardware-and-software/evaluation-boards-kits/dc1304a-b.html
28
29
30
31 Copyright 2018(c) Analog Devices, Inc.
32
33 All rights reserved.
34
35 Redistribution and use in source and binary forms, with or without
36 modification, are permitted provided that the following conditions are met:
37 - Redistributions of source code must retain the above copyright
38 notice, this list of conditions and the following disclaimer.
39 - Redistributions in binary form must reproduce the above copyright
40 notice, this list of conditions and the following disclaimer in
41 the documentation and/or other materials provided with the
42 distribution.
43 - Neither the name of Analog Devices, Inc. nor the names of its
44 contributors may be used to endorse or promote products derived
45 from this software without specific prior written permission.
46 - The use of this software may or may not infringe the patent rights
47 of one or more patent holders. This license does not release you
48 from the requirement that you obtain separate licenses from these
49 patent holders to use this software.
50 - Use of the software either in source or binary form, must be run
51 on or directly connected to an Analog Devices Inc. component.
52
53 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
54 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
55 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
56 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
57 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
58 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
59 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
60 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
61 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
62 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63
64 The views and conclusions contained in the software and documentation are those
65 of the authors and should not be interpreted as representing official policies,
66 either expressed or implied, of Linear Technology Corp.
67
68 The Linear Technology Linduino is not affiliated with the official Arduino team.
69 However, the Linduino is only possible because of the Arduino team's commitment
70 to the open-source community. Please, visit http://www.arduino.cc and
71 http://store.arduino.cc , and consider a purchase that will help fund their
72 ongoing work.
73 */
74
75 /*! @file
76 @ingroup LTC6603
77 */
78
79 #include <Arduino.h>
80 #include <stdint.h>
81 #include "Linduino.h"
82 #include "LT_SPI.h"
83 #include "LT_I2C.h"
84 #include "UserInterface.h"
85 #include "QuikEval_EEPROM.h"
86 #include "LTC6603.h"
87 #include <SPI.h>
88 #include <Wire.h>
89
90 // Function Declaration
91 void print_title(); // Print the title block
92 void print_prompt(); // Prompt the user for an input command
93 void print_user_command(uint8_t menu); // Display selected differential channels
94 void menu_1_filter_settings(); // Sets the gain and cutoff frequencies
95 void menu_2_set_gpo(); // Sets the GPO
96 void menu_3_shutdown(); // Shuts down the LTC6603
97 void menu_4_poweron(); // Power up the LTC6603
98
99 // Global variables
100 uint8_t spi_out;
101 uint8_t control_byte;
102 uint8_t filter_gain_settings = LTC6603_GAIN_0dB;
103 uint8_t filter_lp_settings = LTC6603_LPF0 ;
104 uint8_t filter_noFunc_settings = LTC6603_NOFUNC0 ;
105 uint8_t gpio_settings = LTC6603_GPO_LOW ;
106 uint8_t shdn_settings = LTC6603_SHDN;
107 float freq_settings = LTC6603_FREQ_MIN;
108
109 //! Initialize Linduino
110 void setup()
111 {
112 quikeval_SPI_init(); // Configure the spi port for 4MHz SCK
113 Serial.begin(115200); // Initialize the serial port to the PC
114 print_title(); // Displays the title
115 print_prompt(); // Display user options
116 control_byte = 0x00; // A global variable that contains the whole control byte.
117
118 }
119
120 //! Repeats Linduino loop
121 void loop()
122 {
123 int16_t user_command; // The user input command
124 if (Serial.available()) // Check for user input
125 {
126 user_command = read_int(); // Read the user command
127 if (user_command != 'm')
128 Serial.println(user_command); // Prints the user command to com port
129
130 switch (user_command)
131 {
132 case 1:
133 menu_1_filter_settings();
134 break;
135 case 2:
136 menu_2_set_gpo();
137 break;
138 case 3:
139 menu_3_shutdown();
140 break;
141 case 4:
142 menu_4_poweron();
143 break;
144 default:
145 Serial.println("Incorrect Option");
146 break;
147 }
148 print_prompt();
149 }
150 }
151
152 // Function Definitions
153
154 //! Set filter settings
155 //! @return void
156 void menu_1_filter_settings()
157 {
158 int16_t user_command; // The user input command
159 while (1)
160 {
161 Serial.print(F("*************************\n\n"));
162 Serial.println (F("0-Enter External Frequency"));
163 Serial.println (F("1-Set Gain"));
164 Serial.println (F("2-Set Lowpass"));
165 Serial.println (F("3-Set No Function Code"));
166 Serial.println (F("4-Upload Filter Settings"));
167 Serial.print (F("m-Main Menu\n"));
168 Serial.print (F("\nEnter a Command: "));
169 user_command = read_int(); // Read the single command
170 if (user_command == 'm')
171 return;
172 else
173 Serial.println(user_command);
174 Serial.println();
175
176 switch (user_command)
177 {
178 case 0:
179 Serial.println (F("Enter Frequency(MHz) between 12MHz-80MHZ"));
180 user_command = read_float();
181 if (user_command <= LTC6603_FREQ_MAX && user_command >= LTC6603_FREQ_MIN)
182 freq_settings = user_command;
183 else
184 Serial.println (F("incorrect option"));
185 break;
186 case 1:
187 Serial.println (F("Gain: 0-0dB, 1-6dB, 2-12dB, 3-24dB"));
188 user_command = read_int();
189 switch (user_command)
190 {
191 case 0:
192 control_byte = (control_byte & LTC6603_GAIN_MASK) | LTC6603_GAIN_0dB;
193 break;
194 case 1:
195 control_byte = (control_byte & LTC6603_GAIN_MASK) | LTC6603_GAIN_6dB;
196 break;
197 case 2:
198 control_byte = (control_byte & LTC6603_GAIN_MASK) | LTC6603_GAIN_12dB;
199 break;
200 case 3:
201 control_byte = (control_byte & LTC6603_GAIN_MASK) | LTC6603_GAIN_24dB;
202 break;
203 default:
204 Serial.println (F("incorrect option"));
205 }
206 break;
207 case 2:
208 Serial.println (F("Lowpass Divider: 0-32 1-32 2-128 3-512"));
209 calculate_FreqLow(freq_settings);
210 user_command = read_int();
211 switch (user_command)
212 {
213 case 0:
214 control_byte = (control_byte & LTC6603_LPF_MASK) | LTC6603_LPF3;
215 break;
216 case 1:
217 control_byte = (control_byte & LTC6603_LPF_MASK) | LTC6603_LPF2;
218 break;
219 case 2:
220 control_byte = (control_byte & LTC6603_LPF_MASK) | LTC6603_LPF1;
221 break;
222 case 3:
223 control_byte = (control_byte & LTC6603_LPF_MASK) | LTC6603_LPF0;
224 break;
225 default:
226 Serial.println (F("incorrect option"));
227 }
228 break;
229 case 3:
230 Serial.println (F("No Function Hex Code: 0-0x04, 1-0x08, 2-0x00, 3-0x0C"));
231 user_command = read_int();
232 switch (user_command)
233 {
234 case 0:
235 control_byte = (control_byte & LTC6603_NOFUNC_MASK) | LTC6603_NOFUNC2;
236 break;
237 case 1:
238 control_byte = (control_byte & LTC6603_NOFUNC_MASK) | LTC6603_NOFUNC1;
239 break;
240 case 2:
241 control_byte = (control_byte & LTC6603_NOFUNC_MASK) | LTC6603_NOFUNC0;
242 break;
243 case 3:
244 control_byte = (control_byte & LTC6603_NOFUNC_MASK) | LTC6603_NOFUNC3;
245 break;
246 default:
247 Serial.println (F("incorrect option"));
248 }
249 break;
250 case 4:
251 spi_out = control_byte;
252 LTC6603_write(LTC6603_CS, &spi_out, (uint8_t)1);
253 break;
254 default:
255 Serial.println("Incorrect Option");
256 break;
257 }
258 Serial.print ("\Control byte 0x" + String(control_byte, HEX) + "\n");
259 }
260 }
261
262 void menu_2_set_gpo()
263 {
264 int16_t user_command; // The user input command
265
266 while (1)
267 {
268 Serial.print(F("*************************\n\n"));
269 Serial.println(F("0-Set GPIO Low"));
270 Serial.println (F("1-Set GPIO High"));
271 Serial.print(F("m-Main Menu\n"));
272 Serial.print(F("\nEnter a Command: "));
273 user_command = read_int(); // Read the single command
274 if (user_command == 'm')
275 return;
276 else
277 Serial.println(user_command);
278 Serial.println();
279 switch (user_command)
280 {
281 case 0:
282 control_byte = (control_byte & LTC6603_GPO_MASK) | LTC6603_GPO_LOW;
283 spi_out = control_byte;
284 LTC6603_write(LTC6603_CS, &spi_out, (uint8_t)1);
285 break;
286 case 1:
287 control_byte = (control_byte & LTC6603_GPO_MASK) | LTC6603_GPO_HIGH;
288 spi_out = control_byte;
289 LTC6603_write(LTC6603_CS, &spi_out, (uint8_t)1);
290 break;
291 default:
292 Serial.println (F("incorrect option"));
293 break;
294 }
295 Serial.print ("\Control byte 0x" + String(control_byte, HEX) + "\n");
296 }
297 }
298
299 void menu_3_shutdown()
300 {
301 Serial.print(F("* The LTC6603 is powered down *\n"));
302 control_byte = (control_byte & LTC6603_ONOFF_MASK) | LTC6603_SHDN;
303 spi_out = control_byte;
304 LTC6603_write(LTC6603_CS, &spi_out, (uint8_t)1);
305 Serial.print ("\Control byte 0x" + String(control_byte, HEX) + "\n");
306
307 }
308
309 void menu_4_poweron()
310 {
311 Serial.print(F("* The LTC6603 is turning on *\n"));
312 control_byte = (control_byte & LTC6603_ONOFF_MASK) | LTC6603_PRUP;
313 spi_out = control_byte;
314 LTC6603_write(LTC6603_CS, &spi_out, (uint8_t)1);
315 Serial.print ("\Control byte 0x" + String(control_byte, HEX) + "\n");
316
317 }
318
319
320 //! Prints the title block when program first starts.
321 void print_title()
322 {
323 (F("\n*****************************************************************\n"));
324 Serial.print(F("* DC1304A-B Demonstration Program *\n"));
325 Serial.print(F("* *\n"));
326 Serial.print(F("* This program demonstrates how to send data to the LTC6603. *\n"));
327 Serial.print(F("* *\n"));
328 Serial.print(F("* Set the baud rate to 115200 and select the newline terminator.*\n"));
329 Serial.print(F("* *\n"));
330 Serial.print(F("*****************************************************************\n"));
331 }
332
333 //! Prints main menu.
334 void print_prompt()
335 {
336 Serial.print(F("\n1-Filter Setting\n"));
337 Serial.print(F("2-Set General Purpose Output\n"));
338 Serial.print(F("3-Power Down LTC6603\n"));
339 Serial.print(F("4-Power Up LTC6603\n"));
340 Serial.print(F("5-Change the LTC6903 clock frequency\n"));
341 Serial.println();
342 Serial.print(F("Enter a command:"));
343 }
344
345 void calculate_FreqLow(float freq)
346 {
347 float div0 = freq/32;
348 float div1 = freq/32;
349 float div2 = freq/128;
350 float div3 = freq/512;
351
352 Serial.println ("Lowpass Frequency: 0-" + String(div0,3) + "MHz 1-" + String(div1,3) + "MHz 2-" + String(div2,3) + "MHz 3-"+String(div3,3) + "MHz");
353
354
355 }
LTC6603_CS
#define LTC6603_CS
Define the SPI CS pin.
Definition: LTC6603.h:96
user_command
unsigned char user_command
Definition: Serial_EEPROM_Test.ino:75
filter_lp_settings
static uint8_t filter_lp_settings
Definition: DC1304A_B.ino:103
LTC6603_FREQ_MIN
#define LTC6603_FREQ_MIN
Define external frequency range.
Definition: LTC6603.h:91
LTC6603_LPF0
#define LTC6603_LPF0
Definition: LTC6603.h:113
LTC6603_PRUP
#define LTC6603_PRUP
Turns on LTC6603.
Definition: LTC6603.h:134
Linduino.h
Header File for Linduino Libraries and Demo Code.
LTC6603_LPF_MASK
#define LTC6603_LPF_MASK
Definition: LTC6603.h:117
LTC6603_NOFUNC_MASK
#define LTC6603_NOFUNC_MASK
Definition: LTC6603.h:128
print_user_command
static void print_user_command(uint8_t menu)
spi_out
static uint8_t spi_out
Definition: DC1304A_B.ino:100
gpio_settings
static uint8_t gpio_settings
Definition: DC1304A_B.ino:105
LTC6603_GPO_MASK
#define LTC6603_GPO_MASK
Definition: LTC6603.h:138
control_byte
static uint8_t control_byte
Definition: DC1304A_B.ino:101
LTC6603_NOFUNC3
#define LTC6603_NOFUNC3
Definition: LTC6603.h:127
print_prompt
static void print_prompt()
Prints main menu.
Definition: DC1304A_B.ino:334
LTC6603_GPO_HIGH
#define LTC6603_GPO_HIGH
Sets the general purpose.
Definition: LTC6603.h:136
LTC6603_ONOFF_MASK
#define LTC6603_ONOFF_MASK
Definition: LTC6603.h:135
LTC6603_LPF1
#define LTC6603_LPF1
Definition: LTC6603.h:114
LTC6603_NOFUNC0
#define LTC6603_NOFUNC0
Definition: LTC6603.h:124
menu_4_poweron
static void menu_4_poweron()
Definition: DC1304A_B.ino:309
filter_gain_settings
static uint8_t filter_gain_settings
Definition: DC1304A_B.ino:102
menu_1_filter_settings
static void menu_1_filter_settings()
Set filter settings.
Definition: DC1304A_B.ino:156
LTC6603_NOFUNC1
#define LTC6603_NOFUNC1
Definition: LTC6603.h:125
LTC6603_GAIN_12dB
#define LTC6603_GAIN_12dB
Definition: LTC6603.h:104
shdn_settings
static uint8_t shdn_settings
Definition: DC1304A_B.ino:106
LTC6603_NOFUNC2
#define LTC6603_NOFUNC2
Definition: LTC6603.h:126
QuikEval_EEPROM.h
QuikEval EEPROM Library.
LTC6603_GAIN_24dB
#define LTC6603_GAIN_24dB
Definition: LTC6603.h:105
LTC6603_write
void LTC6603_write(uint8_t cs, uint8_t *tx, uint8_t length)
Sends Data to the LTC6603.
Definition: LTC6603.cpp:89
print_title
static void print_title()
Prints the title block when program first starts.
Definition: DC1304A_B.ino:321
LTC6603_LPF3
#define LTC6603_LPF3
Definition: LTC6603.h:116
LTC6603_SHDN
#define LTC6603_SHDN
Shuts down LTC6603.
Definition: LTC6603.h:133
quikeval_SPI_init
void quikeval_SPI_init(void)
Configure the SPI port for 4Mhz SCK.
Definition: LT_SPI.cpp:151
menu_3_shutdown
static void menu_3_shutdown()
Definition: DC1304A_B.ino:299
loop
static void loop()
Repeats Linduino loop.
Definition: DC1304A_B.ino:121
LTC6603.h
LTC6603: Dual, Matched, High Frequency Bandpass/Lowpass Filters.
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.
LTC6603_GAIN_6dB
#define LTC6603_GAIN_6dB
Definition: LTC6603.h:103
LTC6603_GAIN_MASK
#define LTC6603_GAIN_MASK
Definition: LTC6603.h:106
calculate_FreqLow
static void calculate_FreqLow(float freq)
Definition: DC1304A_B.ino:345
filter_noFunc_settings
static uint8_t filter_noFunc_settings
Definition: DC1304A_B.ino:104
UserInterface.h
read_int
int32_t read_int()
Definition: UserInterface.cpp:93
freq_settings
static float freq_settings
Definition: DC1304A_B.ino:107
menu_2_set_gpo
static void menu_2_set_gpo()
Definition: DC1304A_B.ino:262
read_float
float read_float()
Definition: UserInterface.cpp:78
LTC6603_GAIN_0dB
#define LTC6603_GAIN_0dB
Definition: LTC6603.h:102
LTC6603_GPO_LOW
#define LTC6603_GPO_LOW
Definition: LTC6603.h:137
LTC6603_LPF2
#define LTC6603_LPF2
Definition: LTC6603.h:115
setup
static void setup()
Initialize Linduino.
Definition: DC1304A_B.ino:110