Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
DC2382.ino
Go to the documentation of this file.
1 /*!
2 Linear Technology DC1962C Demonstration Board
3 LTC2975 + LTM4644: Power Management Solution for Application Processors
4 
5 @verbatim
6 
7 NOTES
8  Setup:
9  Set the terminal baud rate to 115200 and select the newline terminator.
10 
11 @endverbatim
12 
13 http://www.linear.com/product/LTC2975
14 
15 http://www.linear.com/demo/DC2382
16 
17 
18 Copyright 2018(c) Analog Devices, Inc.
19 
20 All rights reserved.
21 
22 Redistribution and use in source and binary forms, with or without
23 modification, are permitted provided that the following conditions are met:
24  - Redistributions of source code must retain the above copyright
25  notice, this list of conditions and the following disclaimer.
26  - Redistributions in binary form must reproduce the above copyright
27  notice, this list of conditions and the following disclaimer in
28  the documentation and/or other materials provided with the
29  distribution.
30  - Neither the name of Analog Devices, Inc. nor the names of its
31  contributors may be used to endorse or promote products derived
32  from this software without specific prior written permission.
33  - The use of this software may or may not infringe the patent rights
34  of one or more patent holders. This license does not release you
35  from the requirement that you obtain separate licenses from these
36  patent holders to use this software.
37  - Use of the software either in source or binary form, must be run
38  on or directly connected to an Analog Devices Inc. component.
39 
40 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
41 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
42 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
43 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
44 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
45 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
46 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
47 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
48 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
49 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50 */
51 
52 /*! @file
53  @ingroup LTC2975
54 */
55 
56 #include <Arduino.h>
57 #include <stdint.h>
58 #include "Linduino.h"
59 #include "UserInterface.h"
60 #include "LT_I2CBus.h"
61 #include "LT_SMBusNoPec.h"
62 #include "LT_SMBusPec.h"
63 #include "LT_PMBusMath.h"
64 #include "LT_PMBus.h"
65 
66 #define LTC2975_I2C_ADDRESS 0x5C
67 
68 // Global variables
69 static uint8_t ltc2975_i2c_address;
70 static LT_PMBusMath *math = new LT_PMBusMath();
71 static LT_SMBus *smbus = new LT_SMBusPec();
72 static LT_PMBus *pmbus = new LT_PMBus(smbus);
73 
74 //! Initialize Linduino
75 //! @return void
76 void setup()
77 {
78  Serial.begin(115200); //! Initialize the serial port to the PC
79  print_title();
81  print_prompt();
82 }
83 
84 //! Repeats Linduino loop
85 //! @return void
86 void loop()
87 {
88  uint8_t user_command;
89  uint8_t res;
90  uint8_t model[7];
91  uint8_t revision[10];
92  uint8_t *addresses = NULL;
93 
94  if (Serial.available()) //! Checks for user input
95  {
96  user_command = read_int(); //! Reads the user command
97  if (user_command != 'm')
98  Serial.println(user_command);
99 
100  switch (user_command) //! Prints the appropriate submenu
101  {
102  case 1:
103  menu_1_basic_commands(); // Print single-ended voltage menu
104  break;
105  case 2:
106  menu_2_vid_commands(); // Print VID menu
107  break;
108  case 3:
109  menu_3_vid_commands(); // Print VID menu
110  break;
111  case 4:
113  delete smbus;
114  delete pmbus;
115  smbus = new LT_SMBusPec();
116  pmbus = new LT_PMBus(smbus);
117  break;
118  case 5:
120  delete smbus;
121  delete pmbus;
122  smbus = new LT_SMBusNoPec();
123  pmbus = new LT_PMBus(smbus);
124  break;
125  case 6:
126  addresses = smbus->probe(0);
127  while (*addresses != 0)
128  {
129  Serial.print(F("ADDR 0x"));
130  Serial.println(*addresses++, HEX);
131  }
132  break;
133  case 7 :
134  pmbus->startGroupProtocol();
136  pmbus->executeGroupProtocol();
137  break;
138  default:
139  Serial.println(F("Incorrect Option"));
140  break;
141  }
142  print_prompt();
143  }
144 
145 }
146 
147 // Function Definitions
148 
149 //! Prints the title block when program first starts.
150 //! @return void
152 {
153  Serial.print(F("\n*****************************************************************\n"));
154  Serial.print(F("* DC2382C Hello World Demonstration Program *\n"));
155  Serial.print(F("* *\n"));
156  Serial.print(F("* This program demonstrates how to send and receive data from *\n"));
157  Serial.print(F("* the LTC2382 demo board. *\n"));
158  Serial.print(F("* *\n"));
159  Serial.print(F("* Set the baud rate to 115200 and select the newline terminator.*\n"));
160  Serial.print(F("* *\n"));
161  Serial.print(F("*****************************************************************\n"));
162 }
163 
164 //! Prints main menu.
165 //! @return void
167 {
168  Serial.print(F("\n 1-Basic Commands\n"));
169  Serial.print(F(" 2-VID Commands (L16)\n"));
170  Serial.print(F(" 3-VID Commands (float) \n"));
171  Serial.print(F(" 4-PEC On\n"));
172  Serial.print(F(" 5-PEC Off\n"));
173  Serial.print(F(" 6-Bus Probe\n"));
174  Serial.print(F(" 7-Reset\n"));
175  Serial.print(F("\nEnter a command:"));
176 }
177 
178 //! Prints a warning if the demo board is not detected.
179 //! @return void
181 {
182  Serial.println(F("\nWarning: Demo board not detected. Linduino will attempt to proceed."));
183 }
184 
185 //! Print all voltages
186 //! @return void
188 {
189  float voltage;
190  uint8_t page;
191 
192  for (page = 0; page < 4; page++)
193  {
194  pmbus->setPage(ltc2975_i2c_address, page);
195  voltage = pmbus->readVout(ltc2975_i2c_address, false);
196  Serial.print(F("LTC2975 VOUT "));
197  Serial.println(voltage, DEC);
198  }
199 }
200 
201 //! Print all currents
202 //! @return void
204 {
205  float current;
206  uint8_t page;
207 
208  for (page = 0; page < 4; page++)
209  {
210  pmbus->setPage(ltc2975_i2c_address, page);
211  current = pmbus->readIout(ltc2975_i2c_address, false);
212  Serial.print(F("LTC2975 IOUT "));
213  Serial.println(current, DEC);
214  }
215 }
216 
217 //! Print all status bytes and words
218 //! @return void
220 {
221  uint8_t b;
222  uint16_t w;
223  uint8_t page;
224 
225  for (page = 0; page < 4; page++)
226  {
227  Serial.print(F("PAGE "));
228  Serial.println(page, DEC);
229  pmbus->setPage(ltc2975_i2c_address, page);
231  Serial.print(F("LTC2975 STATUS BYTE 0x"));
232  Serial.println(b, HEX);
234  Serial.print(F("LTC2975 STATUS WORD 0x"));
235  Serial.println(w, HEX);
236  }
237 }
238 
239 //! Sequence off then on
240 //! @return void
242 {
243  pmbus->sequenceOffGlobal();
244  delay (2000);
245  pmbus->sequenceOnGlobal();
246 }
247 
248 //! Margin high
249 //! @return void
251 {
252  pmbus->marginHighGlobal();
253 }
254 
255 //! Margin low
256 //! @return void
258 {
259  pmbus->marginLowGlobal();
260 }
261 
262 //! Go to nominal
263 //! @return void
265 {
266  pmbus->sequenceOnGlobal();
267 }
268 
269 //! Display menu 1
270 //! @return void
272 {
273  uint8_t user_command;
274 
275  do
276  {
277  //! Displays the Read/Write menu
278  Serial.print(F(" 1-Read All Voltages\n"));
279  Serial.print(F(" 2-Read All Currents\n"));
280  Serial.print(F(" 3-Read All Status\n"));
281  Serial.print(F(" 4-Sequence Off/On\n"));
282  Serial.print(F(" 5-Margin High\n"));
283  Serial.print(F(" 6-Margin Low\n"));
284  Serial.print(F(" 7-Margin Off\n"));
285  Serial.print(F(" m-Main Menu\n"));
286  Serial.print(F("\nEnter a command: "));
287 
288  user_command = read_int(); //! Reads the user command
289  if (user_command == 'm') // Print m if it is entered
290  {
291  Serial.print(F("m\n"));
292  }
293  else
294  Serial.println(user_command); // Print user command
295 
296  switch (user_command)
297  {
298  case 1:
300  break;
301  case 2:
303  break;
304  case 3:
306  break;
307  case 4:
308  sequence_off_on();
309  break;
310  case 5:
311  margin_high();
312  break;
313  case 6:
314  margin_low();
315  break;
316  case 7:
317  margin_off();
318  break;
319  default:
320  if (user_command != 'm')
321  Serial.println(F("Invalid Selection"));
322  break;
323  }
324  }
325  while (user_command != 'm');
326 }
327 
328 //! Display menu 2
329 //! @return void
331 {
332  uint8_t user_command;
333  uint16_t vcode;
334  float voltage;
335 
336  vcode = math->float_to_lin16 (1.0, 0x13);
337  smbus->writeByte(ltc2975_i2c_address, 0x00, 0x00); // Set to page 0
338  smbus->writeWord (ltc2975_i2c_address, 0x21, vcode); // Set starting point
339 
340  do
341  {
342  //! Displays the Read/Write menu
343  Serial.print(F(" 1-VID UP 40 LSB\n"));
344  Serial.print(F(" 2-VID DN 40 LSB\n"));
345  Serial.print(F(" m-Main Menu\n"));
346  Serial.print(F("\nEnter a command: "));
347 
348  user_command = read_int(); //! Reads the user command
349  if (user_command == 'm') // Print m if it is entered
350  {
351  Serial.print(F("m\n"));
352  }
353  else
354  Serial.println(user_command); // Print user command
355 
356  switch (user_command)
357  {
358  case 1:
359  vcode += 40;
360  smbus->writeWord (ltc2975_i2c_address, 0x21, vcode);
361  Serial.print(F("LTC2975 VOUT Code "));
362  Serial.println(vcode, HEX);
363  delay (1000);
364  voltage = pmbus->readVout(ltc2975_i2c_address, false);
365  Serial.print(F("LTC2975 VOUT Telemetry "));
366  Serial.println(voltage, DEC);
367  break;
368  case 2:
369  vcode -= 40;
370  smbus->writeWord (ltc2975_i2c_address, 0x21, vcode);
371  Serial.print(F("LTC2975 VOUT Code "));
372  Serial.println(vcode, HEX);
373  delay (1000);
374  voltage = pmbus->readVout(ltc2975_i2c_address, false);
375  Serial.print(F("LTC2975 VOUT Telemetry "));
376  Serial.println(voltage, DEC);
377  Serial.print(F("\n"));
378  break;
379  default:
380  if (user_command != 'm')
381  Serial.println(F("Invalid Selection"));
382  break;
383  }
384  }
385  while (user_command != 'm');
386 }
387 
388 //! Display menu 3
389 //! @return void
391 {
392  uint8_t user_command;
393  float vid_value;
394  float voltage;
395 
396  vid_value = 1.0;
397  pmbus->setPage(ltc2975_i2c_address, 0x00); // Set to page 0
398  pmbus->setVout(ltc2975_i2c_address, vid_value); // Set starting voltage
399 
400  do
401  {
402  //! Displays the Read/Write menu
403  Serial.print(F(" 1-VID UP 4mV\n"));
404  Serial.print(F(" 2-VID DN 4mV\n"));
405  Serial.print(F(" m-Main Menu\n"));
406  Serial.print(F("\nEnter a command: "));
407 
408  user_command = read_int(); //! Reads the user command
409  if (user_command == 'm') // Print m if it is entered
410  {
411  Serial.print(F("m\n"));
412  }
413  else
414  Serial.println(user_command); // Print user command
415 
416  switch (user_command)
417  {
418  case 1:
419  vid_value += 0.004;
420  pmbus->setVout (ltc2975_i2c_address, vid_value);
421  Serial.print(F("LTC2975 VOUT "));
422  Serial.println(vid_value, DEC);
423  delay (1000);
424  voltage = pmbus->readVout(ltc2975_i2c_address, false);
425  Serial.print(F("LTC2975 VOUT Telemetry "));
426  Serial.println(voltage, DEC);
427  break;
428  case 2:
429  vid_value -= 0.004;
430  pmbus->setVout (ltc2975_i2c_address, vid_value);
431  Serial.print(F("LTC2975 VOUT "));
432  Serial.println(vid_value, DEC);
433  delay (1000);
434  voltage = pmbus->readVout(ltc2975_i2c_address, false);
435  Serial.print(F("LTC2975 VOUT Telemetry "));
436  Serial.println(voltage, DEC);
437  Serial.print(F("\n"));
438  break;
439  default:
440  if (user_command != 'm')
441  Serial.println(F("Invalid Selection"));
442  break;
443  }
444  }
445  while (user_command != 'm');
446 }
447 
448 
lin16_t float_to_lin16(float xin, lin16m_t vout_mode)
unsigned char user_command
static void margin_low()
Margin low.
Definition: DC2382.ino:257
LTC SMBus Support: Implementation for a shared SMBus layer.
uint8_t readStatusByte(uint8_t address)
Get the status byte.
Definition: LT_PMBus.cpp:2423
static void margin_off()
Go to nominal.
Definition: DC2382.ino:264
static void loop()
Repeats Linduino loop.
Definition: DC2382.ino:86
Header File for Linduino Libraries and Demo Code.
void enablePec(uint8_t address)
Enable pec for all transactions.
Definition: LT_PMBus.cpp:3173
uint16_t readStatusWord(uint8_t address)
Get the status word.
Definition: LT_PMBus.cpp:2470
float readIout(uint8_t address, bool polling)
Get the measured output current.
Definition: LT_PMBus.cpp:1898
static void menu_2_vid_commands()
Display menu 2.
Definition: DC2382.ino:330
static void print_all_status()
Print all status bytes and words.
Definition: DC2382.ino:219
static void print_warning_prompt()
Prints a warning if the demo board is not detected.
Definition: DC2382.ino:180
void disablePec(uint8_t address)
Disable pec for all transactions.
Definition: LT_PMBus.cpp:3210
virtual void writeWord(uint8_t address, uint8_t command, uint16_t data)=0
SMBus write word command.
static void margin_high()
Margin high.
Definition: DC2382.ino:250
static LT_PMBusMath * math
Definition: DC2382.ino:70
static void print_all_currents()
Print all currents.
Definition: DC2382.ino:203
void startGroupProtocol(void)
starts group protocol
Definition: LT_PMBus.cpp:3350
float readVout(uint8_t address, bool polling)
Get the measured output voltage.
Definition: LT_PMBus.cpp:1598
static void print_all_voltages()
Print all voltages.
Definition: DC2382.ino:187
static void menu_3_vid_commands()
Display menu 3.
Definition: DC2382.ino:390
LT_I2CBus: Routines to communicate to I2C by Wire Library.
virtual void writeByte(uint8_t address, uint8_t command, uint8_t data)=0
SMBus write byte command.
#define LTC2975_I2C_ADDRESS
Definition: DC2382.ino:66
void setPage(uint8_t address, uint8_t page)
Set the page.
Definition: LT_PMBus.cpp:3156
static void menu_1_basic_commands()
Display menu 1.
Definition: DC2382.ino:271
void marginLowGlobal(void)
Margin all rails low.
Definition: LT_PMBus.cpp:3078
static void print_title()
Prints the title block when program first starts.
Definition: DC2382.ino:151
static void sequence_off_on()
Sequence off then on.
Definition: DC2382.ino:241
void sequenceOnGlobal(void)
Sequence on all rails.
Definition: LT_PMBus.cpp:2896
virtual uint8_t * probe(uint8_t command)=0
SMBus bus probe.
LTC SMBus Support: Implementation for a shared SMBus layer.
static void print_prompt()
Prints main menu.
Definition: DC2382.ino:166
int32_t read_int()
void sequenceOffGlobal(void)
Sequence off all rails.
Definition: LT_PMBus.cpp:2876
void setVout(uint8_t address, float voltage)
Set output voltage.
Definition: LT_PMBus.cpp:239
void executeGroupProtocol(void)
ends group protocol
Definition: LT_PMBus.cpp:3356
static void setup()
Initialize Linduino.
Definition: DC2382.ino:76
void restoreFromNvm(uint8_t address)
Restore device from NVM.
Definition: LT_PMBus.cpp:2663
LTC PMBus Support.
static float voltage
Definition: DC2289AA.ino:71
static LT_SMBus * smbus
Definition: DC2382.ino:71
static uint16_t current
the current measurement from the LTC3335&#39;s counter test mode.
Definition: DC2343A.ino:114
void marginHighGlobal(void)
Margin all rails high.
Definition: LT_PMBus.cpp:3068
LTC PMBus Support: Math conversion routines.
static LT_PMBus * pmbus
Definition: DC2382.ino:72
PMBus communication.
Definition: LT_PMBus.h:370
static uint8_t ltc2975_i2c_address
Definition: DC2382.ino:69