| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

DC1697A.ino
Go to the documentation of this file.
1 /*!
2 DC1697A
3 LTC2945: Wide Range Power Monitor
4
5 @verbatim
6
7 Setting the Alerts:
8 1. Select the Alert option from the main menu.
9 2. Select the desired alerts to be changed. Then enter the minimum and maximum
10 values.
11 3. Select the Enable and Disable Alert Option and Enable the desired alerts.
12 4. Lastly, go back to the main menu and start reading values in Continuous Mode
13 or Snapshot Mode.
14 Note: Alerts only respond when conversion is done. Therefore, in continuous
15 mode the alerts will constantly be updated.
16
17 Reading and Clearing an Alert:
18 1. Select the Alert option from the main menu.
19 2. Select the Read and Clear Alerts option. This reads all faults that occured
20 and clears the alerts.
21
22 NOTES
23 Setup:
24 Set the terminal baud rate to 115200 and select the newline terminator.
25 Requires a power supply.
26 Refer to demo manual DC1697A.
27
28 USER INPUT DATA FORMAT:
29 decimal : 1024
30 hex : 0x400
31 octal : 02000 (leading 0 "zero")
32 binary : B10000000000
33 float : 1024.0
34
35 @endverbatim
36
37
38 Copyright 2018(c) Analog Devices, Inc.
39
40 All rights reserved.
41
42 Redistribution and use in source and binary forms, with or without
43 modification, are permitted provided that the following conditions are met:
44 - Redistributions of source code must retain the above copyright
45 notice, this list of conditions and the following disclaimer.
46 - Redistributions in binary form must reproduce the above copyright
47 notice, this list of conditions and the following disclaimer in
48 the documentation and/or other materials provided with the
49 distribution.
50 - Neither the name of Analog Devices, Inc. nor the names of its
51 contributors may be used to endorse or promote products derived
52 from this software without specific prior written permission.
53 - The use of this software may or may not infringe the patent rights
54 of one or more patent holders. This license does not release you
55 from the requirement that you obtain separate licenses from these
56 patent holders to use this software.
57 - Use of the software either in source or binary form, must be run
58 on or directly connected to an Analog Devices Inc. component.
59
60 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
61 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
62 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
63 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
64 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
65 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
66 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
67 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
68 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
69 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
70 */
71
72 /*! @file
73 @ingroup LTC2945
74 */
75
76 #include <Arduino.h>
77 #include <stdint.h>
78 #include "Linduino.h"
79 #include "LT_I2C.h"
80 #include "LT_SPI.h"
81 #include "UserInterface.h"
82 #include "QuikEval_EEPROM.h"
83 #include "LTC2945.h"
84 #include <Wire.h>
85 #include <SPI.h>
86
87 // Function Declaration
88 void print_title(); // Print the title block
89 void print_prompt(); // Print the Prompt
90 void store_alert_settings(); // Store the alert settings to the EEPROM
91 int8_t restore_alert_settings(); // Read the alert settings from EEPROM
92
93 int8_t menu_1_continuous_mode(int8_t VDD_or_SENSE_monitoring, int8_t ADIN_or_SENSE, float scale);
94 int8_t menu_2_snapshot_mode(int8_t VDD_or_SENSE_monitoring, int8_t ADIN_or_SENSE);
95 int8_t menu_2_snapshot_mode_menu_1_current(int8_t VDD_or_SENSE_monitoring, int8_t ADIN_or_SENSE);
96 int8_t menu_2_snapshot_mode_menu_2_vin();
97 int8_t menu_2_snapshot_mode_menu_3_ADIN();
98 int8_t menu_3_alert(int8_t ADIN_or_SENSE);
99 int8_t menu_3_alert_menu_1_set_power_alerts(int8_t ADIN_or_SENSE);
100 int8_t menu_3_alert_menu_2_set_current_alerts();
101 int8_t menu_3_alert_menu_3_set_vin_alerts();
102 int8_t menu_3_alert_menu_4_set_adin_alerts();
103 int8_t menu_3_alert_menu_5_enable_disable_alerts();
104 int8_t menu_3_alert_menu_6_read_clear_alerts();
105 int8_t menu_4_shutdown();
106 void menu_5_settings(int8_t *VDD_or_SENSE_monitoring, int8_t *ADIN_or_SENSE, float *scale);
107 int8_t menu_6_clear_min_max();
108
109 #define CONTINUOUS_MODE_DISPLAY_DELAY 1000 //!< The delay between readings
110
111 // LSB Weights
112 const float LTC2945_ADIN_lsb = 5.001221E-04; //!< Typical ADIN lsb weight in volts
113 const float LTC2945_DELTA_SENSE_lsb = 2.5006105E-05; //!< Typical Delta lsb weight in volts
114 const float LTC2945_VIN_lsb = 2.5006105E-02; //!< Typical VIN lsb weight in volts
115 const float LTC2945_Power_lsb = 6.25305E-07; //!< Typical POWER lsb weight in V^2
116 const float LTC2945_ADIN_DELTA_SENSE_lsb = 1.25061E-08; //!< Typical sense lsb weight in V^2 *ADIN_lsb * DELTA_SENSE_lsb
117
118 const float resistor = .02; //!< resistor value on demo board
119
120 // Error string
121 const char ack_error[] = "Error: No Acknowledge. Check I2C Address."; //!< Error message
122
123 // Global variables
124 static int8_t demo_board_connected; //!< Set to 1 if the board is connected
125 static uint8_t alert_code = 0; //!< Value stored or read from ALERT register. Shared between loop() and restore_alert_settings()
126
127 //! Initialize Linduino
128 void setup()
129 {
130 char demo_name[] = "DC1697"; // Demo Board Name stored in QuikEval EEPROM
131
132 quikeval_I2C_init(); //! Configure the EEPROM I2C port for 100kHz
133 quikeval_I2C_connect(); //! Connects to main I2C port
134 Serial.begin(115200); //! Initialize the serial port to the PC
135 print_title();
136 demo_board_connected = discover_demo_board(demo_name);
137 if (!demo_board_connected)
138 {
139 Serial.println(F("Demo board not detected, will attempt to proceed"));
140 demo_board_connected = true;
141 }
142 if (demo_board_connected)
143 {
144 restore_alert_settings();
145 print_prompt();
146 }
147 }
148
149 //! Repeats Linduino loop
150 void loop()
151 {
152 int8_t ack = 0; // I2C acknowledge indicator
153 static uint8_t user_command; // The user input command
154
155 static int8_t VDD_or_SENSE_monitoring = 1; // Choose whether VIN is sensed at VDD pin or SENSE pin (A2 bit of CONTROL Register A)
156 static int8_t ADIN_or_SENSE = 1; // Choose whether power multiplier uses ADIN pin or SENSE pin as voltage input (A0 bit in CONTROL Register A)
157
158 static float scale; // Stores division ration for resistive divider on ADIN pin. Configured inside "Settings" menu.
159
160 if (demo_board_connected) //! Do nothing if the demo board is not connected
161 {
162 if (Serial.available()) //! Do nothing if serial is not available
163 {
164 user_command = read_int(); //! Read user input command
165 if (user_command != 'm')
166 Serial.println(user_command);
167 Serial.println();
168 ack = 0;
169 switch (user_command) //! Prints the appropriate submenu
170 {
171 case 1:
172 ack |= menu_1_continuous_mode(VDD_or_SENSE_monitoring, ADIN_or_SENSE, scale); // Continuous Mode
173 break;
174
175 case 2:
176 ack |= menu_2_snapshot_mode(VDD_or_SENSE_monitoring, ADIN_or_SENSE);
177 break;
178
179 case 3:
180 ack |= menu_3_alert(ADIN_or_SENSE); // Alert
181 break;
182
183 case 4:
184 ack |= menu_4_shutdown(); // Shutdown Down Mode
185 break;
186
187 case 5:
188 menu_5_settings(&VDD_or_SENSE_monitoring, &ADIN_or_SENSE, &scale); // Settings
189 break;
190
191 case 6:
192 ack |= menu_6_clear_min_max(); // Clear Min/Max
193 break;
194
195 default:
196 Serial.println("Incorrect Option");
197 break;
198 }
199 if (ack != 0)
200 Serial.println(ack_error);
201 Serial.print(F("*************************"));
202 print_prompt();
203 }
204 }
205 }
206
207 // Function Definitions
208 //! Print the title block
209 void print_title()
210 {
211 Serial.println(F("\n*****************************************************************"));
212 Serial.print(F("* DC1697 Demonstration Program *\n"));
213 Serial.print(F("* *\n"));
214 Serial.print(F("* This program communicates with the LTC2945 12-Bit Wide Range *\n"));
215 Serial.print(F("* I2C Power Monitor found on the DC1697 demo board. *\n"));
216 Serial.print(F("* Set the baud rate to 115200 and select the newline terminator.*\n"));
217 Serial.print(F("* *\n"));
218 Serial.print(F("*****************************************************************\n"));
219 }
220
221 //! Print the Prompt
222 void print_prompt()
223 {
224 Serial.print(F("\n1-Continuous Mode\n"));
225 Serial.print(F("2-Snapshot Mode\n"));
226 Serial.print(F("3-Alert\n"));
227 Serial.print(F("4-Shutdown Mode\n"));
228 Serial.print(F("5-Settings\n"));
229 Serial.print(F("6-Clear Min/Max\n\n"));
230 Serial.print(F("Enter a command: "));
231 }
232
233 //! Continuous Mode.
234 int8_t menu_1_continuous_mode(int8_t VDD_or_SENSE_monitoring, //!< Choose whether VIN is sensed at VDD pin or SENSE pin (A2 bit of CONTROL Register A)
235 int8_t ADIN_or_SENSE, //!< Choose whether power multiplier uses ADIN pin or SENSE pin as voltage input (A0 bit in CONTROL Register A)
236 float scale) //!< Stores division ratio for resistive divider on ADIN pin. Configured inside "Settings" menu.
237 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
238 {
239 int8_t LTC2945_mode;
240 int8_t ack = 0;
241 LTC2945_mode = LTC2945_CONTINUOUS_MODE;
242 if (VDD_or_SENSE_monitoring == 1)
243 LTC2945_mode = LTC2945_mode | LTC2945_SENSE_MONITOR; //! Enables SENSE+ voltage monitor
244 if (ADIN_or_SENSE == 1)
245 LTC2945_mode = LTC2945_mode | LTC2945_SENSE_MULTIPLIER; //! Selects VIN as a multiplier for power
246 Serial.println();
247 ack |= LTC2945_write(LTC2945_I2C_ADDRESS, LTC2945_CONTROL_REG, LTC2945_mode); //! Sets the LTC2945 to continuous mode
248 do
249 {
250 if (ADIN_or_SENSE == 1)
251 {
252 Serial.print(F("*************************\n\n"));
253
254 int32_t power_code, max_power_code, min_power_code;
255 ack |= LTC2945_read_24_bits(LTC2945_I2C_ADDRESS, LTC2945_POWER_MSB2_REG, &power_code);
256 ack |= LTC2945_read_24_bits(LTC2945_I2C_ADDRESS, LTC2945_MAX_POWER_MSB2_REG, &max_power_code);
257 ack |= LTC2945_read_24_bits(LTC2945_I2C_ADDRESS, LTC2945_MIN_POWER_MSB2_REG, &min_power_code);
258
259 float power, max_power, min_power; // Store power results
260 power = LTC2945_code_to_power(power_code, resistor, LTC2945_Power_lsb);
261 max_power = LTC2945_code_to_power(max_power_code, resistor, LTC2945_Power_lsb);
262 min_power = LTC2945_code_to_power(min_power_code, resistor, LTC2945_Power_lsb);
263
264 Serial.print(F("****Power: "));
265 Serial.print(power, 4);
266 Serial.print(F(" W\n"));
267
268 Serial.print(F("Max Power: "));
269 Serial.print(max_power, 4);
270 Serial.print(F(" W\n"));
271
272 Serial.print(F("Min Power: "));
273 Serial.print(min_power, 4);
274 Serial.print(F(" W\n"));
275 }
276 else
277 {
278 Serial.print(F("*************************"));
279 Serial.println();
280 Serial.println();
281
282 int32_t power_code, max_power_code, min_power_code;
283 ack |= LTC2945_read_24_bits(LTC2945_I2C_ADDRESS, LTC2945_POWER_MSB2_REG, &power_code);
284 ack |= LTC2945_read_24_bits(LTC2945_I2C_ADDRESS, LTC2945_MAX_POWER_MSB2_REG, &max_power_code);
285 ack |= LTC2945_read_24_bits(LTC2945_I2C_ADDRESS, LTC2945_MIN_POWER_MSB2_REG, &min_power_code);
286
287 float power, max_power, min_power;
288 power = LTC2945_code_to_ADIN_power(power_code, resistor, LTC2945_ADIN_DELTA_SENSE_lsb) * scale;
289 max_power = LTC2945_code_to_ADIN_power(max_power_code, resistor, LTC2945_ADIN_DELTA_SENSE_lsb) * scale;
290 min_power = LTC2945_code_to_ADIN_power(min_power_code, resistor, LTC2945_ADIN_DELTA_SENSE_lsb) * scale;
291
292 Serial.print(F("\n***ADIN Power: "));
293 Serial.print(power, 4);
294 Serial.print(F(" W\n"));
295
296 Serial.print(F("Max ADIN Power: "));
297 Serial.print(max_power, 4);
298 Serial.print(F(" W\n"));
299
300 Serial.print(F("Min ADIN Power: "));
301 Serial.print(min_power, 4);
302 Serial.print(F(" W\n"));
303 }
304
305 uint16_t current_code, max_current_code, min_current_code;
306 ack |= LTC2945_read_12_bits(LTC2945_I2C_ADDRESS, LTC2945_DELTA_SENSE_MSB_REG, &current_code);
307 ack |= LTC2945_read_12_bits(LTC2945_I2C_ADDRESS, LTC2945_MAX_DELTA_SENSE_MSB_REG, &max_current_code);
308 ack |= LTC2945_read_12_bits(LTC2945_I2C_ADDRESS, LTC2945_MIN_DELTA_SENSE_MSB_REG, &min_current_code);
309
310 float current, max_current, min_current;
311 current = LTC2945_code_to_current(current_code, resistor, LTC2945_DELTA_SENSE_lsb);
312 max_current = LTC2945_code_to_current(max_current_code, resistor, LTC2945_DELTA_SENSE_lsb);
313 min_current = LTC2945_code_to_current(min_current_code, resistor, LTC2945_DELTA_SENSE_lsb);
314
315 Serial.print(F("\n****Current: "));
316 Serial.print(current, 4);
317 Serial.print(F(" A\n"));
318
319 Serial.print(F("Max Current: "));
320 Serial.print(max_current, 4);
321 Serial.print(F(" A\n"));
322
323 Serial.print(F("Min Current: "));
324 Serial.print(min_current, 4);
325 Serial.print(F(" A\n"));
326
327 uint16_t VIN_code, max_VIN_code, min_VIN_code;
328 ack |= LTC2945_read_12_bits(LTC2945_I2C_ADDRESS, LTC2945_VIN_MSB_REG, &VIN_code);
329 ack |= LTC2945_read_12_bits(LTC2945_I2C_ADDRESS, LTC2945_MAX_VIN_MSB_REG, &max_VIN_code);
330 ack |= LTC2945_read_12_bits(LTC2945_I2C_ADDRESS, LTC2945_MIN_VIN_MSB_REG, &min_VIN_code);
331
332 float VIN, max_VIN, min_VIN;
333 VIN = LTC2945_VIN_code_to_voltage(VIN_code , LTC2945_VIN_lsb);
334 max_VIN = LTC2945_VIN_code_to_voltage(max_VIN_code, LTC2945_VIN_lsb);
335 min_VIN = LTC2945_VIN_code_to_voltage(min_VIN_code, LTC2945_VIN_lsb);
336
337 Serial.print(F("\n****VIN: "));
338 Serial.print(VIN, 4);
339 Serial.print(F(" V\n"));
340
341 Serial.print(F("Max VIN: "));
342 Serial.print(max_VIN, 4);
343 Serial.print(F(" V\n"));
344
345 Serial.print(F("Min VIN: "));
346 Serial.print(min_VIN, 4);
347 Serial.print(F(" V\n"));
348
349 uint16_t ADIN_code, max_ADIN_code, min_ADIN_code;
350 ack |= LTC2945_read_12_bits(LTC2945_I2C_ADDRESS, LTC2945_ADIN_MSB_REG, &ADIN_code);
351 ack |= LTC2945_read_12_bits(LTC2945_I2C_ADDRESS, LTC2945_MAX_ADIN_MSB_REG, &max_ADIN_code);
352 ack |= LTC2945_read_12_bits(LTC2945_I2C_ADDRESS, LTC2945_MIN_ADIN_MSB_REG, &min_ADIN_code);
353
354 float ADIN, max_ADIN, min_ADIN;
355 ADIN = LTC2945_ADIN_code_to_voltage(ADIN_code, LTC2945_ADIN_lsb);
356 max_ADIN = LTC2945_ADIN_code_to_voltage(max_ADIN_code, LTC2945_ADIN_lsb);
357 min_ADIN = LTC2945_ADIN_code_to_voltage(min_ADIN_code, LTC2945_ADIN_lsb);
358
359 Serial.print(F("\n****ADIN: "));
360 Serial.print(ADIN, 4);
361 Serial.print(F(" V\n"));
362
363 Serial.print(F("Max ADIN: "));
364 Serial.print(max_ADIN, 4);
365 Serial.print(F(" V\n"));
366
367 Serial.print(F("Min ADIN: "));
368 Serial.print(min_ADIN, 4);
369 Serial.print(F(" V\n"));
370 Serial.print(F("m-Main Menu\n\n"));
371 Serial.flush();
372 delay(CONTINUOUS_MODE_DISPLAY_DELAY);
373 }
374 while (Serial.available() == false);
375 read_int(); // clears the Serial.available
376 return(ack);
377 }
378
379 // DJE: Should user_command be passed as a pointer to allow 'm' option to break properly?
380 //! Snapshot Mode Menu
381 int8_t menu_2_snapshot_mode(int8_t VDD_or_SENSE_monitoring, //!< Choose whether VIN is sensed at VDD pin or SENSE pin (A2 bit of CONTROL Register A)
382 int8_t ADIN_or_SENSE) //!< Choose whether power multiplier uses ADIN pin or SENSE pin as voltage input (A0 bit in CONTROL Register A)
383 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
384 {
385 int8_t ack = 0;
386 //! Print submenu
387 Serial.print(F("*************************\n\n"));
388 Serial.print(F("Snapshot Mode\n"));
389 Serial.print(F("1-Current\n"));
390 Serial.print(F("2-VIN\n"));
391
392 Serial.print(F("3-ADIN\n"));
393 Serial.print(F("m-Main Menu\n"));
394 uint8_t user_command;
395 do
396 {
397 Serial.print(F("\n\nEnter a Command: "));
398 user_command = read_int();
399 if (user_command == 'm')
400 Serial.println("m");
401 else
402 {
403 Serial.println(user_command);
404 }
405 if (user_command != 'm')
406 {
407 Serial.print(F("*************************\n\n"));
408 Serial.print(F("Snapshot Mode\n"));
409 Serial.print(F("1-Current\n"));
410 Serial.print(F("2-VIN\n"));
411 Serial.print(F("3-ADIN\n"));
412 Serial.print(F("m-Main Menu\n"));
413 }
414 Serial.println();
415 switch (user_command)
416 {
417 case 1: // Current - Snapshot Mode
418 ack |= menu_2_snapshot_mode_menu_1_current(VDD_or_SENSE_monitoring, ADIN_or_SENSE);
419 break;
420
421 case 2: // VIN - Snapshot Mode
422 ack |= menu_2_snapshot_mode_menu_2_vin();
423 break;
424
425 case 3: // ADIN - Snapshot Mode
426 ack |= menu_2_snapshot_mode_menu_3_ADIN();
427 break;
428
429 default:
430 if (user_command != 'm')
431 Serial.println("Incorrect Option");
432 break;
433 }
434 }
435 while (!((user_command == 'm') || (ack)));
436 return(ack);
437 }
438
439 //! Current - Snapshot mode
440 int8_t menu_2_snapshot_mode_menu_1_current(int8_t VDD_or_SENSE_monitoring, //!< Choose whether VIN is sensed at VDD pin or SENSE pin (A2 bit of CONTROL Register A)
441 int8_t ADIN_or_SENSE) //!< Choose whether power multiplier uses ADIN pin or SENSE pin as voltage input (A0 bit in CONTROL Register A)
442 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
443 {
444 int8_t ack = 0;
445 int8_t LTC2945_mode;
446 LTC2945_mode = LTC2945_DELTA_SENSE_SNAPSHOT;
447 if (ADIN_or_SENSE == 1) LTC2945_mode = LTC2945_mode | LTC2945_SENSE_MONITOR;
448 if (VDD_or_SENSE_monitoring == 1) LTC2945_mode = LTC2945_mode | LTC2945_SENSE_MULTIPLIER;
449 ack |= LTC2945_write(LTC2945_I2C_ADDRESS, LTC2945_CONTROL_REG, LTC2945_mode);
450
451 uint8_t busy;
452 do
453 {
454 ack |= LTC2945_read(LTC2945_I2C_ADDRESS, LTC2945_CONTROL_REG, &busy);
455 }
456 while (0x8 & busy);
457
458 uint16_t current_code;
459 ack |= LTC2945_read_12_bits(LTC2945_I2C_ADDRESS, LTC2945_DELTA_SENSE_MSB_REG, &current_code);
460
461 float current;
462 current = LTC2945_code_to_current(current_code, resistor, LTC2945_DELTA_SENSE_lsb);
463 Serial.print(F("Current: "));
464 Serial.print(current, 4);
465 Serial.print(F(" A"));
466 return(ack);
467 }
468
469 //! VIN - Snapshot Mode
470 int8_t menu_2_snapshot_mode_menu_2_vin()
471 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
472 {
473 int8_t ack = 0;
474 ack |= LTC2945_write(LTC2945_I2C_ADDRESS, LTC2945_CONTROL_REG, LTC2945_VIN_SNAPSHOT);
475
476 uint8_t busy;
477 do
478 {
479 ack |= LTC2945_read(LTC2945_I2C_ADDRESS, LTC2945_CONTROL_REG, &busy);
480 }
481 while (0x8 & busy);
482
483 uint16_t VIN_code;
484 ack |= LTC2945_read_12_bits(LTC2945_I2C_ADDRESS, LTC2945_VIN_MSB_REG, &VIN_code);
485
486 float VIN;
487 VIN = LTC2945_VIN_code_to_voltage(VIN_code, LTC2945_VIN_lsb);
488 Serial.print(F("VIN: "));
489 Serial.print(VIN, 4);
490 Serial.print(F(" V"));
491 return(ack);
492 }
493
494 //! ADIN - Snapshot Mode
495 int8_t menu_2_snapshot_mode_menu_3_ADIN()
496 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
497 {
498 int8_t ack = 0;
499
500 ack |= LTC2945_write(LTC2945_I2C_ADDRESS, LTC2945_CONTROL_REG, LTC2945_ADIN_SNAPSHOT);
501
502 uint8_t busy;
503 do
504 {
505 ack |= LTC2945_read(LTC2945_I2C_ADDRESS, LTC2945_CONTROL_REG, &busy);
506 }
507 while (0x8 & busy);
508
509 uint16_t ADIN_code;
510 ack |= LTC2945_read_12_bits(LTC2945_I2C_ADDRESS, LTC2945_ADIN_MSB_REG, &ADIN_code);
511
512 float ADIN;
513 ADIN = LTC2945_ADIN_code_to_voltage(ADIN_code, LTC2945_ADIN_lsb);
514 Serial.print(F("ADIN: "));
515 Serial.print(ADIN, 4);
516 Serial.print(F(" V"));
517 return(ack);
518 }
519
520 //! Alert Menu
521 int8_t menu_3_alert(int8_t ADIN_or_SENSE) //!< Choose whether power multiplier uses ADIN pin or SENSE pin as voltage input (A0 bit in CONTROL Register A)
522 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
523 {
524 int8_t ack = 0;
525 int8_t user_command;
526 do
527 {
528 Serial.print(F("*************************\n\n"));
529 Serial.print(F("1-Set Power Alerts\n"));
530 Serial.print(F("2-Set Current Alerts\n"));
531 Serial.print(F("3-Set VIN Alerts\n"));
532 Serial.print(F("4-Set ADIN Alerts\n"));
533 Serial.print(F("5-Enable and Disable Alerts\n"));
534 Serial.print(F("6-Read and Clear Alerts\n"));
535 Serial.print(F("7-Store Alert Settings to EEPROM\n"));
536 Serial.print(F("m-Main Menu\n\n"));
537 Serial.print(F("Enter a command: "));
538
539 user_command = read_int();
540 if (user_command == 'm')
541 Serial.println("m");
542 else
543 Serial.println(user_command);
544 Serial.println();
545 switch (user_command)
546 {
547 case 1:
548 ack |= menu_3_alert_menu_1_set_power_alerts(ADIN_or_SENSE); // Set Power Alerts
549 break;
550
551 case 2:
552 ack |= menu_3_alert_menu_2_set_current_alerts(); // Set Current Alerts
553 break;
554
555 case 3:
556 ack |= menu_3_alert_menu_3_set_vin_alerts(); // Set VIN Alerts
557 break;
558
559 case 4:
560 ack |= menu_3_alert_menu_4_set_adin_alerts(); // Set ADIN Alerts
561 break;
562
563 case 5:
564 ack |= menu_3_alert_menu_5_enable_disable_alerts(); // Enable/Disable Alerts
565 break;
566
567 case 6:
568 ack |= menu_3_alert_menu_6_read_clear_alerts(); // Read Alerts
569 break;
570
571 case 7:
572 // Read current min/max alarm and store to EEPROM
573 store_alert_settings();
574 break;
575 default:
576 if (user_command != 'm')
577 Serial.println("Incorrect Option");
578 break;
579 }
580 }
581 while (!((user_command == 'm') || (ack)));
582 return(ack);
583 }
584
585 //! Set Power Alerts
586 int8_t menu_3_alert_menu_1_set_power_alerts(int8_t ADIN_or_SENSE) //!< Choose whether power multiplier uses ADIN pin or SENSE pin as voltage input (A0 bit in CONTROL Register A)
587 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
588 {
589 int8_t ack = 0;
590 Serial.print(F("Enter Max Power Threshold:"));
591
592 float max_power_threshold;
593 max_power_threshold = read_float();
594 Serial.println(max_power_threshold, 4);
595
596 int32_t max_power_threshold_code;
597 if (ADIN_or_SENSE == 1)
598 max_power_threshold_code = (max_power_threshold / LTC2945_Power_lsb) * resistor;
599 else
600 max_power_threshold_code = (max_power_threshold / LTC2945_ADIN_DELTA_SENSE_lsb) * resistor;
601
602 ack |= LTC2945_write_24_bits(LTC2945_I2C_ADDRESS, LTC2945_MAX_POWER_THRESHOLD_MSB2_REG, max_power_threshold_code);
603
604 Serial.print(F("Enter Min Power Threshold:"));
605
606 float min_power_threshold;
607 min_power_threshold = read_float();
608 Serial.println(min_power_threshold, 4);
609
610 int32_t min_power_threshold_code;
611 if (ADIN_or_SENSE == 1)
612 min_power_threshold_code = (min_power_threshold / LTC2945_Power_lsb) * resistor;
613 else
614 min_power_threshold_code = min_power_threshold / LTC2945_ADIN_DELTA_SENSE_lsb * resistor;
615 ack |= LTC2945_write_24_bits(LTC2945_I2C_ADDRESS, LTC2945_MIN_POWER_THRESHOLD_MSB2_REG, min_power_threshold_code);
616 return(ack);
617 }
618
619 //! Set Current Alerts
620 int8_t menu_3_alert_menu_2_set_current_alerts()
621 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
622 {
623 int8_t ack = 0;
624 Serial.print(F("Enter Max Current Threshold:"));
625
626 float max_current_threshold;
627 max_current_threshold = read_float();
628 Serial.println(max_current_threshold, 4);
629
630 int32_t max_current_threshold_code;
631 max_current_threshold_code = (max_current_threshold / LTC2945_DELTA_SENSE_lsb) * resistor;
632
633 ack |= LTC2945_write_16_bits(LTC2945_I2C_ADDRESS, LTC2945_MAX_DELTA_SENSE_THRESHOLD_MSB_REG, (max_current_threshold_code << 4));
634
635 Serial.print(F("Enter Min Current Threshold:"));
636
637 float min_current_threshold;
638 min_current_threshold = read_float();
639 Serial.println(min_current_threshold, 4);
640
641 int32_t min_current_threshold_code;
642 min_current_threshold_code = (min_current_threshold / LTC2945_DELTA_SENSE_lsb) * resistor;
643 ack |= LTC2945_write_16_bits(LTC2945_I2C_ADDRESS, LTC2945_MIN_DELTA_SENSE_THRESHOLD_MSB_REG, (min_current_threshold_code << 4));
644 return(ack);
645 }
646
647 //! Set VIN Alerts
648 int8_t menu_3_alert_menu_3_set_vin_alerts()
649 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
650 {
651 int8_t ack = 0;
652 Serial.print(F("Enter Max VIN Threshold:"));
653
654 float max_VIN_threshold;
655 max_VIN_threshold = read_float();
656 Serial.println(max_VIN_threshold, 4);
657
658 int32_t max_VIN_threshold_code;
659 max_VIN_threshold_code = max_VIN_threshold / LTC2945_VIN_lsb;
660 ack |= LTC2945_write_16_bits(LTC2945_I2C_ADDRESS, LTC2945_MAX_VIN_THRESHOLD_MSB_REG, (max_VIN_threshold_code << 4));
661
662 Serial.print(F("Enter Min VIN Threshold:"));
663
664 float min_VIN_threshold;
665 min_VIN_threshold = read_float();
666 Serial.println(min_VIN_threshold, 4);
667
668 int32_t min_VIN_threshold_code;
669 min_VIN_threshold_code = min_VIN_threshold / LTC2945_VIN_lsb;
670 ack |= LTC2945_write_16_bits(LTC2945_I2C_ADDRESS, LTC2945_MIN_VIN_THRESHOLD_MSB_REG, (min_VIN_threshold_code << 4));
671 return(ack);
672 }
673
674 //! Set ADIN Alerts
675 int8_t menu_3_alert_menu_4_set_adin_alerts()
676 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
677 {
678 int8_t ack = 0;
679 Serial.print(F("Enter Max ADIN Threshold:"));
680
681 float max_ADIN_threshold;
682 max_ADIN_threshold = read_float();
683 Serial.println(max_ADIN_threshold, 4);
684
685 int32_t max_ADIN_threshold_code;
686 max_ADIN_threshold_code = max_ADIN_threshold / LTC2945_ADIN_lsb;
687 ack |= LTC2945_write_16_bits(LTC2945_I2C_ADDRESS, LTC2945_MAX_ADIN_THRESHOLD_MSB_REG, (max_ADIN_threshold_code << 4));
688
689 Serial.print(F("Enter Min ADIN Threshold:"));
690
691 float min_ADIN_threshold;
692 min_ADIN_threshold = read_float();
693 Serial.println(min_ADIN_threshold, 4);
694
695 int32_t min_ADIN_threshold_code;
696 min_ADIN_threshold_code = min_ADIN_threshold / LTC2945_ADIN_lsb;
697 ack |= LTC2945_write_16_bits(LTC2945_I2C_ADDRESS, LTC2945_MIN_ADIN_THRESHOLD_MSB_REG, (min_ADIN_threshold_code << 4));
698 return(ack);
699 }
700
701 //! Enable/Disable Alerts
702 int8_t menu_3_alert_menu_5_enable_disable_alerts()
703 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
704 {
705 int8_t ack = 0;
706 uint8_t user_command;
707 do
708 {
709 Serial.print(F("*************************\n\n"));
710 Serial.print(F("1-Enable/Disable Power Alerts\n"));
711 Serial.print(F("2-Enable/Disable Current Alerts\n"));
712 Serial.print(F("3-Enable/Disable VIN Alerts\n"));
713 Serial.print(F("4-Enable/Disable ADIN Alerts\n"));
714 Serial.print(F("m-Alert Menu\n\n"));
715 Serial.print(F("Enter a command:"));
716 user_command = read_int();
717 if (user_command == 'm')
718 Serial.println('m');
719 else
720 Serial.println(user_command);
721 if (!(user_command == 0))
722 {
723 Serial.print(F("1-Enable, 2-Disable\n"));
724 }
725 switch (user_command)
726 {
727 case 1:
728 // ENABLE/Disable Power Alerts
729 Serial.print(F(" Max Power:"));
730 user_command = read_int();
731 if ((user_command > 2) || (user_command < 0))
732 user_command = 2;
733 Serial.println(user_command);
734 if (user_command == 1)
735 alert_code = alert_code | LTC2945_ENABLE_MAX_POWER_ALERT;
736 else
737 alert_code = alert_code & LTC2945_DISABLE_MAX_POWER_ALERT;
738
739 Serial.print(F(" Min Power:"));
740 user_command = read_int();
741 if ((user_command > 2) || (user_command < 0))
742 user_command = 2;
743 Serial.println(user_command);
744 if (user_command == 1)
745 alert_code = alert_code | LTC2945_ENABLE_MIN_POWER_ALERT;
746 else
747 alert_code = alert_code & LTC2945_DISABLE_MIN_POWER_ALERT;
748 break;
749 case 2:
750 // ENABLE/Disable Current Alerts
751 Serial.print(F(" Max Current:"));
752 user_command = read_int();
753 if ((user_command > 2) || (user_command < 0))
754 user_command = 2;
755 Serial.println(user_command);
756 if (user_command == 1)
757 alert_code = alert_code | LTC2945_ENABLE_MAX_DELTA_SENSE_ALERT;
758 else
759 alert_code = alert_code & LTC2945_DISABLE_MAX_DELTA_SENSE_ALERT;
760
761 Serial.print(F(" Min Current:"));
762 user_command = read_int();
763 if ((user_command > 2) || (user_command < 0))
764 user_command = 2;
765 Serial.println(user_command);
766 if (user_command == 1)
767 alert_code = alert_code | LTC2945_ENABLE_MIN_DELTA_SENSE_ALERT;
768 else
769 alert_code = alert_code & LTC2945_DISABLE_MIN_DELTA_SENSE_ALERT;
770 break;
771 case 3:
772 // ENABLE/Disable VIN Alerts
773 Serial.print(F(" Max VIN:"));
774 user_command = read_int();
775 if ((user_command > 2) || (user_command < 0))
776 user_command = 2;
777 Serial.println(user_command);
778 if (user_command == 1)
779 alert_code = alert_code | LTC2945_ENABLE_MAX_VIN_ALERT;
780 else
781 alert_code = alert_code & LTC2945_DISABLE_MAX_VIN_ALERT;
782
783 Serial.print(F(" Min VIN:"));
784 user_command = read_int();
785 if ((user_command > 2) || (user_command < 0))
786 user_command = 2;
787 Serial.println(user_command);
788 if (user_command == 1)
789 alert_code = alert_code | LTC2945_ENABLE_MIN_VIN_ALERT;
790 else
791 alert_code = alert_code & LTC2945_DISABLE_MIN_VIN_ALERT;
792 break;
793 case 4:
794 // ENABLE/Disable ADIN Alerts
795 Serial.print(F(" Max ADIN:"));
796 user_command = read_int();
797 if ((user_command > 2) || (user_command < 0))
798 user_command = 2;
799 Serial.println(user_command);
800 if (user_command == 1)
801 alert_code = alert_code | LTC2945_ENABLE_MAX_ADIN_ALERT;
802 else
803 alert_code = alert_code & LTC2945_DISABLE_MAX_ADIN_ALERT;
804
805 Serial.print(F(" Min ADIN:"));
806 user_command = read_int();
807 if ((user_command > 2) || (user_command < 0))
808 user_command = 2;
809 Serial.println(user_command);
810 if (user_command == 1)
811 alert_code = alert_code | LTC2945_ENABLE_MIN_ADIN_ALERT;
812 else
813 alert_code = alert_code & LTC2945_DISABLE_MIN_ADIN_ALERT;
814 break;
815 default:
816 if (user_command != 'm')
817 Serial.println("Incorrect Option");
818 break;
819 }
820 }
821 while (user_command != 'm');
822 ack |= LTC2945_write(LTC2945_I2C_ADDRESS, LTC2945_ALERT_REG, alert_code);
823 return(ack);
824 }
825
826 //! Read Alerts and Clear Alerts
827 int8_t menu_3_alert_menu_6_read_clear_alerts()
828 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
829 {
830 int8_t ack = 0;
831 ack |= LTC2945_read(LTC2945_I2C_ADDRESS, LTC2945_FAULT_CoR_REG, &alert_code);
832 if (alert_code & 0x80) Serial.print(F("Power Overvalue Fault Occurred\n\n"));
833 if (alert_code & 0x40) Serial.print(F("Power Undervalue Fault Occurred\n"));
834 if (alert_code & 0x20) Serial.print(F("Current Overvalue Fault Occurred\n"));
835 if (alert_code & 0x10) Serial.print(F("Current Undervalue Fault Occurred\n"));
836 if (alert_code & 0x08) Serial.print(F("VIN Overvalue Fault Occurred\n"));
837 if (alert_code & 0x04) Serial.print(F("VIN Undervalue Fault Occurred\n"));
838 if (alert_code & 0x02) Serial.print(F("ADIN Overvalue Fault Occurred\n"));
839 if (alert_code & 0x01) Serial.print(F("ADIN Undervalue Fault Occurred\n"));
840 if (!alert_code) Serial.print(F("No Alarms Were Present\n"));
841 return(ack);
842 }
843
844 //! Shutdown Down Mode
845 int8_t menu_4_shutdown()
846 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
847 {
848 int8_t ack = 0;
849
850 ack |= LTC2945_write(LTC2945_I2C_ADDRESS, LTC2945_CONTROL_REG, LTC2945_SHUTDOWN_MODE);
851 Serial.print(F("LTC2945 Has Been Shutdown\n"));
852 return(ack);
853 }
854
855 //! change Settings
856 void menu_5_settings(int8_t *VDD_or_SENSE_monitoring, //!< Choose whether VIN is sensed at VDD pin or SENSE pin (A2 bit of CONTROL Register A)
857 int8_t *ADIN_or_SENSE, //!< Choose whether power multiplier uses ADIN pin or SENSE pin as voltage input (A0 bit in CONTROL Register A)
858 float *scale) //!< Stores division ratio for resistive divider on ADIN pin.
859 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
860 {
861 Serial.print(F("VIN Monitor"));
862 Serial.print(F("\n0-VDD or 1-Sense+ Monitoring (Default=1)\n\n"));
863 *VDD_or_SENSE_monitoring = read_int();
864 if ((*VDD_or_SENSE_monitoring < 0) || (*VDD_or_SENSE_monitoring > 1))
865 *VDD_or_SENSE_monitoring = 1;
866 Serial.println(*VDD_or_SENSE_monitoring);
867 Serial.print(F("Multiplier Select\n"));
868 Serial.print(F("0-ADIN or 1-SENS+/VDD (Default=1)"));
869 *ADIN_or_SENSE = read_int();
870 if ((*ADIN_or_SENSE < 0) || (*ADIN_or_SENSE > 1))
871 *ADIN_or_SENSE = 1;
872 if (*ADIN_or_SENSE == 0)
873 {
874 Serial.print(F("\nresistor divider needs to be set such that New FS is 2.048v to ADIN\n"));
875 Serial.print(F("Enter in new full scale input voltage:"));
876 float user_float;
877 user_float = read_float();
878 *scale = user_float / 2.048;
879 Serial.println(user_float);
880 Serial.print(F("Scale:"));
881 Serial.println(*scale);
882 }
883 }
884
885 //! Clear Min/Max
886 int8_t menu_6_clear_min_max()
887 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
888 {
889 int8_t ack = 0;
890
891 ack |= LTC2945_write_24_bits(LTC2945_I2C_ADDRESS, LTC2945_MAX_POWER_MSB2_REG, LTC2945_MAX_POWER_MSB2_RESET);
892 ack |= LTC2945_write_24_bits(LTC2945_I2C_ADDRESS, LTC2945_MIN_POWER_MSB2_REG, LTC2945_MIN_POWER_MSB2_RESET);
893 ack |= LTC2945_write_16_bits(LTC2945_I2C_ADDRESS, LTC2945_MAX_DELTA_SENSE_MSB_REG, LTC2945_MAX_DELTA_SENSE_MSB_RESET);
894 ack |= LTC2945_write_16_bits(LTC2945_I2C_ADDRESS, LTC2945_MIN_DELTA_SENSE_MSB_REG, LTC2945_MIN_DELTA_SENSE_MSB_RESET);
895 ack |= LTC2945_write_16_bits(LTC2945_I2C_ADDRESS, LTC2945_MAX_VIN_MSB_REG, LTC2945_MAX_VIN_MSB_RESET);
896 ack |= LTC2945_write_16_bits(LTC2945_I2C_ADDRESS, LTC2945_MIN_VIN_MSB_REG, LTC2945_MIN_VIN_MSB_RESET);
897 ack |= LTC2945_write_16_bits(LTC2945_I2C_ADDRESS, LTC2945_MAX_ADIN_MSB_REG, LTC2945_MAX_ADIN_MSB_RESET);
898 ack |= LTC2945_write_16_bits(LTC2945_I2C_ADDRESS, LTC2945_MIN_ADIN_MSB_REG, LTC2945_MIN_ADIN_MSB_RESET);
899 Serial.println();
900 return(ack);
901 }
902
903 //! Used to manipulate EEPROM data.
904 union eeprom_data_union
905 {
906 struct data_struct_type //! EEPROM data structure
907 {
908 int16_t cal_key; //!< The key that keeps track of the calibration
909 uint8_t alert; //!< Used to store the alert settings
910 int32_t max_power_threshold; //!< Used to store max power alert settings
911 int32_t min_power_threshold; //!< Used to store min power alert settings
912 uint16_t max_delta_sense_thresh; //!< Used to store max delta sense alert settings
913 uint16_t min_delta_sense_thresh; //!< Used to store min delta sense alert settings
914 uint16_t max_Vin_thresh; //!< Used to store max Vin alert settings
915 uint16_t min_Vin_thresh; //!< Used to store min Vin alert settings
916 uint16_t max_adin_thresh; //!< Used to store adin max alert settings
917 uint16_t min_adin_thresh; //!< Used to store adin min alert settings
918 } data_struct; //!< Name of structure
919
920 char byte_array[sizeof(data_struct_type)]; //!< Array used to store the structure
921 };
922
923 //! Read the alert settings from EEPROM
924 int8_t restore_alert_settings()
925 //! @return Return 1 if successful, 0 if not
926 {
927 int16_t cal_key;
928
929 // Read the cal key from the EEPROM
930 eeprom_read_int16(EEPROM_I2C_ADDRESS, &cal_key, EEPROM_CAL_STATUS_ADDRESS);
931
932 if (cal_key == EEPROM_CAL_KEY)
933 {
934 // Calibration has been stored, read thresholds
935
936 eeprom_data_union eeprom;
937
938 eeprom_read_byte_array(EEPROM_I2C_ADDRESS, eeprom.byte_array, EEPROM_CAL_STATUS_ADDRESS, sizeof(eeprom_data_union));
939 alert_code = eeprom.data_struct.alert; // Global variable used to communicate with loop()
940
941 LTC2945_write(LTC2945_I2C_ADDRESS, LTC2945_ALERT_REG, eeprom.data_struct.alert);
942 LTC2945_write_24_bits(LTC2945_I2C_ADDRESS, LTC2945_MAX_POWER_THRESHOLD_MSB2_REG, eeprom.data_struct.max_power_threshold);
943 LTC2945_write_24_bits(LTC2945_I2C_ADDRESS, LTC2945_MIN_POWER_THRESHOLD_MSB2_REG, eeprom.data_struct.min_power_threshold);
944 LTC2945_write_16_bits(LTC2945_I2C_ADDRESS, LTC2945_MAX_DELTA_SENSE_THRESHOLD_MSB_REG, eeprom.data_struct.max_delta_sense_thresh);
945 LTC2945_write_16_bits(LTC2945_I2C_ADDRESS, LTC2945_MIN_DELTA_SENSE_THRESHOLD_MSB_REG, eeprom.data_struct.min_delta_sense_thresh);
946 LTC2945_write_16_bits(LTC2945_I2C_ADDRESS, LTC2945_MAX_VIN_THRESHOLD_MSB_REG, eeprom.data_struct.max_Vin_thresh);
947 LTC2945_write_16_bits(LTC2945_I2C_ADDRESS, LTC2945_MIN_VIN_THRESHOLD_MSB_REG, eeprom.data_struct.min_Vin_thresh);
948 LTC2945_write_16_bits(LTC2945_I2C_ADDRESS, LTC2945_MAX_ADIN_THRESHOLD_MSB_REG, eeprom.data_struct.max_adin_thresh);
949 LTC2945_write_16_bits(LTC2945_I2C_ADDRESS, LTC2945_MIN_ADIN_THRESHOLD_MSB_REG, eeprom.data_struct.min_adin_thresh);
950
951 Serial.println("Alert Settings Restored");
952 return(1);
953 }
954 else
955 {
956 Serial.println("Alert Settings not found");
957 return(0);
958 }
959 }
960
961 //! Store the alert settings to the EEPROM
962 void store_alert_settings()
963 {
964 eeprom_data_union eeprom;
965
966 eeprom.data_struct.cal_key = EEPROM_CAL_KEY;
967
968 LTC2945_read(LTC2945_I2C_ADDRESS, LTC2945_ALERT_REG, &eeprom.data_struct.alert);
969 LTC2945_read_24_bits(LTC2945_I2C_ADDRESS, LTC2945_MAX_POWER_THRESHOLD_MSB2_REG, &eeprom.data_struct.max_power_threshold);
970 LTC2945_read_24_bits(LTC2945_I2C_ADDRESS, LTC2945_MIN_POWER_THRESHOLD_MSB2_REG, &eeprom.data_struct.min_power_threshold);
971 LTC2945_read_16_bits(LTC2945_I2C_ADDRESS, LTC2945_MAX_DELTA_SENSE_THRESHOLD_MSB_REG, &eeprom.data_struct.max_delta_sense_thresh);
972 LTC2945_read_16_bits(LTC2945_I2C_ADDRESS, LTC2945_MIN_DELTA_SENSE_THRESHOLD_MSB_REG, &eeprom.data_struct.min_delta_sense_thresh);
973 LTC2945_read_16_bits(LTC2945_I2C_ADDRESS, LTC2945_MAX_VIN_THRESHOLD_MSB_REG, &eeprom.data_struct.max_Vin_thresh);
974 LTC2945_read_16_bits(LTC2945_I2C_ADDRESS, LTC2945_MIN_VIN_THRESHOLD_MSB_REG, &eeprom.data_struct.min_Vin_thresh);
975 LTC2945_read_16_bits(LTC2945_I2C_ADDRESS, LTC2945_MAX_ADIN_THRESHOLD_MSB_REG, &eeprom.data_struct.max_adin_thresh);
976 LTC2945_read_16_bits(LTC2945_I2C_ADDRESS, LTC2945_MIN_ADIN_THRESHOLD_MSB_REG, &eeprom.data_struct.min_adin_thresh);
977
978 eeprom_write_byte_array(EEPROM_I2C_ADDRESS, eeprom.byte_array, EEPROM_CAL_STATUS_ADDRESS, sizeof(eeprom_data_union));
979
980 Serial.println("Alert Settings Stored to EEPROM");
981 }
982
LTC2945_ENABLE_MAX_POWER_ALERT
#define LTC2945_ENABLE_MAX_POWER_ALERT
Definition: LTC2945.h:346
eeprom_read_byte_array
uint8_t eeprom_read_byte_array(uint8_t i2c_address, char *data, uint16_t address, uint8_t num_bytes)
Read a data byte at address from the EEPROM with i2c_address.
Definition: QuikEval_EEPROM.cpp:304
eeprom_data_union::data_struct_type::min_power_threshold
int32_t min_power_threshold
Used to store min power alert settings.
Definition: DC1697A.ino:911
eeprom_data_union::data_struct_type
EEPROM data structure.
Definition: DC2692A.ino:162
menu_6_clear_min_max
static int8_t menu_6_clear_min_max()
Clear Min/Max.
Definition: DC1697A.ino:886
LTC2945_MIN_ADIN_MSB_RESET
#define LTC2945_MIN_ADIN_MSB_RESET
Definition: LTC2945.h:344
eeprom_data_union::data_struct_type::min_Vin_thresh
uint16_t min_Vin_thresh
Used to store min Vin alert settings.
Definition: DC1697A.ino:915
store_alert_settings
static void store_alert_settings()
Store the alert settings to the EEPROM.
Definition: DC1697A.ino:962
eeprom_read_int16
uint8_t eeprom_read_int16(uint8_t i2c_address, int16_t *read_data, uint16_t address)
Read the two byte integer data from the EEPROM starting at address.
Definition: QuikEval_EEPROM.cpp:395
LTC2945_DELTA_SENSE_SNAPSHOT
#define LTC2945_DELTA_SENSE_SNAPSHOT
Definition: LTC2945.h:288
VIN
#define VIN
Definition: LTC2492_original.h:64
eeprom_data_union::data_struct_type::alert
uint8_t alert
Used to store the alert settings.
Definition: DC1697A.ino:909
eeprom_data_union::data_struct_type::min_adin_thresh
uint16_t min_adin_thresh
Used to store adin min alert settings.
Definition: DC1697A.ino:917
user_command
unsigned char user_command
Definition: Serial_EEPROM_Test.ino:75
EEPROM_I2C_ADDRESS
#define EEPROM_I2C_ADDRESS
Definition: QuikEval_EEPROM.h:60
menu_2_snapshot_mode
static int8_t menu_2_snapshot_mode(int8_t VDD_or_SENSE_monitoring, int8_t ADIN_or_SENSE)
Snapshot Mode Menu.
Definition: DC1697A.ino:381
LTC2945_DISABLE_MAX_ADIN_ALERT
#define LTC2945_DISABLE_MAX_ADIN_ALERT
Definition: LTC2945.h:363
print_prompt
static void print_prompt()
Print the Prompt.
Definition: DC1697A.ino:222
LTC2945_MIN_DELTA_SENSE_THRESHOLD_MSB_REG
#define LTC2945_MIN_DELTA_SENSE_THRESHOLD_MSB_REG
Definition: LTC2945.h:251
LTC2945_write_16_bits
int8_t LTC2945_write_16_bits(uint8_t i2c_address, uint8_t adc_command, uint16_t code)
Write a 16-bit code to the LTC2945.
Definition: LTC2945.cpp:88
LTC2945_code_to_ADIN_power
float LTC2945_code_to_ADIN_power(int32_t adc_code, float resistor, float LTC2945_ADIN_DELTA_SENSE_lsb)
Calculate the LTC2945 power with the ADIN.
Definition: LTC2945.cpp:200
LTC2945_MAX_ADIN_MSB_REG
#define LTC2945_MAX_ADIN_MSB_REG
Definition: LTC2945.h:267
LTC2945_ENABLE_MIN_DELTA_SENSE_ALERT
#define LTC2945_ENABLE_MIN_DELTA_SENSE_ALERT
Definition: LTC2945.h:352
LTC2945_DISABLE_MIN_VIN_ALERT
#define LTC2945_DISABLE_MIN_VIN_ALERT
Definition: LTC2945.h:359
eeprom_data_union::data_struct_type::cal_key
int16_t cal_key
The key that keeps track of the calibration.
Definition: DC2692A.ino:164
LTC2945_DISABLE_MIN_POWER_ALERT
#define LTC2945_DISABLE_MIN_POWER_ALERT
Definition: LTC2945.h:349
LTC2945_VIN_SNAPSHOT
#define LTC2945_VIN_SNAPSHOT
Definition: LTC2945.h:289
CONTINUOUS_MODE_DISPLAY_DELAY
#define CONTINUOUS_MODE_DISPLAY_DELAY
The delay between readings.
Definition: DC1697A.ino:109
LTC2945_CONTROL_REG
#define LTC2945_CONTROL_REG
Definition: LTC2945.h:221
LTC2945_code_to_current
float LTC2945_code_to_current(uint16_t adc_code, float resistor, float LTC2945_DELTA_SENSE_lsb)
Calculate the LTC2945 current with a sense resistor.
Definition: LTC2945.cpp:180
Linduino.h
Header File for Linduino Libraries and Demo Code.
LTC2945_I2C_ADDRESS
#define LTC2945_I2C_ADDRESS
Definition: LTC2945.h:153
LTC2945_read_16_bits
int8_t LTC2945_read_16_bits(uint8_t i2c_address, uint8_t adc_command, uint16_t *adc_code)
Reads a 16-bit adc_code from LTC2945.
Definition: LTC2945.cpp:137
LTC2945_ADIN_lsb
const float LTC2945_ADIN_lsb
Typical ADIN lsb weight in volts.
Definition: DC1697A.ino:112
menu_3_alert_menu_4_set_adin_alerts
static int8_t menu_3_alert_menu_4_set_adin_alerts()
Set ADIN Alerts.
Definition: DC1697A.ino:675
LTC2945_VIN_MSB_REG
#define LTC2945_VIN_MSB_REG
Definition: LTC2945.h:254
menu_2_snapshot_mode_menu_1_current
static int8_t menu_2_snapshot_mode_menu_1_current(int8_t VDD_or_SENSE_monitoring, int8_t ADIN_or_SENSE)
Current - Snapshot mode.
Definition: DC1697A.ino:440
eeprom_write_byte_array
uint8_t eeprom_write_byte_array(uint8_t i2c_address, char data[], uint16_t address, uint8_t num_bytes)
Write the data byte array to the EEPROM with i2c_address starting at EEPROM address.
Definition: QuikEval_EEPROM.cpp:234
LTC2945_MIN_VIN_MSB_REG
#define LTC2945_MIN_VIN_MSB_REG
Definition: LTC2945.h:258
LTC2945_FAULT_CoR_REG
#define LTC2945_FAULT_CoR_REG
Definition: LTC2945.h:225
LTC2945_MAX_POWER_THRESHOLD_MSB2_REG
#define LTC2945_MAX_POWER_THRESHOLD_MSB2_REG
Definition: LTC2945.h:236
LTC2945_read
int8_t LTC2945_read(uint8_t i2c_address, uint8_t adc_command, uint8_t *adc_code)
Reads an 8-bit adc_code from LTC2945.
Definition: LTC2945.cpp:112
eeprom_data_union::data_struct_type::max_delta_sense_thresh
uint16_t max_delta_sense_thresh
Used to store max delta sense alert settings.
Definition: DC1697A.ino:912
LTC2945_MAX_POWER_MSB2_REG
#define LTC2945_MAX_POWER_MSB2_REG
Definition: LTC2945.h:230
LTC2945_SENSE_MULTIPLIER
#define LTC2945_SENSE_MULTIPLIER
Definition: LTC2945.h:334
LTC2945_MAX_VIN_MSB_RESET
#define LTC2945_MAX_VIN_MSB_RESET
Definition: LTC2945.h:341
setup
static void setup()
Initialize Linduino.
Definition: DC1697A.ino:128
LTC2945_ENABLE_MIN_ADIN_ALERT
#define LTC2945_ENABLE_MIN_ADIN_ALERT
Definition: LTC2945.h:362
LTC2945_POWER_MSB2_REG
#define LTC2945_POWER_MSB2_REG
Definition: LTC2945.h:227
LTC2945_CONTINUOUS_MODE
#define LTC2945_CONTINUOUS_MODE
Definition: LTC2945.h:330
LTC2945_ADIN_MSB_REG
#define LTC2945_ADIN_MSB_REG
Definition: LTC2945.h:265
LTC2945_MIN_ADIN_THRESHOLD_MSB_REG
#define LTC2945_MIN_ADIN_THRESHOLD_MSB_REG
Definition: LTC2945.h:273
demo_board_connected
static int8_t demo_board_connected
Set to 1 if the board is connected.
Definition: DC1697A.ino:124
loop
static void loop()
Repeats Linduino loop.
Definition: DC1697A.ino:150
LTC2945_write
int8_t LTC2945_write(uint8_t i2c_address, uint8_t adc_command, uint8_t code)
Write an 8-bit code to the LTC2945.
Definition: LTC2945.cpp:76
LTC2945_MIN_VIN_MSB_RESET
#define LTC2945_MIN_VIN_MSB_RESET
Definition: LTC2945.h:342
menu_3_alert
static int8_t menu_3_alert(int8_t ADIN_or_SENSE)
Alert Menu.
Definition: DC1697A.ino:521
LTC2945_code_to_power
float LTC2945_code_to_power(int32_t adc_code, float resistor, float LTC2945_Power_lsb)
Calculate the LTC2945 power.
Definition: LTC2945.cpp:190
LTC2945_MIN_DELTA_SENSE_MSB_RESET
#define LTC2945_MIN_DELTA_SENSE_MSB_RESET
Definition: LTC2945.h:340
eeprom_data_union::data_struct_type::max_Vin_thresh
uint16_t max_Vin_thresh
Used to store max Vin alert settings.
Definition: DC1697A.ino:914
menu_3_alert_menu_2_set_current_alerts
static int8_t menu_3_alert_menu_2_set_current_alerts()
Set Current Alerts.
Definition: DC1697A.ino:620
menu_3_alert_menu_1_set_power_alerts
static int8_t menu_3_alert_menu_1_set_power_alerts(int8_t ADIN_or_SENSE)
Set Power Alerts.
Definition: DC1697A.ino:586
LTC2945_MIN_POWER_THRESHOLD_MSB2_REG
#define LTC2945_MIN_POWER_THRESHOLD_MSB2_REG
Definition: LTC2945.h:239
LTC2945_MAX_ADIN_MSB_RESET
#define LTC2945_MAX_ADIN_MSB_RESET
Definition: LTC2945.h:343
QuikEval_EEPROM.h
QuikEval EEPROM Library.
LTC2945_DELTA_SENSE_MSB_REG
#define LTC2945_DELTA_SENSE_MSB_REG
Definition: LTC2945.h:243
LTC2945_Power_lsb
const float LTC2945_Power_lsb
Typical POWER lsb weight in V^2.
Definition: DC1697A.ino:115
print_title
static void print_title()
Print the title block.
Definition: DC1697A.ino:209
LTC2945_ENABLE_MAX_DELTA_SENSE_ALERT
#define LTC2945_ENABLE_MAX_DELTA_SENSE_ALERT
Definition: LTC2945.h:351
LTC2945_MIN_ADIN_MSB_REG
#define LTC2945_MIN_ADIN_MSB_REG
Definition: LTC2945.h:269
eeprom_data_union
Used to manipulate EEPROM data.
Definition: DC2692A.ino:160
LTC2945_ENABLE_MAX_ADIN_ALERT
#define LTC2945_ENABLE_MAX_ADIN_ALERT
Definition: LTC2945.h:361
LTC2945_ADIN_code_to_voltage
float LTC2945_ADIN_code_to_voltage(uint16_t adc_code, float LTC2945_ADIN_lsb)
Calculate the LTC2945 ADIN voltage.
Definition: LTC2945.cpp:171
EEPROM_CAL_STATUS_ADDRESS
#define EEPROM_CAL_STATUS_ADDRESS
Definition: QuikEval_EEPROM.h:58
LTC2945_ENABLE_MAX_VIN_ALERT
#define LTC2945_ENABLE_MAX_VIN_ALERT
Definition: LTC2945.h:356
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
menu_3_alert_menu_6_read_clear_alerts
static int8_t menu_3_alert_menu_6_read_clear_alerts()
Read Alerts and Clear Alerts.
Definition: DC1697A.ino:827
menu_3_alert_menu_3_set_vin_alerts
static int8_t menu_3_alert_menu_3_set_vin_alerts()
Set VIN Alerts.
Definition: DC1697A.ino:648
LTC2945_SHUTDOWN_MODE
#define LTC2945_SHUTDOWN_MODE
Definition: LTC2945.h:331
LTC2945_VIN_code_to_voltage
float LTC2945_VIN_code_to_voltage(uint16_t adc_code, float LTC2945_VIN_lsb)
Calculate the LTC2945 VIN voltage.
Definition: LTC2945.cpp:162
LTC2945_MIN_POWER_MSB2_RESET
#define LTC2945_MIN_POWER_MSB2_RESET
Definition: LTC2945.h:338
LTC2945_DISABLE_MIN_ADIN_ALERT
#define LTC2945_DISABLE_MIN_ADIN_ALERT
Definition: LTC2945.h:364
LT_SPI.h
LT_SPI: Routines to communicate with ATmega328P&#39;s hardware SPI port.
eeprom_data_union::data_struct_type::max_power_threshold
int32_t max_power_threshold
Used to store max power alert settings.
Definition: DC1697A.ino:910
resistor
const float resistor
resistor value on demo board
Definition: DC1697A.ino:118
LTC2945_DISABLE_MAX_VIN_ALERT
#define LTC2945_DISABLE_MAX_VIN_ALERT
Definition: LTC2945.h:358
menu_1_continuous_mode
static int8_t menu_1_continuous_mode(int8_t VDD_or_SENSE_monitoring, int8_t ADIN_or_SENSE, float scale)
Continuous Mode.
Definition: DC1697A.ino:234
eeprom_data_union::data_struct_type::max_adin_thresh
uint16_t max_adin_thresh
Used to store adin max alert settings.
Definition: DC1697A.ino:916
LT_I2C.h
LT_I2C: Routines to communicate with ATmega328P&#39;s hardware I2C port.
LTC2945_MAX_DELTA_SENSE_MSB_REG
#define LTC2945_MAX_DELTA_SENSE_MSB_REG
Definition: LTC2945.h:245
LTC2945_ADIN_DELTA_SENSE_lsb
const float LTC2945_ADIN_DELTA_SENSE_lsb
Typical sense lsb weight in V^2 *ADIN_lsb * DELTA_SENSE_lsb.
Definition: DC1697A.ino:116
menu_5_settings
static void menu_5_settings(int8_t *VDD_or_SENSE_monitoring, int8_t *ADIN_or_SENSE, float *scale)
change Settings
Definition: DC1697A.ino:856
LTC2945_MAX_VIN_MSB_REG
#define LTC2945_MAX_VIN_MSB_REG
Definition: LTC2945.h:256
demo_name
char demo_name[]
Demo Board Name stored in QuikEval EEPROM.
Definition: DC1880A.ino:97
LTC2945_VIN_lsb
const float LTC2945_VIN_lsb
Typical VIN lsb weight in volts.
Definition: DC1697A.ino:114
UserInterface.h
eeprom
eeprom_data_union eeprom
Definition: DC2692A.ino:177
read_int
int32_t read_int()
Definition: UserInterface.cpp:93
restore_alert_settings
static int8_t restore_alert_settings()
Read the alert settings from EEPROM.
Definition: DC1697A.ino:924
LTC2945_MAX_DELTA_SENSE_THRESHOLD_MSB_REG
#define LTC2945_MAX_DELTA_SENSE_THRESHOLD_MSB_REG
Definition: LTC2945.h:249
read_float
float read_float()
Definition: UserInterface.cpp:78
LTC2945_ADIN_SNAPSHOT
#define LTC2945_ADIN_SNAPSHOT
Definition: LTC2945.h:290
eeprom_data_union::byte_array
char byte_array[sizeof(data_struct_type)]
Array used to store the structure.
Definition: DC2692A.ino:174
menu_4_shutdown
static int8_t menu_4_shutdown()
Shutdown Down Mode.
Definition: DC1697A.ino:845
eeprom_data_union::data_struct_type::min_delta_sense_thresh
uint16_t min_delta_sense_thresh
Used to store min delta sense alert settings.
Definition: DC1697A.ino:913
LTC2945_DISABLE_MAX_POWER_ALERT
#define LTC2945_DISABLE_MAX_POWER_ALERT
Definition: LTC2945.h:348
LTC2945_DISABLE_MAX_DELTA_SENSE_ALERT
#define LTC2945_DISABLE_MAX_DELTA_SENSE_ALERT
Definition: LTC2945.h:353
LTC2945_read_12_bits
int8_t LTC2945_read_12_bits(uint8_t i2c_address, uint8_t adc_command, uint16_t *adc_code)
Reads a 12-bit adc_code from LTC2945.
Definition: LTC2945.cpp:123
menu_2_snapshot_mode_menu_2_vin
static int8_t menu_2_snapshot_mode_menu_2_vin()
VIN - Snapshot Mode.
Definition: DC1697A.ino:470
quikeval_I2C_init
void quikeval_I2C_init(void)
Initializes Linduino I2C port.
Definition: LT_I2C.cpp:394
LTC2945_MAX_POWER_MSB2_RESET
#define LTC2945_MAX_POWER_MSB2_RESET
Definition: LTC2945.h:337
LTC2945_DELTA_SENSE_lsb
const float LTC2945_DELTA_SENSE_lsb
Typical Delta lsb weight in volts.
Definition: DC1697A.ino:113
LTC2945_read_24_bits
int8_t LTC2945_read_24_bits(uint8_t i2c_address, uint8_t adc_command, int32_t *adc_code)
Reads a 24-bit adc_code from LTC2945.
Definition: LTC2945.cpp:148
quikeval_I2C_connect
void quikeval_I2C_connect(void)
Switch MUX to connect I2C pins to QuikEval connector.
Definition: LT_I2C.cpp:401
LTC2945_MAX_DELTA_SENSE_MSB_RESET
#define LTC2945_MAX_DELTA_SENSE_MSB_RESET
Definition: LTC2945.h:339
LTC2945_ALERT_REG
#define LTC2945_ALERT_REG
Definition: LTC2945.h:222
current
static uint16_t current
the current measurement from the LTC3335&#39;s counter test mode.
Definition: DC2343A.ino:114
eeprom_data_union::data_struct
struct eeprom_data_union::data_struct_type data_struct
Name of structure.
LTC2945_MIN_VIN_THRESHOLD_MSB_REG
#define LTC2945_MIN_VIN_THRESHOLD_MSB_REG
Definition: LTC2945.h:262
LTC2945.h
LTC2945: 12-Bit Wide Range Power Monitor.
alert_code
static uint8_t alert_code
Value stored or read from ALERT register.
Definition: DC1697A.ino:125
ack_error
const char ack_error[]
Error message.
Definition: DC1697A.ino:121
LTC2945_MAX_ADIN_THRESHOLD_MSB_REG
#define LTC2945_MAX_ADIN_THRESHOLD_MSB_REG
Definition: LTC2945.h:271
EEPROM_CAL_KEY
#define EEPROM_CAL_KEY
Definition: QuikEval_EEPROM.h:59
LTC2945_ENABLE_MIN_VIN_ALERT
#define LTC2945_ENABLE_MIN_VIN_ALERT
Definition: LTC2945.h:357
menu_3_alert_menu_5_enable_disable_alerts
static int8_t menu_3_alert_menu_5_enable_disable_alerts()
Enable/Disable Alerts.
Definition: DC1697A.ino:702
LTC2945_write_24_bits
int8_t LTC2945_write_24_bits(uint8_t i2c_address, uint8_t adc_command, int32_t code)
Write a 24-bit code to the LTC2945.
Definition: LTC2945.cpp:98
LTC2945_MAX_VIN_THRESHOLD_MSB_REG
#define LTC2945_MAX_VIN_THRESHOLD_MSB_REG
Definition: LTC2945.h:260
LTC2945_ENABLE_MIN_POWER_ALERT
#define LTC2945_ENABLE_MIN_POWER_ALERT
Definition: LTC2945.h:347
LTC2945_MIN_DELTA_SENSE_MSB_REG
#define LTC2945_MIN_DELTA_SENSE_MSB_REG
Definition: LTC2945.h:247
LTC2945_DISABLE_MIN_DELTA_SENSE_ALERT
#define LTC2945_DISABLE_MIN_DELTA_SENSE_ALERT
Definition: LTC2945.h:354
menu_2_snapshot_mode_menu_3_ADIN
static int8_t menu_2_snapshot_mode_menu_3_ADIN()
ADIN - Snapshot Mode.
Definition: DC1697A.ino:495
LTC2945_MIN_POWER_MSB2_REG
#define LTC2945_MIN_POWER_MSB2_REG
Definition: LTC2945.h:233
LTC2945_SENSE_MONITOR
#define LTC2945_SENSE_MONITOR
Definition: LTC2945.h:335