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
147  }; //!< Builds the command for single-ended mode
148 
149 //! Lookup table to build the command for differential mode
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 
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;
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;
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;
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;
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 
static float LTC2498_vref
The LTC2498 ideal reference voltage.
unsigned char user_command
static uint8_t rejection_mode
The LTC2498 rejection mode settings.
#define LTC2498_INTERNAL_TEMP
Definition: LTC2498.h:126
#define LTC2498_P7_N6
Definition: LTC2498.h:168
#define LTC2498_P12_N13
Definition: LTC2498.h:176
#define LTC2498_CH4
Definition: LTC2498.h:142
#define LTC2498_CH6
Definition: LTC2498.h:144
#define imon_gain
Header File for Linduino Libraries and Demo Code.
LTC2498: 24-Bit, 16-Channel Delta Sigma ADCs with Easy Drive Input Current Cancellation.
const uint8_t BUILD_1X_2X_COMMAND[2]
Lookup table to build 1X / 2X bits.
#define LTC2498_CH5
Definition: LTC2498.h:143
int8_t LTC2498_EOC_timeout(uint8_t cs, uint16_t miso_timeout)
Checks for EOC with a specified timeout.
Definition: LTC2498.cpp:72
#define LTC2498_P2_N3
Definition: LTC2498.h:161
static uint8_t demo_board_connected
Two-Channel Panel Meter based on the LTC2492, using any 2x16 LCD display compatible with the Arduino ...
static uint8_t two_x_mode
The LTC2498 2X Mode settings.
#define LTC2498_CH2
Definition: LTC2498.h:140
#define LTC2498_CH7
Definition: LTC2498.h:145
#define LTC2498_CH0
Definition: LTC2498.h:138
static float adc_voltage
Definition: DC2071AA.ino:115
#define LTC2498_P4_N5
Definition: LTC2498.h:164
#define LTC2498_CH9
Definition: LTC2498.h:147
LTC24XX General Library: Functions and defines for all SINC4 Delta Sigma ADCs.
#define tmon_gain
static void setup()
Initialize Linduino.
#define LTC2498_P15_N14
Definition: LTC2498.h:180
static uint16_t eoc_timeout
timeout in ms
#define LTC2498_P14_N15
Definition: LTC2498.h:179
QuikEval EEPROM Library.
#define LTC2498_CH15
Definition: LTC2498.h:153
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
void quikeval_SPI_init(void)
Configure the SPI port for 4Mhz SCK.
Definition: LT_SPI.cpp:151
int8_t discover_demo_board(char *demo_name)
Read the ID string from the EEPROM and determine if the correct board is connected.
#define LTC2498_P10_N11
Definition: LTC2498.h:173
#define LTC2498_P6_N7
Definition: LTC2498.h:167
#define LTC2498_P3_N2
Definition: LTC2498.h:162
#define LTC2498_SPEED_2X
Definition: LTC2498.h:125
LT_SPI: Routines to communicate with ATmega328P&#39;s hardware SPI port.
#define LTC2498_P11_N10
Definition: LTC2498.h:174
const uint8_t BUILD_COMMAND_DIFF[16]
Lookup table to build the command for differential mode.
#define LTC2498_P0_N1
Definition: LTC2498.h:158
#define LTC2498_CH12
Definition: LTC2498.h:150
LT_I2C: Routines to communicate with ATmega328P&#39;s hardware I2C port.
#define LTC2498_CH13
Definition: LTC2498.h:151
#define LTC2498_CH8
Definition: LTC2498.h:146
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
#define LTC2498_SPEED_1X
Definition: LTC2498.h:124
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
#define LTC2498_P1_N0
Definition: LTC2498.h:159
#define LTC2498_P9_N8
Definition: LTC2498.h:171
#define LTC2498_CS
Define the SPI CS pin.
Definition: LTC2498.h:116
#define LTC2498_CH1
Definition: LTC2498.h:139
#define LTC2498_CH10
Definition: LTC2498.h:148
static void loop()
Repeats Linduino loop.
#define LTC2498_P13_N12
Definition: LTC2498.h:177
void quikeval_I2C_init(void)
Initializes Linduino I2C port.
Definition: LT_I2C.cpp:394
#define LTC2498_CH14
Definition: LTC2498.h:152
#define LTC2498_CH3
Definition: LTC2498.h:141
#define LTC2498_P8_N9
Definition: LTC2498.h:170
#define LTC2498_R50_R60
Definition: LTC2498.h:131
#define LTC2498_P5_N4
Definition: LTC2498.h:165
static uint32_t adc_code
Definition: DC2071AA.ino:113
#define LTC2498_CH11
Definition: LTC2498.h:149
const uint8_t BUILD_COMMAND_SINGLE_ENDED[16]
Lookup table to build the command for single-ended mode.
LiquidCrystal lcd(2, 3, 4, A0, A1, A2, A3)
#define vdiv_gain