Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
DC2222AB.ino
Go to the documentation of this file.
1 /*!
2 Linear Technology DC2222AB Demonstration Board.
3 LTC2508: 32-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 40 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/LTC2508-32
38 
39 http://www.linear.com/product/LTC2508-32#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 LTC2508
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 "LTC2508.h"
91 
92 float VREF = 5.0;
94 uint16_t num_of_mclk_pulses = 1024;
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
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 = LTC2508_read_data(QUIKEVAL_CS, &DF);
152  voltage = LTC2508_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
166 {
167  uint8_t user_command;
168  Serial.print(F("\n Enter the new DF option (1-256, 2-1024, 3-4096, 4-16384) : "));
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:
175  num_of_mclk_pulses = 256;
176  break;
177  case 2:
179  num_of_mclk_pulses = 1024;
180  break;
181  case 3:
183  num_of_mclk_pulses = 4096;
184  break;
185  case 4:
187  num_of_mclk_pulses = 16384;
188  break;
189  default:
190  Serial.println("Incorrect Option");
191  break;
192  }
193 
195 }
196 
197 //! Function to change the voltage reference
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.
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 
237  quikeval_SPI_init(); // SPI Mode for QuikEval connector
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.
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 LTC2508 to set DF value, *\n"));
283  Serial.print(F("* and to read out 32 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 LTC2508 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.
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 }
#define CONFIG_DF_4096
Definition: LTC2508.h:66
static uint16_t num_of_mclk_pulses
Definition: DC2222AB.ino:94
static float code_to_voltage(uint8_t rx[5])
unsigned char user_command
static float VREF
Definition: DC2222AB.ino:92
int8_t i2c_write_byte(uint8_t address, uint8_t value)
Write "value" byte to device at "address".
Definition: LT_I2C.cpp:109
#define CS_HIGH
Definition: LTC2508.h:70
float LTC2508_code_to_voltage(int32_t code, float vref)
Calculates the output voltage from the given digital code and reference voltage.
Definition: LTC2508.cpp:76
#define CONFIG_DF_1024
Definition: LTC2508.h:65
static void initialise_i2c_data(uint16_t value, uint8_t i2c_data[48])
Definition: DC2222AB.ino:242
static void setup()
Definition: DC2222AB.ino:104
uint32_t LTC2508_read_data(uint8_t QUIKEVAL_CS, uint16_t *DF)
Reads 5 bytes of data on SPI - D31:D0 + W7:W0.
Definition: LTC2508.cpp:98
Header File for Linduino Libraries and Demo Code.
static void print_prompt()
Prints main menu.
Definition: DC2222AB.ino:297
static void menu_3_set_VREF()
Function to change the voltage reference.
Definition: DC2222AB.ino:198
static uint8_t address
Definition: DC2091A.ino:83
static void menu_1_read_voltage()
Displays the ADC output and calculated voltage.
Definition: DC2222AB.ino:144
static void menu_2_change_DF()
Function to change the DF value for filter.
Definition: DC2222AB.ino:165
LTC2508: 32-Bit Over-Sampling ADC with Configurable Digital Filter.
#define QUIKEVAL_GPIO
Linduino QuikEval GPIO pin (QuikEval connector pin 14) connects to Arduino pin 9. ...
Definition: Linduino.h:56
static void loop()
Definition: DC2222AB.ino:116
static void sneaker_port_init()
Send configuration data through sneaker port.
Definition: DC2222AB.ino:212
QuikEval EEPROM Library.
static uint16_t decode_DF_value(uint8_t byte0)
void quikeval_SPI_init(void)
Configure the SPI port for 4Mhz SCK.
Definition: LT_SPI.cpp:151
static void print_title()
Prints the title block when program first starts.
Definition: DC2222AB.ino:277
#define CS_LOW
Definition: LTC2508.h:69
LT_SPI: Routines to communicate with ATmega328P&#39;s hardware SPI port.
#define CONFIG_DF_256
Definition: LTC2508.h:64
LT_I2C: Routines to communicate with ATmega328P&#39;s hardware I2C port.
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()
#define CONFIG_DF_16384
Definition: LTC2508.h:67
void quikeval_I2C_init(void)
Initializes Linduino I2C port.
Definition: LT_I2C.cpp:394
void quikeval_I2C_connect(void)
Switch MUX to connect I2C pins to QuikEval connector.
Definition: LT_I2C.cpp:401
static int i
Definition: DC2430A.ino:184
static float voltage
Definition: DC2289AA.ino:71
static int8_t i2c_write_block_data_no_command(uint8_t address, uint8_t length, uint8_t *values)
#define QUIKEVAL_CS
QuikEval CS pin (SPI chip select on QuikEval connector pin 6) connects to Arduino SS pin...
Definition: Linduino.h:57
#define SNEAKER_PORT_ADDRESS
Definition: LTC2508.h:62
void send_pulses(uint8_t pin, uint16_t num_of_pulses)
Send n num of pulses on pin given.
Definition: LTC2508.cpp:84
static uint16_t global_config_data
Definition: DC2222AB.ino:93
static uint8_t values[4]
Definition: DC2218A.ino:117
#define MCLK_pin
Definition: LTC2508.h:63