Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
DC2289AA.ino
Go to the documentation of this file.
1 /*!
2 LTC2380-24: Low Noise, High Speed, 24-Bit SAR ADC With Digital Filter
3 
4 @verbatim
5 
6 
7 @endverbatim
8 http://www.linear.com/product/LTC2380-24
9 
10 
11 Copyright 2018(c) Analog Devices, Inc.
12 
13 All rights reserved.
14 
15 Redistribution and use in source and binary forms, with or without
16 modification, are permitted provided that the following conditions are met:
17  - Redistributions of source code must retain the above copyright
18  notice, this list of conditions and the following disclaimer.
19  - Redistributions in binary form must reproduce the above copyright
20  notice, this list of conditions and the following disclaimer in
21  the documentation and/or other materials provided with the
22  distribution.
23  - Neither the name of Analog Devices, Inc. nor the names of its
24  contributors may be used to endorse or promote products derived
25  from this software without specific prior written permission.
26  - The use of this software may or may not infringe the patent rights
27  of one or more patent holders. This license does not release you
28  from the requirement that you obtain separate licenses from these
29  patent holders to use this software.
30  - Use of the software either in source or binary form, must be run
31  on or directly connected to an Analog Devices Inc. component.
32 
33 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
34 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
35 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
36 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
37 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
38 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
39 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
40 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
41 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
42 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 */
44 
45 /*! @file
46  @ingroup LTC2380-24
47 */
48 
49 #include <stdint.h>
50 #include "Linduino.h"
51 #include "LT_SPI.h"
52 #include "UserInterface.h"
53 #include "LT_I2C.h"
54 #include <SPI.h>
55 #include "LTC2380_24.h"
56 
57 #ifndef LTC2380_CNV
58 #define LTC2380_CNV QUIKEVAL_CS
59 #endif
60 
61 // Function Declaration
62 void print_title(); // Print the title block
63 void print_prompt();
64 void menu_1_read_input();
66 void configureCNV();
67 
68 // Global variables
69 static uint8_t LTC2380_dgc = 0; //!< Default set for no gain compression
70 float LTC2380_vref = 10;
71 float voltage;
72 
73 //! Initialize Linduino
74 void setup()
75 {
76  quikeval_SPI_init(); // Configure the spi port for 4MHz SCK
77  quikeval_SPI_connect(); // Connect SPI to main data port
78  Serial.begin(115200); // Initialize the serial port to the PC
79 
80  configureCNV();
81 
82  print_title();
83  print_prompt();
84 }
85 
86 //! Repeats Linduino loop
87 void loop()
88 {
89  uint16_t user_command;
90  if (Serial.available())
91  {
92  user_command = read_int(); // Read the user command
93  if (user_command != 'm')
94  Serial.println(user_command); // Prints the user command to com port
95  switch (user_command)
96  {
97  case 1:
99  break;
100  case 2:
102  break;
103  default:
104  Serial.println(" Invalid Option");
105  break;
106  }
107  Serial.println();
108  print_prompt();
109  }
110 }
111 
112 //! Read Input voltage
113 //! @return void
115 {
116  int32_t adc_code; // The LTC2380 code
117  float adc_voltage;
118  int16_t cycles;
119 
120  LTC2380_read(&adc_code, &cycles);
121  adc_voltage = LTC2380_code_to_voltage(adc_code, LTC2380_dgc, LTC2380_vref); // Convert the received code to voltage
122 
123  Serial.print("\n24-bit decimal data: 0x ");
124  Serial.println(adc_code & 0xFFFFFF, HEX);
125  Serial.print("Voltage calculated: ");
126  Serial.print(adc_voltage);
127  Serial.println(" V");
128  Serial.print("No:of averaging cycles: ");
129  Serial.println(cycles + 1);
130  Serial.println();
131 }
132 
133 //! Select gain compression
134 //! @return void
136 {
137  uint8_t user_command;
138  Serial.println(F(" 0 = No Gain Compression"));
139  Serial.println(F(" 1 = Gain Compression"));
140  Serial.print(F(" Enter a Command, based upon the position of jumper JP6: "));
141 
142  user_command = read_int(); // Read user input
143  Serial.println(user_command); // Prints the user command to com port
144  switch (user_command)
145  {
146  case 0:
147  Serial.println(F(" No Gain compression"));
148  LTC2380_dgc = 0;
149  break;
150  case 1:
151  Serial.println(F(" Gain compression"));
152  LTC2380_dgc = 1;
153  break;
154  default:
155  {
156  Serial.println(" Invalid Option");
157  return;
158  }
159  break;
160  }
161 }
162 
163 //! Prints main menu.
165 {
166  Serial.println(F("*************************"));
167  Serial.println(F("1-Read ADC Input"));
168  Serial.println(F("2-Select No Gain Compression / Gain Compression (default is no compression)"));
169  Serial.print(F("Enter a command:"));
170 }
171 
172 //! Prints the title block when program first starts.
174 {
175  Serial.println();
176  Serial.println(F("*****************************************************************"));
177  Serial.println(F("* DC2289A Demonstration Program *"));
178  Serial.println(F("* *"));
179  Serial.println(F("* This program demonstrates how to read data *"));
180  Serial.println(F("* from LTC2380-24 bit part. *"));
181  Serial.println(F("* *"));
182  Serial.println(F("* Set the baud rate to 115200 and select the newline terminator.*"));
183  Serial.println(F("* *"));
184  Serial.println(F("*****************************************************************"));
185 }
186 
187 //! Function to configure CNV pin as an output
189 {
190  DDRB = DDRB | B00000100; // Setting PB2 (CS) as output, connected to CNV pin.
191 }
static void print_title()
Prints the title block when program first starts.
Definition: DC2289AA.ino:173
unsigned char user_command
static void loop()
Repeats Linduino loop.
Definition: DC2289AA.ino:87
static uint8_t LTC2380_dgc
Default set for no gain compression.
Definition: DC2289AA.ino:69
Header File for Linduino Libraries and Demo Code.
static void configureCNV()
Function to configure CNV pin as an output.
Definition: DC2289AA.ino:188
static float adc_voltage
Definition: DC2071AA.ino:115
void LTC2380_read(uint8_t cs, int32_t *ptr_adc_code)
Reads the LTC2380 and returns 32-bit data in 2&#39;s complement format.
Definition: LTC2380.cpp:114
LTC2380-24: Low Noise, High Speed, 24-Bit SAR ADC With Digital Filter.
void quikeval_SPI_init(void)
Configure the SPI port for 4Mhz SCK.
Definition: LT_SPI.cpp:151
LT_SPI: Routines to communicate with ATmega328P&#39;s hardware SPI port.
static void menu_2_select_gain_compression()
Select gain compression.
Definition: DC2289AA.ino:135
static void print_prompt()
Prints main menu.
Definition: DC2289AA.ino:164
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 LTC2380_code_to_voltage(int32_t adc_code, uint8_t gain_compression, float vref)
Calculates the LTC2380 input voltage given the binary data and lsb weight.
Definition: LTC2380.cpp:136
static void menu_1_read_input()
Read Input voltage.
Definition: DC2289AA.ino:114
static float voltage
Definition: DC2289AA.ino:71
static void setup()
Initialize Linduino.
Definition: DC2289AA.ino:74
static float LTC2380_vref
Definition: DC2289AA.ino:70
static uint32_t adc_code
Definition: DC2071AA.ino:113