Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
LTC2449_Datalogger.ino
Go to the documentation of this file.
1 /*!
2 LTC2449: 24-Bit High Speed 16-Channel Delta Sigma ADCs with Selectable Speed/Resolution
3 
4 @verbatim
5 
6 The LTC2449 is a 16-channel (8-differential) high speed 24-bit No Latency Delta Sigma ADCs.
7 They use a proprietary delta-sigma architecture enabling variable speed/resolution. Through
8 a simple 4-wire serial interface, ten speed/resolution combinations 6.9Hz/280nVRMS to
9 3.5kHz/25uVRMS (4kHz with external oscillator) can be selected with no latency between
10 conversion results or shift in DC accuracy (offset, full-scale, linearity, drift).
11 Additionally, a 2X speed mode can be selected enabling output rates up to 7kHz (8kHz if an
12 external oscillator is used) with one cycle latency.
13 
14 @endverbatim
15 
16 http://www.linear.com/product/LTC2449
17 
18 http://www.linear.com/product/LTC2449#demoboards
19 
20 
21 Copyright 2018(c) Analog Devices, Inc.
22 
23 All rights reserved.
24 
25 Redistribution and use in source and binary forms, with or without
26 modification, are permitted provided that the following conditions are met:
27  - Redistributions of source code must retain the above copyright
28  notice, this list of conditions and the following disclaimer.
29  - Redistributions in binary form must reproduce the above copyright
30  notice, this list of conditions and the following disclaimer in
31  the documentation and/or other materials provided with the
32  distribution.
33  - Neither the name of Analog Devices, Inc. nor the names of its
34  contributors may be used to endorse or promote products derived
35  from this software without specific prior written permission.
36  - The use of this software may or may not infringe the patent rights
37  of one or more patent holders. This license does not release you
38  from the requirement that you obtain separate licenses from these
39  patent holders to use this software.
40  - Use of the software either in source or binary form, must be run
41  on or directly connected to an Analog Devices Inc. component.
42 
43 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
44 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
45 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
46 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
47 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
48 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
49 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
50 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
51 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
52 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53 */
54 
55 #include <stdint.h>
56 #include <Arduino.h>
57 #include "Linduino.h"
58 #include "QuikEval_EEPROM.h"
59 #include "UserInterface.h"
60 #include <SPI.h>
61 #include "LT_SPI.h"
62 #include <Wire.h>
63 #include "LT_I2C.h"
64 #include "LTC24XX_general.h"
65 
66 #define CS QUIKEVAL_CS //!< The chip select
67 
68 // Constants
69 
70 //! Lookup table to build the command for single-ended mode
75  }; //!< Builds the command for single-ended mode
76 
77 //! Lookup table to build the command for differential mode
82  }; //!< Build the command for differential mode
83 
84 
85 //! Lookup table to build the OSR command
89  }; //!< Build the command for different OSR modes
90 
91 // Prototypes
92 void read_LTC2449(float vref, uint16_t eoc_timeout, uint16_t channel_delay);
93 void print_all(float *results);
94 void print_prompt();
95 void print_all(float *results);
96 
97 //! Initialize Linduino
98 void setup()
99 {
100  char demo_name[] = "DC742"; // Demo Board Name stored in QuikEval EEPROM
101  int8_t demo_board_connected; // Set to 1 if the board is connected
102 
103  Serial.begin(115200); // Initialize the serial port to the PC
104  Serial.println(F("Welcome to the LTC2499 Test Program\n"));
105  delay(200);
106 
107  quikeval_I2C_init(); // Enable the I2C port
108  quikeval_SPI_init(); // Configure the spi port for 4volts SCK
109  quikeval_SPI_connect(); // Connect SPI to main data port
110 
111  demo_board_connected = discover_demo_board(demo_name);
112 
113  // If demo board is not connected loop forever
114  if (!demo_board_connected)
115  Serial.println(F("Standard demo board not detected, verify hardware connections to your circuit."));
116 
117 } // End of setup()
118 
119 
120 //! Repeats Linduino loop
121 void loop()
122 {
123  static float LTC2499_vref = 5.0; // Reference voltage
124  static uint16_t EOC_timout = 250; // End of conversion timeout
125  static uint16_t loop_delay = 500; // the delay between loops
126  static uint16_t channel_read_delay = 20; // The delay between channel readings
127  static char user_command; // The user input command
128 
129  print_prompt(); // Prints the prompt
130 
131  user_command = read_char(); // Reads the users input
132  Serial.println(user_command); // Displays the user input
133 
134  switch (user_command)
135  {
136  case 'S':
137  case 's':
138  // Single loop
139  read_LTC2449(LTC2499_vref, EOC_timout, channel_read_delay); // Read all the channels
140  break;
141  case 'C':
142  case 'c':
143  // Continous loop
144  do
145  {
146  read_LTC2449(LTC2499_vref, EOC_timout, channel_read_delay); // Read all the channels
147  delay(loop_delay); // Delay before repeating the loop
148  }
149  while (Serial.available() == false); // Check to see is anything was entered
150  read_int(); // Clears the Serial.available
151  break;
152  default:
153  Serial.println(F("Incorrect Option"));
154  break;
155  }
156 }
157 
158 //! Print the Prompt
160 {
161  Serial.println();
162  Serial.println(F("S-Single Loop"));
163  Serial.println(F("C-Continuous Loop"));
164  Serial.println(F(" Enter any character to exit Continuous Loop"));
165 
166  Serial.print(F("Enter a command: "));
167 }
168 
169 //! Reads the LTC2449 and displays the results
170 void read_LTC2449(float vref, uint16_t eoc_timeout, uint16_t channel_delay)
171 {
172  float results[16];
173  int32_t adc_code = 0;
174  uint8_t i;
175 
176  LTC24XX_EOC_timeout(CS, eoc_timeout); // Wait for end of conversion
178 
179  for (i=0; i<=15; i++)
180  {
181  delay(channel_delay);
182  LTC24XX_EOC_timeout(CS, eoc_timeout); // Wait for end of conversion
183  LTC24XX_SPI_16bit_command_32bit_data(CS, SINGLE_ENDED_CONFIG_ARRAY[(i+1)%16], OSR_CONFIG_ARRAY[7], &adc_code); // Read the ADC
184  results[i%16] = LTC24XX_diff_code_to_voltage(adc_code, vref); // Convert ADC code to voltage
185  }
186 
187  print_all(results); // Display results
188 }
189 
190 //! Displays the the data in the array
191 void print_all(float *results)
192 {
193  uint8_t i;
194  for (i=0; i<=15; i++)
195  {
196  Serial.print(results[i], 8);
197  if (!((i+1)%16)) Serial.println();
198  else Serial.print(F(" , "));
199  }
200 }
#define LTC24XX_MULTI_CH_OSR_32768
#define LTC24XX_MULTI_CH_CH3
static void print_prompt()
Print the Prompt.
#define LTC24XX_MULTI_CH_CH14
#define LTC24XX_MULTI_CH_OSR_8192
unsigned char user_command
#define LTC24XX_MULTI_CH_CH8
#define LTC24XX_MULTI_CH_CH15
static uint16_t loop_delay
#define LTC24XX_MULTI_CH_CH13
#define LTC24XX_MULTI_CH_CH1
#define LTC24XX_MULTI_CH_OSR_256
#define LTC24XX_MULTI_CH_CH6
#define LTC24XX_MULTI_CH_P13_N12
#define LTC24XX_MULTI_CH_OSR_1024
#define LTC24XX_MULTI_CH_P1_N0
Header File for Linduino Libraries and Demo Code.
int8_t LTC24XX_EOC_timeout(uint8_t cs, uint16_t miso_timeout)
Checks for EOC with a specified timeout.
#define LTC24XX_MULTI_CH_CH5
static void setup()
Initialize Linduino.
#define LTC24XX_MULTI_CH_P4_N5
#define LTC24XX_MULTI_CH_CH0
#define LTC24XX_MULTI_CH_CH11
static void loop()
Repeats Linduino loop.
const uint8_t DIFF_CONFIG_ARRAY[16]
Lookup table to build the command for differential mode.
static float LTC2499_vref
The LTC2499 reference voltage.
Definition: DC1012AA.ino:112
LTC24XX General Library: Functions and defines for all SINC4 Delta Sigma ADCs.
#define LTC24XX_MULTI_CH_P9_N8
#define LTC24XX_MULTI_CH_P14_N15
void LTC24XX_SPI_16bit_command_32bit_data(uint8_t cs, uint8_t adc_command_high, uint8_t adc_command_low, int32_t *adc_code)
Reads from LTC24XX ADC that accepts a 16 bit configuration and returns a 32 bit result.
#define LTC24XX_MULTI_CH_OSR_64
#define LTC24XX_MULTI_CH_CH2
const uint8_t SINGLE_ENDED_CONFIG_ARRAY[16]
Lookup table to build the command for single-ended mode.
static uint16_t eoc_timeout
timeout in ms
#define LTC24XX_MULTI_CH_P3_N2
QuikEval EEPROM Library.
#define LTC24XX_MULTI_CH_OSR_4096
#define LTC24XX_MULTI_CH_P2_N3
#define LTC24XX_MULTI_CH_OSR_16384
#define LTC24XX_MULTI_CH_OSR_128
void quikeval_SPI_init(void)
Configure the SPI port for 4Mhz SCK.
Definition: LT_SPI.cpp:151
static void read_LTC2449(float vref, uint16_t eoc_timeout, uint16_t channel_delay)
Reads the LTC2449 and displays the results.
int8_t discover_demo_board(char *demo_name)
Read the ID string from the EEPROM and determine if the correct board is connected.
#define LTC24XX_MULTI_CH_P10_N11
#define LTC24XX_MULTI_CH_CH12
#define LTC24XX_MULTI_CH_OSR_512
#define LTC24XX_MULTI_CH_P12_N13
LT_SPI: Routines to communicate with ATmega328P&#39;s hardware SPI port.
#define LTC24XX_MULTI_CH_CH7
#define LTC24XX_MULTI_CH_P5_N4
static void print_all(float *results)
Displays the the data in the array.
const uint8_t OSR_CONFIG_ARRAY[10]
Lookup table to build the OSR command.
LT_I2C: Routines to communicate with ATmega328P&#39;s hardware I2C port.
#define CS
LTC2449: 24-Bit High Speed 16-Channel Delta Sigma ADCs with Selectable Speed/Resolution.
#define LTC24XX_MULTI_CH_P8_N9
#define LTC24XX_MULTI_CH_P7_N6
float LTC24XX_diff_code_to_voltage(int32_t adc_code, float vref)
Calculates the voltage corresponding to an ADC code, given the reference voltage. ...
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()
#define LTC24XX_MULTI_CH_CH10
static uint16_t EOC_timout
#define LTC24XX_MULTI_CH_CH9
#define LTC24XX_MULTI_CH_P15_N14
void quikeval_I2C_init(void)
Initializes Linduino I2C port.
Definition: LT_I2C.cpp:394
static int i
Definition: DC2430A.ino:184
#define LTC24XX_MULTI_CH_P11_N10
#define LTC24XX_MULTI_CH_OSR_2048
#define LTC24XX_MULTI_CH_P0_N1
#define LTC24XX_MULTI_CH_CH4
static uint16_t channel_read_delay
int8_t read_char()
static uint32_t adc_code
Definition: DC2071AA.ino:113
#define LTC24XX_MULTI_CH_P6_N7
static uint8_t demo_board_connected
Set to 1 if the board is connected.