Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
DC2561.ino
Go to the documentation of this file.
1 /*!
2 LTC2992: Dual Wide Range Power Monitor
3 
4 @verbatim
5 
6 Setting the Thresholds:
7  1. Select the Threshold Configuration from the main menu.
8  2. Select the desired Threshold to be changed. Then enter the minimum and maximum
9  values.
10  3. If any reading exceeds the set threshold, a fault will be generated that can be viewed in
11  the Read/Clear Faults Menu
12 
13 
14 Reading and Clearing a Fault:
15  1. Select the Read/Clear Fault option from the main menu.
16  2. To read all the faults, select Read Faults option. This will display all the faults that have occured.
17  3. To clear all faults, go back to the Read/Clear Faults menu and select Clear Faults option.
18 
19 NOTE: Due to memory limitations of the Atmega328 processor this sketch shows limited functionality of the LTC2992. Please
20  check the datasheet for a picture of the full functionality of the LTC2992.
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 DC2561A.
27 
28 USER INPUT DATA FORMAT:
29  decimal : 1024
30  hex : 0x400
31  octal : 02000 (leGPIOg 0 "zero")
32  binary : B10000000000
33  float : 1024.0
34 
35 @endverbatim
36 http://www.linear.com/product/LTC2992
37 
38 http://www.linear.com/product/LTC2992#demoboards
39 
40 Copyright 2018(c) Analog Devices, Inc.
41 
42 All rights reserved.
43 
44 Redistribution and use in source and binary forms, with or without
45 modification, are permitted provided that the following conditions are met:
46  - Redistributions of source code must retain the above copyright
47  notice, this list of conditions and the following disclaimer.
48  - Redistributions in binary form must reproduce the above copyright
49  notice, this list of conditions and the following disclaimer in
50  the documentation and/or other materials provided with the
51  distribution.
52  - Neither the name of Analog Devices, Inc. nor the names of its
53  contributors may be used to endorse or promote products derived
54  from this software without specific prior written permission.
55  - The use of this software may or may not infringe the patent rights
56  of one or more patent holders. This license does not release you
57  from the requirement that you obtain separate licenses from these
58  patent holders to use this software.
59  - Use of the software either in source or binary form, must be run
60  on or directly connected to an Analog Devices Inc. component.
61 
62 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
63 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
64 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
65 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
66 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
67 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
68 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
69 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
70 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
71 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
72  */
73 
74 /*! @file
75  @ingroup LTC2992
76 */
77 
78 #include <Arduino.h>
79 #include <stdint.h>
80 #include "Linduino.h"
81 #include "LT_I2C.h"
82 #include "LT_SPI.h"
83 #include "UserInterface.h"
84 #include "QuikEval_EEPROM.h"
85 #include "LTC2992.h"
86 #include <Wire.h>
87 #include <SPI.h>
88 
89 // Function Declaration
90 void print_title(); // Print the title block
91 void print_prompt(); // Print the Prompt
92 
93 int8_t menu_1_continuous_mode(int8_t CTRLA_mode, int8_t bit_resolution, float scale);
94 int8_t menu_2_threshold_config(float scale, int8_t bit_resolution);
95 int8_t menu_3_GPIO_config();
96 int8_t menu_4_settings(int8_t *CTRLA_mode, int8_t *bit_resolution);
98 
99 int8_t menu_2_threshold_menu_1_set_power(int8_t bit_resolution);
100 int8_t menu_2_threshold_menu_2_set_current(int8_t bit_resolution);
101 int8_t menu_2_threshold_menu_3_set_SENSE(int8_t bit_resolution);
102 int8_t menu_2_alert_menu_4_set_adin_alerts(float scale, int8_t bit_resolution);
104 
105 /* void store_alert_settings(); // Store the alert settings to the EEPROM
106 int8_t restore_alert_settings(); // Read the alert settings from EEPROM */
107 
108 #define CONTINUOUS_MODE_DISPLAY_DELAY 1000 //!< The delay between readings in continious mode
109 
110 // LSB Weights
111 const float LTC2992_GPIO_8bit_lsb = 8.000E-3; //!< Typical GPIO lsb weight for 8-bit mode in volts
112 const float LTC2992_GPIO_12bit_lsb = 0.500E-3; //!< Typical GPIO lsb weight for 12-bit mode in volts
113 const float LTC2992_DELTA_SENSE_8bit_lsb = 200.00E-6; //!< Typical Delta lsb weight for 8-bit mode in volts
114 const float LTC2992_DELTA_SENSE_12bit_lsb = 12.50E-6; //!< Typical Delta lsb weight for 12-bit mode in volts
115 const float LTC2992_SENSE_8bit_lsb = 400.00E-3; //!< Typical SENSE lsb weight for 8-bit mode in volts
116 const float LTC2992_SENSE_12bit_lsb = 25.00E-3; //!< Typical SENSE lsb weight for 12-bit mode in volts
117 const float LTC2992_Power_8bit_lsb = LTC2992_DELTA_SENSE_8bit_lsb*LTC2992_SENSE_8bit_lsb; //!< Typical POWER lsb weight for 8-bit mode in V^2
118 const float LTC2992_Power_12bit_lsb = LTC2992_DELTA_SENSE_12bit_lsb*LTC2992_SENSE_12bit_lsb; //!< Typical POWER lsb weight for 12-bit mode in V^2
119 
120 const float resistor = .01; //!< resistor value on demo board
121 
122 // Error string
123 const char ack_error[] = "Error: No Acknowledge. Check I2C Address."; //!< Error message
124 
125 // Global variables
126 static int8_t demo_board_connected; //!< Set to 1 if the board is connected
127 
128 
129 //! Initialize Linduino
130 void setup()
131 {
132  char demo_name[] = "DC2561"; // Demo Board Name stored in QuikEval EEPROM
133 
134  quikeval_I2C_init(); //! Configure the EEPROM I2C port for 100kHz
135  quikeval_I2C_connect(); //! Connects to main I2C port
136  Serial.begin(115200); //! Initialize the serial port to the PC
137  print_title();
140  {
141  Serial.println(F("Demo board not detected, will attempt to proceed"));
142  demo_board_connected = true;
143  }
145  {
146  // restore_alert_settings();
147  print_prompt();
148  }
149 }
150 
151 //! Repeats Linduino loop
152 void loop()
153 {
154  int8_t ack = 0; //! I2C acknowledge indicator
155  static uint8_t user_command; //! The user input command
156 
157  static int8_t CTRLA_mode = 0x00; //! CTRLA Register Setting Default.
158  static int8_t bit_resolution = 1; //! Variable to select ADC Resolution. 1 = 12-bit, 0 = 8-bit. Settable in Settings.
159 
160  static float scale = (150/3); //! Stores division ratio for resistive divider on GPIO pin. Configured inside "Settings" menu.
161 
162  if (demo_board_connected) //! Do nothing if the demo board is not connected
163  {
164  if (Serial.available()) //! Do nothing if serial is not available
165  {
166  user_command = read_int(); //! Read user input command
167  if (user_command != 'm')
168  Serial.println(user_command);
169  Serial.println();
170  ack = 0;
171  switch (user_command) //! Prints the appropriate submenu
172  {
173  case 1:
174  ack |= menu_1_continuous_mode(CTRLA_mode, bit_resolution, scale); //! Continuous Mode
175  break;
176 
177  case 2:
178  ack |= menu_2_threshold_config(scale, bit_resolution); //! Configure Threshold Values
179  break;
180 
181  case 3:
182  ack |= menu_3_GPIO_config(); //! Toggle GPIO States
183  break;
184 
185  case 4:
186  ack |= menu_4_settings(&CTRLA_mode, &bit_resolution); //! Configure ADC Resolution and Shutdown mode in Settings.
187  break;
188 
189  case 5:
190  ack |= menu_5_read_clear_faults(); //! Read/Clear Faults
191  break;
192 
193  default:
194  Serial.println(F("Incorrect Option"));
195  break;
196  }
197  if (ack != 0)
198  Serial.println(ack_error);
199  Serial.print(F("*************************"));
200  print_prompt();
201  }
202  }
203 }
204 
205 // Function Definitions
206 
207 //! Print the title block
209 {
210  Serial.println(F("\n*****************************************************************"));
211  Serial.print(F("* DC2561 Demonstration Program *\n"));
212  Serial.print(F("* *\n"));
213  Serial.print(F("* This program communicates with the LTC2992 12-Bit Dual Wide *\n"));
214  Serial.print(F("* Range I2C Power Monitor found on the DC2561 demo board. *\n"));
215  Serial.print(F("* Set the baud rate to 115200 and select the newline terminator.*\n"));
216  Serial.print(F("* *\n"));
217  Serial.print(F("*****************************************************************\n"));
218 }
219 
220 //! Print the Prompt
222 {
223  Serial.print(F("\n1-Continuous Mode\n"));
224  Serial.print(F("2-Threshold Configuration\n"));
225  Serial.print(F("3-GPIO Control\n"));
226  Serial.print(F("4-Settings\n"));
227  Serial.print(F("5-Read/Clear Faults\n\n"));
228  Serial.print(F("Enter a command: "));
229 }
230 
231 //! Continuous Mode.
232 int8_t menu_1_continuous_mode(int8_t CTRLA_mode, //!< Set Continious Mode
233  int8_t bit_resolution, //!< Set ADC Resolution
234  float scale) //!< Stores division ratio for resistive divider on GPIO pin. Configured inside "Settings" menu.
235 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
236 {
237  int8_t LTC2992_mode;
238  int8_t ack = 0;
240  Serial.println();
241  ack |= LTC2992_write(LTC2992_I2C_ADDRESS, LTC2992_CTRLA_REG, LTC2992_mode); //! Sets the LTC2992 to continuous mode
242  do
243  {
244 
245  Serial.print(F("**********************************************************************************************\n\n"));
246  Serial.print(F(" Channel 1 Channel 2\n\n"));
247  if (bit_resolution == 1)
248  {
249  uint32_t power1_code, power2_code, max_power1_code, max_power2_code, min_power1_code, min_power2_code;
256 
257  float power1, power2, max_power1, max_power2, min_power1, min_power2; // Store power results
260  max_power1 = LTC2992_code_to_power(max_power1_code, resistor, LTC2992_Power_12bit_lsb);
261  max_power2 = LTC2992_code_to_power(max_power2_code, resistor, LTC2992_Power_12bit_lsb);
262  min_power1 = LTC2992_code_to_power(min_power1_code, resistor, LTC2992_Power_12bit_lsb);
263  min_power2 = LTC2992_code_to_power(min_power2_code, resistor, LTC2992_Power_12bit_lsb);
264 
265  Serial.print(F(" Power 1: "));
266  Serial.print(power1, 4);
267  Serial.print(F(" W"));
268 
269  Serial.print(F(" Power 2: "));
270  Serial.print(power2, 4);
271  Serial.print(F(" W\n"));
272 
273  Serial.print(F(" Max Power 1: "));
274  Serial.print(max_power1, 4);
275  Serial.print(F(" W"));
276 
277  Serial.print(F(" Max Power 2: "));
278  Serial.print(max_power2, 4);
279  Serial.print(F(" W\n"));
280 
281  Serial.print(F(" Min Power 1: "));
282  Serial.print(min_power1, 4);
283  Serial.print(F(" W"));
284 
285  Serial.print(F(" Min Power 2: "));
286  Serial.print(min_power2, 4);
287  Serial.print(F(" W\n"));
288 
289  uint16_t current1_code, current2_code, max_current1_code, max_current2_code, min_current1_code, min_current2_code;
293 
297 
298  float current1, current2, max_current1, max_current2, min_current1, min_current2;
300  max_current1 = LTC2992_code_to_current(max_current1_code, resistor, LTC2992_DELTA_SENSE_12bit_lsb);
301  min_current1 = LTC2992_code_to_current(min_current1_code, resistor, LTC2992_DELTA_SENSE_12bit_lsb);
302 
304  max_current2 = LTC2992_code_to_current(max_current2_code, resistor, LTC2992_DELTA_SENSE_12bit_lsb);
305  min_current2 = LTC2992_code_to_current(min_current2_code, resistor, LTC2992_DELTA_SENSE_12bit_lsb);
306 
307  Serial.print(F("\n Current 1: "));
308  Serial.print(current1, 4);
309  Serial.print(F(" A"));
310 
311  Serial.print(F(" Current 2: "));
312  Serial.print(current2, 4);
313  Serial.print(F(" A\n"));
314 
315  Serial.print(F("Max Current 1: "));
316  Serial.print(max_current1, 4);
317  Serial.print(F(" A"));
318 
319  Serial.print(F(" Max Current 2: "));
320  Serial.print(max_current2, 4);
321  Serial.print(F(" A\n"));
322 
323  Serial.print(F("Min Current 1: "));
324  Serial.print(min_current1, 4);
325  Serial.print(F(" A"));
326 
327  Serial.print(F(" Min Current 2: "));
328  Serial.print(min_current2, 4);
329  Serial.print(F(" A\n"));
330 
331  uint16_t SENSE1_code, max_SENSE1_code, min_SENSE1_code;
335 
336  float SENSE1, max_SENSE1, min_SENSE1;
338  max_SENSE1 = LTC2992_SENSE_code_to_voltage(max_SENSE1_code, LTC2992_SENSE_12bit_lsb);
339  min_SENSE1 = LTC2992_SENSE_code_to_voltage(min_SENSE1_code, LTC2992_SENSE_12bit_lsb);
340 
341  uint16_t SENSE2_code, max_SENSE2_code, min_SENSE2_code;
345 
346  float SENSE2, max_SENSE2, min_SENSE2;
348  max_SENSE2 = LTC2992_SENSE_code_to_voltage(max_SENSE2_code, LTC2992_SENSE_12bit_lsb);
349  min_SENSE2 = LTC2992_SENSE_code_to_voltage(min_SENSE2_code, LTC2992_SENSE_12bit_lsb);
350 
351  Serial.print(F("\n SENSE 1: "));
352  Serial.print(SENSE1, 4);
353  Serial.print(F(" V"));
354 
355  Serial.print(F(" SENSE 2: "));
356  Serial.print(SENSE2, 4);
357  Serial.print(F(" V\n"));
358 
359  Serial.print(F(" Max SENSE 1: "));
360  Serial.print(max_SENSE1, 4);
361  Serial.print(F(" V"));
362 
363  Serial.print(F(" Max SENSE 2: "));
364  Serial.print(max_SENSE2, 4);
365  Serial.print(F(" V\n"));
366 
367  Serial.print(F(" Min SENSE 1: "));
368  Serial.print(min_SENSE1, 4);
369  Serial.print(F(" V"));
370 
371  Serial.print(F(" Min SENSE 2: "));
372  Serial.print(min_SENSE2, 4);
373  Serial.print(F(" V\n"));
374 
375  uint32_t power_sum_code;
376  uint16_t current_sum_code;
379 
380  float power_sum, current_sum;
381  power_sum = LTC2992_code_to_power_sum(power_sum_code, resistor, LTC2992_Power_12bit_lsb);
382  current_sum = LTC2992_code_to_current_sum(current_sum_code, resistor, LTC2992_DELTA_SENSE_12bit_lsb);
383 
384  Serial.print(F("\n Power Sum: "));
385  Serial.print(power_sum, 4);
386  Serial.print(F(" W\n"));
387 
388  Serial.print(F(" Current Sum: "));
389  Serial.print(current_sum, 4);
390  Serial.print(F(" A\n"));
391 
392  uint16_t GPIO1_code, max_GPIO1_code, min_GPIO1_code, GPIO2_code, max_GPIO2_code, min_GPIO2_code,
393  GPIO3_code, max_GPIO3_code, min_GPIO3_code, GPIO4_code, max_GPIO4_code, min_GPIO4_code;
397 
401 
405 
409 
410  float GPIO1, max_GPIO1, min_GPIO1, GPIO2, max_GPIO2, min_GPIO2, GPIO3, max_GPIO3, min_GPIO3, GPIO4, max_GPIO4, min_GPIO4;
412  max_GPIO1 = LTC2992_GPIO_code_to_voltage(max_GPIO1_code, LTC2992_GPIO_12bit_lsb);
413  min_GPIO1 = LTC2992_GPIO_code_to_voltage(min_GPIO1_code, LTC2992_GPIO_12bit_lsb);
414 
416  max_GPIO2 = LTC2992_GPIO_code_to_voltage(max_GPIO2_code, LTC2992_GPIO_12bit_lsb);
417  min_GPIO2 = LTC2992_GPIO_code_to_voltage(min_GPIO2_code, LTC2992_GPIO_12bit_lsb);
418 
420  max_GPIO3 = LTC2992_GPIO_code_to_voltage(max_GPIO3_code, LTC2992_GPIO_12bit_lsb);
421  min_GPIO3 = LTC2992_GPIO_code_to_voltage(min_GPIO3_code, LTC2992_GPIO_12bit_lsb);
422 
424  max_GPIO4 = LTC2992_GPIO_code_to_voltage(max_GPIO4_code, LTC2992_GPIO_12bit_lsb);
425  min_GPIO4 = LTC2992_GPIO_code_to_voltage(min_GPIO4_code, LTC2992_GPIO_12bit_lsb);
426 
427  Serial.print(F("\n GPIO1: "));
428  Serial.print(GPIO1*scale, 4);
429  Serial.print(F(" V"));
430 
431  Serial.print(F(" GPIO2: "));
432  Serial.print(GPIO2*scale, 4);
433  Serial.print(F(" V"));
434 
435  Serial.print(F(" GPIO3: "));
436  Serial.print(GPIO3, 4);
437  Serial.print(F(" V"));
438 
439  Serial.print(F(" GPIO4: "));
440  Serial.print(GPIO4, 4);
441  Serial.print(F(" V\n"));
442 
443  Serial.print(F("Max GPIO1: "));
444  Serial.print(max_GPIO1, 4);
445  Serial.print(F(" V"));
446 
447  Serial.print(F(" Max GPIO2: "));
448  Serial.print(max_GPIO2, 4);
449  Serial.print(F(" V"));
450 
451  Serial.print(F(" Max GPIO3: "));
452  Serial.print(max_GPIO3, 4);
453  Serial.print(F(" V"));
454 
455  Serial.print(F(" Max GPIO4: "));
456  Serial.print(max_GPIO4, 4);
457  Serial.print(F(" V\n"));
458 
459  Serial.print(F("Min GPIO1: "));
460  Serial.print(min_GPIO1, 4);
461  Serial.print(F(" V"));
462 
463  Serial.print(F(" Min GPIO2: "));
464  Serial.print(min_GPIO2, 4);
465  Serial.print(F(" V"));
466 
467  Serial.print(F(" Min GPIO3: "));
468  Serial.print(min_GPIO3, 4);
469  Serial.print(F(" V"));
470 
471  Serial.print(F(" Min GPIO4: "));
472  Serial.print(min_GPIO4, 4);
473  Serial.print(F(" V\n"));
474 
475  Serial.println();
476 
477  Serial.print(F("In 12 - bit mode\n"));
478 
479 
480  }
481  else
482  {
483 
484 
485 
486  uint32_t power1_code, power2_code, max_power1_code, max_power2_code, min_power1_code, min_power2_code;
493 
494  float power1, power2, max_power1, max_power2, min_power1, min_power2; // Store power results
495  power1 = LTC2992_code_to_power(power1_code>>8, resistor, LTC2992_Power_8bit_lsb);
496  power2 = LTC2992_code_to_power(power2_code>>8, resistor, LTC2992_Power_8bit_lsb);
497  max_power1 = LTC2992_code_to_power(max_power1_code>>8, resistor, LTC2992_Power_8bit_lsb);
498  max_power2 = LTC2992_code_to_power(max_power2_code>>8, resistor, LTC2992_Power_8bit_lsb);
499  min_power1 = LTC2992_code_to_power(min_power1_code>>8, resistor, LTC2992_Power_8bit_lsb);
500  min_power2 = LTC2992_code_to_power(min_power2_code>>8, resistor, LTC2992_Power_8bit_lsb);
501 
502  Serial.print(F(" Power 1: "));
503  Serial.print(power1, 4);
504  Serial.print(F(" W"));
505 
506  Serial.print(F(" Power 2: "));
507  Serial.print(power2, 4);
508  Serial.print(F(" W\n"));
509 
510  Serial.print(F(" Max Power 1: "));
511  Serial.print(max_power1, 4);
512  Serial.print(F(" W"));
513 
514  Serial.print(F(" Max Power 2: "));
515  Serial.print(max_power2, 4);
516  Serial.print(F(" W\n"));
517 
518  Serial.print(F(" Min Power 1: "));
519  Serial.print(min_power1, 4);
520  Serial.print(F(" W"));
521 
522  Serial.print(F(" Min Power 2: "));
523  Serial.print(min_power2, 4);
524  Serial.print(F(" W\n"));
525 
526  uint16_t current1_code, current2_code, max_current1_code, max_current2_code, min_current1_code, min_current2_code;
530 
534 
535  float current1, current2, max_current1, max_current2, min_current1, min_current2;
536  current1 = LTC2992_code_to_current(current1_code>>4, resistor, LTC2992_DELTA_SENSE_8bit_lsb);
537  max_current1 = LTC2992_code_to_current(max_current1_code>>4, resistor, LTC2992_DELTA_SENSE_8bit_lsb);
538  min_current1 = LTC2992_code_to_current(min_current1_code>>4, resistor, LTC2992_DELTA_SENSE_8bit_lsb);
539 
540  current2 = LTC2992_code_to_current(current2_code>>4, resistor, LTC2992_DELTA_SENSE_8bit_lsb);
541  max_current2 = LTC2992_code_to_current(max_current2_code>>4, resistor, LTC2992_DELTA_SENSE_8bit_lsb);
542  min_current2 = LTC2992_code_to_current(min_current2_code>>4, resistor, LTC2992_DELTA_SENSE_8bit_lsb);
543 
544  Serial.print(F("\n Current 1: "));
545  Serial.print(current1, 4);
546  Serial.print(F(" A"));
547 
548  Serial.print(F(" Current 2: "));
549  Serial.print(current2, 4);
550  Serial.print(F(" A\n"));
551 
552  Serial.print(F("Max Current 1: "));
553  Serial.print(max_current1, 4);
554  Serial.print(F(" A"));
555 
556  Serial.print(F(" Max Current 2: "));
557  Serial.print(max_current2, 4);
558  Serial.print(F(" A\n"));
559 
560  Serial.print(F("Min Current 1: "));
561  Serial.print(min_current1, 4);
562  Serial.print(F(" A"));
563 
564  Serial.print(F(" Min Current 2: "));
565  Serial.print(min_current2, 4);
566  Serial.print(F(" A\n"));
567 
568  uint16_t SENSE1_code, max_SENSE1_code, min_SENSE1_code;
572 
573  float SENSE1, max_SENSE1, min_SENSE1;
574  SENSE1 = LTC2992_SENSE_code_to_voltage(SENSE1_code>>4, LTC2992_SENSE_8bit_lsb);
575  max_SENSE1 = LTC2992_SENSE_code_to_voltage(max_SENSE1_code>>4, LTC2992_SENSE_8bit_lsb);
576  min_SENSE1 = LTC2992_SENSE_code_to_voltage(min_SENSE1_code>>4, LTC2992_SENSE_8bit_lsb);
577 
578  uint16_t SENSE2_code, max_SENSE2_code, min_SENSE2_code;
582 
583  float SENSE2, max_SENSE2, min_SENSE2;
584  SENSE2 = LTC2992_SENSE_code_to_voltage(SENSE2_code>>4, LTC2992_SENSE_8bit_lsb);
585  max_SENSE2 = LTC2992_SENSE_code_to_voltage(max_SENSE2_code>>4, LTC2992_SENSE_8bit_lsb);
586  min_SENSE2 = LTC2992_SENSE_code_to_voltage(min_SENSE2_code>>4, LTC2992_SENSE_8bit_lsb);
587 
588  Serial.print(F("\n SENSE 1: "));
589  Serial.print(SENSE1, 4);
590  Serial.print(F(" V"));
591 
592  Serial.print(F(" SENSE 2: "));
593  Serial.print(SENSE2, 4);
594  Serial.print(F(" V\n"));
595 
596  Serial.print(F(" Max SENSE 1: "));
597  Serial.print(max_SENSE1, 4);
598  Serial.print(F(" V"));
599 
600  Serial.print(F(" Max SENSE 2: "));
601  Serial.print(max_SENSE2, 4);
602  Serial.print(F(" V\n"));
603 
604  Serial.print(F(" Min SENSE 1: "));
605  Serial.print(min_SENSE1, 4);
606  Serial.print(F(" V"));
607 
608  Serial.print(F(" Min SENSE 2: "));
609  Serial.print(min_SENSE2, 4);
610  Serial.print(F(" V\n"));
611 
612  uint32_t power_sum_code;
613  uint16_t current_sum_code;
616 
617  float power_sum, current_sum;
618  power_sum = LTC2992_code_to_power_sum(power_sum_code>>8, resistor, LTC2992_Power_8bit_lsb);
619  current_sum = LTC2992_code_to_current_sum(current_sum_code>>4, resistor, LTC2992_DELTA_SENSE_8bit_lsb);
620 
621  Serial.print(F("\n Power Sum: "));
622  Serial.print(power_sum, 4);
623  Serial.print(F(" W\n"));
624 
625  Serial.print(F(" Current Sum: "));
626  Serial.print(current_sum, 4);
627  Serial.print(F(" A\n"));
628 
629  uint16_t GPIO1_code, max_GPIO1_code, min_GPIO1_code, GPIO2_code, max_GPIO2_code, min_GPIO2_code,
630  GPIO3_code, max_GPIO3_code, min_GPIO3_code, GPIO4_code, max_GPIO4_code, min_GPIO4_code;
634 
638 
642 
646 
647  float GPIO1, max_GPIO1, min_GPIO1, GPIO2, max_GPIO2, min_GPIO2, GPIO3, max_GPIO3, min_GPIO3, GPIO4, max_GPIO4, min_GPIO4;
648  GPIO1 = LTC2992_GPIO_code_to_voltage(GPIO1_code>>4, LTC2992_GPIO_8bit_lsb);
649  max_GPIO1 = LTC2992_GPIO_code_to_voltage(max_GPIO1_code>>4, LTC2992_GPIO_8bit_lsb);
650  min_GPIO1 = LTC2992_GPIO_code_to_voltage(min_GPIO1_code>>4, LTC2992_GPIO_8bit_lsb);
651 
652  GPIO2 = LTC2992_GPIO_code_to_voltage(GPIO2_code>>4, LTC2992_GPIO_8bit_lsb);
653  max_GPIO2 = LTC2992_GPIO_code_to_voltage(max_GPIO2_code>>4, LTC2992_GPIO_8bit_lsb);
654  min_GPIO2 = LTC2992_GPIO_code_to_voltage(min_GPIO2_code>>4, LTC2992_GPIO_8bit_lsb);
655 
656  GPIO3 = LTC2992_GPIO_code_to_voltage(GPIO3_code>>4, LTC2992_GPIO_8bit_lsb);
657  max_GPIO3 = LTC2992_GPIO_code_to_voltage(max_GPIO3_code>>4, LTC2992_GPIO_8bit_lsb);
658  min_GPIO3 = LTC2992_GPIO_code_to_voltage(min_GPIO3_code>>4, LTC2992_GPIO_8bit_lsb);
659 
660  GPIO4 = LTC2992_GPIO_code_to_voltage(GPIO4_code>>4, LTC2992_GPIO_8bit_lsb);
661  max_GPIO4 = LTC2992_GPIO_code_to_voltage(max_GPIO4_code>>4, LTC2992_GPIO_8bit_lsb);
662  min_GPIO4 = LTC2992_GPIO_code_to_voltage(min_GPIO4_code>>4, LTC2992_GPIO_8bit_lsb);
663 
664  Serial.print(F("\n GPIO1: "));
665  Serial.print(GPIO1*scale, 4);
666  Serial.print(F(" V"));
667 
668  Serial.print(F(" GPIO2: "));
669  Serial.print(GPIO2*scale, 4);
670  Serial.print(F(" V"));
671 
672  Serial.print(F(" GPIO3: "));
673  Serial.print(GPIO3, 4);
674  Serial.print(F(" V"));
675 
676  Serial.print(F(" GPIO4: "));
677  Serial.print(GPIO4, 4);
678  Serial.print(F(" V\n"));
679 
680  Serial.print(F("Max GPIO1: "));
681  Serial.print(max_GPIO1, 4);
682  Serial.print(F(" V"));
683 
684  Serial.print(F(" Max GPIO2: "));
685  Serial.print(max_GPIO2, 4);
686  Serial.print(F(" V"));
687 
688  Serial.print(F(" Max GPIO3: "));
689  Serial.print(max_GPIO3, 4);
690  Serial.print(F(" V"));
691 
692  Serial.print(F(" Max GPIO4: "));
693  Serial.print(max_GPIO4, 4);
694  Serial.print(F(" V\n"));
695 
696  Serial.print(F("Min GPIO1: "));
697  Serial.print(min_GPIO1, 4);
698  Serial.print(F(" V"));
699 
700  Serial.print(F(" Min GPIO2: "));
701  Serial.print(min_GPIO2, 4);
702  Serial.print(F(" V"));
703 
704  Serial.print(F(" Min GPIO3: "));
705  Serial.print(min_GPIO3, 4);
706  Serial.print(F(" V"));
707 
708  Serial.print(F(" Min GPIO4: "));
709  Serial.print(min_GPIO4, 4);
710  Serial.print(F(" V\n"));
711 
712  Serial.println();
713 
714 
715  Serial.print(F("In 8 - bit mode\n"));
716 
717  }
718 
719  Serial.print(F("\n\n**********************************************************************************************\n\n"));
720 
721  Serial.print(F("m-Main Menu\n\n"));
722  Serial.flush();
724  }
725  while (Serial.available() == false);
726  read_int(); // clears the Serial.available
727  return (ack);
728 }
729 
730 //! Configure Threshold Values
731 int8_t menu_2_threshold_config(float scale, //!< Stores division ratio for resistive divider on GPIO pin. Configured inside "Settings" menu.
732  int8_t bit_resolution) //!< Sets ADC Resolution
733 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
734 {
735  int8_t ack = 0;
736  int8_t user_command;
737  do
738  {
739  Serial.print(F("*************************\n\n"));
740  Serial.print(F("1-Set Power Threshold\n"));
741  Serial.print(F("2-Set Current Threshold\n"));
742  Serial.print(F("3-Set SENSE Threshold\n"));
743  Serial.print(F("4-Set GPIO Threshold\n"));
744  Serial.print(F("5-Reset Thresholds To Default\n"));
745  Serial.print(F("m-Main Menu\n\n"));
746  Serial.print(F("Enter a command: "));
747 
748  user_command = read_int();
749  if (user_command == 'm')
750  Serial.println(F("m"));
751  else
752  Serial.println(user_command);
753  Serial.println();
754  switch (user_command)
755  {
756  case 1:
757  ack |= menu_2_threshold_menu_1_set_power(bit_resolution); //! Set Power Min/Max Thresholds
758  break;
759 
760  case 2:
761  ack |= menu_2_threshold_menu_2_set_current(bit_resolution); //! Set Current Min/Max Thresholds
762  break;
763 
764  case 3:
765  ack |= menu_2_threshold_menu_3_set_SENSE(bit_resolution); //! Set Voltage Min/Max Thresholds
766  break;
767 
768  case 4:
769  ack |= menu_2_alert_menu_4_set_adin_alerts(scale, bit_resolution); //! Set GPIO Min/Max Thresholds
770  break;
771  case 5:
772  ack |= menu_2_threshold_menu_5_reset_thresholds(); //! Set All Min/Max Thresholds to Default Value
773  break;
774 
775  default:
776  if (user_command != 'm')
777  Serial.println(F("Incorrect Option"));
778  break;
779  }
780  }
781  while (!((user_command == 'm') || (ack)));
782  return (ack);
783 }
784 //! Set Power Min/Max Values
785 int8_t menu_2_threshold_menu_1_set_power(int8_t bit_resolution) //!< Sets ADC Resolution
786 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
787 {
788 
789  int8_t ack = 0;
790  Serial.print(F("Enter Max Channel 1 Power Threshold:"));
791 
792  float max_power_threshold;
793  max_power_threshold = read_float();
794  Serial.println(max_power_threshold, 4);
795 
796  uint32_t max_power_threshold_code;
797  if (bit_resolution == 1)
798  {
799  max_power_threshold_code = (max_power_threshold / LTC2992_Power_12bit_lsb) * resistor;
801  }
802  else
803  {
804  max_power_threshold_code = (max_power_threshold / LTC2992_Power_8bit_lsb) * resistor;
806  }
807  Serial.print(F("Enter Min Channel 1 Power Threshold:"));
808 
809  float min_power_threshold;
810  min_power_threshold = read_float();
811  Serial.println(min_power_threshold, 4);
812  Serial.println();
813 
814  uint32_t min_power_threshold_code;
815  if (bit_resolution == 1)
816  {
817  min_power_threshold_code = (min_power_threshold / LTC2992_Power_12bit_lsb) * resistor;
819 
820  }
821  else
822  {
823  min_power_threshold_code = (min_power_threshold / LTC2992_Power_8bit_lsb) * resistor;
825  }
826  Serial.print(F("Enter Max Channel 2 Power Threshold:"));
827  max_power_threshold = read_float();
828  Serial.println(max_power_threshold, 4);
829 
830  if (bit_resolution == 1)
831  {
832  max_power_threshold_code = (max_power_threshold / LTC2992_Power_12bit_lsb) * resistor;
834 
835  }
836  else
837  {
838  max_power_threshold_code = (max_power_threshold / LTC2992_Power_8bit_lsb) * resistor;
840  }
841  Serial.print(F("Enter Min Channel 2 Power Threshold:"));
842 
843  min_power_threshold = read_float();
844  Serial.println(min_power_threshold, 4);
845  Serial.println();
846 
847  if (bit_resolution == 1)
848  {
849  min_power_threshold_code = (min_power_threshold / LTC2992_Power_12bit_lsb) * resistor;
851 
852  }
853  else
854  {
855  min_power_threshold_code = (min_power_threshold / LTC2992_Power_8bit_lsb) * resistor;
857  }
858  Serial.print(F("Enter Max Power SUM Threshold:"));
859  max_power_threshold = read_float();
860  Serial.println(max_power_threshold, 4);
861 
862  if (bit_resolution == 1)
863  {
864  max_power_threshold_code = (max_power_threshold / (2 * LTC2992_Power_12bit_lsb)) * resistor;
866 
867  }
868  else
869  {
870  max_power_threshold_code = (max_power_threshold / (2 * LTC2992_Power_8bit_lsb)) * resistor;
872  }
873 
874  Serial.print(F("Enter Min Power Sum Threshold:"));
875 
876  min_power_threshold = read_float();
877  Serial.println(min_power_threshold, 4);
878  Serial.println();
879  if (bit_resolution == 1)
880  {
881  min_power_threshold_code = (min_power_threshold / (2 * LTC2992_Power_12bit_lsb)) * resistor;
883  }
884  else
885  {
886  min_power_threshold_code = (min_power_threshold / (2 * LTC2992_Power_8bit_lsb)) * resistor;
888  }
889 
890  return (ack);
891 }
892 
893 //! Set Min/Max Current Threshold
894 int8_t menu_2_threshold_menu_2_set_current(int8_t bit_resolution) //!< Sets ADC Resolution
895 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
896 
897 {
898  int8_t ack = 0;
899  Serial.print(F("Enter Max Channel 1 Current Threshold:"));
900 
901  float max_current_threshold;
902  max_current_threshold = read_float();
903  Serial.println(max_current_threshold, 4);
904 
905  uint16_t max_current_threshold_code;
906  if (bit_resolution == 1)
907  {
908  max_current_threshold_code = (max_current_threshold / LTC2992_DELTA_SENSE_12bit_lsb) * resistor;
910 
911  }
912  else
913  {
914  max_current_threshold_code = (max_current_threshold / LTC2992_DELTA_SENSE_8bit_lsb) * resistor;
916  }
917 
918  Serial.print(F("Enter Min Channel 1 Current Threshold:"));
919 
920  float min_current_threshold;
921  min_current_threshold = read_float();
922  Serial.println(min_current_threshold, 4);
923  Serial.println();
924 
925  uint16_t min_current_threshold_code;
926  if (bit_resolution == 1)
927  {
928  min_current_threshold_code = (min_current_threshold / LTC2992_DELTA_SENSE_12bit_lsb) * resistor;
930  }
931  else
932  {
933  min_current_threshold_code = (min_current_threshold / LTC2992_DELTA_SENSE_8bit_lsb) * resistor;
935 
936  }
937 
938  Serial.print(F("Enter Max Channel 2 Current Threshold:"));
939  max_current_threshold = read_float();
940  Serial.println(max_current_threshold, 4);
941 
942  if (bit_resolution == 1)
943  {
944  max_current_threshold_code = (max_current_threshold / LTC2992_DELTA_SENSE_12bit_lsb) * resistor;
946  }
947  else
948  {
949  max_current_threshold_code = (max_current_threshold / LTC2992_DELTA_SENSE_8bit_lsb) * resistor;
951  }
952  Serial.print(F("Enter Min Channel 2 Current Threshold:"));
953 
954  min_current_threshold = read_float();
955  Serial.println(min_current_threshold, 4);
956  Serial.println();
957 
958  if (bit_resolution == 1)
959  {
960  min_current_threshold_code = (min_current_threshold / LTC2992_DELTA_SENSE_12bit_lsb) * resistor;
962 
963  }
964  else
965  {
966  min_current_threshold_code = (min_current_threshold / LTC2992_DELTA_SENSE_8bit_lsb) * resistor;
968  }
969  Serial.print(F("Enter Max Current Sum Threshold:"));
970  max_current_threshold = read_float();
971  Serial.println(max_current_threshold, 4);
972 
973  if (bit_resolution == 1)
974  {
975  max_current_threshold_code = (max_current_threshold / (2 * LTC2992_DELTA_SENSE_12bit_lsb)) * resistor;
976  ack |= LTC2992_write_16_bits(LTC2992_I2C_ADDRESS, LTC2992_MAX_ISUM_THRESHOLD_MSB_REG, (max_current_threshold_code << 4));
977  }
978  else
979  {
980  max_current_threshold_code = (max_current_threshold / (2 * LTC2992_DELTA_SENSE_8bit_lsb)) * resistor;
981  ack |= LTC2992_write_16_bits(LTC2992_I2C_ADDRESS, LTC2992_MAX_ISUM_THRESHOLD_MSB_REG, (max_current_threshold_code << 8));
982  }
983  Serial.print(F("Enter Min Current Sum Threshold:"));
984 
985  min_current_threshold = read_float();
986  Serial.println(min_current_threshold, 4);
987  Serial.println();
988  if (bit_resolution == 1)
989  {
990  min_current_threshold_code = (min_current_threshold / (2 * LTC2992_DELTA_SENSE_12bit_lsb)) * resistor;
991  ack |= LTC2992_write_16_bits(LTC2992_I2C_ADDRESS, LTC2992_MIN_ISUM_THRESHOLD_MSB_REG, (min_current_threshold_code << 4));
992 
993  }
994  else
995  {
996  min_current_threshold_code = (min_current_threshold / (2 * LTC2992_DELTA_SENSE_8bit_lsb)) * resistor;
997  ack |= LTC2992_write_16_bits(LTC2992_I2C_ADDRESS, LTC2992_MIN_ISUM_THRESHOLD_MSB_REG, (min_current_threshold_code << 8));
998  }
999 
1000  return (ack);
1001 }
1002 
1003 //! Set Min/Max Voltage Thresholds
1004 int8_t menu_2_threshold_menu_3_set_SENSE(int8_t bit_resolution)
1005 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
1006 {
1007  int8_t ack = 0;
1008  Serial.print(F("Enter Max Channel 1 SENSE Threshold:"));
1009 
1010  float max_sense_threshold;
1011  max_sense_threshold = read_float();
1012  Serial.println(max_sense_threshold, 4);
1013 
1014  uint16_t max_sense_threshold_code;
1015  if (bit_resolution == 1)
1016  {
1017  max_sense_threshold_code = (max_sense_threshold / LTC2992_SENSE_12bit_lsb);
1018  ack |= LTC2992_write_16_bits(LTC2992_I2C_ADDRESS, LTC2992_MAX_SENSE1_THRESHOLD_MSB_REG, (max_sense_threshold_code << 4));
1019  }
1020  else
1021  {
1022  max_sense_threshold_code = (max_sense_threshold / LTC2992_SENSE_8bit_lsb);
1023  ack |= LTC2992_write_16_bits(LTC2992_I2C_ADDRESS, LTC2992_MAX_SENSE1_THRESHOLD_MSB_REG, (max_sense_threshold_code << 8));
1024  }
1025  Serial.print(F("Enter Min Channel 1 SENSE Threshold:"));
1026 
1027  float min_sense_threshold;
1028  min_sense_threshold = read_float();
1029  Serial.println(min_sense_threshold, 4);
1030  Serial.println();
1031 
1032  uint16_t min_sense_threshold_code;
1033  if (bit_resolution == 1)
1034  {
1035  min_sense_threshold_code = (min_sense_threshold / LTC2992_SENSE_12bit_lsb);
1036  ack |= LTC2992_write_16_bits(LTC2992_I2C_ADDRESS, LTC2992_MIN_SENSE1_THRESHOLD_MSB_REG, (min_sense_threshold_code << 4));
1037 
1038  }
1039  else
1040  {
1041  min_sense_threshold_code = (min_sense_threshold / LTC2992_SENSE_8bit_lsb);
1042  ack |= LTC2992_write_16_bits(LTC2992_I2C_ADDRESS, LTC2992_MIN_SENSE1_THRESHOLD_MSB_REG, (min_sense_threshold_code << 8));
1043  }
1044  Serial.print(F("Enter Max Channel 2 SENSE Threshold:"));
1045  max_sense_threshold = read_float();
1046  Serial.println(max_sense_threshold, 4);
1047 
1048  if (bit_resolution == 1)
1049  {
1050  max_sense_threshold_code = (max_sense_threshold / LTC2992_SENSE_12bit_lsb);
1051  ack |= LTC2992_write_16_bits(LTC2992_I2C_ADDRESS, LTC2992_MAX_SENSE2_THRESHOLD_MSB_REG, (max_sense_threshold_code << 4));
1052  }
1053  else
1054  {
1055  max_sense_threshold_code = (max_sense_threshold / LTC2992_SENSE_8bit_lsb);
1056  ack |= LTC2992_write_16_bits(LTC2992_I2C_ADDRESS, LTC2992_MAX_SENSE2_THRESHOLD_MSB_REG, (max_sense_threshold_code << 8));
1057  }
1058 
1059  Serial.print(F("Enter Min Channel 2 SENSE Threshold:"));
1060 
1061  min_sense_threshold = read_float();
1062  Serial.println(min_sense_threshold, 4);
1063  Serial.println();
1064 
1065  if (bit_resolution == 1)
1066  {
1067  min_sense_threshold_code = (min_sense_threshold / LTC2992_SENSE_12bit_lsb);
1068  ack |= LTC2992_write_16_bits(LTC2992_I2C_ADDRESS, LTC2992_MIN_SENSE2_THRESHOLD_MSB_REG, (min_sense_threshold_code << 4));
1069  }
1070  else
1071  {
1072  min_sense_threshold_code = (min_sense_threshold / LTC2992_SENSE_8bit_lsb);
1073  ack |= LTC2992_write_16_bits(LTC2992_I2C_ADDRESS, LTC2992_MIN_SENSE2_THRESHOLD_MSB_REG, (min_sense_threshold_code << 8));
1074  }
1075 
1076 
1077  return (ack);
1078 }
1079 //Set Min/Max GPIO Thresholds
1080 int8_t menu_2_alert_menu_4_set_adin_alerts(float scale, //!< Stores division ratio for resistive divider on GPIO pin. Configured inside "Settings" menu.
1081  int8_t bit_resolution) //!< Sets ADC Resolution
1082 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
1083 {
1084  int8_t ack = 0;
1085  Serial.print(F("Enter Max GPIO1 Threshold (Range: 0V - 100V):"));
1086 
1087  float max_gpio_threshold;
1088  max_gpio_threshold = read_float();
1089  Serial.println(max_gpio_threshold, 4);
1090 
1091  uint16_t max_gpio_threshold_code;
1092  if (bit_resolution == 1)
1093  {
1094  max_gpio_threshold_code = (1 / scale) * (max_gpio_threshold / LTC2992_GPIO_12bit_lsb);
1095  ack |= LTC2992_write_16_bits(LTC2992_I2C_ADDRESS, LTC2992_MAX_GPIO1_THRESHOLD_MSB_REG, (max_gpio_threshold_code << 4));
1096  }
1097  else
1098  {
1099  max_gpio_threshold_code = (1 / scale) * (max_gpio_threshold / LTC2992_GPIO_8bit_lsb);
1100  ack |= LTC2992_write_16_bits(LTC2992_I2C_ADDRESS, LTC2992_MAX_GPIO1_THRESHOLD_MSB_REG, (max_gpio_threshold_code << 8));
1101  }
1102  Serial.print(F("Enter Min GPIO1 Threshold (Range: 0V - 100V):"));
1103 
1104  float min_gpio_threshold;
1105  min_gpio_threshold = read_float();
1106  Serial.println(min_gpio_threshold, 4);
1107  Serial.println();
1108 
1109  uint16_t min_gpio_threshold_code;
1110  if (bit_resolution == 1)
1111  {
1112  min_gpio_threshold_code = (1 / scale) * (min_gpio_threshold / LTC2992_GPIO_12bit_lsb);
1113  ack |= LTC2992_write_16_bits(LTC2992_I2C_ADDRESS, LTC2992_MIN_GPIO1_THRESHOLD_MSB_REG, (min_gpio_threshold_code << 4));
1114  }
1115  else
1116  {
1117  min_gpio_threshold_code = (1 / scale) * (min_gpio_threshold / LTC2992_GPIO_8bit_lsb);
1118  ack |= LTC2992_write_16_bits(LTC2992_I2C_ADDRESS, LTC2992_MIN_GPIO1_THRESHOLD_MSB_REG, (min_gpio_threshold_code << 8));
1119  }
1120 
1121  Serial.print(F("Enter Max GPIO2 Threshold (Range: 0V - 100V):"));
1122  max_gpio_threshold = read_float();
1123  Serial.println(max_gpio_threshold, 4);
1124 
1125  if (bit_resolution == 1)
1126  {
1127  max_gpio_threshold_code = (1 / scale) * (max_gpio_threshold / LTC2992_GPIO_12bit_lsb);
1128  ack |= LTC2992_write_16_bits(LTC2992_I2C_ADDRESS, LTC2992_MAX_GPIO2_THRESHOLD_MSB_REG, (max_gpio_threshold_code << 4));
1129  }
1130  else
1131  {
1132  max_gpio_threshold_code = (1 / scale) * (max_gpio_threshold / LTC2992_GPIO_8bit_lsb);
1133  ack |= LTC2992_write_16_bits(LTC2992_I2C_ADDRESS, LTC2992_MAX_GPIO2_THRESHOLD_MSB_REG, (max_gpio_threshold_code << 8));
1134  }
1135 
1136  Serial.print(F("Enter Min GPIO2 Threshold (Range: 0V - 100V):"));
1137 
1138  min_gpio_threshold = read_float();
1139  Serial.println(min_gpio_threshold, 4);
1140  Serial.println();
1141 
1142  if (bit_resolution == 1)
1143  {
1144  min_gpio_threshold_code = (1 / scale) * (min_gpio_threshold / LTC2992_GPIO_12bit_lsb);
1145  ack |= LTC2992_write_16_bits(LTC2992_I2C_ADDRESS, LTC2992_MIN_GPIO2_THRESHOLD_MSB_REG, (min_gpio_threshold_code << 4));
1146  }
1147  else
1148  {
1149  min_gpio_threshold_code = (1 / scale) * (min_gpio_threshold / LTC2992_GPIO_8bit_lsb);
1150  ack |= LTC2992_write_16_bits(LTC2992_I2C_ADDRESS, LTC2992_MIN_GPIO2_THRESHOLD_MSB_REG, (min_gpio_threshold_code << 8));
1151  }
1152 
1153  Serial.print(F("Enter Max GPIO3 Threshold (Range: 0V - 2.048V):"));
1154  max_gpio_threshold = read_float();
1155  Serial.println(max_gpio_threshold, 4);
1156 
1157  if (bit_resolution == 1)
1158  {
1159  max_gpio_threshold_code = (max_gpio_threshold / LTC2992_GPIO_12bit_lsb);
1160  ack |= LTC2992_write_16_bits(LTC2992_I2C_ADDRESS, LTC2992_MAX_GPIO3_THRESHOLD_MSB_REG, (max_gpio_threshold_code << 4));
1161  }
1162  else
1163  {
1164  max_gpio_threshold_code = (max_gpio_threshold / LTC2992_GPIO_8bit_lsb);
1165  ack |= LTC2992_write_16_bits(LTC2992_I2C_ADDRESS, LTC2992_MAX_GPIO3_THRESHOLD_MSB_REG, (max_gpio_threshold_code << 8));
1166  }
1167 
1168  Serial.print(F("Enter Min GPIO3 Threshold (Range: 0V - 2.048V):"));
1169 
1170  min_gpio_threshold = read_float();
1171  Serial.println(min_gpio_threshold, 4);
1172  Serial.println();
1173 
1174  if (bit_resolution == 1)
1175  {
1176  min_gpio_threshold_code = (min_gpio_threshold / LTC2992_GPIO_12bit_lsb);
1177  ack |= LTC2992_write_16_bits(LTC2992_I2C_ADDRESS, LTC2992_MIN_GPIO3_THRESHOLD_MSB_REG, (min_gpio_threshold_code << 4));
1178  }
1179  else
1180  {
1181  min_gpio_threshold_code = (min_gpio_threshold / LTC2992_GPIO_8bit_lsb);
1182  ack |= LTC2992_write_16_bits(LTC2992_I2C_ADDRESS, LTC2992_MIN_GPIO3_THRESHOLD_MSB_REG, (min_gpio_threshold_code << 8));
1183  }
1184 
1185  Serial.print(F("Enter Max GPIO4 Threshold (Range: 0V - 2.048V):"));
1186  max_gpio_threshold = read_float();
1187  Serial.println(max_gpio_threshold, 4);
1188 
1189  if (bit_resolution == 1)
1190  {
1191  max_gpio_threshold_code = (max_gpio_threshold / LTC2992_GPIO_12bit_lsb);
1192  ack |= LTC2992_write_16_bits(LTC2992_I2C_ADDRESS, LTC2992_MAX_GPIO4_THRESHOLD_MSB_REG, (max_gpio_threshold_code << 4));
1193  }
1194  else
1195  {
1196  max_gpio_threshold_code = (max_gpio_threshold / LTC2992_GPIO_8bit_lsb);
1197  ack |= LTC2992_write_16_bits(LTC2992_I2C_ADDRESS, LTC2992_MAX_GPIO4_THRESHOLD_MSB_REG, (max_gpio_threshold_code << 8));
1198  }
1199 
1200  Serial.print(F("Enter Min GPIO4 Threshold (Range: 0V - 2.048V):"));
1201 
1202  min_gpio_threshold = read_float();
1203  Serial.println(min_gpio_threshold, 4);
1204  Serial.println();
1205 
1206  if (bit_resolution == 1)
1207  {
1208  min_gpio_threshold_code = (min_gpio_threshold / LTC2992_GPIO_12bit_lsb);
1209  ack |= LTC2992_write_16_bits(LTC2992_I2C_ADDRESS, LTC2992_MIN_GPIO4_THRESHOLD_MSB_REG, (min_gpio_threshold_code << 4));
1210  }
1211  else
1212  {
1213  min_gpio_threshold_code = (min_gpio_threshold / LTC2992_GPIO_8bit_lsb);
1214  ack |= LTC2992_write_16_bits(LTC2992_I2C_ADDRESS, LTC2992_MIN_GPIO4_THRESHOLD_MSB_REG, (min_gpio_threshold_code << 8));
1215  }
1216 
1217 
1218  return (ack);
1219 }
1220 //! Set All Thresholds to Default Values
1222 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
1223 {
1224 
1225  int8_t ack = 0;
1226 
1227  uint32_t max_32bit_threshold = 0xFFFFFF;
1228  uint16_t max_16bit_threshold = 0xFFF0;
1229  uint32_t min_32bit_threshold = 0x000000;
1230  uint16_t min_16bit_threshold = 0x00000;
1231 
1232  uint32_t max_power_threshold_code = 0;
1233  uint32_t min_power_threshold_code = 0;
1234 
1235  //Reset Power Thresholds
1236 
1239 
1242 
1245 
1246  //Reset Current Thresholds
1247 
1250 
1253 
1256 
1257  //Reset Voltage Thresholds
1260 
1263 
1264  //Reset GPIO Thresholds
1269 
1274 
1275  if (ack == 0)
1276  {
1277  Serial.println(F("\nThresholds Reset to Defaults\n"));
1278  }
1279 
1280  return (ack);
1281 }
1282 
1283 //Toggle and Configure GPIO Pins
1285 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
1286 {
1287  int8_t ack = 0;
1288  int8_t user_command;
1289  uint8_t gpio_io_code;
1290  uint8_t gpio4_control_code;
1291 
1292  do
1293  {
1294  Serial.print(F("*************************\n\n"));
1295  Serial.print(F("1-Configure GPIO1\n"));
1296  Serial.print(F("2-Configure GPIO2\n"));
1297  Serial.print(F("3-Configure GPIO3\n"));
1298  Serial.print(F("4-Configure GPIO4\n"));
1299  Serial.print(F("m-Main Menu\n\n"));
1300  Serial.print(F("Enter a command: "));
1301 
1303  ack |= LTC2992_read(LTC2992_I2C_ADDRESS, LTC2992_GPIO4_CFG_REG, & gpio4_control_code);
1304 
1305  user_command = read_int();
1306  if (user_command == 'm')
1307  Serial.println(F("m"));
1308  else
1309  Serial.println(user_command);
1310  Serial.println();
1311  switch (user_command)
1312  {
1313  case 1:
1314  Serial.print(F("1-GPIO1 Pulls Low, 2-GPIO1 High-Z\n"));
1315  user_command = read_int();
1316  if ((user_command > 2) || (user_command < 0))
1317  user_command = 2;
1318  Serial.println(user_command);
1319  if (user_command == 1)
1320  gpio_io_code = gpio_io_code | LTC2992_GPIO1_OUT_LOW;
1321  else
1322  gpio_io_code = gpio_io_code & LTC2992_GPIO1_OUT_HIGH_Z;
1323 
1324  break;
1325 
1326  case 2:
1327  Serial.print(F("1-GPIO2 Pulls Low, 2-GPIO2 High-Z\n"));
1328  user_command = read_int();
1329  if ((user_command > 2) || (user_command < 0))
1330  user_command = 2;
1331  Serial.println(user_command);
1332  if (user_command == 1)
1333  gpio_io_code = gpio_io_code | LTC2992_GPIO2_OUT_LOW;
1334  else
1335  gpio_io_code = gpio_io_code & LTC2992_GPIO2_OUT_HIGH_Z;
1336  break;
1337 
1338  case 3:
1339  Serial.print(F("*************************\n\n"));
1340  Serial.print(F("1-Configure GPIO3 as Data Ready (Latching)\n"));
1341  Serial.print(F("2-Configure GPIO3 as Data Ready (128us Pulse)\n"));
1342  Serial.print(F("3-Configure GPIO3 as Data Ready (16us Pulse)\n"));
1343  Serial.print(F("4-Configure GPIO3 as I/O Pin\n"));
1344  Serial.print(F("m-Main Menu\n\n"));
1345  Serial.print(F("Enter a command: "));
1346  user_command = read_int();
1347  Serial.println(user_command);
1348  switch (user_command)
1349  {
1350  case 1:
1351  gpio_io_code = gpio_io_code | LTC2992_GPIO3_CONFIG_LOW_DATARDY;
1352  break;
1353  case 2:
1354  gpio_io_code = gpio_io_code & LTC2992_GPIOCFG_GPIO3_MASK;
1355  gpio_io_code = gpio_io_code | LTC2992_GPIO3_CONFIG_128_LOW;
1356  break;
1357  case 3:
1358  gpio_io_code = gpio_io_code & LTC2992_GPIOCFG_GPIO3_MASK;
1359  gpio_io_code = gpio_io_code | LTC2992_GPIO3_CONFIG_16_LOW;
1360  break;
1361  case 4:
1362  gpio_io_code = gpio_io_code & LTC2992_GPIOCFG_GPIO3_MASK;
1363  gpio_io_code = gpio_io_code | LTC2992_GPIO3_CONFIG_IO;
1364  Serial.print(F("1-GPIO3 Pulls Low, 2-GPIO3 High-Z\n"));
1365  user_command = read_int();
1366  if ((user_command > 2) || (user_command < 0))
1367  user_command = 2;
1368  Serial.println(user_command);
1369  if (user_command == 1)
1370  gpio_io_code = gpio_io_code | LTC2992_GPIO3_OUT_LOW;
1371  else
1372  gpio_io_code = gpio_io_code & LTC2992_GPIO3_OUT_HIGH_Z;
1373  break;
1374  default:
1375  break;
1376  }
1377  break;
1378  case 4:
1379  Serial.print(F("1-GPIO4 Pulls Low, 2-GPIO1 High-Z\n"));
1380  user_command = read_int();
1381  if ((user_command > 2) || (user_command < 0))
1382  user_command = 2;
1383  Serial.println(user_command);
1384  if (user_command == 1)
1385  gpio4_control_code = gpio4_control_code | LTC2992_GPIO4_OUT_LOW;
1386  else
1387  gpio4_control_code = gpio4_control_code & LTC2992_GPIO4_OUT_HI_Z;
1388  break;
1389  default:
1390  if (user_command != 'm')
1391  Serial.println(F("Incorrect Option"));
1392  break;
1393  }
1395  ack |= LTC2992_write(LTC2992_I2C_ADDRESS, LTC2992_GPIO4_CFG_REG, gpio4_control_code);
1396  }
1397  while (!((user_command == 'm') || (ack)));
1398 
1399  return (ack);
1400 }
1401 //! Read/Clear Faults
1403 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
1404 {
1405 
1406  int8_t ack = 0;
1407  int8_t user_command;
1408  uint8_t fault_code;
1409  uint8_t no_fault_code = 0x00;
1410 
1411  do
1412  {
1413  Serial.print(F("*************************\n\n"));
1414  Serial.print(F("1-Real All Faults\n"));
1415  Serial.print(F("2-Clear All Faults\n"));
1416  Serial.print(F("m-Main Menu\n\n"));
1417  Serial.print(F("Enter a command: "));
1418 
1419  user_command = read_int();
1420  if (user_command == 'm')
1421  Serial.println(F("m"));
1422  else
1423  Serial.println(user_command);
1424  Serial.println();
1425  switch (user_command)
1426  {
1427  case 1:
1428  ack |= LTC2992_read(LTC2992_I2C_ADDRESS, LTC2992_FAULT1_REG, & fault_code);
1429 
1430  if ((fault_code & (1 << 7)) != 0)
1431  Serial.println(F("Max Channel 1 Power Fault Occured!"));
1432  else
1433  no_fault_code++;
1434  if ((fault_code & (1 << 6)) != 0)
1435  Serial.println(F("Min Channel 1 Power Fault Occured!"));
1436  else
1437  no_fault_code++;
1438  if ((fault_code & (1 << 5)) != 0)
1439  Serial.println(F("Max Channel 1 Current Fault Occured!"));
1440  else
1441  no_fault_code++;
1442  if ((fault_code & (1 << 4)) != 0)
1443  Serial.println(F("Min Channel 1 Current Fault Occured!"));
1444  else
1445  no_fault_code++;
1446  if ((fault_code & (1 << 3)) != 0)
1447  Serial.println(F("Max Channel 1 Voltage Fault Occured!"));
1448  else
1449  no_fault_code++;;
1450  if ((fault_code & (1 << 2)) != 0)
1451  Serial.println(F("Min Channel 1 Voltage Fault Occured!"));
1452  else
1453  no_fault_code++;;
1454  if ((fault_code & (1 << 1)) != 0)
1455  Serial.println(F("Max GPIO1 Fault Occured!"));
1456  else
1457  no_fault_code++;
1458  if ((fault_code & (1 << 0)) != 0)
1459  Serial.println(F("Min GPIO1 Fault Occured!"));
1460  else
1461  no_fault_code++;
1462 
1463  ack |= LTC2992_read(LTC2992_I2C_ADDRESS, LTC2992_FAULT2_REG, & fault_code);
1464 
1465  if ((fault_code & (1 << 7)) != 0)
1466  Serial.println(F("Max Channel 2 Power Fault Occured!"));
1467  else
1468  no_fault_code++;
1469  if ((fault_code & (1 << 6)) != 0)
1470  Serial.println(F("Min Channel 2 Power Fault Occured!"));
1471  else
1472  no_fault_code++;
1473  if ((fault_code & (1 << 5)) != 0)
1474  Serial.println(F("Max Channel 2 Current Fault Occured!"));
1475  else
1476  no_fault_code++;
1477  if ((fault_code & (1 << 4)) != 0)
1478  Serial.println(F("Min Channel 2 Current Fault Occured!"));
1479  else
1480  no_fault_code++;
1481  if ((fault_code & (1 << 3)) != 0)
1482  Serial.println(F("Max Channel 2 Voltage Fault Occured!"));
1483  else
1484  no_fault_code++;
1485  if ((fault_code & (1 << 2)) != 0)
1486  Serial.println(F("Min Channel 2 Voltage Fault Occured!"));
1487  else
1488  no_fault_code++;
1489  if ((fault_code & (1 << 1)) != 0)
1490  Serial.println(F("Max GPIO2 Fault Occured!"));
1491  else
1492  no_fault_code++;
1493  if ((fault_code & (1 << 0)) != 0)
1494  Serial.println(F("Min GPIO2 Fault Occured!"));
1495  else
1496  no_fault_code++;
1497 
1498  ack |= LTC2992_read(LTC2992_I2C_ADDRESS, LTC2992_FAULT3_REG, & fault_code);
1499 
1500  if ((fault_code & (1 << 7)) != 0)
1501  Serial.println(F("Max GPIO3 Fault Occured!"));
1502  else
1503  no_fault_code++;
1504  if ((fault_code & (1 << 6)) != 0)
1505  Serial.println(F("Min GPIO3 Fault Occured!"));
1506  else
1507  no_fault_code++;
1508  if ((fault_code & (1 << 5)) != 0)
1509  Serial.println(F("Max GPIO4 Fault Occured!"));
1510  else
1511  no_fault_code++;
1512  if ((fault_code & (1 << 4)) != 0)
1513  Serial.println(F("Min GPIO4 Fault Occured!"));
1514  else
1515  no_fault_code++;
1516  if ((fault_code & (1 << 3)) != 0)
1517  Serial.println(F("Max Current SUM Fault Occured!"));
1518  else
1519  no_fault_code++;
1520  if ((fault_code & (1 << 2)) != 0)
1521  Serial.println(F("Min Current SUM Fault Occured!"));
1522  else
1523  no_fault_code++;
1524  if ((fault_code & (1 << 1)) != 0)
1525  Serial.println(F("Max Power SUM Fault Occured!"));
1526  else
1527  no_fault_code++;
1528  if ((fault_code & (1 << 0)) != 0)
1529  Serial.println(F("Min Power SUM Fault Occured!"));
1530  else
1531  no_fault_code++;
1532 
1533  ack |= LTC2992_read(LTC2992_I2C_ADDRESS, LTC2992_FAULT4_REG, & fault_code);
1534 
1535  if ((fault_code & (1 << 4)) != 0)
1536  Serial.println(F("Stuck Bus Fault Occured!"));
1537  else
1538  no_fault_code++;
1539  if ((fault_code & (1 << 3)) != 0)
1540  Serial.println(F("GPIO1 Input Fault Occured!"));
1541  else
1542  no_fault_code++;
1543  if ((fault_code & (1 << 2)) != 0)
1544  Serial.println(F("GPIO2 Input Fault Occured!"));
1545  else
1546  no_fault_code++;
1547  if ((fault_code & (1 << 1)) != 0)
1548  Serial.println(F("GPIO3 Input Fault Occured!"));
1549  else
1550  no_fault_code++;
1551 
1552  if (no_fault_code == 28)
1553  {
1554  Serial.println(F("No Faults Occured\n"));
1555  Serial.println();
1556  }
1557 
1558  break;
1559 
1560  case 2:
1561  fault_code = 0;
1566 
1567  if (ack == 0)
1568  {
1569  Serial.println(F("\nAll Faults Cleared\n"));
1570  }
1571  break;
1572 
1573  default:
1574  if (user_command != 'm')
1575  Serial.println(F("Incorrect Option"));
1576  break;
1577  }
1578  }
1579  while (!((user_command == 'm') || (ack)));
1580 
1581  return (ack);
1582 
1583 }
1584 //! Settings to configure shutdown mode and ADC Resolution
1585 int8_t menu_4_settings(int8_t *CTRLA_mode, //! CTRLA Register. Used to set device in Shutdown
1586  int8_t *bit_resolution) //! Sets ADC Bit Resolution.
1587 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
1588 {
1589  int8_t ack = 0;
1590  int8_t user_command;
1591 
1592  do
1593  {
1594  Serial.print(F("*************************\n\n"));
1595  Serial.print(F("1-Configure ADC Resolution\n"));
1596  Serial.print(F("2-Enable/Disable Shutdown Mode\n"));
1597  Serial.print(F("m-Main Menu\n\n"));
1598  Serial.print(F("Enter a command: "));
1599 
1600  user_command = read_int();
1601  if (user_command == 'm')
1602  Serial.println(F("m"));
1603  else
1604  Serial.println(user_command);
1605  Serial.println();
1606  switch (user_command)
1607  {
1608  case 1:
1609  Serial.print(F("1-12-bit resolution, 2-8-bit resolution\n"));
1610  user_command = read_int();
1611  if ((user_command > 2) || (user_command < 0))
1612  user_command = 2;
1613  Serial.println(user_command);
1614  if (user_command == 1)
1615  {
1616  * bit_resolution = 1;
1618  }
1619  else
1620  {
1621  *bit_resolution = 0;
1623  }
1624  uint8_t nadc_code;
1626  Serial.println(nadc_code);
1627  break;
1628 
1629  case 2:
1630  Serial.print(F("1-Enable Shutdown, 2-Disable Shutdown\n"));
1631  user_command = read_int();
1632  if ((user_command > 2) || (user_command < 0))
1633  user_command = 2;
1634  Serial.println(user_command);
1635  if (user_command == 1)
1636  {
1637  * CTRLA_mode = * CTRLA_mode | LTC2992_MODE_SHUTDOWN;
1638  Serial.print(F("Shutdown Mode is enabled. Selecting Continious Mode in main menu will disable Shutdown mode\n"));
1639  }
1640  else
1641  {
1642  * CTRLA_mode = ( * CTRLA_mode & LTC2992_CTRLA_MEASUREMENT_MODE_MASK) | LTC2992_MODE_CONTINUOUS;
1643  Serial.print(F("Shutdown Mode is disabled. \n"));
1644  }
1645  ack |= LTC2992_write(LTC2992_I2C_ADDRESS, LTC2992_CTRLA_REG, *CTRLA_mode);
1646  break;
1647  default:
1648  if (user_command != 'm')
1649  Serial.println(F("Incorrect Option"));
1650  break;
1651  }
1652  }
1653  while (!((user_command == 'm') || (ack)));
1654  return (ack);
1655 
1656 }
1657 
#define LTC2992_MAX_POWER1_THRESHOLD_MSB2_REG
Definition: LTC2992.h:348
static void print_title()
Print the title block.
Definition: DC2561.ino:208
#define LTC2992_GPIO3_OUT_LOW
Definition: LTC2992.h:627
#define LTC2992_MIN_POWER2_MSB2_REG
Definition: LTC2992.h:393
#define LTC2992_I2C_ADDRESS
Definition: LTC2992.h:160
#define LTC2992_MAX_DELTA1_SENSE_THRESHOLD_MSB_REG
Definition: LTC2992.h:360
#define LTC2992_DELTA_SENSE2_MSB_REG
Definition: LTC2992.h:402
#define LTC2992_MIN_DELTA2_SENSE_MSB_REG
Definition: LTC2992.h:406
#define LTC2992_MAX_POWER1_MSB2_REG
Definition: LTC2992.h:342
unsigned char user_command
#define LTC2992_MIN_SENSE1_THRESHOLD_MSB_REG
Definition: LTC2992.h:372
#define LTC2992_MAX_SENSE2_THRESHOLD_MSB_REG
Definition: LTC2992.h:418
static int8_t demo_board_connected
Set to 1 if the board is connected.
Definition: DC2561.ino:126
#define LTC2992_MIN_GPIO3_MSB_REG
Definition: LTC2992.h:436
static int8_t menu_2_threshold_menu_1_set_power(int8_t bit_resolution)
Set Power Min/Max Values.
Definition: DC2561.ino:785
#define LTC2992_MAX_SENSE1_THRESHOLD_MSB_REG
Definition: LTC2992.h:370
const float LTC2992_GPIO_8bit_lsb
Typical GPIO lsb weight for 8-bit mode in volts.
Definition: DC2561.ino:111
#define LTC2992_MAX_GPIO3_THRESHOLD_MSB_REG
Definition: LTC2992.h:438
float LTC2992_code_to_current(uint16_t adc_code, float resistor, float LTC2992_DELTA_SENSE_lsb)
Calculate the LTC2992 current with a sense resistor.
Definition: LTC2992.cpp:243
Header File for Linduino Libraries and Demo Code.
#define LTC2992_MIN_DELTA2_SENSE_THRESHOLD_MSB_REG
Definition: LTC2992.h:410
LTC2992: Dual Wide Range Power Monitor.
int8_t LTC2992_read(uint8_t i2c_address, uint8_t adc_command, uint8_t *adc_code)
Reads an 8-bit adc_code from LTC2992.
Definition: LTC2992.cpp:175
#define LTC2992_MIN_DELTA1_SENSE_MSB_REG
Definition: LTC2992.h:358
#define LTC2992_MAX_SENSE1_MSB_REG
Definition: LTC2992.h:366
const float LTC2992_GPIO_12bit_lsb
Typical GPIO lsb weight for 12-bit mode in volts.
Definition: DC2561.ino:112
#define LTC2992_MIN_ISUM_THRESHOLD_MSB_REG
Definition: LTC2992.h:460
const char ack_error[]
Error message.
Definition: DC2561.ino:123
static int8_t menu_2_threshold_menu_5_reset_thresholds()
Set All Thresholds to Default Values.
Definition: DC2561.ino:1221
#define LTC2992_GPIO2_MSB_REG
Definition: LTC2992.h:422
#define LTC2992_MIN_DELTA1_SENSE_THRESHOLD_MSB_REG
Definition: LTC2992.h:362
const float LTC2992_DELTA_SENSE_8bit_lsb
Typical Delta lsb weight for 8-bit mode in volts.
Definition: DC2561.ino:113
#define LTC2992_POWER1_MSB2_REG
Definition: LTC2992.h:339
static void setup()
Initialize Linduino.
Definition: DC2561.ino:130
#define LTC2992_MAX_DELTA2_SENSE_MSB_REG
Definition: LTC2992.h:404
#define LTC2992_MAX_GPIO1_THRESHOLD_MSB_REG
Definition: LTC2992.h:380
#define LTC2992_MIN_SENSE1_MSB_REG
Definition: LTC2992.h:368
#define LTC2992_FAULT3_REG
Definition: LTC2992.h:478
#define LTC2992_CTRLA_MEASUREMENT_MODE_MASK
Definition: LTC2992.h:641
#define LTC2992_MAX_PSUM_THRESHOLD_MSB1_REG
Definition: LTC2992.h:471
#define LTC2992_DELTA_SENSE1_MSB_REG
Definition: LTC2992.h:354
const float LTC2992_DELTA_SENSE_12bit_lsb
Typical Delta lsb weight for 12-bit mode in volts.
Definition: DC2561.ino:114
#define LTC2992_GPIO4_CFG_REG
Definition: LTC2992.h:483
int8_t LTC2992_write_24_bits(uint8_t i2c_address, uint8_t adc_command, uint32_t code)
Write a 24-bit code to the LTC2992.
Definition: LTC2992.cpp:160
static void loop()
Repeats Linduino loop.
Definition: DC2561.ino:152
#define LTC2992_MAX_GPIO2_THRESHOLD_MSB_REG
Definition: LTC2992.h:428
#define LTC2992_MODE_CONTINUOUS
Definition: LTC2992.h:498
#define LTC2992_FAULT1_REG
Definition: LTC2992.h:337
float LTC2992_SENSE_code_to_voltage(uint16_t adc_code, float LTC2992_SENSE_lsb)
Calculate the LTC2992 SENSE voltage.
Definition: LTC2992.cpp:225
float LTC2992_code_to_current_sum(uint16_t adc_code, float resistor, float LTC2992_DELTA_SENSE_lsb)
Calculate the LTC2992 current sum with a sense resistor.
Definition: LTC2992.cpp:253
const float LTC2992_SENSE_12bit_lsb
Typical SENSE lsb weight for 12-bit mode in volts.
Definition: DC2561.ino:116
#define LTC2992_PSUM_MSB1_REG
Definition: LTC2992.h:462
static int8_t menu_2_threshold_config(float scale, int8_t bit_resolution)
Configure Threshold Values.
Definition: DC2561.ino:731
#define LTC2992_MIN_GPIO3_THRESHOLD_MSB_REG
Definition: LTC2992.h:440
#define LTC2992_GPIO3_OUT_HIGH_Z
Definition: LTC2992.h:628
int8_t LTC2992_write(uint8_t i2c_address, uint8_t adc_command, uint8_t code)
Write an 8-bit code to the LTC2992.
Definition: LTC2992.cpp:138
#define LTC2992_MIN_GPIO4_THRESHOLD_MSB_REG
Definition: LTC2992.h:450
#define LTC2992_GPIO4_MSB_REG
Definition: LTC2992.h:442
#define LTC2992_GPIO4_OUT_HI_Z
Definition: LTC2992.h:634
#define LTC2992_MAX_GPIO4_THRESHOLD_MSB_REG
Definition: LTC2992.h:448
float LTC2992_code_to_power_sum(int32_t adc_code, float resistor, float LTC2992_Power_lsb)
Power LSB Weight.
Definition: LTC2992.cpp:273
#define LTC2992_MIN_GPIO2_MSB_REG
Definition: LTC2992.h:426
static int8_t menu_2_alert_menu_4_set_adin_alerts(float scale, int8_t bit_resolution)
Definition: DC2561.ino:1080
#define LTC2992_MIN_GPIO1_MSB_REG
Definition: LTC2992.h:378
#define LTC2992_GPIO3_CONFIG_LOW_DATARDY
Definition: LTC2992.h:616
#define LTC2992_GPIO3_CONFIG_IO
Definition: LTC2992.h:619
#define LTC2992_MIN_PSUM_THRESHOLD_MSB1_REG
Definition: LTC2992.h:474
QuikEval EEPROM Library.
#define LTC2992_MIN_SENSE2_THRESHOLD_MSB_REG
Definition: LTC2992.h:420
#define LTC2992_MAX_GPIO3_MSB_REG
Definition: LTC2992.h:434
#define LTC2992_MAX_GPIO4_MSB_REG
Definition: LTC2992.h:444
float LTC2992_GPIO_code_to_voltage(uint16_t adc_code, float LTC2992_GPIO_lsb)
Calculate the LTC2992 GPIO voltage.
Definition: LTC2992.cpp:234
int8_t discover_demo_board(char *demo_name)
Read the ID string from the EEPROM and determine if the correct board is connected.
#define LTC2992_FAULT2_REG
Definition: LTC2992.h:386
static int8_t menu_3_GPIO_config()
Definition: DC2561.ino:1284
#define LTC2992_ISUM_MSB_REG
Definition: LTC2992.h:452
LT_SPI: Routines to communicate with ATmega328P&#39;s hardware SPI port.
#define LTC2992_GPIO_IO_CONT_REG
Definition: LTC2992.h:482
#define LTC2992_GPIO1_MSB_REG
Definition: LTC2992.h:374
static int8_t menu_5_read_clear_faults()
Read/Clear Faults.
Definition: DC2561.ino:1402
#define LTC2992_GPIO3_CONFIG_128_LOW
Definition: LTC2992.h:617
#define LTC2992_SENSE2_MSB_REG
Definition: LTC2992.h:412
#define LTC2992_GPIO2_OUT_LOW
Definition: LTC2992.h:614
LT_I2C: Routines to communicate with ATmega328P&#39;s hardware I2C port.
#define LTC2992_MIN_POWER1_THRESHOLD_MSB2_REG
Definition: LTC2992.h:351
const float LTC2992_SENSE_8bit_lsb
Typical SENSE lsb weight for 8-bit mode in volts.
Definition: DC2561.ino:115
#define LTC2992_GPIO2_OUT_HIGH_Z
Definition: LTC2992.h:613
int8_t LTC2992_read_12_bits(uint8_t i2c_address, uint8_t adc_command, uint16_t *adc_code)
Reads a 12-bit adc_code from LTC2992.
Definition: LTC2992.cpp:186
const float LTC2992_Power_8bit_lsb
Typical POWER lsb weight for 8-bit mode in V^2.
Definition: DC2561.ino:117
char demo_name[]
Demo Board Name stored in QuikEval EEPROM.
Definition: DC1880A.ino:97
#define LTC2992_MAX_DELTA1_SENSE_MSB_REG
Definition: LTC2992.h:356
int32_t read_int()
static void print_prompt()
Print the Prompt.
Definition: DC2561.ino:221
#define LTC2992_CTRLA_REG
Definition: LTC2992.h:334
#define LTC2992_GPIO4_OUT_LOW
Definition: LTC2992.h:633
static int8_t menu_2_threshold_menu_3_set_SENSE(int8_t bit_resolution)
Set Min/Max Voltage Thresholds.
Definition: DC2561.ino:1004
#define LTC2992_MAX_GPIO1_MSB_REG
Definition: LTC2992.h:376
#define LTC2992_GPIO1_OUT_HIGH_Z
Definition: LTC2992.h:611
float read_float()
#define LTC2992_MAX_ISUM_THRESHOLD_MSB_REG
Definition: LTC2992.h:458
int8_t LTC2992_write_16_bits(uint8_t i2c_address, uint8_t adc_command, uint16_t code)
Write a 16-bit code to the LTC2992.
Definition: LTC2992.cpp:150
int8_t LTC2992_read_24_bits(uint8_t i2c_address, uint8_t adc_command, uint32_t *adc_code)
Reads a 24-bit adc_code from LTC2992.
Definition: LTC2992.cpp:211
float LTC2992_code_to_power(int32_t adc_code, float resistor, float LTC2992_Power_lsb)
Calculate the LTC2992 power.
Definition: LTC2992.cpp:263
static int8_t menu_1_continuous_mode(int8_t CTRLA_mode, int8_t bit_resolution, float scale)
Continuous Mode.
Definition: DC2561.ino:232
const float resistor
resistor value on demo board
Definition: DC2561.ino:120
#define LTC2992_GPIO1_OUT_LOW
Definition: LTC2992.h:612
void quikeval_I2C_init(void)
Initializes Linduino I2C port.
Definition: LT_I2C.cpp:394
#define LTC2992_MIN_GPIO1_THRESHOLD_MSB_REG
Definition: LTC2992.h:382
#define LTC2992_GPIOCFG_GPIO3_MASK
Definition: LTC2992.h:648
#define LTC2992_MIN_POWER1_MSB2_REG
Definition: LTC2992.h:345
void quikeval_I2C_connect(void)
Switch MUX to connect I2C pins to QuikEval connector.
Definition: LT_I2C.cpp:401
#define LTC2992_ADC_RESOLUTION
Definition: LTC2992.h:548
#define LTC2992_MIN_GPIO2_THRESHOLD_MSB_REG
Definition: LTC2992.h:430
#define LTC2992_MAX_GPIO2_MSB_REG
Definition: LTC2992.h:424
#define LTC2992_GPIO3_CONFIG_16_LOW
Definition: LTC2992.h:618
#define LTC2992_MIN_GPIO4_MSB_REG
Definition: LTC2992.h:446
#define LTC2992_MIN_POWER2_THRESHOLD_MSB2_REG
Definition: LTC2992.h:399
static int8_t menu_4_settings(int8_t *CTRLA_mode, int8_t *bit_resolution)
Settings to configure shutdown mode and ADC Resolution.
Definition: DC2561.ino:1585
#define CONTINUOUS_MODE_DISPLAY_DELAY
The delay between readings in continious mode.
Definition: DC2561.ino:108
const float LTC2992_Power_12bit_lsb
Typical POWER lsb weight for 12-bit mode in V^2.
Definition: DC2561.ino:118
#define LTC2992_MAX_DELTA2_SENSE_THRESHOLD_MSB_REG
Definition: LTC2992.h:408
#define LTC2992_POWER2_MSB2_REG
Definition: LTC2992.h:387
#define LTC2992_MIN_SENSE2_MSB_REG
Definition: LTC2992.h:416
#define LTC2992_NADC_REG
Definition: LTC2992.h:338
#define LTC2992_MODE_SHUTDOWN
Definition: LTC2992.h:495
#define LTC2992_MAX_POWER2_THRESHOLD_MSB2_REG
Definition: LTC2992.h:396
#define LTC2992_MAX_POWER2_MSB2_REG
Definition: LTC2992.h:390
#define LTC2992_GPIO3_MSB_REG
Definition: LTC2992.h:432
#define LTC2992_SENSE1_MSB_REG
Definition: LTC2992.h:364
#define LTC2992_FAULT4_REG
Definition: LTC2992.h:480
#define LTC2992_MAX_SENSE2_MSB_REG
Definition: LTC2992.h:414
static int8_t menu_2_threshold_menu_2_set_current(int8_t bit_resolution)
Set Min/Max Current Threshold.
Definition: DC2561.ino:894