| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

LTC2492_Panel_Meter.ino
Go to the documentation of this file.
1 /*!
2 Two-Channel Panel Meter based on the LTC2492, using any 2x16 LCD display
3 compatible with the Arduino LiquidCrystal library.
4
5 (The LTC2492 is a code-compatible subset of the LTC2498.)
6
7 Initial scaling factors are for the DC2132A, Constant Voltage, Constant Current
8 Bench Supply, which uses two LT3018 regulators.
9
10 LTC2492 mapping:
11 CH0 - voltage measurement divider, define vdiv_gain accordingly
12 CH1 - current monitor output
13 CH2 - LT3080 junction temperature monitor output
14 (Ambient temperature read from LTC2498 internal sensor)
15
16 @verbatim
17
18 NOTES:
19
20 LCD pin mapping is designed to be "minimally obtrusive", not interfering
21 with an Uno's SPI, I2C or UART. Since we're using an external,
22 high-performance ADC, the "analog" pins can be re-used as digital outputs.
23
24 LiquidCrystal lcd(2, 3, 4, A0, A1, A2, A3); // RS, RW, EN, D4:D7.
25
26 For reference, the standard character LCD pinout is as follows:
27 1 GROUND
28 2 VDD (usually +5V)
29 3 Contrast
30 4 RS (register select)
31 5 RW (High = READ, low = WRITE)
32 6 EN (Enable)
33 7 D0 (ground in 4-bit mode)
34 8 D1 (ground in 4-bit mode)
35 9 D2 (ground in 4-bit mode)
36 10 D3 (ground in 4-bit mode)
37 11 D4
38 12 D5
39 13 D6
40 14 D7
41 15 - Pins 15, 16 are often used for backlight.
42 16 - Check datasheet for voltage / polarity.
43
44
45
46 Setup:
47 Set the terminal baud rate to 115200 and select the newline terminator. Equipment
48 required is a precision voltage source and a precision voltmeter. Additionally,
49 an external power supply is required to provide a negative voltage for Amp V-.
50 Set it to anywhere from -1V to -5V. Set Amp V+ to Vcc. Ensure the COM and REF-
51 pins are connected to ground. The REF+ pin should be connected to +5V.
52
53 How to test Single-Ended mode:
54 The voltage source should be connected to the ADC such that the negative lead is
55 connected to the COM(common) pin. The positive lead may be connected to any
56 channel input. Ensure voltage is within analog input voltage range -0.3 to 2.5V.
57
58 How to test Differential Mode:
59 The voltage source should be connected with positive and negative leads to paired
60 channels. The voltage source negative output must also be connected to the COM
61 pin in order to provide a ground-referenced voltage. Ensure voltage is within
62 analog input voltage range -0.3V to +2.5V. Swapping input voltages results in a
63 reversed polarity reading.
64
65
66 @endverbatim
67
68 http://www.linear.com/product/LTC2498
69
70 http://www.linear.com/product/LTC2498#demoboards
71
72
73 The Linear Technology Linduino is not affiliated with the official Arduino team.
74 However, the Linduino is only possible because of the Arduino team's commitment
75 to the open-source community. Please, visit http://www.arduino.cc and
76 http://store.arduino.cc , and consider a purchase that will help fund their
77 ongoing work.
78
79
80
81 Copyright 2011(c) Analog Devices, Inc.
82
83 All rights reserved.
84
85 Redistribution and use in source and binary forms, with or without modification,
86 are permitted provided that the following conditions are met:
87 - Redistributions of source code must retain the above copyright
88 notice, this list of conditions and the following disclaimer.
89 - Redistributions in binary form must reproduce the above copyright
90 notice, this list of conditions and the following disclaimer in
91 the documentation and/or other materials provided with the
92 distribution.
93 - Neither the name of Analog Devices, Inc. nor the names of its
94 contributors may be used to endorse or promote products derived
95 from this software without specific prior written permission.
96 - The use of this software may or may not infringe the patent rights
97 of one or more patent holders. This license does not release you
98 from the requirement that you obtain separate licenses from these
99 patent holders to use this software.
100 - Use of the software either in source or binary form, must be run
101 on or directly connected to an Analog Devices Inc. component.
102
103 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
104 INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A
105 PARTICULAR PURPOSE ARE DISCLAIMED.
106
107 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
108 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, INTELLECTUAL PROPERTY
109 RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
110 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
111 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
112 THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
113 */
114
115
116 #include <Arduino.h>
117 #include <LiquidCrystal.h>
118 #include <stdint.h>
119 #include "Linduino.h"
120 #include "LT_SPI.h"
121 #include <SPI.h>
122 #include "UserInterface.h"
123 #include "LT_I2C.h"
124 #include "QuikEval_EEPROM.h"
125 #include "LTC24XX_general.h"
126 #include "LTC2498.h"
127
128 // Function Declaration
129
130 // Global variables
131 static uint8_t demo_board_connected; //!< Set to 1 if the board is connected
132 static uint8_t two_x_mode = LTC2498_SPEED_1X; //!< The LTC2498 2X Mode settings
133 static uint8_t rejection_mode = LTC2498_R50_R60; //!< The LTC2498 rejection mode settings
134 static float LTC2498_vref = 5.0; //!< The LTC2498 ideal reference voltage
135 static uint16_t eoc_timeout = 250; //!< timeout in ms
136 // Constants
137 #define vdiv_gain 10.75 // Measured from actual supply
138 #define imon_gain 10.0
139 #define tmon_gain 100.0
140
141
142 //! Lookup table to build the command for single-ended mode
143 const uint8_t BUILD_COMMAND_SINGLE_ENDED[16] = {LTC2498_CH0, LTC2498_CH1, LTC2498_CH2, LTC2498_CH3,
144 LTC2498_CH4, LTC2498_CH5, LTC2498_CH6, LTC2498_CH7,
145 LTC2498_CH8, LTC2498_CH9, LTC2498_CH10, LTC2498_CH11,
146 LTC2498_CH12, LTC2498_CH13, LTC2498_CH14, LTC2498_CH15
147 }; //!< Builds the command for single-ended mode
148
149 //! Lookup table to build the command for differential mode
150 const uint8_t BUILD_COMMAND_DIFF[16] = {LTC2498_P0_N1, LTC2498_P2_N3, LTC2498_P4_N5, LTC2498_P6_N7,
151 LTC2498_P8_N9, LTC2498_P10_N11, LTC2498_P12_N13, LTC2498_P14_N15,
152 LTC2498_P1_N0, LTC2498_P3_N2, LTC2498_P5_N4, LTC2498_P7_N6,
153 LTC2498_P9_N8, LTC2498_P11_N10, LTC2498_P13_N12, LTC2498_P15_N14
154 }; //!< Build the command for differential mode
155
156 //! Lookup table to build 1X / 2X bits
157 const uint8_t BUILD_1X_2X_COMMAND[2] = {LTC2498_SPEED_1X, LTC2498_SPEED_2X}; //!< Build the command for 1x or 2x mode
158
159 LiquidCrystal lcd(2, 3, 4, A0, A1, A2, A3); // RS, RW, EN, D4:D7. This pinout does not
160 // interfere with any Linduino functionality.
161
162 //! Initialize Linduino
163 void setup()
164 {
165
166 lcd.begin(16,2);
167 lcd.setCursor(0, 0);
168 lcd.print("Hello, DC2132");
169 lcd.setCursor(0, 1);
170 lcd.print("Power Supply! :)");
171
172 delay(2000);
173 lcd.setCursor(0, 0);
174 lcd.print(" ");
175 lcd.setCursor(0, 1);
176 lcd.print(" ");
177 char demo_name[]="DC1011"; // Demo Board Name stored in QuikEval EEPROM
178 quikeval_SPI_init(); // Configure the spi port for 4MHz SCK
179 quikeval_SPI_connect(); // Connect SPI to main data port
180 quikeval_I2C_init(); // Configure the EEPROM I2C port for 100kHz
181 Serial.begin(115200); // Initialize the serial port to the PC
182
183 demo_board_connected = discover_demo_board(demo_name);
184 // if (demo_board_connected)
185 // {
186 // print_prompt();
187 // }
188 // else
189 // {
190 // Serial.println(F("EEPROM not detected, will attempt to proceed"));
191 // demo_board_connected = 1;
192 // print_prompt();
193 // }
194 quikeval_SPI_connect(); //Initialize for SPI
195 }
196
197 //! Repeats Linduino loop
198 void loop()
199 {
200 uint8_t adc_command_high; // The LTC2498 command high byte
201 uint8_t adc_command_low; // The LTC2498 command low byte
202 int16_t user_command; // The user input command
203 uint8_t ack_EOC = 0; // Keeps track of the EOC timeout
204 int32_t adc_code = 0; // The LTC2498 code
205 float temperature, tj, adc_voltage, vout_voltage, iout_current;
206
207 // Program channel 1, read channel 0
208 adc_command_high = BUILD_COMMAND_SINGLE_ENDED[1]; // Build ADC command for channel 0
209 adc_command_low = rejection_mode | two_x_mode;
210 LTC2498_EOC_timeout(LTC2498_CS, eoc_timeout);
211 LTC2498_read(LTC2498_CS, adc_command_high, adc_command_low, &adc_code); // Throws out last reading
212 adc_voltage = LTC2498_code_to_voltage(adc_code, LTC2498_vref);
213 vout_voltage = adc_voltage * vdiv_gain;
214 lcd.setCursor(0, 0);
215 lcd.print(" ");
216 lcd.setCursor(0, 0);
217 lcd.print("V=");
218 lcd.print(vout_voltage, 2);
219 // Program temperature, read channel 1
220 adc_command_high = BUILD_COMMAND_SINGLE_ENDED[0]; // Any channel can be selected
221 adc_command_low = LTC2498_INTERNAL_TEMP | rejection_mode;
222 LTC2498_EOC_timeout(LTC2498_CS, eoc_timeout);
223 LTC2498_read(LTC2498_CS, adc_command_high, adc_command_low, &adc_code); // Throws out last reading
224 adc_voltage = LTC2498_code_to_voltage(adc_code, LTC2498_vref);
225 iout_current = adc_voltage * imon_gain;
226 lcd.setCursor(8, 0);
227 lcd.print(" ");
228 lcd.setCursor(8, 0);
229 lcd.print("I=");
230 lcd.print(iout_current, 2);
231
232
233 // Program channel 2, read temperature
234
235
236 adc_command_high = BUILD_COMMAND_SINGLE_ENDED[2]; // Any channel can be selected
237 adc_command_low = rejection_mode | two_x_mode;
238 LTC2498_EOC_timeout(LTC2498_CS, eoc_timeout);
239 LTC2498_read(LTC2498_CS, adc_command_high, adc_command_low, &adc_code); // Throws out last reading
240 adc_voltage = LTC2498_code_to_voltage(adc_code, LTC2498_vref);
241 temperature = 27.0 + ((adc_voltage-0.028) / 93.5e-6);
242 lcd.setCursor(0, 1);
243 lcd.print(" ");
244 lcd.setCursor(0, 1);
245 lcd.print("Ta=");
246 lcd.print(temperature, 1);
247
248 // Program channel 0, read channel 2
249 adc_command_high = BUILD_COMMAND_SINGLE_ENDED[0]; // Any channel can be selected
250 adc_command_low = rejection_mode | two_x_mode;
251 LTC2498_EOC_timeout(LTC2498_CS, eoc_timeout);
252 LTC2498_read(LTC2498_CS, adc_command_high, adc_command_low, &adc_code); // Throws out last reading
253 adc_voltage = LTC2498_code_to_voltage(adc_code, LTC2498_vref);
254 tj = (adc_voltage * tmon_gain);
255 lcd.setCursor(8, 1);
256 lcd.print(" ");
257 lcd.setCursor(8, 1);
258 lcd.print("Tj=");
259 lcd.print(tj, 1);
260
261
262
263 }
264
LTC2498_vref
static float LTC2498_vref
The LTC2498 ideal reference voltage.
Definition: LTC2492_Panel_Meter.ino:134
user_command
unsigned char user_command
Definition: Serial_EEPROM_Test.ino:75
rejection_mode
static uint8_t rejection_mode
The LTC2498 rejection mode settings.
Definition: LTC2492_Panel_Meter.ino:133
LTC2498_INTERNAL_TEMP
#define LTC2498_INTERNAL_TEMP
Definition: LTC2498.h:126
LTC2498_P7_N6
#define LTC2498_P7_N6
Definition: LTC2498.h:168
LTC2498_P12_N13
#define LTC2498_P12_N13
Definition: LTC2498.h:176
LTC2498_CH4
#define LTC2498_CH4
Definition: LTC2498.h:142
LTC2498_CH6
#define LTC2498_CH6
Definition: LTC2498.h:144
imon_gain
#define imon_gain
Definition: LTC2492_Panel_Meter.ino:138
Linduino.h
Header File for Linduino Libraries and Demo Code.
LTC2498.h
LTC2498: 24-Bit, 16-Channel Delta Sigma ADCs with Easy Drive Input Current Cancellation.
BUILD_1X_2X_COMMAND
const uint8_t BUILD_1X_2X_COMMAND[2]
Lookup table to build 1X / 2X bits.
Definition: LTC2492_Panel_Meter.ino:157
LTC2498_CH5
#define LTC2498_CH5
Definition: LTC2498.h:143
LTC2498_EOC_timeout
int8_t LTC2498_EOC_timeout(uint8_t cs, uint16_t miso_timeout)
Checks for EOC with a specified timeout.
Definition: LTC2498.cpp:72
LTC2498_P2_N3
#define LTC2498_P2_N3
Definition: LTC2498.h:161
demo_board_connected
static uint8_t demo_board_connected
Two-Channel Panel Meter based on the LTC2492, using any 2x16 LCD display compatible with the Arduino ...
Definition: LTC2492_Panel_Meter.ino:131
two_x_mode
static uint8_t two_x_mode
The LTC2498 2X Mode settings.
Definition: LTC2492_Panel_Meter.ino:132
LTC2498_CH2
#define LTC2498_CH2
Definition: LTC2498.h:140
LTC2498_CH7
#define LTC2498_CH7
Definition: LTC2498.h:145
LTC2498_CH0
#define LTC2498_CH0
Definition: LTC2498.h:138
adc_voltage
static float adc_voltage
Definition: DC2071AA.ino:115
LTC2498_P4_N5
#define LTC2498_P4_N5
Definition: LTC2498.h:164
LTC2498_CH9
#define LTC2498_CH9
Definition: LTC2498.h:147
LTC24XX_general.h
LTC24XX General Library: Functions and defines for all SINC4 Delta Sigma ADCs.
tmon_gain
#define tmon_gain
Definition: LTC2492_Panel_Meter.ino:139
setup
static void setup()
Initialize Linduino.
Definition: LTC2492_Panel_Meter.ino:163
LTC2498_P15_N14
#define LTC2498_P15_N14
Definition: LTC2498.h:180
eoc_timeout
static uint16_t eoc_timeout
timeout in ms
Definition: LTC2492_Panel_Meter.ino:135
LTC2498_P14_N15
#define LTC2498_P14_N15
Definition: LTC2498.h:179
QuikEval_EEPROM.h
QuikEval EEPROM Library.
LTC2498_CH15
#define LTC2498_CH15
Definition: LTC2498.h:153
LTC2498_read
void LTC2498_read(uint8_t cs, uint8_t adc_command_high, uint8_t adc_command_low, int32_t *adc_code)
Reads from LTC2498.
Definition: LTC2498.cpp:79
quikeval_SPI_init
void quikeval_SPI_init(void)
Configure the SPI port for 4Mhz SCK.
Definition: LT_SPI.cpp:151
discover_demo_board
int8_t discover_demo_board(char *demo_name)
Read the ID string from the EEPROM and determine if the correct board is connected.
Definition: QuikEval_EEPROM.cpp:141
LTC2498_P10_N11
#define LTC2498_P10_N11
Definition: LTC2498.h:173
LTC2498_P6_N7
#define LTC2498_P6_N7
Definition: LTC2498.h:167
LTC2498_P3_N2
#define LTC2498_P3_N2
Definition: LTC2498.h:162
LTC2498_SPEED_2X
#define LTC2498_SPEED_2X
Definition: LTC2498.h:125
LT_SPI.h
LT_SPI: Routines to communicate with ATmega328P&#39;s hardware SPI port.
LTC2498_P11_N10
#define LTC2498_P11_N10
Definition: LTC2498.h:174
BUILD_COMMAND_DIFF
const uint8_t BUILD_COMMAND_DIFF[16]
Lookup table to build the command for differential mode.
Definition: LTC2492_Panel_Meter.ino:150
LTC2498_P0_N1
#define LTC2498_P0_N1
Definition: LTC2498.h:158
LTC2498_CH12
#define LTC2498_CH12
Definition: LTC2498.h:150
LT_I2C.h
LT_I2C: Routines to communicate with ATmega328P&#39;s hardware I2C port.
LTC2498_CH13
#define LTC2498_CH13
Definition: LTC2498.h:151
LTC2498_CH8
#define LTC2498_CH8
Definition: LTC2498.h:146
demo_name
char demo_name[]
Demo Board Name stored in QuikEval EEPROM.
Definition: DC1880A.ino:97
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
LTC2498_SPEED_1X
#define LTC2498_SPEED_1X
Definition: LTC2498.h:124
LTC2498_code_to_voltage
float LTC2498_code_to_voltage(int32_t adc_code, float vref)
Calculates the voltage corresponding to an adc code, given the reference (in volts) ...
Definition: LTC2498.cpp:85
LTC2498_P1_N0
#define LTC2498_P1_N0
Definition: LTC2498.h:159
LTC2498_P9_N8
#define LTC2498_P9_N8
Definition: LTC2498.h:171
LTC2498_CS
#define LTC2498_CS
Define the SPI CS pin.
Definition: LTC2498.h:116
LTC2498_CH1
#define LTC2498_CH1
Definition: LTC2498.h:139
LTC2498_CH10
#define LTC2498_CH10
Definition: LTC2498.h:148
loop
static void loop()
Repeats Linduino loop.
Definition: LTC2492_Panel_Meter.ino:198
LTC2498_P13_N12
#define LTC2498_P13_N12
Definition: LTC2498.h:177
quikeval_I2C_init
void quikeval_I2C_init(void)
Initializes Linduino I2C port.
Definition: LT_I2C.cpp:394
LTC2498_CH14
#define LTC2498_CH14
Definition: LTC2498.h:152
LTC2498_CH3
#define LTC2498_CH3
Definition: LTC2498.h:141
LTC2498_P8_N9
#define LTC2498_P8_N9
Definition: LTC2498.h:170
LTC2498_R50_R60
#define LTC2498_R50_R60
Definition: LTC2498.h:131
LTC2498_P5_N4
#define LTC2498_P5_N4
Definition: LTC2498.h:165
adc_code
static uint32_t adc_code
Definition: DC2071AA.ino:113
LTC2498_CH11
#define LTC2498_CH11
Definition: LTC2498.h:149
BUILD_COMMAND_SINGLE_ENDED
const uint8_t BUILD_COMMAND_SINGLE_ENDED[16]
Lookup table to build the command for single-ended mode.
Definition: LTC2492_Panel_Meter.ino:143
lcd
LiquidCrystal lcd(2, 3, 4, A0, A1, A2, A3)
vdiv_gain
#define vdiv_gain
Definition: LTC2492_Panel_Meter.ino:137