| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

DC2978A.ino
Go to the documentation of this file.
1 /*!
2 Analog Devices DC2978A Demonstration
3
4 LTC7841: Six Channel Sequencer and Voltage Supervisor with EEPROM
5
6 @verbatim
7 Setup:
8 Set the terminal baud rate to 115200 and select the newline terminator.
9
10 @endverbatim
11
12 http://www.analog.com/products/LTC7841
13
14 http://www.analog.com/design-center/evaluation-hardware-and-software/evaluation-boards-kits/dc1798a-a.html
15
16
17 Copyright 2020(c) Analog Devices, Inc.
18
19 All rights reserved.
20
21 Redistribution and use in source and binary forms, with or without
22 modification, are permitted provided that the following conditions are met:
23 - Redistributions of source code must retain the above copyright
24 notice, this list of conditions and the following disclaimer.
25 - Redistributions in binary form must reproduce the above copyright
26 notice, this list of conditions and the following disclaimer in
27 the documentation and/or other materials provided with the
28 distribution.
29 - Neither the name of Analog Devices, Inc. nor the names of its
30 contributors may be used to endorse or promote products derived
31 from this software without specific prior written permission.
32 - The use of this software may or may not infringe the patent rights
33 of one or more patent holders. This license does not release you
34 from the requirement that you obtain separate licenses from these
35 patent holders to use this software.
36 - Use of the software either in source or binary form, must be run
37 on or directly connected to an Analog Devices Inc. component.
38
39 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
40 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
41 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
42 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
43 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
44 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
45 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
46 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
47 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
48 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49 */
50
51 /*! @file
52 @ingroup LTC7841
53 */
54
55 #include <Arduino.h>
56 #include <stdint.h>
57 #include "Linduino.h"
58 #include "UserInterface.h"
59 //#include "LT_I2CBus.h"
60 #include "LT_SMBusNoPec.h"
61 //#include "LT_SMBusPec.h"
62 //#include "LT_PMBUS.h"
63 //#include "LT_I2C.h"
64 #include "LTC7841.h"
65
66 #define LTC7841_I2C_ADDRESS 0x20
67
68 /****************************************************************************/
69 // Global variables
70 static uint8_t ltc7841_i2c_address;
71
72 //static LT_I2CBus *i2cbus = new LT_I2CBus();
73 //static LT_I2CBus *i2cbus = new LT_I2CBus();
74 //static LT_SMBusNoPec *smbus = new LT_SMBusNoPec(i2cbus);
75 static LT_SMBusNoPec *smbus = new LT_SMBusNoPec();
76
77 /****************************************************************************/
78 //! Initialize Linduino
79 //! @return void
80 void setup()
81 {
82 uint16_t return_val;
83
84 ltc7841_i2c_address = LTC7841_I2C_ADDRESS;
85
86 Serial.begin(115200); //! Initialize the serial port to the PC
87 print_title();
88 print_prompt();
89
90 // ltc7841_config0();
91 }
92
93 /****************************************************************************/
94 //! Main Linduino Loop
95 //! @return void
96 void loop()
97 {
98 uint8_t user_command;
99 double voltage = 0.0;
100
101 if (Serial.available()) //! Checks for user input
102 {
103 user_command = read_int(); //! Reads the user command
104
105 switch (user_command)
106 {
107
108 case 1 :
109 reset();
110 break;
111
112 case 2 :
113 clear_faults();
114 break;
115
116 case 3 :
117 turn_off();
118 break;
119
120 case 4 :
121 turn_on();
122 break;
123
124 case 5 :
125 margin_high();
126 break;
127
128 case 6 :
129 margin_low();
130 break;
131
132 case 7 :
133 Serial.print(F("Enter voltage: "));
134 voltage = read_float();
135 set_output_voltage(voltage);
136 break;
137
138 case 8 :
139 Serial.print(F("Enter voltage: "));
140 voltage = read_float();
141 set_output_high_voltage(voltage);
142 break;
143
144 case 9 :
145 Serial.print(F("Enter voltage: "));
146 voltage = read_float();
147 set_output_low_voltage(voltage);
148 break;
149
150 case 10 :
151 read_output_voltage();
152 break;
153
154 case 11 :
155 read_input_voltage();
156 break;
157
158 case 12 :
159 read_output_current();
160 break;
161
162 case 13 :
163 read_input_current();
164 break;
165
166 case 14 :
167 set_slew(LTC7841_CONFIG_FAST_SLEW);
168 break;
169
170 case 15 :
171 set_slew(LTC7841_CONFIG_NORMAL_SLEW);
172 break;
173
174 case 16 :
175 set_slew(LTC7841_CONFIG_SLOW_SLEW);
176 break;
177
178 case 17 :
179 read_status();
180 break;
181
182
183 default:
184 Serial.print(F("15\n"));
185 Serial.println(F("Incorrect Option"));
186 break;
187 }
188 print_prompt();
189 }
190 }
191
192
193 /************************************************************************/
194 // Function Definitions
195
196 //! Prints the title block when program first starts.
197 //! @return void
198 void print_title()
199 {
200 Serial.print(F("\n***************************************************************\n"));
201 Serial.print(F("* DC2978A Control Program *\n"));
202 Serial.print(F("* *\n"));
203 Serial.print(F("* This program provides a simple interface to control the *\n"));
204 Serial.print(F("* the LTC7841 on the DC2978A Demo Board *\n"));
205 Serial.print(F("* *\n"));
206 Serial.print(F("* Set the baud rate to 115200 and select the newline terminator.*\n"));
207 Serial.print(F("* *\n"));
208 Serial.print(F("*****************************************************************\n"));
209 }
210
211 //! Prints main menu.
212 //! @return void
213 void print_prompt()
214 {
215 Serial.print(F("\n"));
216 Serial.print(F(" 1 - Reset\n"));
217 Serial.print(F(" 2 - Clear faults\n"));
218 Serial.print(F(" 3 - Turn off output\n"));
219 Serial.print(F(" 4 - Turn on output\n"));
220 Serial.print(F(" 5 - Margin high output\n"));
221 Serial.print(F(" 6 - Margin low output\n"));
222 Serial.print(F(" 7 - Set output voltage\n"));
223 Serial.print(F(" 8 - Set output high voltage\n"));
224 Serial.print(F(" 9 - Set output low voltage\n"));
225 Serial.print(F(" 10 - Read output voltage\n"));
226 Serial.print(F(" 11 - Read input voltage\n"));
227 Serial.print(F(" 12 - Read output current\n"));
228 Serial.print(F(" 13 - Read input current\n"));
229 Serial.print(F(" 14 - Fast slew\n"));
230 Serial.print(F(" 15 - Normal slew\n"));
231 Serial.print(F(" 16 - Slow slew\n"));
232
233 Serial.print(F(" 17 - Read status\n"));
234
235 Serial.print(F("\n Enter a command number: "));
236 }
237
238 //! Reset.
239 //! @return void
240 void reset()
241 {
242 smbus->sendByte(LTC7841_I2C_ADDRESS, LTC7841_MFR_RESET);
243 }
244
245 //! Clear faults.
246 //! @return void
247 void clear_faults()
248 {
249 smbus->writeWord(LTC7841_I2C_ADDRESS, LTC7841_STATUS_WORD, 0xFFFF);
250 }
251
252 //! Turn off output.
253 //! @return void
254 void turn_off()
255 {
256
257 smbus->writeByte(LTC7841_I2C_ADDRESS, LTC7841_OPERATION, LTC7841_OPERATION_OFF);
258 }
259
260 //! Turn on output.
261 //! @return void
262 void turn_on()
263 {
264
265 smbus->writeByte(LTC7841_I2C_ADDRESS, LTC7841_OPERATION, LTC7841_OPERATION_ON);
266 }
267
268 //! Margin high output.
269 //! @return void
270 void margin_high()
271 {
272
273 smbus->writeByte(LTC7841_I2C_ADDRESS, LTC7841_OPERATION, LTC7841_OPERATION_MARGIN_HIGH);
274 }
275
276 //! Margin low output.
277 //! @return void
278 void margin_low()
279 {
280
281 smbus->writeByte(LTC7841_I2C_ADDRESS, LTC7841_OPERATION, LTC7841_OPERATION_MARGIN_LOW);
282 }
283
284 //! Set output voltage.
285 //! @return void
286 void set_output_voltage(double v)
287 {
288 double v_clamp = max(0.0, min(v, 48.0));
289 double v_scale = (100.0 * v_clamp / 48.0) / 0.2;
290 uint16_t w = (uint16_t) v_scale;
291
292 smbus->writeWord(LTC7841_I2C_ADDRESS, LTC7841_MFR_VOUT_COMMAND, w);
293 }
294
295 //! Set output high voltage.
296 //! @return void
297 void set_output_high_voltage(double v)
298 {
299 double v_clamp = max(0.0, min(v, 48.0));
300 double v_scale = (100.0 * v_clamp / 48.0) / 0.2;
301 uint16_t w = (uint16_t) v_scale;
302
303 smbus->writeWord(LTC7841_I2C_ADDRESS, LTC7841_MFR_VOUT_MARGIN_HIGH, w);
304 }
305
306 //! Set output low voltage.
307 //! @return void
308 void set_output_low_voltage(double v)
309 {
310 double v_clamp = max(0.0, min(v, 48.0));
311 double v_scale = (100.0 * v_clamp / 48.0) / 0.2;
312 uint16_t w = (uint16_t) v_scale;
313
314 smbus->writeWord(LTC7841_I2C_ADDRESS, LTC7841_MFR_VOUT_MARGIN_LOW, w);
315 }
316
317 //! Read output voltage.
318 //! @return void
319 void read_output_voltage()
320 {
321 uint16_t w;
322 double v;
323
324 w = smbus->readWord(LTC7841_I2C_ADDRESS, LTC7841_READ_VOUT);
325
326 v = 10.0E-3 * ((double) w);
327 Serial.print(F("VOUT: "));
328 Serial.println(v);
329 }
330
331 //! Read input voltage.
332 //! @return void
333 void read_input_voltage()
334 {
335 uint16_t w;
336 double v;
337
338 w = smbus->readWord(LTC7841_I2C_ADDRESS, LTC7841_READ_VIN);
339
340 v = 10.0E-3 * ((double) w);
341 Serial.print(F("VIN: "));
342 Serial.println(v);
343 }
344
345 //! Read input current.
346 //! @return void
347 void read_input_current()
348 {
349 uint16_t w;
350 double v;
351 double R = 0.002;
352
353 w = smbus->readWord(LTC7841_I2C_ADDRESS, LTC7841_READ_IIN);
354
355 v = 50.0E-6 * R * ((double) w);
356 Serial.print(F("IIN: "));
357 Serial.println(v);
358 }
359
360 //! Read output current.
361 //! @return void
362 void read_output_current()
363 {
364 uint16_t w;
365 double v;
366 double R = 0.002;
367
368 w = smbus->readWord(LTC7841_I2C_ADDRESS, LTC7841_READ_IOUT);
369
370 v = 50.0E-6 * R * ((double) w);
371 Serial.print(F("IOUT: "));
372 Serial.println(v);
373 }
374
375 //! Set slew.
376 //! @return void
377 void set_slew(uint8_t s)
378 {
379 uint8_t v;
380
381 v = smbus->readByte(LTC7841_I2C_ADDRESS, LTC7841_MFR_CONFIG);
382 v &= 0xFC;
383 v |= s;
384 smbus->writeByte(LTC7841_I2C_ADDRESS, LTC7841_MFR_CONFIG, v);
385 }
386
387 //! Read status.
388 //! @return void
389 void read_status()
390 {
391 uint16_t w;
392
393 w = smbus->readWord(LTC7841_I2C_ADDRESS, LTC7841_STATUS_WORD);
394 Serial.print(F("STATUS WORD: "));
395 if (w & LTC7841_STATUS_NONE) Serial.print(F("NONE "));
396 if (w & LTC7841_STATUS_COM) Serial.print(F("COM "));
397 if (w & LTC7841_STATUS_TEMP) Serial.print(F("TEMP "));
398 if (w & LTC7841_STATUS_VOUT_OV) Serial.print(F("VOUT_OV "));
399 if (w & LTC7841_STATUS_OFF) Serial.print(F("OFF "));
400 if (w & LTC7841_STATUS_PGOODB) Serial.print(F("PGOODB "));
401 if (w & LTC7841_STATUS_VOUT) Serial.print(F("VOUT "));
402 Serial.println();
403 }
LTC7841_READ_IIN
#define LTC7841_READ_IIN
Definition: LTC7841.h:87
LTC7841_READ_VOUT
#define LTC7841_READ_VOUT
Definition: LTC7841.h:88
ltc7841_i2c_address
static uint8_t ltc7841_i2c_address
Definition: DC2978A.ino:70
LT_SMBusBase::sendByte
void sendByte(uint8_t address, uint8_t command)
SMBus send byte command.
Definition: LT_SMBusBase.cpp:508
set_output_high_voltage
static void set_output_high_voltage(double v)
Set output high voltage.
Definition: DC2978A.ino:297
user_command
unsigned char user_command
Definition: Serial_EEPROM_Test.ino:75
LT_SMBusBase::writeWord
void writeWord(uint8_t address, uint8_t command, uint16_t data)
SMBus write word command.
Definition: LT_SMBusBase.cpp:265
turn_on
static void turn_on()
Turn on output.
Definition: DC2978A.ino:262
LTC7841_STATUS_NONE
#define LTC7841_STATUS_NONE
Definition: LTC7841.h:123
LTC7841_STATUS_COM
#define LTC7841_STATUS_COM
Definition: LTC7841.h:124
LTC7841_STATUS_TEMP
#define LTC7841_STATUS_TEMP
Definition: LTC7841.h:125
reset
static void reset()
Reset.
Definition: DC2978A.ino:240
margin_low
static void margin_low()
Margin low output.
Definition: DC2978A.ino:278
Linduino.h
Header File for Linduino Libraries and Demo Code.
LT_SMBusNoPec
Definition: LT_SMBusNoPec.h:60
LT_SMBusBase::writeByte
void writeByte(uint8_t address, uint8_t command, uint8_t data)
SMBus write byte command.
Definition: LT_SMBusBase.cpp:177
loop
static void loop()
Main Linduino Loop.
Definition: DC2978A.ino:96
LTC7841_STATUS_VOUT
#define LTC7841_STATUS_VOUT
Definition: LTC7841.h:129
read_output_current
static void read_output_current()
Read output current.
Definition: DC2978A.ino:362
LTC7841_STATUS_PGOODB
#define LTC7841_STATUS_PGOODB
Definition: LTC7841.h:128
min
#define min(a, b)
Definition: Adafruit_GFX.cpp:66
LTC7841_STATUS_VOUT_OV
#define LTC7841_STATUS_VOUT_OV
Definition: LTC7841.h:126
set_output_low_voltage
static void set_output_low_voltage(double v)
Set output low voltage.
Definition: DC2978A.ino:308
LTC7841_CONFIG_NORMAL_SLEW
#define LTC7841_CONFIG_NORMAL_SLEW
Definition: LTC7841.h:116
clear_faults
static void clear_faults()
Clear faults.
Definition: DC2978A.ino:247
LTC7841_MFR_VOUT_COMMAND
#define LTC7841_MFR_VOUT_COMMAND
Definition: LTC7841.h:100
read_output_voltage
static void read_output_voltage()
Read output voltage.
Definition: DC2978A.ino:319
print_prompt
static void print_prompt()
Prints main menu.
Definition: DC2978A.ino:213
set_output_voltage
static void set_output_voltage(double v)
Set output voltage.
Definition: DC2978A.ino:286
LTC7841_READ_IOUT
#define LTC7841_READ_IOUT
Definition: LTC7841.h:89
LTC7841_MFR_RESET
#define LTC7841_MFR_RESET
Definition: LTC7841.h:104
LTC7841_CONFIG_SLOW_SLEW
#define LTC7841_CONFIG_SLOW_SLEW
Definition: LTC7841.h:117
LTC7841_STATUS_WORD
#define LTC7841_STATUS_WORD
Definition: LTC7841.h:85
LTC7841_MFR_CONFIG
#define LTC7841_MFR_CONFIG
Definition: LTC7841.h:101
LT_SMBusBase::readByte
uint8_t readByte(uint8_t address, uint8_t command)
SMBus read byte command.
Definition: LT_SMBusBase.cpp:234
LTC7841_OPERATION
#define LTC7841_OPERATION
Definition: LTC7841.h:83
LTC7841_OPERATION_OFF
#define LTC7841_OPERATION_OFF
Definition: LTC7841.h:111
LTC7841_STATUS_OFF
#define LTC7841_STATUS_OFF
Definition: LTC7841.h:127
LTC7841_OPERATION_ON
#define LTC7841_OPERATION_ON
Definition: LTC7841.h:112
setup
static void setup()
Initialize Linduino.
Definition: DC2978A.ino:80
turn_off
static void turn_off()
Turn off output.
Definition: DC2978A.ino:254
LT_SMBusNoPec.h
LTC SMBus Support: Implementation for a shared SMBus layer.
LTC7841_CONFIG_FAST_SLEW
#define LTC7841_CONFIG_FAST_SLEW
Definition: LTC7841.h:118
UserInterface.h
read_int
int32_t read_int()
Definition: UserInterface.cpp:93
LTC7841_I2C_ADDRESS
#define LTC7841_I2C_ADDRESS
Definition: DC2978A.ino:66
LTC7841.h
Header for LTC7841: PolyPhase Synchronous Boost Controller with PMBus Interface.
read_float
float read_float()
Definition: UserInterface.cpp:78
LTC7841_OPERATION_MARGIN_LOW
#define LTC7841_OPERATION_MARGIN_LOW
Definition: LTC7841.h:113
margin_high
static void margin_high()
Margin high output.
Definition: DC2978A.ino:270
smbus
static LT_SMBusNoPec * smbus
Definition: DC2978A.ino:75
set_slew
static void set_slew(uint8_t s)
Set slew.
Definition: DC2978A.ino:377
LTC7841_OPERATION_MARGIN_HIGH
#define LTC7841_OPERATION_MARGIN_HIGH
Definition: LTC7841.h:114
LTC7841_MFR_VOUT_MARGIN_LOW
#define LTC7841_MFR_VOUT_MARGIN_LOW
Definition: LTC7841.h:102
read_input_current
static void read_input_current()
Read input current.
Definition: DC2978A.ino:347
voltage
static float voltage
Definition: DC2289AA.ino:71
read_input_voltage
static void read_input_voltage()
Read input voltage.
Definition: DC2978A.ino:333
print_title
static void print_title()
Prints the title block when program first starts.
Definition: DC2978A.ino:198
LTC7841_MFR_VOUT_MARGIN_HIGH
#define LTC7841_MFR_VOUT_MARGIN_HIGH
Definition: LTC7841.h:98
LTC7841_READ_VIN
#define LTC7841_READ_VIN
Definition: LTC7841.h:86
read_status
static void read_status()
Read status.
Definition: DC2978A.ino:389
LT_SMBusBase::readWord
uint16_t readWord(uint8_t address, uint8_t command)
SMBus read word command.
Definition: LT_SMBusBase.cpp:301