| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

DC1304A_A.ino
Go to the documentation of this file.
1 /*!
2 Linear Technology DC1304A-A Demonstration Board.
3 LTC6602: Dual Matched, High Frequency Bandpass/Lowpass Filters
4
5 @verbatim
6
7 NOTES
8 Setup:
9 Set the terminal baud rate to 115200 and select the newline terminator.
10 Equipment required is a precision voltage source and a precision
11 voltmeter. No external power supply is required. Ensure all jumpers on
12 the demo board are installed in their default positions from the
13 factory.
14
15 USER INPUT DATA FORMAT:
16 decimal : 1024
17 hex : 0x400
18 octal : 02000 (leading 0 "zero")
19 binary : B10000000000
20 float : 1024.0
21
22 @endverbatim
23
24 http://www.linear.com/product/LTC6602
25
26 http://www.linear.com/product/LTC6602#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 LTC6602
65 */
66
67 #include <Arduino.h>
68 #include <stdint.h>
69 #include "Linduino.h"
70 #include "LT_SPI.h"
71 #include "LT_I2C.h"
72 #include "UserInterface.h"
73 #include "QuikEval_EEPROM.h"
74 #include "LTC6602.h"
75 #include <SPI.h>
76 #include <Wire.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 void print_user_command(uint8_t menu); // Display selected differential channels
82 void menu_1_filter_settings(); // Sets the gain and cutoff frequencies
83 void menu_2_set_gpo(); // Sets the GPO
84 void menu_3_shutdown(); // Shuts down the LTC6602
85 void menu_4_poweron(); // Power up the LTC6602
86
87 // Global variables
88 uint8_t spi_out;
89 uint8_t control_byte;
90 uint8_t filter_gain_settings = LTC6602_GAIN_0dB;
91 uint8_t filter_lp_settings = LTC6602_LPF0 ;
92 uint8_t filter_hp_settings = LTC6602_HPF0 ;
93 uint8_t gpio_settings = LTC6602_GPO_LOW ;
94 uint8_t shdn_settings = LTC6602_SHDN;
95
96 //! Initialize Linduino
97 void setup()
98 {
99 quikeval_SPI_init(); // Configure the spi port for 4MHz SCK
100 Serial.begin(115200); // Initialize the serial port to the PC
101 print_title(); // Displays the title
102 print_prompt(); // Display user options
103 control_byte = 0x00; // A global variable that contains the whole control byte.
104
105 }
106
107 //! Repeats Linduino loop
108 void loop()
109 {
110 int16_t user_command; // The user input command
111 if (Serial.available()) // Check for user input
112 {
113 user_command = read_int(); // Read the user command
114 if (user_command != 'm')
115 Serial.println(user_command); // Prints the user command to com port
116
117 switch (user_command)
118 {
119 case 1:
120 menu_1_filter_settings();
121 break;
122 case 2:
123 menu_2_set_gpo();
124 break;
125 case 3:
126 menu_3_shutdown();
127 break;
128 case 4:
129 menu_4_poweron();
130 break;
131 default:
132 Serial.println("Incorrect Option");
133 break;
134 }
135 print_prompt();
136 }
137 }
138
139 // Function Definitions
140
141 //! Set filter settings
142 //! @return void
143 void menu_1_filter_settings()
144 {
145 int16_t user_command; // The user input command
146 while (1)
147 {
148 Serial.print(F("*************************\n\n"));
149 Serial.println (F("0-Set Gain"));
150 Serial.println (F("1-Set Lowpass"));
151 Serial.println (F("2-Set Highpass"));
152 Serial.println (F("3-Upload Filter Settings"));
153 Serial.print (F("m-Main Menu\n"));
154 Serial.print (F("\nEnter a Command: "));
155 user_command = read_int(); // Read the single command
156 if (user_command == 'm')
157 return;
158 else
159 Serial.println(user_command);
160 Serial.println();
161
162 switch (user_command)
163 {
164 case 0:
165 Serial.println (F("Gain: 0-0dB, 1-12dB, 2-24dB, 3-30dB"));
166 user_command = read_int();
167 switch (user_command)
168 {
169 case 0:
170 control_byte = (control_byte & LTC6602_GAIN_MASK) | LTC6602_GAIN_0dB;
171 break;
172 case 1:
173 control_byte = (control_byte & LTC6602_GAIN_MASK) | LTC6602_GAIN_12dB;
174 break;
175 case 2:
176 control_byte = (control_byte & LTC6602_GAIN_MASK) | LTC6602_GAIN_24dB;
177 break;
178 case 3:
179 control_byte = (control_byte & LTC6602_GAIN_MASK) | LTC6602_GAIN_30dB;
180 break;
181 default:
182 Serial.println (F("incorrect option"));
183 }
184 break;
185 case 1:
186 Serial.println (F("Lowpass Divider: 0-100, 1-100, 2-300, 3-600"));
187 user_command = read_int();
188 switch (user_command)
189 {
190 case 0:
191 control_byte = (control_byte & LTC6602_LPF_MASK) | LTC6602_LPF3;
192 break;
193 case 1:
194 control_byte = (control_byte & LTC6602_LPF_MASK) | LTC6602_LPF2;
195 break;
196 case 2:
197 control_byte = (control_byte & LTC6602_LPF_MASK) | LTC6602_LPF1;
198 break;
199 case 3:
200 control_byte = (control_byte & LTC6602_LPF_MASK) | LTC6602_LPF0;
201 break;
202 default:
203 Serial.println (F("incorrect option"));
204 }
205 break;
206 case 2:
207 Serial.println (F("Highpass Divider: 0-1000, 1-2000, 2-6000, 3-Bypass HPF"));
208 user_command = read_int();
209 switch (user_command)
210 {
211 case 0:
212 control_byte = (control_byte & LTC6602_HPF_MASK) | LTC6602_HPF2;
213 break;
214 case 1:
215 control_byte = (control_byte & LTC6602_HPF_MASK) | LTC6602_HPF1;
216 break;
217 case 2:
218 control_byte = (control_byte & LTC6602_HPF_MASK) | LTC6602_HPF0;
219 break;
220 case 3:
221 control_byte = (control_byte & LTC6602_HPF_MASK) | LTC6602_HPF3;
222 break;
223 default:
224 Serial.println (F("incorrect option"));
225 }
226 break;
227 case 3:
228 spi_out = control_byte;
229 LTC6602_write(LTC6602_CS, &spi_out, (uint8_t)1);
230 break;
231 default:
232 Serial.println("Incorrect Option");
233 break;
234 }
235 Serial.print ("\Control byte 0x" + String(control_byte, HEX) + "\n");
236 }
237 }
238
239 void menu_2_set_gpo()
240 {
241 int16_t user_command; // The user input command
242
243 while (1)
244 {
245 Serial.print(F("*************************\n\n"));
246 Serial.println(F("0-Set GPIO Low"));
247 Serial.println (F("1-Set GPIO High"));
248 Serial.print(F("m-Main Menu\n"));
249 Serial.print(F("\nEnter a Command: "));
250 user_command = read_int(); // Read the single command
251 if (user_command == 'm')
252 return;
253 else
254 Serial.println(user_command);
255 Serial.println();
256 switch (user_command)
257 {
258 case 0:
259 control_byte = (control_byte & LTC6602_GPO_MASK) | LTC6602_GPO_LOW;
260 spi_out = control_byte;
261 LTC6602_write(LTC6602_CS, &spi_out, (uint8_t)1);
262 break;
263 case 1:
264 control_byte = (control_byte & LTC6602_GPO_MASK) | LTC6602_GPO_HIGH;
265 spi_out = control_byte;
266 LTC6602_write(LTC6602_CS, &spi_out, (uint8_t)1);
267 break;
268 default:
269 Serial.println (F("incorrect option"));
270 break;
271 }
272 Serial.print ("\Control byte 0x" + String(control_byte, HEX) + "\n");
273 }
274 }
275
276 void menu_3_shutdown()
277 {
278 Serial.print(F("* The LTC6602 is powered down *\n"));
279 control_byte = (control_byte & LTC6602_ONOFF_MASK) | LTC6602_SHDN;
280 spi_out = control_byte;
281 LTC6602_write(LTC6602_CS, &spi_out, (uint8_t)1);
282 Serial.print ("\Control byte 0x" + String(control_byte, HEX) + "\n");
283
284 }
285
286 void menu_4_poweron()
287 {
288 Serial.print(F("* The LTC6602 is turning on *\n"));
289 control_byte = (control_byte & LTC6602_ONOFF_MASK) | LTC6602_PRUP;
290 spi_out = control_byte;
291 LTC6602_write(LTC6602_CS, &spi_out, (uint8_t)1);
292 Serial.print ("\Control byte 0x" + String(control_byte, HEX) + "\n");
293
294 }
295
296 //! Prints the title block when program first starts.
297 void print_title()
298 {
299 (F("\n*****************************************************************\n"));
300 Serial.print(F("* DC1304A-A Demonstration Program *\n"));
301 Serial.print(F("* *\n"));
302 Serial.print(F("* This program demonstrates how to send data to the LTC6602. *\n"));
303 Serial.print(F("* *\n"));
304 Serial.print(F("* Set the baud rate to 115200 and select the newline terminator.*\n"));
305 Serial.print(F("* *\n"));
306 Serial.print(F("*****************************************************************\n"));
307 }
308
309 //! Prints main menu.
310 void print_prompt()
311 {
312 Serial.print(F("\n1-Filter Setting\n"));
313 Serial.print(F("2-Set General Purpose Output\n"));
314 Serial.print(F("3-Power Down LTC6602\n"));
315 Serial.print(F("4-Power Up LTC6602\n"));
316 Serial.println();
317 Serial.print(F("Enter a command:"));
318 }
LTC6602_GAIN_12dB
#define LTC6602_GAIN_12dB
Definition: LTC6602.h:87
LTC6602_HPF2
#define LTC6602_HPF2
Definition: LTC6602.h:110
LTC6602_HPF3
#define LTC6602_HPF3
Definition: LTC6602.h:111
user_command
unsigned char user_command
Definition: Serial_EEPROM_Test.ino:75
filter_hp_settings
static uint8_t filter_hp_settings
Definition: DC1304A_A.ino:92
filter_lp_settings
static uint8_t filter_lp_settings
Definition: DC1304A_A.ino:91
Linduino.h
Header File for Linduino Libraries and Demo Code.
print_user_command
static void print_user_command(uint8_t menu)
LTC6602_SHDN
#define LTC6602_SHDN
Shuts down LTC6602.
Definition: LTC6602.h:117
print_prompt
static void print_prompt()
Prints main menu.
Definition: DC1304A_A.ino:310
LTC6602_GPO_HIGH
#define LTC6602_GPO_HIGH
Sets the general purpose.
Definition: LTC6602.h:120
gpio_settings
static uint8_t gpio_settings
Definition: DC1304A_A.ino:93
LTC6602_LPF1
#define LTC6602_LPF1
Definition: LTC6602.h:98
filter_gain_settings
static uint8_t filter_gain_settings
Definition: DC1304A_A.ino:90
spi_out
static uint8_t spi_out
Definition: DC1304A_A.ino:88
menu_4_poweron
static void menu_4_poweron()
Definition: DC1304A_A.ino:286
LTC6602_GPO_LOW
#define LTC6602_GPO_LOW
Definition: LTC6602.h:121
control_byte
static uint8_t control_byte
Definition: DC1304A_A.ino:89
LTC6602_CS
#define LTC6602_CS
Define the SPI CS pin.
Definition: LTC6602.h:80
LTC6602_GAIN_0dB
#define LTC6602_GAIN_0dB
Definition: LTC6602.h:86
menu_1_filter_settings
static void menu_1_filter_settings()
Set filter settings.
Definition: DC1304A_A.ino:143
LTC6602_HPF_MASK
#define LTC6602_HPF_MASK
Definition: LTC6602.h:112
LTC6602_LPF3
#define LTC6602_LPF3
Definition: LTC6602.h:100
shdn_settings
static uint8_t shdn_settings
Definition: DC1304A_A.ino:94
menu_3_shutdown
static void menu_3_shutdown()
Definition: DC1304A_A.ino:276
print_title
static void print_title()
Prints the title block when program first starts.
Definition: DC1304A_A.ino:297
QuikEval_EEPROM.h
QuikEval EEPROM Library.
loop
static void loop()
Repeats Linduino loop.
Definition: DC1304A_A.ino:108
quikeval_SPI_init
void quikeval_SPI_init(void)
Configure the SPI port for 4Mhz SCK.
Definition: LT_SPI.cpp:151
LTC6602_GPO_MASK
#define LTC6602_GPO_MASK
Definition: LTC6602.h:122
LTC6602_GAIN_30dB
#define LTC6602_GAIN_30dB
Definition: LTC6602.h:89
LTC6602_GAIN_24dB
#define LTC6602_GAIN_24dB
Definition: LTC6602.h:88
LT_SPI.h
LT_SPI: Routines to communicate with ATmega328P&#39;s hardware SPI port.
LTC6602_HPF1
#define LTC6602_HPF1
Definition: LTC6602.h:109
LT_I2C.h
LT_I2C: Routines to communicate with ATmega328P&#39;s hardware I2C port.
LTC6602_PRUP
#define LTC6602_PRUP
Turns on LTC6602.
Definition: LTC6602.h:118
UserInterface.h
read_int
int32_t read_int()
Definition: UserInterface.cpp:93
LTC6602_LPF0
#define LTC6602_LPF0
Definition: LTC6602.h:97
LTC6602_HPF0
#define LTC6602_HPF0
Definition: LTC6602.h:108
menu_2_set_gpo
static void menu_2_set_gpo()
Definition: DC1304A_A.ino:239
LTC6602_LPF2
#define LTC6602_LPF2
Definition: LTC6602.h:99
LTC6602_LPF_MASK
#define LTC6602_LPF_MASK
Definition: LTC6602.h:101
LTC6602_ONOFF_MASK
#define LTC6602_ONOFF_MASK
Definition: LTC6602.h:119
LTC6602_write
void LTC6602_write(uint8_t cs, uint8_t *tx, uint8_t length)
Sends Data to the LTC6602.
Definition: LTC6602.cpp:72
LTC6602_GAIN_MASK
#define LTC6602_GAIN_MASK
Definition: LTC6602.h:90
setup
static void setup()
Initialize Linduino.
Definition: DC1304A_A.ino:97
LTC6602.h
LTC6602: Dual, Matched, High Frequency Bandpass/Lowpass Filters.