| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

DC2222AC.ino
Go to the documentation of this file.
1 /*!
2 Linear Technology DC2222AC Demonstration Board.
3 LTC2512: 24-Bit Over-Sampling ADC with Configurable Digital Filter
4
5 @verbatim
6
7 NOTES
8
9 Set the terminal baud rate to 115200 and select the newline terminator.
10 Provide an external voltage supply of +/-9V or 10 V.
11 QUIKEVAL_GPIO is connected to the SYNC pin.
12 16 bits of configuration data: 1 0 0 0 0 0 0 0 0 SEL0 SEL1 0 0 0 0 0
13
14 Steps involved:
15 1. Set I2C mode on QuikEval connector.
16 2. Send configuration data through sneaker port to set DF.
17 3. Send a SYNC pulse.
18 4. Set SPI mode on QuikEval connector.
19 5. Send DF number of MCLK pulses.
20 6. Read data out through SPI.
21
22 Explanation of Commands:
23
24 Option 1: Read 32 bits of data and calculate input analog voltage.
25 Option 2: Set the DF value for filter.
26 Option 3: Set the reference voltage.
27
28 USER INPUT DATA FORMAT:
29 decimal : 1024
30 hex : 0x400
31 octal : 02000 (leading 0 "zero")
32 binary : B10000000000
33 float : 1024.0
34
35 @endverbatim
36
37 http://www.linear.com/product/LTC2512-24
38
39 http://www.linear.com/product/LTC2512-24#demoboards
40
41
42 Copyright 2018(c) Analog Devices, Inc.
43
44 All rights reserved.
45
46 Redistribution and use in source and binary forms, with or without
47 modification, are permitted provided that the following conditions are met:
48 - Redistributions of source code must retain the above copyright
49 notice, this list of conditions and the following disclaimer.
50 - Redistributions in binary form must reproduce the above copyright
51 notice, this list of conditions and the following disclaimer in
52 the documentation and/or other materials provided with the
53 distribution.
54 - Neither the name of Analog Devices, Inc. nor the names of its
55 contributors may be used to endorse or promote products derived
56 from this software without specific prior written permission.
57 - The use of this software may or may not infringe the patent rights
58 of one or more patent holders. This license does not release you
59 from the requirement that you obtain separate licenses from these
60 patent holders to use this software.
61 - Use of the software either in source or binary form, must be run
62 on or directly connected to an Analog Devices Inc. component.
63
64 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
65 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
66 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
67 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
68 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
69 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
70 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
71 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
72 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
73 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
74 */
75
76 /*! @file
77 @ingroup LTC2512
78 */
79
80
81 #include <Arduino.h>
82 #include "LT_I2C.h"
83 #include "LT_SPI.h"
84 #include "UserInterface.h"
85 #include "QuikEval_EEPROM.h"
86 #include "Linduino.h"
87 #include <Wire.h>
88 #include <stdint.h>
89 #include <SPI.h>
90 #include "LTC2512.h"
91
92 float VREF = 5.0;
93 uint16_t global_config_data = CONFIG_DF_8;
94 uint16_t num_of_mclk_pulses = 8;
95
96 // Function Declarations
97 void sneaker_port_init();
98 void initialise_i2c_data(uint16_t value, uint8_t i2c_data[48]);
99 int8_t i2c_write_block_data_no_command(uint8_t address, uint8_t length, uint8_t *values);
100 uint16_t decode_DF_value(uint8_t byte0);
101 float code_to_voltage(uint8_t rx[5]);
102
103 // Setup function
104 void setup()
105 {
106 Serial.begin(115200); // Initialize the serial port to the PC
107 print_title();
108
109 sneaker_port_init(); // Send configuration data through sneaker port and a SYNC pulse
110
111 print_prompt();
112 }
113
114
115 // Loop function
116 void loop()
117 {
118 uint8_t user_command;
119 if (Serial.available()) // Check for user input
120 {
121 user_command = read_int(); //! Reads the user command
122 if (user_command != 'm')
123 Serial.println(user_command);
124 switch (user_command) //! Prints the appropriate submenu
125 {
126 case 1:
127 menu_1_read_voltage(); // Print single-ended voltage menu
128 break;
129 case 2:
130 menu_2_change_DF(); // Differential voltage menu
131 break;
132 case 3:
133 menu_3_set_VREF(); // Sequencing menu
134 break;
135 default:
136 Serial.println("Incorrect Option");
137 break;
138 }
139 print_prompt();
140 }
141 }
142
143 //! Displays the ADC output and calculated voltage
144 void menu_1_read_voltage()
145 {
146 uint16_t DF;
147 float voltage;
148 uint32_t code = 0;
149
150 send_pulses(MCLK_pin, num_of_mclk_pulses); // Send MCLK pulses
151 code = LTC2512_read_data(QUIKEVAL_CS, &DF);
152 voltage = LTC2512_code_to_voltage(code, VREF);
153
154 Serial.print(F("\n Data : 0x"));
155 Serial.println(code, HEX);
156 Serial.print(F(" DF : "));
157 Serial.println(DF);
158 Serial.print(F(" Input Voltage : "));
159 Serial.print(voltage, 9);
160 Serial.println(F(" V"));
161
162 }
163
164 //! Function to change the DF value for filter
165 void menu_2_change_DF()
166 {
167 uint8_t user_command;
168 Serial.print(F("\n Enter the new DF option (1-4, 2-8, 3-16, 4-32) : "));
169 user_command = read_int(); //! Reads the user command
170 Serial.println(user_command);
171 switch (user_command) //! Prints the appropriate submenu
172 {
173 case 1:
174 global_config_data = CONFIG_DF_4;
175 num_of_mclk_pulses = 4;
176 break;
177 case 2:
178 global_config_data = CONFIG_DF_8;
179 num_of_mclk_pulses = 8;
180 break;
181 case 3:
182 global_config_data = CONFIG_DF_16;
183 num_of_mclk_pulses = 16;
184 break;
185 case 4:
186 global_config_data = CONFIG_DF_32;
187 num_of_mclk_pulses = 32;
188 break;
189 default:
190 Serial.println("Incorrect Option");
191 break;
192 }
193
194 sneaker_port_init();
195 }
196
197 //! Function to change the voltage reference
198 void menu_3_set_VREF()
199 {
200 Serial.println(F("\n Remove the R37 resistor and probe in the new reference voltage at VREF"));
201 Serial.print(F("\n Enter the new reference voltage : "));
202 VREF = read_float();
203 Serial.print(VREF);
204 Serial.println(F(" V"));
205 }
206
207
208 //! Send configuration data through sneaker port
209 // Send I2C data to sneaker port to bit bang WRIN_I2C(CS) at P2,
210 // SCK at P5 and SDI at P6.
211 //! Send a SYNC pulse after configuration.
212 void sneaker_port_init()
213 {
214 uint8_t i;
215 uint16_t config_value = global_config_data;
216 uint8_t i2c_data[48]; // 48 bytes of data: 3 bytes each for 16 bits
217
218 quikeval_I2C_init(); // I2C Mode at 100kHz
219 quikeval_I2C_connect(); // Connect I2C to main data port
220 initialise_i2c_data(config_value, i2c_data); // Populate i2c_data array with values to bit bang P3, P5, P6
221
222 i2c_write_byte(SNEAKER_PORT_ADDRESS, CS_LOW); // P3 = 0 pulls WRIN_CS low
223
224 for (i = 0; i < 48; ++i)
225 {
226 i2c_write_byte(SNEAKER_PORT_ADDRESS, i2c_data[i]); // Sending configuration data
227 }
228 i2c_write_byte(SNEAKER_PORT_ADDRESS, CS_HIGH); // P3 = 1 pulls WRIN_CS high
229
230 // Send a SYNC pulse and leave it low
231 pinMode(QUIKEVAL_GPIO, OUTPUT); // Make SYNC pin on output mode
232 digitalWrite(QUIKEVAL_GPIO, LOW); // SYNC is connected to GPIO pin of the QuikEval connector
233 digitalWrite(QUIKEVAL_GPIO, HIGH);
234 digitalWrite(QUIKEVAL_GPIO, LOW);
235
236 delay(1);
237 quikeval_SPI_init(); // SPI Mode for QuikEval connector
238 quikeval_SPI_connect();
239 }
240
241 // Create the array of 3 bytes each for 16 bits sneaker port data
242 void initialise_i2c_data(uint16_t value, uint8_t i2c_data[48])
243 {
244 uint8_t i;
245 uint8_t set_bit;
246 uint8_t *p = i2c_data;
247 for (i = 0; i < 16; ++i)
248 {
249 set_bit = (value >> i) & 0x01;
250 if (set_bit)
251 {
252 *p++ = 0x40;
253 *p++ = 0x60;
254 *p++ = 0x40;
255 }
256 else
257 {
258 *p++ = 0x00;
259 *p++ = 0x20;
260 *p++ = 0x00;
261 }
262 }
263
264 /* Serial.println("\nI2C values to configure DF: ");
265 for(i = 0; i<48; ++i)
266 {
267 if(i%3 == 0)
268 Serial.print("\n");
269 Serial.print("\t0x");
270 Serial.print(i2c_data[i], HEX);
271 } */
272 Serial.print("\n");
273 }
274
275
276 //! Prints the title block when program first starts.
277 void print_title()
278 {
279 Serial.print(F("\n************************************************************************\n"));
280 Serial.print(F("* DC2222AB Demonstration Program *\n"));
281 Serial.print(F("* *\n"));
282 Serial.print(F("* This program demonstrates how to configure LTC2512 to set DF value, *\n"));
283 Serial.print(F("* and to read out 24 bits of data and configuration information *\n"));
284 Serial.print(F("* *\n"));
285 Serial.print(F("* Setup: *\n"));
286 Serial.print(F("* Set the baud rate to 115200 and select the newline terminator. *\n"));
287 Serial.print(F("* Power the board with +/- 9V or 10 V. *\n"));
288 Serial.print(F("* *\n"));
289 Serial.print(F("* NOTES: *\n"));
290 Serial.print(F("* Please note that LTC2512 requires 10 samples to settle and hence, *\n"));
291 Serial.print(F("* the first few samples do not reflect the exact input voltage. *\n"));
292 Serial.print(F("* *\n"));
293 Serial.print(F("************************************************************************\n"));
294 }
295
296 //! Prints main menu.
297 void print_prompt()
298 {
299 Serial.print(F("\nMain Menu:\n"));
300 Serial.print(F(" 1-Read Voltage input\n"));
301 Serial.print(F(" 2-Change DF\n"));
302 Serial.print(F(" 3-Set VREF\n"));
303 Serial.print(F("\nEnter a command:"));
304 }
initialise_i2c_data
static void initialise_i2c_data(uint16_t value, uint8_t i2c_data[48])
Definition: DC2222AC.ino:242
CONFIG_DF_8
#define CONFIG_DF_8
Definition: LTC2512.h:67
user_command
unsigned char user_command
Definition: Serial_EEPROM_Test.ino:75
i2c_write_byte
int8_t i2c_write_byte(uint8_t address, uint8_t value)
Write "value" byte to device at "address".
Definition: LT_I2C.cpp:109
CS_HIGH
#define CS_HIGH
Definition: LTC2508.h:70
menu_3_set_VREF
static void menu_3_set_VREF()
Function to change the voltage reference.
Definition: DC2222AC.ino:198
Linduino.h
Header File for Linduino Libraries and Demo Code.
decode_DF_value
static uint16_t decode_DF_value(uint8_t byte0)
global_config_data
static uint16_t global_config_data
Definition: DC2222AC.ino:93
CONFIG_DF_4
#define CONFIG_DF_4
Definition: LTC2512.h:66
LTC2512_code_to_voltage
float LTC2512_code_to_voltage(int32_t code, float vref)
Calculates the output voltage from the given digital code and reference voltage.
Definition: LTC2512.cpp:76
num_of_mclk_pulses
static uint16_t num_of_mclk_pulses
Definition: DC2222AC.ino:94
loop
static void loop()
Definition: DC2222AC.ino:116
print_prompt
static void print_prompt()
Prints main menu.
Definition: DC2222AC.ino:297
address
static uint8_t address
Definition: DC2091A.ino:83
CONFIG_DF_16
#define CONFIG_DF_16
Definition: LTC2512.h:68
QUIKEVAL_GPIO
#define QUIKEVAL_GPIO
Linduino QuikEval GPIO pin (QuikEval connector pin 14) connects to Arduino pin 9. ...
Definition: Linduino.h:56
menu_1_read_voltage
static void menu_1_read_voltage()
Displays the ADC output and calculated voltage.
Definition: DC2222AC.ino:144
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
menu_2_change_DF
static void menu_2_change_DF()
Function to change the DF value for filter.
Definition: DC2222AC.ino:165
sneaker_port_init
static void sneaker_port_init()
Send configuration data through sneaker port.
Definition: DC2222AC.ino:212
CONFIG_DF_32
#define CONFIG_DF_32
Definition: LTC2512.h:69
CS_LOW
#define CS_LOW
Definition: LTC2508.h:69
LT_SPI.h
LT_SPI: Routines to communicate with ATmega328P&#39;s hardware SPI port.
LTC2512.h
LTC2512: 24-Bit Over-Sampling ADC with Configurable Digital Filter.
LT_I2C.h
LT_I2C: Routines to communicate with ATmega328P&#39;s hardware I2C port.
code_to_voltage
static float code_to_voltage(uint8_t rx[5])
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
read_float
float read_float()
Definition: UserInterface.cpp:78
LTC2512_read_data
uint32_t LTC2512_read_data(uint8_t QUIKEVAL_CS, uint16_t *DF)
Reads 4 bytes of data on SPI - D23:D0 + W7:W0.
Definition: LTC2512.cpp:101
VREF
static float VREF
Definition: DC2222AC.ino:92
i2c_write_block_data_no_command
static int8_t i2c_write_block_data_no_command(uint8_t address, uint8_t length, uint8_t *values)
quikeval_I2C_init
void quikeval_I2C_init(void)
Initializes Linduino I2C port.
Definition: LT_I2C.cpp:394
quikeval_I2C_connect
void quikeval_I2C_connect(void)
Switch MUX to connect I2C pins to QuikEval connector.
Definition: LT_I2C.cpp:401
i
static int i
Definition: DC2430A.ino:184
voltage
static float voltage
Definition: DC2289AA.ino:71
setup
static void setup()
Definition: DC2222AC.ino:104
QUIKEVAL_CS
#define QUIKEVAL_CS
QuikEval CS pin (SPI chip select on QuikEval connector pin 6) connects to Arduino SS pin...
Definition: Linduino.h:57
print_title
static void print_title()
Prints the title block when program first starts.
Definition: DC2222AC.ino:277
SNEAKER_PORT_ADDRESS
#define SNEAKER_PORT_ADDRESS
Definition: LTC2508.h:62
send_pulses
void send_pulses(uint8_t pin, uint16_t num_of_pulses)
Send n num of pulses on pin given.
Definition: LTC2508.cpp:84
values
static uint8_t values[4]
Definition: DC2218A.ino:117
MCLK_pin
#define MCLK_pin
Definition: LTC2508.h:63