Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
DC1339A.ino
Go to the documentation of this file.
1 /*!
2 Linear Technology DC1186A Demonstration Board.
3 LTC2302: 12-Bit, 1-Channel 500ksps SAR ADC with SPI Interface.
4 
5 @verbatim
6 
7 NOTES
8  Setup:
9  Set the terminal baud rate to 115200 and select the newline terminator. No
10  external power supply is required and it has an on-board reference voltage
11  of 4.096V. The analog input is given at IN+ and IN-.
12 
13  There are options to chose between unipolar and bipolar modes.
14 
15 USER INPUT DATA FORMAT:
16  decimal : 1024
17  hex : 0x400
18  octal : 02000 (leading 0 "zero")
19  binary : B10000000000
20  float : 1024.0
21 
22 @endverbatim
23 
24 http://www.linear.com/product/LTC2302
25 
26 http://www.linear.com/product/LTC2302#demoboards
27 
28 
29 Copyright 2018(c) Analog Devices, Inc.
30 
31 All rights reserved.
32 
33 Redistribution and use in source and binary forms, with or without
34 modification, are permitted provided that the following conditions are met:
35  - Redistributions of source code must retain the above copyright
36  notice, this list of conditions and the following disclaimer.
37  - Redistributions in binary form must reproduce the above copyright
38  notice, this list of conditions and the following disclaimer in
39  the documentation and/or other materials provided with the
40  distribution.
41  - Neither the name of Analog Devices, Inc. nor the names of its
42  contributors may be used to endorse or promote products derived
43  from this software without specific prior written permission.
44  - The use of this software may or may not infringe the patent rights
45  of one or more patent holders. This license does not release you
46  from the requirement that you obtain separate licenses from these
47  patent holders to use this software.
48  - Use of the software either in source or binary form, must be run
49  on or directly connected to an Analog Devices Inc. component.
50 
51 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
52 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
53 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
54 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
55 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
57 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
58 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
59 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 */
62 
63 /*! @file
64  @ingroup LTC2302
65 */
66 
67 // Headerfiles
68 #include <Arduino.h>
69 #include <stdint.h>
70 #include "Linduino.h"
71 #include "LT_SPI.h"
72 #include "UserInterface.h"
73 #include "LT_I2C.h"
74 #include "QuikEval_EEPROM.h"
75 #include <SPI.h>
76 #include "LTC2302.h"
77 
78 // Global variables
79 static uint16_t uni_bipolar = LTC2302_UNIPOLAR; //!< Default set for unipolar mode
80 static float LTC2302_vref = 4.096;
81 
82 //! Initialize Linduino
83 void setup()
84 {
85  quikeval_I2C_init(); // Configure the EEPROM I2C port for 100kHz
86  quikeval_SPI_init(); // Configure the spi port for 4MHz SCK
87  quikeval_SPI_connect(); // Connect SPI to main data port
88 
89  Serial.begin(115200); // Initialize the serial port to the PC
90  print_title();
91  print_prompt();
92 }
93 
94 //! Repeats Linduino loop
95 void loop()
96 {
97  uint16_t user_command;
98  if (Serial.available()) // Check for user input
99  {
100  user_command = read_int(); // Read the user command
101  if (user_command != 'm')
102  Serial.println(user_command); // Prints the user command to com port
103  Serial.flush();
104  switch (user_command)
105  {
106  case 1:
108  break;
109  case 2:
111  break;
112  default:
113  Serial.println(F("Invalid Option"));
114  break;
115  }
116  Serial.println();
117  Serial.println(F("*************************\n"));
118  print_prompt();
119  }
120 }
121 
122 //! Read ADC code and display the measured voltage
124 {
125  uint16_t adc_command;
126  uint16_t adc_code;
127  float voltage;
128 
129  adc_command = uni_bipolar;
130  LTC2302_read(QUIKEVAL_CS, adc_command, &adc_code);
131  adc_code = (adc_code >> 4) & 0x0FFF;
132  voltage = LTC2302_code_to_voltage(adc_code, LTC2302_vref, uni_bipolar);
133  Serial.print("\nMeasured Voltage = ");
134  Serial.println(voltage);
135 }
136 
137 //! Select unipolar (0-VREF) or bipolar (+/- 0.5 x VREF) mode
139 {
140  uint8_t user_command;
141 
142  Serial.println(F("\n 0 = Bipolar"));
143  Serial.println(F(" 1 = Unipolar"));
144  Serial.print(F(" Enter an option: "));
145 
146  user_command = read_int(); // Read user input for uni_bipolar
147  Serial.println(user_command);
148  switch (user_command)
149  {
150  case 0:
151  Serial.println(F("\n Bipolar mode selected"));
153  break;
154  case 1:
155  Serial.println(F("\n Unipolar mode selected"));
157  break;
158  default:
159  Serial.println("\n Invalid Option");
160  return;
161  break;
162  }
163 }
164 
165 //! Prints the title block when program first starts.
167 {
168  Serial.println();
169  Serial.println(F("*****************************************************************"));
170  Serial.println(F("* DC1339A Demonstration Program *"));
171  Serial.println(F("* *"));
172  Serial.println(F("* This program demonstrates how to send data and receive data *"));
173  Serial.println(F("* from the LTC2302 12-bit ADC. *"));
174  Serial.println(F("* *"));
175  Serial.println(F("* Set the baud rate to 115200 and select the newline terminator.*"));
176  Serial.println(F("* *"));
177  Serial.println(F("*****************************************************************"));
178 }
179 
180 
181 //! Prints main menu.
183 {
184  Serial.println(F(" OPTIONS\n"));
185  Serial.println(F("1-Read ADC Input "));
186  Serial.println(F("2-Select Unipolar / Bipolar measurement (default is Unipolar)"));
187  Serial.println();
188  Serial.print(F("Enter a command: "));
189 }
190 
static void print_prompt()
Prints main menu.
Definition: DC1339A.ino:182
unsigned char user_command
void LTC2302_read(uint8_t cs, uint16_t adc_command, uint16_t *adc_code)
Reads the ADC and returns 16-bit data.
Definition: LTC2302.cpp:77
static uint8_t adc_command
Definition: DC2071AA.ino:111
static void loop()
Repeats Linduino loop.
Definition: DC1339A.ino:95
LTC2302: 12-Bit, 1-Channel 500ksps SAR ADC with SPI Interface.
static float LTC2302_vref
Definition: DC1339A.ino:80
static void menu_1_read_input()
Read ADC code and display the measured voltage.
Definition: DC1339A.ino:123
Header File for Linduino Libraries and Demo Code.
static void print_title()
Prints the title block when program first starts.
Definition: DC1339A.ino:166
float LTC2302_code_to_voltage(uint16_t adc_code, float vref, uint8_t uni_bipolar)
Calculates the LTC2302 input voltage given the data, range, and unipolar/bipolar status.
Definition: LTC2302.cpp:84
static uint16_t uni_bipolar
Default set for unipolar mode.
Definition: DC1339A.ino:79
QuikEval EEPROM Library.
#define LTC2302_BIPOLAR
Definition: LTC2302.h:80
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_uni_bipolar()
Select unipolar (0-VREF) or bipolar (+/- 0.5 x VREF) mode.
Definition: DC1339A.ino:138
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()
static void setup()
Initialize Linduino.
Definition: DC1339A.ino:83
void quikeval_I2C_init(void)
Initializes Linduino I2C port.
Definition: LT_I2C.cpp:394
static float voltage
Definition: DC2289AA.ino:71
#define QUIKEVAL_CS
QuikEval CS pin (SPI chip select on QuikEval connector pin 6) connects to Arduino SS pin...
Definition: Linduino.h:57
#define LTC2302_UNIPOLAR
Definition: LTC2302.h:78
static uint32_t adc_code
Definition: DC2071AA.ino:113