| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

LTC2668_backpage_app.ino
Go to the documentation of this file.
1 /*!
2 Linear Technology DC2025A Demonstration Board.
3 LTC2668: 16 Channel SPI 16-/12-Bit Rail-to-Rail DACs with 10ppm/C Max Reference.
4
5 @verbatim
6 NOTES
7 Setup:
8 Set the terminal baud rate to 115200 and select the newline terminator.
9
10 This program uses the DC1908A along with the DC2025A demo board.
11 The program is based on an application note located near the end
12 of the LTC2668 datasheet. Follow the schematic to properly connect
13 the Linduino to the two demo boards.
14
15 An external +- 15V power supply is required to power the circuit.
16
17 The program displays calculated voltages which are based on the voltage
18 of the reference used, be it internal or external. A precision voltmeter
19 is needed to verify the actual measured voltages against the calculated
20 voltage displayed. If an external reference is used, a precision voltage
21 source is required to apply the external reference voltage. A
22 precision voltmeter is also required to measure the external reference
23 voltage.
24
25 USER INPUT DATA FORMAT:
26 decimal : 1024
27 hex : 0x400
28 octal : 02000 (leading 0 "zero")
29 binary : B10000000000
30 float : 1024.0
31
32 @endverbatim
33
34 http://www.linear.com/product/LTC2668
35
36 http://www.linear.com/product/LTC2668#demoboards
37
38
39 Copyright 2018(c) Analog Devices, Inc.
40
41 All rights reserved.
42
43 Redistribution and use in source and binary forms, with or without
44 modification, are permitted provided that the following conditions are met:
45 - Redistributions of source code must retain the above copyright
46 notice, this list of conditions and the following disclaimer.
47 - Redistributions in binary form must reproduce the above copyright
48 notice, this list of conditions and the following disclaimer in
49 the documentation and/or other materials provided with the
50 distribution.
51 - Neither the name of Analog Devices, Inc. nor the names of its
52 contributors may be used to endorse or promote products derived
53 from this software without specific prior written permission.
54 - The use of this software may or may not infringe the patent rights
55 of one or more patent holders. This license does not release you
56 from the requirement that you obtain separate licenses from these
57 patent holders to use this software.
58 - Use of the software either in source or binary form, must be run
59 on or directly connected to an Analog Devices Inc. component.
60
61 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
62 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
63 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
64 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
65 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
66 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
67 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
68 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
69 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
70 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
71 */
72
73 /*! @file
74 @ingroup LTC2668
75 */
76
77 #include <Arduino.h>
78 #include <stdint.h>
79 #include "Linduino.h"
80 #include "LT_SPI.h"
81 #include "UserInterface.h"
82 #include "LT_I2C.h"
83 #include "QuikEval_EEPROM.h"
84 #include "LTC2668.h"
85 #include "LTC2378.h"
86 #include <SPI.h>
87 #include <Wire.h>
88
89 #define LTC2378_CS 9
90
91 // Function Decoration
92 void demo_board_test();
93 void print_title();
94 void print_prompt();
95
96 //! Initialize Linduino
97 void setup()
98 // Setup the program
99 {
100 // Set The Linduino Auxiliary Pin To be The LTC2378 Chip Select Pin
101 pinMode(LTC2378_CS, OUTPUT);
102 digitalWrite(LTC2378_CS, HIGH);
103
104 quikeval_SPI_init(); // Configure the spi port for 4MHz SCK
105 quikeval_SPI_connect(); // Connect SPI to main data port
106 quikeval_I2C_init(); // Configure the EEPROM I2C port for 100kHz
107 Serial.begin(115200); // Initialize the serial port to the PC
108 print_title(); // Prints the title block when program first starts
109 }
110
111 //! Repeats Linduino loop
112 void loop()
113 {
114 print_prompt();
115 demo_board_test();
116 }
117
118 // Function Definitions
119
120 //! Displays The Prompt
121 void print_prompt()
122 {
123 Serial.println(F("\nPress any key when ready to start\n"));
124 Serial.flush();
125 read_int();
126 }
127
128 //! Prints the title block when program first starts.
129 void print_title()
130 {
131 Serial.println(F("*****************************************************************"));
132 Serial.println(F("* DC2025 Demonstration Program *"));
133 Serial.println(F("* *"));
134 Serial.println(F("* This program demonstrates the application noted at the end *"));
135 Serial.println(F("* of the LTC2668 16/12-bit DAC datasheet. The purpose of this *"));
136 Serial.println(F("* program is to demonstrate the use of the MUX pin on the *"));
137 Serial.println(F("* LTC2668. *"));
138 Serial.println(F("* *"));
139 Serial.println(F("* Set the baud rate to 115200 and select the newline terminator.*"));
140 Serial.println(F("* *"));
141 Serial.println(F("*****************************************************************"));
142 }
143
144
145 //! Set DAC's From -10V to 10V, Reads DAC Channels Through MUX, and Displays The Results
146 void demo_board_test()
147 {
148 int32_t adc_code[16];
149 float voltage[16];
150 float ideal_voltage;
151 float full_scale = 10.24;
152
153 LTC2668_write(LTC2668_CS,LTC2668_CMD_SPAN_ALL, 0, LTC2668_SPAN_PLUS_MINUS_10V); // Set DAC's To +-10V
154
155 // Set Channels From -10v to 10V Incrementing By Channel.
156 for (uint8_t i = 0; i <= 15; ++i)
157 {
158 LTC2668_write(LTC2668_CS,LTC2668_CMD_WRITE_N_UPDATE_N, i, i * 4369);
159 }
160
161 LTC2668_write(LTC2668_CS,LTC2668_CMD_MUX, 0, LTC2668_MUX_ENABLE | 0); // Set To Channel 0
162 LTC2378_read(LTC2378_CS, &adc_code[0]); // Discard reading
163
164 // Cycle Through the Channels of the MUX and Reads the MUX Voltage
165 for (uint8_t i = 1; i <= 15; ++i)
166 {
167 LTC2668_write(LTC2668_CS,LTC2668_CMD_MUX, 0, LTC2668_MUX_ENABLE | i);
168 LTC2378_read(LTC2378_CS, &adc_code[i-1]);
169 }
170 LTC2378_read(LTC2378_CS, &adc_code[15]);
171
172 // Display The Results
173 for (uint8_t i = 0; i<=15; ++i)
174 {
175 voltage[i] = LTC2378_code_to_voltage(adc_code[i], full_scale);
176 ideal_voltage = LTC2668_code_to_voltage(i * 4369, -10.0, 10.0);
177 Serial.print(F("Channel "));
178 Serial.print(i);
179 if (i < 10)
180 Serial.print(" ");
181 Serial.print(F(" : Ideal Voltage - "));
182 if (ideal_voltage >= 0)
183 Serial.print(" ");
184 Serial.print(ideal_voltage, 6);
185 if ((ideal_voltage < 10.0) && (ideal_voltage > -10.0))
186 Serial.print(" ");
187 Serial.print(F(" V Measured Voltage - "));
188 if (voltage[i] >= 0)
189 Serial.print(" ");
190 Serial.print(voltage[i],6);
191 if ((voltage[i] < 10.0) && (voltage[i] > -10.0))
192 Serial.print(" ");
193 Serial.print(F(" V difference - "));
194 if ((ideal_voltage-voltage[i]) >= 0)
195 Serial.print(" ");
196 Serial.print((ideal_voltage-voltage[i]),6);
197 Serial.println(" V");
198 }
199
200 Serial.println();
201 Serial.println("Test Complete\n");
202 }
LTC2668_SPAN_PLUS_MINUS_10V
#define LTC2668_SPAN_PLUS_MINUS_10V
Definition: LTC2668.h:122
LTC2378_CS
#define LTC2378_CS
Definition: LTC2668_backpage_app.ino:89
LTC2668_CMD_MUX
#define LTC2668_CMD_MUX
Select MUX channel (controlled by 5 LSbs in data word)
Definition: LTC2668.h:107
print_title
static void print_title()
Prints the title block when program first starts.
Definition: LTC2668_backpage_app.ino:129
loop
static void loop()
Repeats Linduino loop.
Definition: LTC2668_backpage_app.ino:112
LTC2668_code_to_voltage
float LTC2668_code_to_voltage(uint16_t dac_code, float min_output, float max_output)
Calculate the LTC2668 DAC output voltage given the DAC code, offset, and LSB.
Definition: LTC2668.cpp:117
Linduino.h
Header File for Linduino Libraries and Demo Code.
LTC2668_write
int8_t LTC2668_write(uint8_t cs, uint8_t dac_command, uint8_t dac_address, uint16_t dac_code)
Write the 16-bit dac_code to the LTC2668.
Definition: LTC2668.cpp:70
LTC2378_code_to_voltage
float LTC2378_code_to_voltage(int32_t adc_code, uint8_t gain_compression, float vref)
Calculates the LTC2378 input voltage given the binary data and lsb weight.
Definition: LTC2378.cpp:104
LTC2378.h
LTC2376-20: 20-Bit, 250Ksps ADC LTC2377-20: 20-Bit, 500Ksps ADC LTC2378-20: 20-Bit, 1Msps ADC.
demo_board_test
static void demo_board_test()
Set DAC&#39;s From -10V to 10V, Reads DAC Channels Through MUX, and Displays The Results.
Definition: LTC2668_backpage_app.ino:146
LTC2378_read
void LTC2378_read(uint8_t cs, int32_t *ptr_adc_code)
Reads the LTC2378 and returns 32-bit data in 2&#39;s complement format.
Definition: LTC2378.cpp:82
LTC2668.h
LTC2668: 16-Channel SPI 16-/12-Bit +/-10V Vout SoftSpan DACs with 10ppm/C Max Reference.
LTC2668_CMD_SPAN_ALL
#define LTC2668_CMD_SPAN_ALL
Set span for all DACs.
Definition: LTC2668.h: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
LT_SPI.h
LT_SPI: Routines to communicate with ATmega328P&#39;s hardware SPI port.
setup
static void setup()
Initialize Linduino.
Definition: LTC2668_backpage_app.ino:97
LT_I2C.h
LT_I2C: Routines to communicate with ATmega328P&#39;s hardware I2C port.
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
read_int
int32_t read_int()
Definition: UserInterface.cpp:93
LTC2668_CMD_WRITE_N_UPDATE_N
#define LTC2668_CMD_WRITE_N_UPDATE_N
Write to input register n, update (power-up)
Definition: LTC2668.h:98
quikeval_I2C_init
void quikeval_I2C_init(void)
Initializes Linduino I2C port.
Definition: LT_I2C.cpp:394
i
static int i
Definition: DC2430A.ino:184
voltage
static float voltage
Definition: DC2289AA.ino:71
print_prompt
static void print_prompt()
Displays The Prompt.
Definition: LTC2668_backpage_app.ino:121
adc_code
static uint32_t adc_code
Definition: DC2071AA.ino:113
LTC2668_MUX_ENABLE
#define LTC2668_MUX_ENABLE
Definition: LTC2668.h:144
LTC2668_CS
#define LTC2668_CS
Define the SPI CS pin.
Definition: LTC2668.h:90