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);
76 
77 /****************************************************************************/
78 //! Initialize Linduino
79 //! @return void
80 void setup()
81 {
82  uint16_t return_val;
83 
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 :
152  break;
153 
154  case 11 :
156  break;
157 
158  case 12 :
160  break;
161 
162  case 13 :
164  break;
165 
166  case 14 :
168  break;
169 
170  case 15 :
172  break;
173 
174  case 16 :
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
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
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 {
243 }
244 
245 //! Clear faults.
246 //! @return void
248 {
250 }
251 
252 //! Turn off output.
253 //! @return void
254 void turn_off()
255 {
256 
258 }
259 
260 //! Turn on output.
261 //! @return void
262 void turn_on()
263 {
264 
266 }
267 
268 //! Margin high output.
269 //! @return void
271 {
272 
274 }
275 
276 //! Margin low output.
277 //! @return void
279 {
280 
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 
293 }
294 
295 //! Set output high voltage.
296 //! @return void
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 
304 }
305 
306 //! Set output low voltage.
307 //! @return void
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 
315 }
316 
317 //! Read output voltage.
318 //! @return void
320 {
321  uint16_t w;
322  double v;
323 
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
334 {
335  uint16_t w;
336  double v;
337 
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
348 {
349  uint16_t w;
350  double v;
351  double R = 0.002;
352 
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
363 {
364  uint16_t w;
365  double v;
366  double R = 0.002;
367 
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 
382  v &= 0xFC;
383  v |= s;
385 }
386 
387 //! Read status.
388 //! @return void
390 {
391  uint16_t w;
392 
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 }
#define LTC7841_READ_IIN
Definition: LTC7841.h:87
#define LTC7841_READ_VOUT
Definition: LTC7841.h:88
static uint8_t ltc7841_i2c_address
Definition: DC2978A.ino:70
void sendByte(uint8_t address, uint8_t command)
SMBus send byte command.
static void set_output_high_voltage(double v)
Set output high voltage.
Definition: DC2978A.ino:297
unsigned char user_command
void writeWord(uint8_t address, uint8_t command, uint16_t data)
SMBus write word command.
static void turn_on()
Turn on output.
Definition: DC2978A.ino:262
#define LTC7841_STATUS_NONE
Definition: LTC7841.h:123
#define LTC7841_STATUS_COM
Definition: LTC7841.h:124
#define LTC7841_STATUS_TEMP
Definition: LTC7841.h:125
static void reset()
Reset.
Definition: DC2978A.ino:240
static void margin_low()
Margin low output.
Definition: DC2978A.ino:278
Header File for Linduino Libraries and Demo Code.
void writeByte(uint8_t address, uint8_t command, uint8_t data)
SMBus write byte command.
static void loop()
Main Linduino Loop.
Definition: DC2978A.ino:96
#define LTC7841_STATUS_VOUT
Definition: LTC7841.h:129
static void read_output_current()
Read output current.
Definition: DC2978A.ino:362
#define LTC7841_STATUS_PGOODB
Definition: LTC7841.h:128
#define min(a, b)
#define LTC7841_STATUS_VOUT_OV
Definition: LTC7841.h:126
static void set_output_low_voltage(double v)
Set output low voltage.
Definition: DC2978A.ino:308
#define LTC7841_CONFIG_NORMAL_SLEW
Definition: LTC7841.h:116
static void clear_faults()
Clear faults.
Definition: DC2978A.ino:247
#define LTC7841_MFR_VOUT_COMMAND
Definition: LTC7841.h:100
static void read_output_voltage()
Read output voltage.
Definition: DC2978A.ino:319
static void print_prompt()
Prints main menu.
Definition: DC2978A.ino:213
static void set_output_voltage(double v)
Set output voltage.
Definition: DC2978A.ino:286
#define LTC7841_READ_IOUT
Definition: LTC7841.h:89
#define LTC7841_MFR_RESET
Definition: LTC7841.h:104
#define LTC7841_CONFIG_SLOW_SLEW
Definition: LTC7841.h:117
#define LTC7841_STATUS_WORD
Definition: LTC7841.h:85
#define LTC7841_MFR_CONFIG
Definition: LTC7841.h:101
uint8_t readByte(uint8_t address, uint8_t command)
SMBus read byte command.
#define LTC7841_OPERATION
Definition: LTC7841.h:83
#define LTC7841_OPERATION_OFF
Definition: LTC7841.h:111
#define LTC7841_STATUS_OFF
Definition: LTC7841.h:127
#define LTC7841_OPERATION_ON
Definition: LTC7841.h:112
static void setup()
Initialize Linduino.
Definition: DC2978A.ino:80
static void turn_off()
Turn off output.
Definition: DC2978A.ino:254
LTC SMBus Support: Implementation for a shared SMBus layer.
#define LTC7841_CONFIG_FAST_SLEW
Definition: LTC7841.h:118
int32_t read_int()
#define LTC7841_I2C_ADDRESS
Definition: DC2978A.ino:66
Header for LTC7841: PolyPhase Synchronous Boost Controller with PMBus Interface.
float read_float()
#define LTC7841_OPERATION_MARGIN_LOW
Definition: LTC7841.h:113
static void margin_high()
Margin high output.
Definition: DC2978A.ino:270
static LT_SMBusNoPec * smbus
Definition: DC2978A.ino:75
static void set_slew(uint8_t s)
Set slew.
Definition: DC2978A.ino:377
#define LTC7841_OPERATION_MARGIN_HIGH
Definition: LTC7841.h:114
#define LTC7841_MFR_VOUT_MARGIN_LOW
Definition: LTC7841.h:102
static void read_input_current()
Read input current.
Definition: DC2978A.ino:347
static float voltage
Definition: DC2289AA.ino:71
static void read_input_voltage()
Read input voltage.
Definition: DC2978A.ino:333
static void print_title()
Prints the title block when program first starts.
Definition: DC2978A.ino:198
#define LTC7841_MFR_VOUT_MARGIN_HIGH
Definition: LTC7841.h:98
#define LTC7841_READ_VIN
Definition: LTC7841.h:86
static void read_status()
Read status.
Definition: DC2978A.ino:389
uint16_t readWord(uint8_t address, uint8_t command)
SMBus read word command.