Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
DC572A.ino
Go to the documentation of this file.
1 /*!
2 Linear Technology DC572A Demonstration Board.
3 LTC1592: 16-bit SoftSpan DAC with Programmable Output Range
4 
5 @verbatim
6 NOTES
7  Setup:
8  Set the terminal baud rate to 115200 and select the newline terminator.
9 
10  An external +/- 15V power supply is required to power the circuit.
11 
12  Explanation of Commands:
13  1- Voltage Output
14  Displays the calculated voltage depending on the code input from user and
15  voltage range selected.
16 
17  2- Square Wave Output
18  Generates a square wave on the output pin. This function helps to measure
19  settling time and glitch impulse.
20 
21  3- Change Range
22  | Command | Range Selected |
23  | C3 C2 C1 C0 | |
24  |------------------------------|
25  | 1 0 0 0 | 0V - 5V |
26  | 1 0 0 1 | 0V - 10V |
27  | 1 0 1 0 | -5V - +5V |
28  | 1 0 1 1 | -10V - +10V |
29  | 1 1 0 0 | -2.5V - +2.5V |
30  | 1 1 0 1 | -2.5V - 7.5V |
31 
32 
33 USER INPUT DATA FORMAT:
34  decimal : 1024
35  hex : 0x400
36  octal : 02000 (leading 0 "zero")
37  binary : B10000000000
38  float : 1024.0
39 
40 @endverbatim
41 
42 http://www.linear.com/product/LTC1592
43 
44 http://www.linear.com/product/LTC1592#demoboards
45 
46 
47 Copyright 2018(c) Analog Devices, Inc.
48 
49 All rights reserved.
50 
51 Redistribution and use in source and binary forms, with or without
52 modification, are permitted provided that the following conditions are met:
53  - Redistributions of source code must retain the above copyright
54  notice, this list of conditions and the following disclaimer.
55  - Redistributions in binary form must reproduce the above copyright
56  notice, this list of conditions and the following disclaimer in
57  the documentation and/or other materials provided with the
58  distribution.
59  - Neither the name of Analog Devices, Inc. nor the names of its
60  contributors may be used to endorse or promote products derived
61  from this software without specific prior written permission.
62  - The use of this software may or may not infringe the patent rights
63  of one or more patent holders. This license does not release you
64  from the requirement that you obtain separate licenses from these
65  patent holders to use this software.
66  - Use of the software either in source or binary form, must be run
67  on or directly connected to an Analog Devices Inc. component.
68 
69 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
70 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
71 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
72 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
73 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
74 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
75 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
76 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
77 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
78 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
79 */
80 
81 /*! @file
82  @ingroup LTC1592
83 */
84 
85 // Headerfiles
86 #include "LT_SPI.h"
87 #include "UserInterface.h"
88 #include "LT_I2C.h"
89 #include "QuikEval_EEPROM.h"
90 #include "Linduino.h"
91 #include <SPI.h>
92 #include "LTC1592.h"
93 #include <Stream.h>
94 
95 // Global variables
96 static uint8_t demo_board_connected; //!< Set to 1 if the board is connected
99 uint16_t data = 0x0000;
100 uint8_t range_selected = 0x00;
101 
102 // Function Declarations
103 void print_title();
104 void print_prompt();
105 uint8_t menu_1_voltage_output();
106 uint8_t menu_2_square_wave_output();
107 void menu_3_change_range();
108 
109 //! Initialize Linduino
110 void setup()
111 {
112  char demo_name[] = "DC572"; // Demo Board Name stored in QuikEval EEPROM
113 
114  quikeval_SPI_init(); // Configure the spi port for 4MHz SCK
115  quikeval_SPI_connect(); // Connect SPI to main data port
116  quikeval_I2C_init(); // Configure the EEPROM I2C port for 100kHz
117 
118  Serial.begin(115200); // Initialize the serial port to the PC
119  print_title();
120 
122  ui_buffer[48] = 0;
123  Serial.println(ui_buffer);
124 
127  {
128  Serial.println("Connected...");
129  print_prompt();
130  }
131 }
132 
133 //! Repeats Linduino loop
134 void loop()
135 {
136  int16_t user_command;
137  if (Serial.available()) // Check for user input
138  {
139  user_command = read_int(); // Read the user command
140  Serial.println(user_command);
141  Serial.flush();
142  switch (user_command)
143  {
144  case 1:
146  break;
147  case 2:
149  break;
150  case 3:
152  break;
153  default:
154  Serial.println(F("Incorrect Option"));
155  break;
156  }
157  Serial.println(F("\n************************************************************"));
158  print_prompt();
159  }
160 }
161 
162 //! Prints the title block when program first starts.
164 {
165  Serial.println();
166  Serial.println(F("*****************************************************************"));
167  Serial.println(F("* DC572A Demonstration Program *"));
168  Serial.println(F("* *"));
169  Serial.println(F("* This program demonstrates how to send data to the LTC1592 *"));
170  Serial.println(F("* 16-bit SoftSpan DAC found on the DC572A demo board. *"));
171  Serial.println(F("* *"));
172  Serial.println(F("* Set the baud rate to 115200 and select the newline terminator.*"));
173  Serial.println(F("* *"));
174  Serial.println(F("*****************************************************************\n"));
175 }
176 
177 //! Prints main menu.
179 {
180  Serial.println(F("\nCommand Summary:"));
181  Serial.println(F(" 1-Voltage Output"));
182  Serial.println(F(" 2-Square wave output"));
183  Serial.println(F(" 3-Change Range"));
184 
185  Serial.println(F("\nPresent Values:"));
186  Serial.print(F(" Range: "));
187  switch (range_selected)
188  {
189  case 0:
190  Serial.print(F("0V to 5V"));
191  break;
192 
193  case 1:
194  Serial.print(F("0V to 10V"));
195  break;
196 
197  case 2:
198  Serial.print(F("-5V to +5V"));
199  break;
200 
201  case 3:
202  Serial.print(F("-10V to +10V"));
203  break;
204 
205  case 4:
206  Serial.print(F("-2.5V to +2.5V"));
207  break;
208 
209  case 5:
210  Serial.print(F("-2.5V to 7.5V"));
211  break;
212 
213  default:
214  Serial.println("0V to 5V");
215  }
216 
217  Serial.print(F("\n\nEnter a command: "));
218  Serial.flush();
219 }
220 
221 //! Function to enter a digital value and get the analog output
223 {
224  float voltage;
225  uint8_t dac_command;
226  Serial.print("\nEnter the 16-bit data as decimal or hex: ");
227  data = read_int();
228  Serial.print("0x");
229  Serial.println(data, HEX);
230 
231  switch (range_selected)
232  {
233  case 0:
234  dac_command = LTC1592_RANGE_0_TO_5V;
235  break;
236 
237  case 1:
238  dac_command = LTC1592_RANGE_0_TO_10V;
239  break;
240 
241  case 2:
242  dac_command = LTC1592_RANGE_PLUS_MINUS_5V;
243  break;
244 
245  case 3:
246  dac_command = LTC1592_RANGE_PLUS_MINUS_10V;
247  break;
248 
249  case 4:
250  dac_command = LTC1592_RANGE_PLUS_MINUS_2_5V;
251  break;
252 
253  case 5:
255  break;
256  }
257 
258  LTC1592_write(LTC1592_CS, dac_command, data);
260 
261  Serial.print("\nOutput voltage = ");
262  Serial.print(voltage);
263  Serial.println(" V");
264  return 0;
265 }
266 
267 //! Function to generate a square wave of desired frequency and voltage ranges
269 {
270  uint16_t freq;
271  float time;
272  float voltage_high, voltage_low;
273  uint16_t data_voltage_high, data_voltage_low;
274  uint8_t receive_enter; // To receive enter key pressed
275  uint8_t dac_command;
276 
277  Serial.print("\nEnter voltage_high: ");
278  while (!Serial.available());
279  voltage_high = read_float();
280  Serial.print(voltage_high);
281  Serial.println(" V");
282  receive_enter = read_int();
283 
284  Serial.print("\nEnter voltage_low: ");
285  while (!Serial.available());
286  voltage_low = read_float();
287  Serial.print(voltage_low);
288  Serial.println(" V");
289  receive_enter = read_int();
290 
291  Serial.print("\nEnter the required frequency in Hz: ");
292  freq = read_int();
293  Serial.print(freq);
294  Serial.println(" Hz");
295 
296  time = (float)1000/freq;
297  Serial.print("\nT = ");
298  Serial.print(time);
299  Serial.println(" ms");
300 
301  //! Converting data into voltage
302  data_voltage_high = LTC1592_voltage_to_code(voltage_high, LTC1592_RANGE_HIGH, LTC1592_RANGE_LOW);
303  data_voltage_low = LTC1592_voltage_to_code(voltage_low, LTC1592_RANGE_HIGH, LTC1592_RANGE_LOW);
304 
305  switch (range_selected)
306  {
307  case 0:
308  dac_command = LTC1592_RANGE_0_TO_5V;
309  break;
310 
311  case 1:
312  dac_command = LTC1592_RANGE_0_TO_10V;
313  break;
314 
315  case 2:
316  dac_command = LTC1592_RANGE_PLUS_MINUS_5V;
317  break;
318 
319  case 3:
320  dac_command = LTC1592_RANGE_PLUS_MINUS_10V;
321  break;
322 
323  case 4:
324  dac_command = LTC1592_RANGE_PLUS_MINUS_2_5V;
325  break;
326 
327  case 5:
329  break;
330  }
331 
332  while (!Serial.available()) //! Generate square wave until a key is pressed
333  {
334  LTC1592_write(LTC1592_CS, dac_command, data_voltage_high);
335  delayMicroseconds(time * 500);
336  LTC1592_write(LTC1592_CS, dac_command, data_voltage_low);
337  delayMicroseconds(time * 500);
338  }
339  receive_enter = read_int();
340  return 0;
341 }
342 
343 //! Function to choose the range of voltages to be used
345 {
346  Serial.println("\n| Choice | Range |");
347  Serial.println("|--------|---------------|");
348  Serial.println("| 0 | 0 - 5 V |");
349  Serial.println("| 1 | 0 - 10 V |");
350  Serial.println("| 2 | -5 - +5 V |");
351  Serial.println("| 3 | -10 - +10 V |");
352  Serial.println("| 4 | -2.5 - +2.5 V |");
353  Serial.println("| 5 | -2.5 - 7.5 V |");
354 
355  Serial.print("\nEnter your choice: ");
357  Serial.println(range_selected);
358 
359  switch (range_selected)
360  {
361  case 0:
362  LTC1592_RANGE_LOW = 0;
363  LTC1592_RANGE_HIGH = 5;
364  break;
365 
366  case 1:
367  LTC1592_RANGE_LOW = 0;
368  LTC1592_RANGE_HIGH = 10;
369  break;
370 
371  case 2:
372  LTC1592_RANGE_LOW = -5;
373  LTC1592_RANGE_HIGH = 5;
374  break;
375 
376  case 3:
377  LTC1592_RANGE_LOW = -10;
378  LTC1592_RANGE_HIGH = 10;
379  break;
380 
381  case 4:
382  LTC1592_RANGE_LOW = -2.5;
383  LTC1592_RANGE_HIGH = 2.5;
384  break;
385 
386  case 5:
387  LTC1592_RANGE_LOW = -2.5;
388  LTC1592_RANGE_HIGH = 7.5;
389  break;
390 
391  default:
392  Serial.println("\nWrong choice!");
393  }
394 }
static uint8_t demo_board_connected
Set to 1 if the board is connected.
Definition: DC572A.ino:96
unsigned char user_command
#define LTC1592_RANGE_MINUS_2_5V_TO_PLUS_7_5V
Definition: LTC1592.h:92
static void menu_3_change_range()
Function to choose the range of voltages to be used.
Definition: DC572A.ino:344
static void print_title()
Prints the title block when program first starts.
Definition: DC572A.ino:163
float LTC1592_code_to_voltage(uint16_t data, float RANGE_HIGH, float RANGE_LOW)
Calculates the voltage from ADC output data depending on the channel configuration.
Definition: LTC1592.cpp:92
#define LTC1592_RANGE_0_TO_10V
Definition: LTC1592.h:88
LTC1592: 16-bit SoftSpan DAC with Programmable Output Range.
Header File for Linduino Libraries and Demo Code.
static float LTC1592_RANGE_LOW
Definition: DC572A.ino:97
#define LTC1592_CS
Headerfiles.
Definition: LTC1592.h:79
#define LTC1592_RANGE_PLUS_MINUS_5V
Definition: LTC1592.h:89
#define LTC1592_RANGE_0_TO_5V
Definition: LTC1592.h:87
static void loop()
Repeats Linduino loop.
Definition: DC572A.ino:134
void LTC1592_write(uint8_t cs, uint8_t dac_command, uint16_t data)
Transmits 24 bit input stream: 4-bit command + 4-bit don&#39;t-care + 16-bit data.
Definition: LTC1592.cpp:80
static uint8_t range_selected
Definition: DC572A.ino:100
#define LTC1592_RANGE_PLUS_MINUS_10V
Definition: LTC1592.h:90
static uint16_t data
Definition: DC572A.ino:99
QuikEval EEPROM Library.
#define LTC1592_RANGE_PLUS_MINUS_2_5V
Definition: LTC1592.h:91
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 float LTC1592_RANGE_HIGH
Definition: DC572A.ino:98
LT_SPI: Routines to communicate with ATmega328P&#39;s hardware SPI port.
static void setup()
Initialize Linduino.
Definition: DC572A.ino:110
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
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()
float read_float()
static uint8_t menu_2_square_wave_output()
Function to generate a square wave of desired frequency and voltage ranges.
Definition: DC572A.ino:268
void quikeval_I2C_init(void)
Initializes Linduino I2C port.
Definition: LT_I2C.cpp:394
static float voltage
Definition: DC2289AA.ino:71
uint16_t LTC1592_voltage_to_code(float voltage, float RANGE_HIGH, float RANGE_LOW)
Calculates the 16 bit data code from voltage.
Definition: LTC1592.cpp:100
uint8_t read_quikeval_id_string(char *buffer)
Read the id string from the EEPROM, then parse the product name, demo board name, and demo board opti...
char ui_buffer[UI_BUFFER_SIZE]
static uint8_t menu_1_voltage_output()
Function to enter a digital value and get the analog output.
Definition: DC572A.ino:222
static void print_prompt()
Prints main menu.
Definition: DC572A.ino:178