| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

DC2156.ino
Go to the documentation of this file.
1 /*!
2 DC2156A
3 LTC2946: 12-Bit Wide Range Power, Charge and Energy Monitor
4
5 @verbatim
6
7 Setting the Alert Thresholds:
8 1. Select the Alert option from the main menu.
9 2. Select the desired Thresholds 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 DC2156A.
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 LTC2946
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 "LTC2946.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(uint8_t CTRLA, uint8_t VOLTAGE_SEL, float scale);
94 int8_t menu_2_snapshot_mode(uint8_t VOLTAGE_SEL, float scale);
95 int8_t menu_2_snapshot_mode_menu_1_SENSE();
96 int8_t menu_2_snapshot_mode_menu_2_ADIN(float scale);
97 int8_t menu_2_snapshot_mode_menu_3_VDD();
98 int8_t menu_2_snapshot_mode_menu_4_Current();
99 int8_t menu_3_alert(uint8_t VOLTAGE_SEL, float scale);
100 int8_t menu_3_alert_menu_1_set_power_alerts(uint8_t VOLTAGE_SEL, float scale);
101 int8_t menu_3_alert_menu_2_set_current_alerts();
102 int8_t menu_3_alert_menu_3_set_vin_alerts();
103 int8_t menu_3_alert_menu_4_set_adin_alerts(float scale);
104 int8_t menu_3_alert_menu_5_enable_disable_alerts();
105 int8_t menu_3_alert_menu_5_enable_disable_alerts_menu_1_ALERT1();
106 int8_t menu_3_alert_menu_5_enable_disable_alerts_menu_2_ALERT2();
107 int8_t menu_3_alert_menu_6_read_clear_faults();
108 int8_t menu_4_shutdown(uint8_t *CTRLB, uint8_t *shutdown);
109 int8_t menu_5_settings(uint8_t *CTRLA, uint8_t *CTRLB, uint8_t *VOLTAGE_SEL, uint8_t *GPIO_CFG, uint8_t *GPIO3_CTRL, float *scale);
110 int8_t menu_5_settings_menu_1_configure_CTRLA_reg(uint8_t *CTRLA, uint8_t *VOLTAGE_SEL);
111 void menu_5_settings_menu_1_configure_CTRLA_reg_menu_1_ADIN_Configuration(uint8_t *CTRLA);
112 void menu_5_settings_menu_1_configure_CTRLA_reg_menu_2_Offset_Configuration(uint8_t *CTRLA);
113 void menu_5_settings_menu_1_configure_CTRLA_reg_menu_3_Voltage_Configuration(uint8_t *CTRLA, uint8_t *VOLTAGE_SEL);
114 void menu_5_settings_menu_1_configure_CTRLA_reg_menu_4_Channel_Configuration(uint8_t *CTRLA);
115 int8_t menu_5_settings_menu_2_configure_CTRLB_reg(uint8_t *CTRLB);
116 int8_t menu_5_settings_menu_3_configure_GPIO(uint8_t *GPIO_CFG, uint8_t *GPIO3_CTRL);
117 void menu_5_settings_menu_4_scaling_for_ADIN(uint8_t *scale);
118 int8_t menu_6_clear_min_max();
119
120 #define CONTINUOUS_MODE_DISPLAY_DELAY 2000 //!< The delay between readings
121
122 const float resistor = .02; //!< resistor value on demo board
123 const float CLK_FREQ = 4E6; //!< CLK Frequency
124
125
126 // LSB Weights
127 const float LTC2946_ADIN_lsb = 5.001221E-04; //!< Typical ADIN lsb weight in volts
128 const float LTC2946_DELTA_SENSE_lsb = 2.5006105E-05; //!< Typical Delta lsb weight in volts
129 const float LTC2946_VIN_lsb = 2.5006105E-02; //!< Typical VIN lsb weight in volts
130 const float LTC2946_Power_lsb = 6.25305E-07; //!< Typical POWER lsb weight in V^2 VIN_lsb * DELTA_SENSE_lsb
131 const float LTC2946_ADIN_DELTA_SENSE_lsb = 1.25061E-08; //!< Typical sense lsb weight in V^2 *ADIN_lsb * DELTA_SENSE_lsb
132 const float LTC2946_INTERNAL_TIME_lsb = 4101.00/250000.00; //!< Internal TimeBase lsb. Use LTC2946_TIME_lsb if an external CLK is used. See Settings menu for how to calculate Time LSB.
133
134 static float LTC2946_TIME_lsb = 16.39543E-3; //!< Static variable which is based off of the default clk frequency of 250KHz.
135
136 // Error string
137 const char ack_error[] = "Error: No Acknowledge. Check I2C Address."; //!< Error message
138
139 // Global variables
140 static int8_t demo_board_connected; //!< Set to 1 if the board is connected
141 static uint8_t alert1_code = 0; //!< Value stored or read from ALERT1 register. Shared between loop() and restore_alert_settings()
142 static uint8_t alert2_code = 0; //!< Value stored or read from ALERT2 register. Shared between loop() and restore_alert_settings()
143 static bool internalCLK = true;
144
145 //! Initialize Linduino
146 void setup()
147 {
148 char demo_name[] = "DC2156"; // Demo Board Name stored in QuikEval EEPROM
149
150 quikeval_I2C_init(); //! Configure the EEPROM I2C port for 100kHz
151 quikeval_I2C_connect(); //! Connects to main I2C port
152 Serial.begin(115200); //! Initialize the serial port to the PC
153 print_title(); //! Print Title
154 demo_board_connected = discover_demo_board(demo_name);
155 if (!demo_board_connected)
156 {
157 Serial.println(F("Demo board not detected, will attempt to proceed"));
158 demo_board_connected = true;
159 }
160 if (demo_board_connected)
161 {
162 restore_alert_settings();
163 print_prompt();
164 }
165 }
166
167 //! Repeats Linduino loop
168 void loop()
169 {
170 int8_t ack = 0; // I2C acknowledge indicator
171 static uint8_t user_command; // The user input command
172
173 static uint8_t CTRLA = LTC2946_CHANNEL_CONFIG_V_C_3|LTC2946_SENSE_PLUS|LTC2946_OFFSET_CAL_EVERY|LTC2946_ADIN_GND; //! Set Control A register to default value.
174 static uint8_t CTRLB = LTC2946_DISABLE_ALERT_CLEAR&LTC2946_DISABLE_SHUTDOWN&LTC2946_DISABLE_CLEARED_ON_READ&LTC2946_DISABLE_STUCK_BUS_RECOVER&LTC2946_ENABLE_ACC&LTC2946_DISABLE_AUTO_RESET; //! Set Control B Register to default value
175 static uint8_t GPIO_CFG = LTC2946_GPIO1_OUT_LOW |LTC2946_GPIO2_IN_ACC|LTC2946_GPIO3_OUT_ALERT; //! Set GPIO_CFG Register to Default value
176 static uint8_t GPIO3_CTRL = LTC2946_GPIO3_OUT_HIGH_Z; //! Set GPIO3_CTRL to Default Value
177 static uint8_t VOLTAGE_SEL = LTC2946_SENSE_PLUS; //! Set Voltage selection to default value.
178 static uint8_t shutdown = 0; //! Set Shutdown = 1 to put part in shutdown. This is done through menu item 4.
179
180
181 static float scale = 102.4/2/046; //! Stores division ration for resistive divider on ADIN pin. Configured inside "Settings" menu.
182
183 if (demo_board_connected) //! Do nothing if the demo board is not connected
184 {
185 if (Serial.available()) //! Do nothing if serial is not available
186 {
187 user_command = read_int(); //! Read user input command
188 if (user_command != 'm')
189 Serial.println(user_command);
190 Serial.println();
191 ack = 0;
192 switch (user_command) //! Prints the appropriate submenu
193 {
194 case 1:
195 ack |= menu_1_continuous_mode(CTRLA, VOLTAGE_SEL, scale); //! Continuous Mode Measurement
196 break ;
197
198 case 2:
199 ack |= menu_2_snapshot_mode(VOLTAGE_SEL, scale); //! SnapShot Mode Measurement
200 break;
201
202 case 3:
203 ack |= menu_3_alert(VOLTAGE_SEL, scale); //! Alert and Threshold Menu
204 break;
205
206 case 4:
207 ack |= menu_4_shutdown(&CTRLB, &shutdown); //! Toggle Shutdown Down Mode
208 break;
209
210 case 5:
211 menu_5_settings(&CTRLA, &CTRLB, &VOLTAGE_SEL, &GPIO_CFG, &GPIO3_CTRL, &scale); // Settings
212 break;
213
214 case 6:
215 ack |= menu_6_clear_min_max(); // Clear Min/Max
216 break;
217
218 default:
219 Serial.println("Incorrect Option");
220 break;
221 }
222 if (ack != 0)
223 Serial.println(ack_error);
224 Serial.print(F("*************************"));
225 print_prompt();
226 }
227 }
228 }
229
230 // Function Definitions
231 //! Print the title block
232 void print_title()
233 {
234 Serial.println(F("\n*****************************************************************"));
235 Serial.print(F("* DC2156 Demonstration Program *\n"));
236 Serial.print(F("* *\n"));
237 Serial.print(F("* This program communicates with the LTC2946 12-Bit Wide Range *\n"));
238 Serial.print(F("* I2C Energy and Power Monitor found on the DC2156 demo board. *\n"));
239 Serial.print(F("* Set the baud rate to 115200 and select the newline terminator.*\n"));
240 Serial.print(F("* *\n"));
241 Serial.print(F("*****************************************************************\n"));
242 }
243
244 //! Print the Prompt
245 void print_prompt()
246 {
247 Serial.print(F("\n1-Continuous Mode\n"));
248 Serial.print(F("2-Snapshot Mode\n"));
249 Serial.print(F("3-Alert and Threshold Menu\n"));
250 Serial.print(F("4-Toggle Shutdown Mode\n"));
251 Serial.print(F("5-Settings\n"));
252 Serial.print(F("6-Clear Min/Max\n\n"));
253 Serial.print(F("Enter a command: "));
254 }
255
256 //! Continuous Mode.
257 int8_t menu_1_continuous_mode(uint8_t CTRLA, //!< CTRLA Register sets the mode in which Continious measurements are made. Configured in "Settings" menu.
258 uint8_t VOLTAGE_SEL, //!< VOLTAGE_SEL variable represents the voltage channel selected. Scaling is done if ADIN channel is selected and resistive dividers are present.
259 float scale) //!< Stores division ratio for resistive divider on ADIN pin. Configured inside "Settings" menu.
260 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
261 {
262 uint8_t LTC2946_mode;
263
264 int8_t ack = 0;
265
266 LTC2946_mode = CTRLA; //! Set the configuration of the CTRLA Register.
267 Serial.println();
268 ack |= LTC2946_write(LTC2946_I2C_ADDRESS, LTC2946_CTRLA_REG, LTC2946_mode); //! Sets the LTC2946 to continuous mode
269
270
271 //! Measurement Loop. Keeps Measuring until 'm' is pressed.
272 //! Measurement is done by first reading the adc code and then converting it to the respective value.
273 do
274 {
275 if (VOLTAGE_SEL != LTC2946_ADIN)
276 {
277
278 Serial.print(F("*************************\n\n"));
279
280 uint32_t power_code, max_power_code, min_power_code;
281 ack |= LTC2946_read_24_bits(LTC2946_I2C_ADDRESS, LTC2946_POWER_MSB2_REG, &power_code);
282 ack |= LTC2946_read_24_bits(LTC2946_I2C_ADDRESS, LTC2946_MAX_POWER_MSB2_REG, &max_power_code);
283 ack |= LTC2946_read_24_bits(LTC2946_I2C_ADDRESS, LTC2946_MIN_POWER_MSB2_REG, &min_power_code);
284
285
286 float power, max_power, min_power; // Store power results
287 power = LTC2946_code_to_power(power_code, resistor, LTC2946_Power_lsb);
288 max_power = LTC2946_code_to_power(max_power_code, resistor, LTC2946_Power_lsb);
289 min_power = LTC2946_code_to_power(min_power_code, resistor, LTC2946_Power_lsb);
290
291 Serial.print(F("****Power: "));
292 Serial.print(power, 4);
293 Serial.print(F(" W\n"));
294
295 Serial.print(F("Max Power: "));
296 Serial.print(max_power, 4);
297 Serial.print(F(" W\n"));
298
299 Serial.print(F("Min Power: "));
300 Serial.print(min_power, 4);
301 Serial.print(F(" W\n"));
302 }
303 else
304 {
305 Serial.print(F("*************************"));
306 Serial.println();
307 Serial.println();
308
309 uint32_t power_code, max_power_code, min_power_code;
310 ack |= LTC2946_read_24_bits(LTC2946_I2C_ADDRESS, LTC2946_POWER_MSB2_REG, &power_code);
311 ack |= LTC2946_read_24_bits(LTC2946_I2C_ADDRESS, LTC2946_MAX_POWER_MSB2_REG, &max_power_code);
312 ack |= LTC2946_read_24_bits(LTC2946_I2C_ADDRESS, LTC2946_MIN_POWER_MSB2_REG, &min_power_code);
313
314 float power, max_power, min_power;
315 power = LTC2946_code_to_power(power_code, resistor, LTC2946_ADIN_DELTA_SENSE_lsb) * scale;
316 max_power = LTC2946_code_to_power(max_power_code, resistor, LTC2946_ADIN_DELTA_SENSE_lsb) * scale;
317 min_power = LTC2946_code_to_power(min_power_code, resistor, LTC2946_ADIN_DELTA_SENSE_lsb) * scale;
318
319 Serial.print(F("\n***ADIN Power: "));
320 Serial.print(power, 4);
321 Serial.print(F(" W\n"));
322
323 Serial.print(F("Max ADIN Power: "));
324 Serial.print(max_power, 4);
325 Serial.print(F(" W\n"));
326
327 Serial.print(F("Min ADIN Power: "));
328 Serial.print(min_power, 4);
329 Serial.print(F(" W\n"));
330 }
331
332 uint16_t current_code, max_current_code, min_current_code;
333 ack |= LTC2946_read_12_bits(LTC2946_I2C_ADDRESS, LTC2946_DELTA_SENSE_MSB_REG, &current_code);
334 ack |= LTC2946_read_12_bits(LTC2946_I2C_ADDRESS, LTC2946_MAX_DELTA_SENSE_MSB_REG, &max_current_code);
335 ack |= LTC2946_read_12_bits(LTC2946_I2C_ADDRESS, LTC2946_MIN_DELTA_SENSE_MSB_REG, &min_current_code);
336
337 float current, max_current, min_current;
338 current = LTC2946_code_to_current(current_code, resistor, LTC2946_DELTA_SENSE_lsb);
339 max_current = LTC2946_code_to_current(max_current_code, resistor, LTC2946_DELTA_SENSE_lsb);
340 min_current = LTC2946_code_to_current(min_current_code, resistor, LTC2946_DELTA_SENSE_lsb);
341
342 Serial.print(F("\n****Current: "));
343 Serial.print(current, 4);
344 Serial.print(F(" A\n"));
345
346 Serial.print(F("Max Current: "));
347 Serial.print(max_current, 4);
348 Serial.print(F(" A\n"));
349
350 Serial.print(F("Min Current: "));
351 Serial.print(min_current, 4);
352 Serial.print(F(" A\n"));
353
354 uint16_t VIN_code, max_VIN_code, min_VIN_code;
355 ack |= LTC2946_read_12_bits(LTC2946_I2C_ADDRESS, LTC2946_VIN_MSB_REG, &VIN_code);
356 ack |= LTC2946_read_12_bits(LTC2946_I2C_ADDRESS, LTC2946_MAX_VIN_MSB_REG, &max_VIN_code);
357 ack |= LTC2946_read_12_bits(LTC2946_I2C_ADDRESS, LTC2946_MIN_VIN_MSB_REG, &min_VIN_code);
358
359 float VIN, max_VIN, min_VIN;
360 VIN = LTC2946_VIN_code_to_voltage(VIN_code , LTC2946_VIN_lsb);
361 max_VIN = LTC2946_VIN_code_to_voltage(max_VIN_code, LTC2946_VIN_lsb);
362 min_VIN = LTC2946_VIN_code_to_voltage(min_VIN_code, LTC2946_VIN_lsb);
363
364 Serial.print(F("\n****VIN: "));
365 Serial.print(VIN, 4);
366 Serial.print(F(" V\n"));
367
368 Serial.print(F("Max VIN: "));
369 Serial.print(max_VIN, 4);
370 Serial.print(F(" V\n"));
371
372 Serial.print(F("Min VIN: "));
373 Serial.print(min_VIN, 4);
374 Serial.print(F(" V\n"));
375
376 uint16_t ADIN_code, max_ADIN_code, min_ADIN_code;
377 ack |= LTC2946_read_12_bits(LTC2946_I2C_ADDRESS, LTC2946_ADIN_MSB_REG, &ADIN_code);
378 ack |= LTC2946_read_12_bits(LTC2946_I2C_ADDRESS, LTC2946_MAX_ADIN_MSB_REG, &max_ADIN_code);
379 ack |= LTC2946_read_12_bits(LTC2946_I2C_ADDRESS, LTC2946_MIN_ADIN_MSB_REG, &min_ADIN_code);
380
381 float ADIN, max_ADIN, min_ADIN;
382 ADIN = LTC2946_ADIN_code_to_voltage(ADIN_code, LTC2946_ADIN_lsb)*scale;
383 max_ADIN = LTC2946_ADIN_code_to_voltage(max_ADIN_code, LTC2946_ADIN_lsb)*scale;
384 min_ADIN = LTC2946_ADIN_code_to_voltage(min_ADIN_code, LTC2946_ADIN_lsb)*scale;
385
386 Serial.print(F("\n****ADIN: "));
387 Serial.print(ADIN, 4);
388 Serial.print(F(" V\n"));
389
390 Serial.print(F("Max ADIN: "));
391 Serial.print(max_ADIN, 4);
392 Serial.print(F(" V\n"));
393
394 Serial.print(F("Min ADIN: "));
395 Serial.print(min_ADIN, 4);
396 Serial.print(F(" V\n"));
397
398
399
400 uint32_t energy_code;
401 ack |= LTC2946_read_32_bits(LTC2946_I2C_ADDRESS, LTC2946_ENERGY_MSB3_REG, &energy_code);
402
403 uint32_t charge_code;
404 ack |= LTC2946_read_32_bits(LTC2946_I2C_ADDRESS, LTC2946_CHARGE_MSB3_REG, &charge_code);
405
406
407 uint32_t time_code;
408 ack |= LTC2946_read_32_bits(LTC2946_I2C_ADDRESS, LTC2946_TIME_COUNTER_MSB3_REG, &time_code);
409
410
411 float energy,charge,time;
412
413 if (internalCLK)
414 {
415 energy = LTC2946_code_to_energy(energy_code,resistor,LTC2946_Power_lsb, LTC2946_INTERNAL_TIME_lsb);
416 charge = LTC2946_code_to_coulombs(charge_code,resistor,LTC2946_DELTA_SENSE_lsb, LTC2946_INTERNAL_TIME_lsb);
417 time = LTC2946_code_to_time(time_code, LTC2946_INTERNAL_TIME_lsb);
418 }
419 else
420 {
421 energy = LTC2946_code_to_energy(energy_code,resistor,LTC2946_Power_lsb, LTC2946_TIME_lsb);
422 charge = LTC2946_code_to_coulombs(charge_code,resistor,LTC2946_DELTA_SENSE_lsb, LTC2946_TIME_lsb);
423 time = LTC2946_code_to_time(time_code, LTC2946_TIME_lsb);
424 }
425
426 Serial.print(F("**********Accumulators**********\n"));
427
428 Serial.print(F("\n****Energy: "));
429 Serial.print(energy, 4);
430 Serial.print(F(" J\n"));
431
432 Serial.print(F("****Charge: "));
433 Serial.print(charge, 4);
434 Serial.print(F(" C\n"));
435
436 Serial.print(F("****Time: "));
437 Serial.print(time, 4);
438 Serial.print(F(" s\n\n"));
439
440 Serial.print(F("********************************\n"));
441
442
443 Serial.print(F("m-Main Menu\n\n"));
444 Serial.flush();
445 delay(CONTINUOUS_MODE_DISPLAY_DELAY);
446 }
447 while (Serial.available() == false);
448 read_int(); // clears the Serial.available
449 return(ack);
450 }
451
452 //! Snapshot Mode Menu
453 int8_t menu_2_snapshot_mode(uint8_t VOLTAGE_SEL, //!< VOLTAGE_SEL variable represents the voltage channel selected. Scaling is done if ADIN channel is selected and resistive dividers are present.
454 float scale) //!< Stores division ratio for resistive divider on ADIN pin. Configured inside "Settings" menu.
455 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
456 {
457 int8_t ack = 0;
458 //! Print submenu
459 Serial.print(F("*************************\n\n"));
460 Serial.print(F("Snapshot Mode\n"));
461 Serial.print(F("1-SENSE+\n"));
462 Serial.print(F("2-ADIN\n"));
463 Serial.print(F("3-VDD\n"));
464 Serial.print(F("4-Current\n"));
465 Serial.print(F("m-Main Menu\n"));
466 uint8_t user_command;
467 do
468 {
469 Serial.print(F("\n\nEnter a Command: "));
470 user_command = read_int();
471 if (user_command == 'm')
472 Serial.println("m");
473 else
474 {
475 Serial.println(user_command);
476 }
477 if (user_command != 'm')
478 {
479 Serial.print(F("*************************\n\n"));
480 Serial.print(F("Snapshot Mode\n"));
481 Serial.print(F("1-SENSE+\n"));
482 Serial.print(F("2-ADIN\n"));
483 Serial.print(F("3-VDD\n"));
484 Serial.print(F("4-Current\n"));
485 Serial.print(F("m-Main Menu\n"));
486 }
487 Serial.println();
488 switch (user_command)
489 {
490 case 1: // SENSE+ - Snapshot Mode
491 ack |= menu_2_snapshot_mode_menu_1_SENSE();
492 break;
493
494 case 2: // VIN - Snapshot Mode
495 ack |= menu_2_snapshot_mode_menu_2_ADIN(scale);
496 break;
497
498 case 3: // ADIN - Snapshot Mode
499 ack |= menu_2_snapshot_mode_menu_3_VDD();
500 break;
501 case 4: //Current - Snapshot Mode
502 ack |= menu_2_snapshot_mode_menu_4_Current();
503 break;
504 default:
505 if (user_command != 'm')
506 Serial.println("Incorrect Option");
507 break;
508 }
509
510 if (user_command != 'm')
511 {
512 Serial.print(F("*************************\n\n"));
513 Serial.print(F("Snapshot Mode\n"));
514 Serial.print(F("1-SENSE+\n"));
515 Serial.print(F("2-ADIN\n"));
516 Serial.print(F("3-VDD\n"));
517 Serial.print(F("4-Current\n"));
518 Serial.print(F("m-Main Menu\n"));
519 }
520
521 }
522 while (!((user_command == 'm') || (ack)));
523 return(ack);
524 }
525
526 //! SENSE+ - Snapshot mode
527 int8_t menu_2_snapshot_mode_menu_1_SENSE()
528 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
529 {
530 int8_t ack = 0;
531 int8_t LTC2946_mode;
532 LTC2946_mode = LTC2946_CHANNEL_CONFIG_SNAPSHOT | LTC2946_SENSE_PLUS;
533 ack |= LTC2946_write(LTC2946_I2C_ADDRESS, LTC2946_CTRLA_REG, LTC2946_mode);
534
535 uint8_t busy;
536 do
537 {
538 ack |= LTC2946_read(LTC2946_I2C_ADDRESS, LTC2946_STATUS2_REG, &busy);
539 }
540 while (0x8 & busy);
541
542 uint16_t voltage_code;
543 ack |= LTC2946_read_12_bits(LTC2946_I2C_ADDRESS, LTC2946_VIN_MSB_REG, &voltage_code);
544
545 float voltage;
546 voltage = LTC2946_VIN_code_to_voltage(voltage_code, LTC2946_VIN_lsb);
547 Serial.print(F("SENSE+: "));
548 Serial.print(voltage, 4);
549 Serial.print(F(" V\n\n"));
550 return(ack);
551 }
552
553 //! ADIN - Snapshot Mode
554 int8_t menu_2_snapshot_mode_menu_2_ADIN(float scale)
555 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
556 {
557 int8_t ack = 0;
558 int8_t LTC2946_mode;
559 LTC2946_mode = LTC2946_CHANNEL_CONFIG_SNAPSHOT | LTC2946_ADIN;
560 ack |= LTC2946_write(LTC2946_I2C_ADDRESS, LTC2946_CTRLA_REG, LTC2946_mode);
561
562 uint8_t busy;
563 do
564 {
565 ack |= LTC2946_read(LTC2946_I2C_ADDRESS, LTC2946_STATUS2_REG, &busy);
566 }
567 while (0x8 & busy);
568
569 uint16_t ADIN_code;
570 ack |= LTC2946_read_12_bits(LTC2946_I2C_ADDRESS, LTC2946_ADIN_MSB_REG, &ADIN_code);
571
572 float ADIN;
573 ADIN = LTC2946_ADIN_code_to_voltage(ADIN_code, LTC2946_ADIN_lsb)*scale;
574 Serial.print(F("ADIN: "));
575 Serial.print(ADIN, 4);
576 Serial.print(F(" V\n\n"));
577 return(ack);
578 }
579
580 //! VDD - Snapshot Mode
581 int8_t menu_2_snapshot_mode_menu_3_VDD()
582 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
583 {
584 int8_t ack = 0;
585 int8_t LTC2946_mode;
586 LTC2946_mode = LTC2946_CHANNEL_CONFIG_SNAPSHOT | LTC2946_VDD;
587 ack |= LTC2946_write(LTC2946_I2C_ADDRESS, LTC2946_CTRLA_REG, LTC2946_mode);
588
589 uint8_t busy;
590 do
591 {
592 ack |= LTC2946_read(LTC2946_I2C_ADDRESS, LTC2946_STATUS2_REG, &busy);
593 }
594 while (0x8 & busy);
595
596 uint16_t VDD_code;
597 ack |= LTC2946_read_12_bits(LTC2946_I2C_ADDRESS, LTC2946_VIN_MSB_REG, &VDD_code);
598
599 float VDD;
600 VDD = LTC2946_VIN_code_to_voltage(VDD_code, LTC2946_VIN_lsb);
601 Serial.print(F("VDD: "));
602 Serial.print(VDD, 4);
603 Serial.print(F(" V\n\n"));
604 return(ack);
605 }
606
607 //! Current - Snapshot Mode
608 int8_t menu_2_snapshot_mode_menu_4_Current()
609 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
610 {
611 int8_t ack = 0;
612 int8_t LTC2946_mode;
613 LTC2946_mode = LTC2946_CHANNEL_CONFIG_SNAPSHOT | LTC2946_DELTA_SENSE;
614 ack |= LTC2946_write(LTC2946_I2C_ADDRESS, LTC2946_CTRLA_REG, LTC2946_mode);
615
616 uint8_t busy;
617 do
618 {
619 ack |= LTC2946_read(LTC2946_I2C_ADDRESS, LTC2946_STATUS2_REG, &busy); //!< Check to see if conversion is still in process
620 }
621 while (0x8 & busy);
622
623 uint16_t current_code;
624 ack |= LTC2946_read_12_bits(LTC2946_I2C_ADDRESS, LTC2946_DELTA_SENSE_MSB_REG, &current_code);
625
626 float current;
627 current = LTC2946_code_to_current(current_code, resistor, LTC2946_DELTA_SENSE_lsb);
628 Serial.print(F("Current: "));
629 Serial.print(current, 4);
630 Serial.print(F(" A\n\n"));
631 return(ack);
632 }
633
634
635 //! Alert and Threshold Menu
636 int8_t menu_3_alert(uint8_t VOLTAGE_SEL, //!< Voltage Selection Variable.
637 float scale) //!< Stores division ratio for resistive divider on ADIN pin. Configured inside "Settings" menu.
638 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
639 {
640 int8_t ack = 0;
641 int8_t user_command;
642 do
643 {
644 //Print Sub-Menu
645 Serial.print(F("*************************\n\n"));
646 Serial.print(F("1-Set Power Alert Thresholds\n"));
647 Serial.print(F("2-Set Current Alert Thresholds\n"));
648 Serial.print(F("3-Set VIN Alert Thresholds\n"));
649 Serial.print(F("4-Set ADIN Alert Thresholds\n"));
650 Serial.print(F("5-Enable and Disable Alerts\n"));
651 Serial.print(F("6-Read and Clear Alerts\n"));
652 Serial.print(F("7-Store Alert Settings to EEPROM\n"));
653 Serial.print(F("m-Main Menu\n\n"));
654 Serial.print(F("Enter a command: "));
655
656 user_command = read_int();
657 if (user_command == 'm')
658 Serial.println("m");
659 else
660 Serial.println(user_command);
661 Serial.println();
662 switch (user_command)
663 {
664 case 1:
665 ack |= menu_3_alert_menu_1_set_power_alerts(VOLTAGE_SEL, scale); // Set Power Alert Thresholds
666 break;
667
668 case 2:
669 ack |= menu_3_alert_menu_2_set_current_alerts(); // Set Current Alert Thresholds
670 break;
671
672 case 3:
673 ack |= menu_3_alert_menu_3_set_vin_alerts(); // Set VIN Alert Thresholds
674 break;
675
676 case 4:
677 ack |= menu_3_alert_menu_4_set_adin_alerts(scale); // Set ADIN Alert Thresholds
678 break;
679
680 case 5:
681 ack |= menu_3_alert_menu_5_enable_disable_alerts(); // Enable/Disable Alert Menu
682 break;
683
684 case 6:
685 ack |= menu_3_alert_menu_6_read_clear_faults(); // Read Fault Register
686 break;
687
688 case 7:
689 // Read current min/max alarm and store to EEPROM
690 store_alert_settings();
691 break;
692 default:
693 if (user_command != 'm')
694 Serial.println("Incorrect Option");
695 break;
696 }
697 }
698 while (!((user_command == 'm') || (ack)));
699 return(ack);
700 }
701
702 //! Set Power Alert Thresholds
703 int8_t menu_3_alert_menu_1_set_power_alerts(uint8_t VOLTAGE_SEL, //!< Choose whether power multiplier uses ADIN pin or SENSE pin as voltage input (A0 bit in CONTROL Register A)
704 float scale) //!< Scale value based on resistive divider on the ADIN pin.
705 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
706 {
707 int8_t ack = 0;
708 Serial.print(F("Enter Max Power Threshold:"));
709
710 float max_power_threshold;
711 max_power_threshold = read_float();
712 Serial.println(max_power_threshold, 4);
713
714 int32_t max_power_threshold_code;
715 if (VOLTAGE_SEL != LTC2946_ADIN)
716 max_power_threshold_code = (max_power_threshold / LTC2946_Power_lsb) * resistor;
717 else
718 max_power_threshold_code = ((1.0/scale)*(max_power_threshold / LTC2946_ADIN_DELTA_SENSE_lsb)) * resistor;
719
720 ack |= LTC2946_write_24_bits(LTC2946_I2C_ADDRESS, LTC2946_MAX_POWER_THRESHOLD_MSB2_REG, max_power_threshold_code);
721
722 Serial.print(F("Enter Min Power Threshold:"));
723
724 float min_power_threshold;
725 min_power_threshold = read_float();
726 Serial.println(min_power_threshold, 4);
727
728 int32_t min_power_threshold_code;
729 if (VOLTAGE_SEL != LTC2946_ADIN)
730 min_power_threshold_code = (min_power_threshold / LTC2946_Power_lsb) * resistor;
731 else
732 min_power_threshold_code = ((1.0/scale)*(min_power_threshold / LTC2946_ADIN_DELTA_SENSE_lsb)) * resistor;
733 ack |= LTC2946_write_24_bits(LTC2946_I2C_ADDRESS, LTC2946_MIN_POWER_THRESHOLD_MSB2_REG, min_power_threshold_code);
734 return(ack);
735 }
736
737 //! Set Current Alert Thresholds
738 int8_t menu_3_alert_menu_2_set_current_alerts()
739 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
740 {
741 int8_t ack = 0;
742 Serial.print(F("Enter Max Current Threshold:"));
743
744 float max_current_threshold;
745 max_current_threshold = read_float();
746 Serial.println(max_current_threshold, 4);
747
748 int32_t max_current_threshold_code;
749 max_current_threshold_code = (max_current_threshold / LTC2946_DELTA_SENSE_lsb) * resistor;
750
751 ack |= LTC2946_write_16_bits(LTC2946_I2C_ADDRESS, LTC2946_MAX_DELTA_SENSE_THRESHOLD_MSB_REG, (max_current_threshold_code << 4));
752
753 Serial.print(F("Enter Min Current Threshold:"));
754
755 float min_current_threshold;
756 min_current_threshold = read_float();
757 Serial.println(min_current_threshold, 4);
758
759 int32_t min_current_threshold_code;
760 min_current_threshold_code = (min_current_threshold / LTC2946_DELTA_SENSE_lsb) * resistor;
761 ack |= LTC2946_write_16_bits(LTC2946_I2C_ADDRESS, LTC2946_MIN_DELTA_SENSE_THRESHOLD_MSB_REG, (min_current_threshold_code << 4));
762 return(ack);
763 }
764
765 //! Set VIN Alert Thresholds
766 int8_t menu_3_alert_menu_3_set_vin_alerts()
767 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
768 {
769 int8_t ack = 0;
770 Serial.print(F("Enter Max VIN Threshold:"));
771
772 float max_VIN_threshold;
773 max_VIN_threshold = read_float();
774 Serial.println(max_VIN_threshold, 4);
775
776 int32_t max_VIN_threshold_code;
777 max_VIN_threshold_code = max_VIN_threshold / LTC2946_VIN_lsb;
778 ack |= LTC2946_write_16_bits(LTC2946_I2C_ADDRESS, LTC2946_MAX_VIN_THRESHOLD_MSB_REG, (max_VIN_threshold_code << 4));
779
780 Serial.print(F("Enter Min VIN Threshold:"));
781
782 float min_VIN_threshold;
783 min_VIN_threshold = read_float();
784 Serial.println(min_VIN_threshold, 4);
785
786 int32_t min_VIN_threshold_code;
787 min_VIN_threshold_code = min_VIN_threshold / LTC2946_VIN_lsb;
788 ack |= LTC2946_write_16_bits(LTC2946_I2C_ADDRESS, LTC2946_MIN_VIN_THRESHOLD_MSB_REG, (min_VIN_threshold_code << 4));
789 return(ack);
790 }
791
792 //! Set ADIN Alert Thresholds
793 int8_t menu_3_alert_menu_4_set_adin_alerts(float scale //!< Scale value based on resistive divider on the ADIN pin.
794 )
795 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
796 {
797 int8_t ack = 0;
798 Serial.print(F("Enter Max ADIN Threshold:"));
799
800 float max_ADIN_threshold;
801 max_ADIN_threshold = read_float();
802 Serial.println(max_ADIN_threshold, 4);
803
804 int32_t max_ADIN_threshold_code;
805 max_ADIN_threshold_code = ((1.0/scale)*max_ADIN_threshold) / LTC2946_ADIN_lsb;
806 ack |= LTC2946_write_16_bits(LTC2946_I2C_ADDRESS, LTC2946_MAX_ADIN_THRESHOLD_MSB_REG, (max_ADIN_threshold_code << 4));
807
808 Serial.print(F("Enter Min ADIN Threshold:"));
809
810 float min_ADIN_threshold;
811 min_ADIN_threshold = read_float();
812 Serial.println(min_ADIN_threshold, 4);
813
814 int32_t min_ADIN_threshold_code;
815 min_ADIN_threshold_code = ((1.0/scale)*min_ADIN_threshold) / LTC2946_ADIN_lsb;
816 ack |= LTC2946_write_16_bits(LTC2946_I2C_ADDRESS, LTC2946_MIN_ADIN_THRESHOLD_MSB_REG, (min_ADIN_threshold_code << 4));
817 return(ack);
818 }
819
820
821 //! Enable/Disable Alert Menu
822 int8_t menu_3_alert_menu_5_enable_disable_alerts()
823 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
824 {
825 int8_t ack = 0;
826 uint8_t user_command;
827 do
828 {
829 Serial.print(F("*************************\n\n"));
830 Serial.print(F("1-Enable/Disable ALERT1 Alerts\n"));
831 Serial.print(F("2-Enable/Disable ALERT2 Alerts\n"));
832 user_command = read_int();
833 if (user_command == 'm')
834 Serial.println('m');
835 else
836 Serial.println(user_command);
837 switch (user_command)
838 {
839 case 1: // Enable/Disable Alerts in ALERT1 Register
840 ack |= menu_3_alert_menu_5_enable_disable_alerts_menu_1_ALERT1();
841 break;
842 case 2: // Enable/Disable Alerts in ALERT2 Register
843 ack |= menu_3_alert_menu_5_enable_disable_alerts_menu_2_ALERT2();
844 break;
845 default:
846 if (user_command != 'm')
847 Serial.println("Incorrect Option");
848 break;
849 }
850
851 }
852 while (user_command != 'm');
853
854 return(ack);
855 }
856
857 //! Enable/Disable Alert in ALERT1 Register
858 int8_t menu_3_alert_menu_5_enable_disable_alerts_menu_1_ALERT1()
859 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
860 {
861 int8_t ack = 0;
862 uint8_t user_command;
863 do
864 {
865 //Print Sub-Menu
866 Serial.print(F("*************************\n\n"));
867 Serial.print(F("1-Enable/Disable Power Alerts\n"));
868 Serial.print(F("2-Enable/Disable Current Alerts\n"));
869 Serial.print(F("3-Enable/Disable VIN Alerts\n"));
870 Serial.print(F("4-Enable/Disable ADIN Alerts\n"));
871 Serial.print(F("m-Alert Menu\n\n"));
872 Serial.print(F("Enter a command:"));
873 user_command = read_int();
874 if (user_command == 'm')
875 Serial.println('m');
876 else
877 Serial.println(user_command);
878 if (!(user_command == 0))
879 {
880 Serial.print(F("1-Enable, 2-Disable\n"));
881 }
882 switch (user_command)
883 {
884 case 1:
885 // ENABLE/Disable Power Alerts
886 Serial.print(F("Max Power :"));
887 user_command = read_int();
888 if ((user_command > 2) || (user_command < 0))
889 user_command = 2;
890 Serial.println(user_command);
891 if (user_command == 1)
892 alert1_code = alert1_code | LTC2946_ENABLE_MAX_POWER_ALERT;
893 else
894 alert1_code = alert1_code & LTC2946_DISABLE_MAX_POWER_ALERT;
895
896 Serial.print(F("Min Power :"));
897 user_command = read_int();
898 if ((user_command > 2) || (user_command < 0))
899 user_command = 2;
900 Serial.println(user_command);
901 if (user_command == 1)
902 alert1_code = alert1_code | LTC2946_ENABLE_MIN_POWER_ALERT;
903 else
904 alert1_code = alert1_code & LTC2946_DISABLE_MIN_POWER_ALERT;
905 break;
906 case 2:
907 // ENABLE/Disable Current Alerts
908 Serial.print(F("Max Current :"));
909 user_command = read_int();
910 if ((user_command > 2) || (user_command < 0))
911 user_command = 2;
912 Serial.println(user_command);
913 if (user_command == 1)
914 alert1_code = alert1_code | LTC2946_ENABLE_MAX_I_SENSE_ALERT;
915 else
916 alert1_code = alert1_code & LTC2946_DISABLE_MAX_I_SENSE_ALERT;
917
918 Serial.print(F("Min Current :"));
919 user_command = read_int();
920 if ((user_command > 2) || (user_command < 0))
921 user_command = 2;
922 Serial.println(user_command);
923 if (user_command == 1)
924 alert1_code = alert1_code | LTC2946_ENABLE_MIN_I_SENSE_ALERT;
925 else
926 alert1_code = alert1_code & LTC2946_DISABLE_MIN_I_SENSE_ALERT;
927 break;
928 case 3:
929 // ENABLE/Disable VIN Alerts
930 Serial.print(F("Max VIN :"));
931 user_command = read_int();
932 if ((user_command > 2) || (user_command < 0))
933 user_command = 2;
934 Serial.println(user_command);
935 if (user_command == 1)
936 alert1_code = alert1_code | LTC2946_ENABLE_MAX_VIN_ALERT;
937 else
938 alert1_code = alert1_code & LTC2946_DISABLE_MAX_VIN_ALERT;
939
940 Serial.print(F("Min VIN :"));
941 user_command = read_int();
942 if ((user_command > 2) || (user_command < 0))
943 user_command = 2;
944 Serial.println(user_command);
945 if (user_command == 1)
946 alert1_code = alert1_code | LTC2946_ENABLE_MIN_VIN_ALERT;
947 else
948 alert1_code = alert1_code & LTC2946_DISABLE_MIN_VIN_ALERT;
949 break;
950 case 4:
951 // ENABLE/Disable ADIN Alerts
952 Serial.print(F("Max ADIN :"));
953 user_command = read_int();
954 if ((user_command > 2) || (user_command < 0))
955 user_command = 2;
956 Serial.println(user_command);
957 if (user_command == 1)
958 alert1_code = alert1_code | LTC2946_ENABLE_MAX_ADIN_ALERT;
959 else
960 alert1_code = alert1_code & LTC2946_DISABLE_MAX_ADIN_ALERT;
961
962 Serial.print(F("Min ADIN :"));
963 user_command = read_int();
964 if ((user_command > 2) || (user_command < 0))
965 user_command = 2;
966 Serial.println(user_command);
967 if (user_command == 1)
968 alert1_code = alert1_code | LTC2946_ENABLE_MIN_ADIN_ALERT;
969 else
970 alert1_code = alert1_code & LTC2946_DISABLE_MIN_ADIN_ALERT;
971 break;
972 default:
973 if (user_command != 'm')
974 Serial.println("Incorrect Option");
975 break;
976 }
977 }
978 while (user_command != 'm');
979 ack |= LTC2946_write(LTC2946_I2C_ADDRESS, LTC2946_ALERT1_REG, alert1_code);
980 return(ack);
981 }
982
983 // Enable/Disable alerts in ALERT2 register
984 int8_t menu_3_alert_menu_5_enable_disable_alerts_menu_2_ALERT2()
985 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
986 {
987 int8_t ack = 0;
988 uint8_t user_command;
989 do
990 {
991 //Print Menu
992 Serial.print(F("*************************\n\n"));
993 Serial.print(F("1-Enable/Disable ADC Conversion Alert\n"));
994 Serial.print(F("2-Enable/Disable GPIO1 Input Alert\n"));
995 Serial.print(F("3-Enable/Disable GPIO2 Input Alert\n"));
996 Serial.print(F("4-Enable/Disable Stuck-Bus Timeout Wake-up Alert\n"));
997 Serial.print(F("5-Enable/Disable Energy Overflow Alert\n"));
998 Serial.print(F("6-Enable/Disable Charge Overflow Alert\n"));
999 Serial.print(F("7-Enable/Disable Time Counter Overflow Alert\n"));
1000 Serial.print(F("m-Alert Menu\n\n"));
1001 Serial.print(F("Enter a command:"));
1002 user_command = read_int();
1003 if (user_command == 'm')
1004 Serial.println('m');
1005 else
1006 Serial.println(user_command);
1007 if (!(user_command == 0))
1008 {
1009 Serial.print(F("1-Enable, 2-Disable\n"));
1010 }
1011 switch (user_command)
1012 {
1013 case 1:
1014 // Enable/Disable ADC Conversion Alert
1015 Serial.print(F("ADC Conv Done: "));
1016 user_command = read_int();
1017 if ((user_command > 2) || (user_command < 0))
1018 user_command = 2;
1019 Serial.println(user_command);
1020 if (user_command == 1)
1021 alert2_code = alert2_code | LTC2946_ENABLE_ADC_DONE_ALERT;
1022 else
1023 alert2_code = alert2_code & ~LTC2946_ENABLE_ADC_DONE_ALERT ;
1024 break;
1025 case 2:
1026 // Enable/Disable GPIO1 Input Alert
1027 Serial.print(F("GPIO1 Input Alert: "));
1028 user_command = read_int();
1029 if ((user_command > 2) || (user_command < 0))
1030 user_command = 2;
1031 Serial.println(user_command);
1032 if (user_command == 1)
1033 alert2_code = alert2_code | LTC2946_ENABLE_GPIO_1_ALERT;
1034 else
1035 alert2_code = alert2_code & LTC2946_DISABLE_GPIO_1_ALERT;
1036 break;
1037 case 3:
1038 // Enable/Disable GPIO2 Input Alert
1039 Serial.print(F("GPIO2 Input Alert: "));
1040 user_command = read_int();
1041 if ((user_command > 2) || (user_command < 0))
1042 user_command = 2;
1043 Serial.println(user_command);
1044 if (user_command == 1)
1045 alert2_code = alert2_code | LTC2946_ENABLE_GPIO_2_ALERT;
1046 else
1047 alert2_code = alert2_code & LTC2946_DISABLE_GPIO_2_ALERT;
1048 break;
1049 case 4:
1050 // Enable/Disable Stuck-Bus Timeout Wake-Up Alert
1051 Serial.print(F("Stuck-Bus Timeout Wake-Up Alert: "));
1052 user_command = read_int();
1053 if ((user_command > 2) || (user_command < 0))
1054 user_command = 2;
1055 Serial.println(user_command);
1056 if (user_command == 1)
1057 alert2_code = alert2_code | LTC2946_ENABLE_STUCK_BUS_WAKE_ALERT;
1058 else
1059 alert2_code = alert2_code & LTC2946_DISABLE_STUCK_BUS_WAKE_ALERT;
1060 break;
1061 case 5:
1062 // Enable/Disable Energy Overflow Alert
1063 Serial.print(F("Energy Overflow Alert: "));
1064 user_command = read_int();
1065 if ((user_command > 2) || (user_command < 0))
1066 user_command = 2;
1067 Serial.println(user_command);
1068 if (user_command == 1)
1069 alert2_code = alert2_code | LTC2946_ENABLE_ENERGY_OVERFLOW_ALERT;
1070 else
1071 alert2_code = alert2_code & LTC2946_DISABLE_ENERGY_OVERFLOW_ALERT;
1072 break;
1073 case 6:
1074 // Enable/Disable Charge Overflow Alert
1075 Serial.print(F("Charge Overflow Alert: "));
1076 user_command = read_int();
1077 if ((user_command > 2) || (user_command < 0))
1078 user_command = 2;
1079 Serial.println(user_command);
1080 if (user_command == 1)
1081 alert2_code = alert2_code | LTC2946_ENABLE_CHARGE_OVERFLOW_ALERT;
1082 else
1083 alert2_code = alert2_code & LTC2946_DISABLE_CHARGE_OVERFLOW_ALERT;
1084 break;
1085 case 7:
1086 // Enable/Disable Time Counter Overflow Alert
1087 Serial.print(F("Time Counter Overflow Alert: "));
1088 user_command = read_int();
1089 if ((user_command > 2) || (user_command < 0))
1090 user_command = 2;
1091 Serial.println(user_command);
1092 if (user_command == 1)
1093 alert2_code = alert2_code | LTC2946_ENABLE_COUNTER_OVERFLOW_ALERT;
1094 else
1095 alert2_code = alert2_code & LTC2946_DISABLE_COUNTER_OVERFLOW_ALERT;
1096 break;
1097 default:
1098 if (user_command != 'm')
1099 Serial.println("Incorrect Option");
1100 break;
1101 }
1102 }
1103 while (user_command != 'm');
1104 ack |= LTC2946_write(LTC2946_I2C_ADDRESS, LTC2946_ALERT2_REG, alert2_code);
1105 return(ack);
1106 }
1107
1108 //! Read Faults and Clear
1109 int8_t menu_3_alert_menu_6_read_clear_faults()
1110 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
1111 {
1112 int8_t ack = 0;
1113 uint8_t fault_code = 0;
1114 ack |= LTC2946_read(LTC2946_I2C_ADDRESS, LTC2946_FAULT1_REG, &fault_code);
1115 if (fault_code & 0x80) Serial.print(F("Power Overvalue Fault Occurred\n\n"));
1116 if (fault_code & 0x40) Serial.print(F("Power Undervalue Fault Occurred\n"));
1117 if (fault_code & 0x20) Serial.print(F("Current Overvalue Fault Occurred\n"));
1118 if (fault_code & 0x10) Serial.print(F("Current Undervalue Fault Occurred\n"));
1119 if (fault_code & 0x08) Serial.print(F("VIN Overvalue Fault Occurred\n"));
1120 if (fault_code & 0x04) Serial.print(F("VIN Undervalue Fault Occurred\n"));
1121 if (fault_code & 0x02) Serial.print(F("ADIN Overvalue Fault Occurred\n"));
1122 if (fault_code & 0x01) Serial.print(F("ADIN Undervalue Fault Occurred\n"));
1123 ack |= LTC2946_read(LTC2946_I2C_ADDRESS, LTC2946_FAULT2_REG, &fault_code);
1124 if (fault_code & 0x40) Serial.print(F("GPIO1 Input Fault Occurred\n"));
1125 if (fault_code & 0x20) Serial.print(F("GPIO2 Input Fault Occurred\n"));
1126 if (fault_code & 0x10) Serial.print(F("GPIO3 Input Fault Occurred\n"));
1127 if (fault_code & 0x08) Serial.print(F("Stuck-Bus Timeout Fault Occurred\n"));
1128 if (fault_code & 0x04) Serial.print(F("Energy Overflow Fault Occurred\n"));
1129 if (fault_code & 0x02) Serial.print(F("Charge Overflow Fault Occurred\n"));
1130 if (fault_code & 0x01) Serial.print(F("Time Counter Overflow Fault Occurred\n"));
1131 if (!fault_code) Serial.print(F("No Alarms Were Present\n\n"));
1132 else
1133 {
1134 fault_code = 0;
1135 ack |= LTC2946_write(LTC2946_I2C_ADDRESS, LTC2946_FAULT1_REG, fault_code);
1136 ack |= LTC2946_write(LTC2946_I2C_ADDRESS, LTC2946_FAULT2_REG, fault_code);
1137 }
1138
1139 return(ack);
1140 }
1141
1142 //! Toggle Shutdown Down Mode
1143 int8_t menu_4_shutdown(uint8_t *CTRLB, uint8_t *shutdown)
1144 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
1145 {
1146 int8_t ack = 0;
1147 if (*shutdown == 0)
1148 {
1149 *CTRLB = *CTRLB | LTC2946_ENABLE_SHUTDOWN;
1150 ack |= LTC2946_write(LTC2946_I2C_ADDRESS, LTC2946_CTRLB_REG, *CTRLB);
1151 *shutdown = 1;
1152 Serial.print(F("LTC2946 Has Been Shutdown\n\n"));
1153 }
1154 else
1155 {
1156 *CTRLB = *CTRLB & LTC2946_DISABLE_SHUTDOWN;
1157 ack |= LTC2946_write(LTC2946_I2C_ADDRESS, LTC2946_CTRLB_REG, *CTRLB);
1158 *shutdown = 0;
1159 Serial.print(F("LTC2946 Is No Longer in Shutdown\n\n"));
1160 }
1161
1162
1163 return(ack);
1164 }
1165
1166
1167
1168 //! Change Settings
1169 int8_t menu_5_settings(uint8_t *CTRLA, //!< Local Copy of Configuration in CTRLA Register.
1170 uint8_t *CTRLB, //!< Local Copy of Configuration in CTRLB Register.
1171 uint8_t *VOLTAGE_SEL, //!< Local Copy of Voltage Selection Channel.
1172 uint8_t *GPIO_CFG, //!< Local Copy of GPIO_CFG Register. Allows Configuration of GPIO1 and GPIO2 Pin states.
1173 uint8_t *GPIO3_CTRL, //!< Local Copy of GPIO3_CTRL Register. Allows Configuration of GPIO3 Pin
1174 float *scale) //!< Stores division ratio for resistive divider on ADIN pin.
1175 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
1176 {
1177 int8_t ack = 0;
1178 uint8_t user_command;
1179 do
1180 {
1181 //Print Sub Menu
1182 Serial.print(F("*************************\n\n"));
1183 Serial.print(F("1-Configure CTRLA Register\n"));
1184 Serial.print(F("2-Configure CTRLB Register\n"));
1185 Serial.print(F("3-Configure GPIO Pins\n"));
1186 Serial.print(F("4-Set scaling value for ADIN pin\n"));
1187 Serial.print(F("m-Main Menu\n\n"));
1188 Serial.print(F("Enter a command:"));
1189 user_command = read_int();
1190 if (user_command == 'm')
1191 Serial.println('m');
1192 else
1193 Serial.println(user_command);
1194 switch (user_command)
1195 {
1196 case 1:
1197 ack |= menu_5_settings_menu_1_configure_CTRLA_reg(CTRLA, VOLTAGE_SEL); //Configure CTRLA Register.
1198 break;
1199 case 2:
1200 ack |= menu_5_settings_menu_2_configure_CTRLB_reg(CTRLB); //Configure CTRLB Register.
1201 break;
1202 case 3:
1203 ack |= menu_5_settings_menu_3_configure_GPIO(GPIO_CFG, GPIO3_CTRL); //Configure GPIO pins.
1204 default:
1205 if (user_command != 'm')
1206 Serial.println("Incorrect Option");
1207 break;
1208 }
1209
1210 }
1211 while (user_command != 'm');
1212
1213 return(ack);
1214 }
1215 //! Configure CTRLA Register.
1216 int8_t menu_5_settings_menu_1_configure_CTRLA_reg(uint8_t *CTRLA, //!<Local Copy of CTRLA Register.
1217 uint8_t *VOLTAGE_SEL) //!<Local Copy of VOLTAGE_SEL. Indicates which voltage channel has been selected for power measurement.
1218 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
1219
1220 {
1221 int8_t ack = 0;
1222 uint8_t user_command;
1223 Serial.println(*CTRLA);
1224 do
1225 {
1226 // Print Sub-Menu
1227 Serial.print(F("*************************\n\n"));
1228 Serial.print(F("1-Configure ADIN reference\n"));
1229 Serial.print(F("2-Configure Offset Calibration\n"));
1230 Serial.print(F("3-Configure Voltage Selection\n"));
1231 Serial.print(F("4-Configure Measurement Channel\n"));
1232 Serial.print(F("m-Settings Menu\n\n"));
1233 Serial.print(F("Enter a command:"));
1234 user_command = read_int();
1235 if (user_command == 'm')
1236 Serial.println('m');
1237 else
1238 Serial.println(user_command);
1239 switch (user_command)
1240 {
1241 case 1:
1242 menu_5_settings_menu_1_configure_CTRLA_reg_menu_1_ADIN_Configuration(CTRLA); //!< Configure the ADIN reference to GND/INTVCC
1243 break;
1244 case 2:
1245 menu_5_settings_menu_1_configure_CTRLA_reg_menu_2_Offset_Configuration(CTRLA); //!< Configure frequency of offset calibration
1246 break;
1247 case 3:
1248 menu_5_settings_menu_1_configure_CTRLA_reg_menu_3_Voltage_Configuration(CTRLA, VOLTAGE_SEL); //!< Select the voltage measurement channel
1249 break;
1250 case 4:
1251 menu_5_settings_menu_1_configure_CTRLA_reg_menu_4_Channel_Configuration(CTRLA); //!< Select duty cycle of measurments and channel configuration.
1252 break;
1253 default:
1254 if (user_command != 'm')
1255 Serial.println("Incorrect Option");
1256 break;
1257 }
1258 }
1259 while (user_command != 'm');
1260
1261 ack |= LTC2946_write(LTC2946_I2C_ADDRESS, LTC2946_CTRLA_REG, *CTRLA);
1262
1263 return(ack);
1264 }
1265
1266
1267 //! Configure the ADIN reference to GND/INTVCC
1268 void menu_5_settings_menu_1_configure_CTRLA_reg_menu_1_ADIN_Configuration(uint8_t *CTRLA)
1269 {
1270
1271 uint8_t user_command;
1272 //Print Sub-Menu
1273 Serial.print(F("1-ADIN Measured with Respect to INTVCC\n"));
1274 Serial.print(F("2-ADIN Measured with Respect to GND\n\n"));
1275 Serial.print(F("Enter a command:"));
1276 user_command = read_int();
1277 if ((user_command > 2) || (user_command < 1))
1278 user_command = 2;
1279 Serial.println(user_command);
1280 if (user_command == 1)
1281 {
1282 *CTRLA = *CTRLA & LTC2946_CTRLA_ADIN_MASK;
1283 *CTRLA = *CTRLA | LTC2946_ADIN_INTVCC;
1284 Serial.print(F("CTRLA set to measure ADIN with respect to INTVCC\n"));
1285 }
1286 else
1287 {
1288 *CTRLA = *CTRLA & LTC2946_CTRLA_ADIN_MASK;
1289 *CTRLA = *CTRLA | LTC2946_ADIN_GND;
1290 Serial.print(F("CTRLA set to measure ADIN with respect to GND\n"));
1291 }
1292
1293 }
1294
1295 //! Configure frequency of offset calibration
1296 void menu_5_settings_menu_1_configure_CTRLA_reg_menu_2_Offset_Configuration(uint8_t *CTRLA)
1297 {
1298 uint8_t user_command;
1299 //Print Sub-Menu
1300 Serial.print(F("1-1st powerup or use last calibrated result\n"));
1301 Serial.print(F("2-Once every 128 conversions\n"));
1302 Serial.print(F("3-Once every 16 conversions\n"));
1303 Serial.print(F("4-Every conversion\n\n"));
1304 Serial.print(F("Enter a command:"));
1305 user_command = read_int();
1306 Serial.println(user_command);
1307 switch (user_command)
1308 {
1309 case 1:
1310 *CTRLA = *CTRLA & LTC2946_CTRLA_OFFSET_MASK;
1311 *CTRLA = *CTRLA | LTC2946_OFFSET_CAL_LAST;
1312 Serial.print(F("Offset Calibration set to use last calibrated result\n"));
1313 break;
1314 case 2:
1315 *CTRLA = *CTRLA & LTC2946_CTRLA_OFFSET_MASK;
1316 *CTRLA = *CTRLA | LTC2946_OFFSET_CAL_128;
1317 Serial.print(F("Offset Calibration set to once every 128 conversions\n"));
1318 break;
1319 case 3:
1320 *CTRLA = *CTRLA & LTC2946_CTRLA_OFFSET_MASK;
1321 *CTRLA = *CTRLA | LTC2946_OFFSET_CAL_16;
1322 Serial.print(F("Offset Calibration set to once every 16 conversions\n"));
1323 break;
1324 case 4:
1325 *CTRLA = *CTRLA & LTC2946_CTRLA_OFFSET_MASK;
1326 *CTRLA = *CTRLA | LTC2946_OFFSET_CAL_EVERY;
1327 Serial.print(F("Offset Calibration set to once every conversion\n"));
1328 break;
1329 default:
1330 if (user_command != 'm')
1331 Serial.println("Incorrect Option");
1332 break;
1333 }
1334 }
1335
1336 //! Select the voltage measurement channel
1337 void menu_5_settings_menu_1_configure_CTRLA_reg_menu_3_Voltage_Configuration(uint8_t *CTRLA, //!< Local copy of CTRLA register.
1338 uint8_t *VOLTAGE_SEL) //!< Voltage selection variable.
1339 {
1340 uint8_t user_command;
1341 Serial.print(F("1-SENSE+:\n"));
1342 Serial.print(F("2-ADIN:\n"));
1343 Serial.print(F("3-VDD:\n\n"));
1344 Serial.print(F("Enter a command:"));
1345 user_command = read_int();
1346 if ((user_command > 3) || (user_command < 0))
1347 user_command = 1;
1348 Serial.println(user_command);
1349
1350 switch (user_command)
1351 {
1352 case 1:
1353 *CTRLA = *CTRLA & LTC2946_CTRLA_VOLTAGE_SEL_MASK;
1354 *CTRLA = *CTRLA | LTC2946_SENSE_PLUS;
1355 *VOLTAGE_SEL = LTC2946_SENSE_PLUS;
1356 Serial.print(F("SENSE+ selected\n"));
1357 break;
1358 case 2:
1359 *CTRLA = *CTRLA & LTC2946_CTRLA_VOLTAGE_SEL_MASK;
1360 *CTRLA = *CTRLA | LTC2946_ADIN;
1361 *VOLTAGE_SEL = LTC2946_ADIN;
1362 Serial.print(F("ADIN selected\n"));
1363 break;
1364 case 3:
1365 *CTRLA = *CTRLA & LTC2946_CTRLA_VOLTAGE_SEL_MASK;
1366 *CTRLA = *CTRLA | LTC2946_VDD;
1367 *VOLTAGE_SEL = LTC2946_VDD;
1368 Serial.print(F("VDD selected\n"));
1369 break;
1370 default:
1371 if (user_command != 'm')
1372 Serial.println("Incorrect Option");
1373 break;
1374 }
1375 }
1376
1377 //!Select duty cycle of measurments and channel configuration.
1378 void menu_5_settings_menu_1_configure_CTRLA_reg_menu_4_Channel_Configuration(uint8_t *CTRLA) //!< Local copy of CTRLA Register
1379 {
1380
1381 uint8_t user_command;
1382 //Print Sub-Menu
1383 Serial.print(F("1-Voltage Once Followed by Current Indefinetly\n"));
1384 Serial.print(F("2-ADIN,Voltage, Current at 1/256, 1/256 and 254/256 Duty Cycle, Respectively\n"));
1385 Serial.print(F("3-ADIN,Voltage, Current at 1/32, 1/32 and 30/32 Duty Cycle, Respectively\n"));
1386 Serial.print(F("4-Aleternate ADIN, Voltage and Current Measurement\n"));
1387 Serial.print(F("5-Voltage and Current at 1/128 and 127/128 Duty Cycle, Respectively\n"));
1388 Serial.print(F("6-Voltage and Current at 1/16 and 15/16 Duty Cycle, Respectively\n"));
1389 Serial.print(F("7-Alternate Voltage and Current Measurement\n\n"));
1390 Serial.print(F("Enter a command:"));
1391 user_command = read_int();
1392 Serial.println(user_command);
1393 switch (user_command)
1394 {
1395 Serial.print(F("Selected Mode = "));
1396 case 1:
1397 *CTRLA = *CTRLA & LTC2946_CTRLA_CHANNEL_CONFIG_MASK;
1398 *CTRLA = *CTRLA | LTC2946_CHANNEL_CONFIG_V_C;
1399 Serial.print(F("Voltage Once Followed by Current Indefinetly\n"));
1400 break;
1401 case 2:
1402 *CTRLA = *CTRLA & LTC2946_CTRLA_CHANNEL_CONFIG_MASK;
1403 *CTRLA = *CTRLA | LTC2946_CHANNEL_CONFIG_A_V_C_1;
1404 Serial.print(F("ADIN,Voltage, Current at 1/256, 1/256 and 254/256 Duty Cycle, Respectively\n"));
1405 break;
1406 case 3:
1407 *CTRLA = *CTRLA & LTC2946_CTRLA_CHANNEL_CONFIG_MASK;
1408 *CTRLA = *CTRLA | LTC2946_CHANNEL_CONFIG_A_V_C_2;
1409 Serial.print(F("ADIN,Voltage, Current at 1/32, 1/32 and 30/32 Duty Cycle, Respectively\n"));
1410 break;
1411 case 4:
1412 *CTRLA = *CTRLA & LTC2946_CTRLA_CHANNEL_CONFIG_MASK;
1413 *CTRLA = *CTRLA | LTC2946_CHANNEL_CONFIG_A_V_C_3;
1414 Serial.print(F("Aleternate ADIN, Voltage and Current Measurement\n"));
1415 break;
1416 case 5:
1417 *CTRLA = *CTRLA & LTC2946_CTRLA_CHANNEL_CONFIG_MASK;
1418 *CTRLA = *CTRLA | LTC2946_CHANNEL_CONFIG_V_C_1;
1419 Serial.print(F("Voltage and Current at 1/128 and 127/128 Duty Cycle, Respectively\n"));
1420 break;
1421 case 6:
1422 *CTRLA = *CTRLA & LTC2946_CTRLA_CHANNEL_CONFIG_MASK;
1423 *CTRLA = *CTRLA | LTC2946_CHANNEL_CONFIG_V_C_2;
1424 Serial.print(F("Voltage and Current at 1/16 and 15/16 Duty Cycle, Respectively\n"));
1425 break;
1426 case 7:
1427 *CTRLA = *CTRLA & LTC2946_CTRLA_CHANNEL_CONFIG_MASK;
1428 *CTRLA = *CTRLA | LTC2946_CHANNEL_CONFIG_V_C_3;
1429 Serial.print(F("Alternate Voltage and Current Measurement\n\n"));
1430 break;
1431 default:
1432 if (user_command != 'm')
1433 Serial.println("Incorrect Option");
1434 break;
1435 }
1436
1437 }
1438
1439 //!Configure CTRLB Register.
1440 int8_t menu_5_settings_menu_2_configure_CTRLB_reg(uint8_t *CTRLB) //!< Local copy of CTRLB register.
1441 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
1442 {
1443 int8_t ack = 0;
1444 uint8_t user_command;
1445 do
1446 {
1447 //Print Sub-Menu
1448 Serial.print(F("*************************\n\n"));
1449 Serial.print(F("1-Enable/Disable Alert Clear Enable\n"));
1450 Serial.print(F("2-Enable/Disable Shutdown\n"));
1451 Serial.print(F("3-Enable/Disable Clear On Read\n"));
1452 Serial.print(F("4-Enable/Disable Stuck Bus Timeout Auto Wake up\n"));
1453 Serial.print(F("5-Enable/Disable Accumulation\n"));
1454 Serial.print(F("6-Enable/Disable Auto Reset Mode\n"));
1455 Serial.print(F("m-Settings Menu\n\n"));
1456 Serial.print(F("Enter a command:"));
1457 user_command = read_int();
1458 if (user_command == 'm')
1459 Serial.println('m');
1460 else
1461 Serial.println(user_command);
1462
1463 switch (user_command)
1464 {
1465
1466 case 1:
1467 Serial.print(F("1-Enable, 2-Disable\n"));
1468 // ENABLE/Disable ADIN Alerts
1469 Serial.print(F(" Alert Clear Enable:"));
1470 user_command = read_int();
1471 if ((user_command > 2) || (user_command < 0))
1472 user_command = 2;
1473 Serial.println(user_command);
1474 if (user_command == 1)
1475 *CTRLB = *CTRLB | LTC2946_ENABLE_ALERT_CLEAR;
1476 else
1477 *CTRLB = *CTRLB & LTC2946_DISABLE_ALERT_CLEAR;
1478 break;
1479 case 2:
1480 Serial.print(F("1-Enable, 2-Disable\n"));
1481 Serial.print(F(" Shutdown:"));
1482 user_command = read_int();
1483 if ((user_command > 2) || (user_command < 0))
1484 user_command = 2;
1485 Serial.println(user_command);
1486 if (user_command == 1)
1487 *CTRLB = *CTRLB | LTC2946_ENABLE_SHUTDOWN;
1488 else
1489 *CTRLB = *CTRLB & LTC2946_DISABLE_SHUTDOWN;
1490 break;
1491 case 3:
1492 Serial.print(F("1-Enable, 2-Disable\n"));
1493 Serial.print(F(" Cleared On Read Control:"));
1494 user_command = read_int();
1495 if ((user_command > 2) || (user_command < 0))
1496 user_command = 2;
1497 Serial.println(user_command);
1498 if (user_command == 1)
1499 *CTRLB = *CTRLB | LTC2946_ENABLE_CLEARED_ON_READ;
1500 else
1501 *CTRLB = *CTRLB & LTC2946_DISABLE_CLEARED_ON_READ;
1502 break;
1503 case 4:
1504 Serial.print(F("1-Enable, 2-Disable\n"));
1505 Serial.print(F(" Stuck Bus Timeout Auto Wake Up:"));
1506 user_command = read_int();
1507 if ((user_command > 2) || (user_command < 0))
1508 user_command = 2;
1509 Serial.println(user_command);
1510 if (user_command == 1)
1511 *CTRLB = *CTRLB | LTC2946_ENABLE_STUCK_BUS_RECOVER;
1512 else
1513 *CTRLB = *CTRLB & LTC2946_DISABLE_STUCK_BUS_RECOVER;
1514 break;
1515 case 5:
1516 Serial.print(F("1-Follow ACC State\n"));
1517 Serial.print(F("2-No Accumulate\n"));
1518 Serial.print(F("3-Accumulate\n"));
1519 Serial.print(F("Enter Command:"));
1520 user_command = read_int();
1521 Serial.println(user_command);
1522 switch (user_command)
1523 {
1524 case 1:
1525 *CTRLB = *CTRLB & LTC2946_CTRLB_ACC_MASK;
1526 *CTRLB = *CTRLB | LTC2946_ACC_PIN_CONTROL;
1527 break;
1528 case 2:
1529 *CTRLB = *CTRLB & LTC2946_CTRLB_ACC_MASK;
1530 *CTRLB = *CTRLB | LTC2946_DISABLE_ACC;
1531 break;
1532 case 3:
1533 *CTRLB = *CTRLB & LTC2946_CTRLB_ACC_MASK;
1534 *CTRLB = *CTRLB | LTC2946_ENABLE_ACC;
1535 break;
1536 default:
1537 Serial.println("Incorrect Option");
1538 }
1539 break;
1540 case 6:
1541 Serial.print(F("1-Reset All Registers\n"));
1542 Serial.print(F("2-Reset Accumulator\n"));
1543 Serial.print(F("3-Enable Auto-Reset\n"));
1544 Serial.print(F("4-Disable Auto-Reset\n"));
1545 Serial.print(F("Enter Command:"));
1546 user_command = read_int();
1547 Serial.println(user_command);
1548 switch (user_command)
1549 {
1550 case 1:
1551 *CTRLB = *CTRLB & LTC2946_CTRLB_RESET_MASK;
1552 *CTRLB = *CTRLB | LTC2946_RESET_ALL;
1553 break;
1554 case 2:
1555 *CTRLB = *CTRLB & LTC2946_CTRLB_RESET_MASK;
1556 *CTRLB = *CTRLB | LTC2946_RESET_ACC;
1557 break;
1558 case 3:
1559 *CTRLB = *CTRLB & LTC2946_CTRLB_RESET_MASK;
1560 *CTRLB = *CTRLB | LTC2946_ENABLE_AUTO_RESET;
1561 break;
1562 case 4:
1563 *CTRLB = *CTRLB & LTC2946_CTRLB_RESET_MASK;
1564 *CTRLB = *CTRLB | LTC2946_DISABLE_AUTO_RESET;
1565 break;
1566 default:
1567 Serial.println("Incorrect Option");
1568 }
1569 break;
1570 default:
1571 if (user_command != 'm')
1572 Serial.println("Incorrect Option");
1573 break;
1574 }
1575 }
1576 while (user_command != 'm');
1577 ack |= LTC2946_write(LTC2946_I2C_ADDRESS, LTC2946_CTRLB_REG, *CTRLB);
1578 return(ack);
1579 }
1580
1581 //! Configure GPIO pin States
1582 int8_t menu_5_settings_menu_3_configure_GPIO(uint8_t *GPIO_CFG, //!< Local copy of GPIO_CFG register.
1583 uint8_t *GPIO3_CTRL) //!< Local copy of GPIO3_CTRL register.
1584 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
1585 {
1586 int8_t ack = 0;
1587 uint8_t user_command;
1588
1589
1590 do
1591 {
1592 //Print Sub-Menu
1593 Serial.print(F("*************************\n\n"));
1594 Serial.print(F("1-GPIO1 Configure\n"));
1595 Serial.print(F("2-GPIO2 Configure\n"));
1596 Serial.print(F("3-GPIO3 Configure\n"));
1597 Serial.print(F("m-Settings Menu\n\n"));
1598 Serial.print(F("Enter a command:"));
1599
1600 user_command = read_int();
1601 if (user_command == 'm')
1602 Serial.println('m');
1603 else
1604 Serial.println(user_command);
1605
1606 switch (user_command)
1607 {
1608 case 1: //Configure GPIO1 state
1609 Serial.print(F("1-General Purpose Input, Active High\n"));
1610 Serial.print(F("2-General Purpose Input, Active Low\n"));
1611 Serial.print(F("3-General Purpose Output, Hi-Z\n"));
1612 Serial.print(F("4-General Purpose Output, Pulls Low\n"));
1613 user_command = read_int();
1614 if (user_command == 'm')
1615 Serial.println('m');
1616 else
1617 Serial.println(user_command);
1618 switch (user_command)
1619 {
1620 case 1:
1621 *GPIO_CFG = *GPIO_CFG & LTC2946_GPIOCFG_GPIO1_MASK;
1622 *GPIO_CFG = *GPIO_CFG | LTC2946_GPIO1_IN_ACTIVE_HIGH;
1623 break;
1624 case 2:
1625 *GPIO_CFG = *GPIO_CFG & LTC2946_GPIOCFG_GPIO1_MASK;
1626 *GPIO_CFG = *GPIO_CFG | LTC2946_GPIO1_IN_ACTIVE_LOW;
1627 break;
1628 case 3:
1629 *GPIO_CFG = *GPIO_CFG & LTC2946_GPIOCFG_GPIO1_MASK;
1630 *GPIO_CFG = *GPIO_CFG | LTC2946_GPIO1_OUT_HIGH_Z;
1631 break;
1632 case 4:
1633 *GPIO_CFG = *GPIO_CFG & LTC2946_GPIOCFG_GPIO1_MASK;
1634 *GPIO_CFG = *GPIO_CFG | LTC2946_GPIO1_OUT_LOW;
1635 break;
1636 default:
1637 Serial.println("Incorrect Option");
1638 }
1639 Serial.println(*GPIO_CFG);
1640 break;
1641 case 2: //Configure GPIO2 state
1642 Serial.print(F("1-General Purpose Input, Active High\n"));
1643 Serial.print(F("2-General Purpose Input, Active Low\n"));
1644 Serial.print(F("3-General Purpose Output, Hi-Z\n"));
1645 Serial.print(F("4-General Purpose Output, Pulls Low\n"));
1646 Serial.print(F("5-Accumulate Input\n"));
1647 user_command = read_int();
1648 if (user_command == 'm')
1649 Serial.println('m');
1650 else
1651 Serial.println(user_command);
1652 switch (user_command)
1653 {
1654 case 1:
1655 *GPIO_CFG = *GPIO_CFG & LTC2946_GPIOCFG_GPIO2_MASK;
1656 *GPIO_CFG = *GPIO_CFG | LTC2946_GPIO2_IN_ACTIVE_HIGH;
1657 break;
1658 case 2:
1659 *GPIO_CFG = *GPIO_CFG & LTC2946_GPIOCFG_GPIO2_MASK;
1660 *GPIO_CFG = *GPIO_CFG | LTC2946_GPIO2_IN_ACTIVE_LOW;
1661 break;
1662 case 3:
1663 *GPIO_CFG = *GPIO_CFG & LTC2946_GPIOCFG_GPIO2_MASK & LTC2946_GPIOCFG_GPIO2_OUT_MASK;
1664 *GPIO_CFG = *GPIO_CFG | LTC2946_GPIO2_OUT_HIGH_Z;
1665 break;
1666 case 4:
1667 *GPIO_CFG = *GPIO_CFG & LTC2946_GPIOCFG_GPIO2_MASK & LTC2946_GPIOCFG_GPIO2_OUT_MASK;
1668 *GPIO_CFG = *GPIO_CFG | LTC2946_GPIO2_OUT_LOW;
1669 break;
1670 case 5:
1671 *GPIO_CFG = *GPIO_CFG & LTC2946_GPIOCFG_GPIO2_MASK;
1672 *GPIO_CFG = *GPIO_CFG | LTC2946_GPIO2_IN_ACC;
1673 break;
1674 default:
1675 Serial.println("Incorrect Option");
1676 }
1677 Serial.println(*GPIO_CFG);
1678 break;
1679 case 3: //Confugure GPIO3 state
1680 Serial.print(F("1-General Purpose Input, Active High\n"));
1681 Serial.print(F("2-General Purpose Input, Active Low\n"));
1682 Serial.print(F("3-General Purpose Output, Hi-Z\n"));
1683 Serial.print(F("4-General Purpose Output, Pulls Low\n"));
1684 Serial.print(F("5-ALERT/ Output\n"));
1685 user_command = read_int();
1686 if (user_command == 'm')
1687 Serial.println('m');
1688 else
1689 Serial.println(user_command);
1690 switch (user_command)
1691 {
1692 case 1:
1693 *GPIO_CFG = *GPIO_CFG & LTC2946_GPIOCFG_GPIO3_MASK;
1694 *GPIO_CFG = *GPIO_CFG | LTC2946_GPIO3_IN_ACTIVE_HIGH;
1695 break;
1696 case 2:
1697 *GPIO_CFG = *GPIO_CFG & LTC2946_GPIOCFG_GPIO3_MASK;
1698 *GPIO_CFG = *GPIO_CFG | LTC2946_GPIO3_IN_ACTIVE_LOW;
1699 break;
1700 case 3:
1701 *GPIO_CFG = *GPIO_CFG & LTC2946_GPIOCFG_GPIO3_MASK;
1702 *GPIO_CFG = *GPIO_CFG | LTC2946_GPIO3_OUT_REG_42;
1703 *GPIO3_CTRL = *GPIO3_CTRL & LTC2946_GPIO3_CTRL_GPIO3_MASK;
1704 *GPIO3_CTRL = *GPIO3_CTRL | LTC2946_GPIO3_OUT_HIGH_Z;
1705 break;
1706 case 4:
1707 *GPIO_CFG = *GPIO_CFG & LTC2946_GPIOCFG_GPIO3_MASK;
1708 *GPIO_CFG = *GPIO_CFG | LTC2946_GPIO3_OUT_REG_42;
1709 *GPIO3_CTRL = *GPIO3_CTRL & LTC2946_GPIO3_CTRL_GPIO3_MASK;
1710 *GPIO3_CTRL = *GPIO3_CTRL | LTC2946_GPIO3_OUT_LOW;
1711 break;
1712 case 5:
1713 *GPIO_CFG = *GPIO_CFG & LTC2946_GPIOCFG_GPIO3_MASK;
1714 *GPIO_CFG = *GPIO_CFG | LTC2946_GPIO3_OUT_ALERT;
1715 break;
1716 default:
1717 Serial.println("Incorrect Option");
1718 }
1719 Serial.println(*GPIO_CFG);
1720 Serial.println(*GPIO3_CTRL);
1721 break;
1722 default:
1723 if (user_command != 'm')
1724 Serial.println("Incorrect Option");
1725 break;
1726 }
1727 ack |= LTC2946_write(LTC2946_I2C_ADDRESS, LTC2946_GPIO_CFG_REG, *GPIO_CFG);
1728 ack |= LTC2946_write(LTC2946_I2C_ADDRESS, LTC2946_GPIO3_CTRL_REG, *GPIO3_CTRL);
1729 }
1730 while (user_command != 'm');
1731 return(ack);
1732 }
1733
1734
1735
1736 //! Select duty cycle of measurments and channel configuration.
1737 void menu_5_settings_menu_4_scaling_for_ADIN(uint8_t *scale) //!< Stores division ratio for resistive divider on ADIN pin.
1738 {
1739
1740 float user_value;
1741
1742 Serial.print(F("Enter desired maximum voltage for ADIN pin measurement\n"));
1743 Serial.print(F("Note: Ensure that you have the proper resistor divider ratio on the ADIN pin for this voltage level\n"));
1744
1745 user_value = read_float();
1746 *scale = user_value/2.048;
1747 Serial.print(user_value);
1748 Serial.print(F("Scale = "));
1749 Serial.print(*scale);
1750 }
1751
1752 //! Clear Min/Max
1753 int8_t menu_6_clear_min_max()
1754 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
1755 {
1756 int8_t ack = 0;
1757
1758 ack |= LTC2946_write_24_bits(LTC2946_I2C_ADDRESS, LTC2946_MAX_POWER_MSB2_REG, LTC2946_MAX_POWER_MSB2_RESET);
1759 ack |= LTC2946_write_24_bits(LTC2946_I2C_ADDRESS, LTC2946_MIN_POWER_MSB2_REG, LTC2946_MIN_POWER_MSB2_RESET);
1760 ack |= LTC2946_write_16_bits(LTC2946_I2C_ADDRESS, LTC2946_MAX_DELTA_SENSE_MSB_REG, LTC2946_MAX_DELTA_SENSE_MSB_RESET);
1761 ack |= LTC2946_write_16_bits(LTC2946_I2C_ADDRESS, LTC2946_MIN_DELTA_SENSE_MSB_REG, LTC2946_MIN_DELTA_SENSE_MSB_RESET);
1762 ack |= LTC2946_write_16_bits(LTC2946_I2C_ADDRESS, LTC2946_MAX_VIN_MSB_REG, LTC2946_MAX_VIN_MSB_RESET);
1763 ack |= LTC2946_write_16_bits(LTC2946_I2C_ADDRESS, LTC2946_MIN_VIN_MSB_REG, LTC2946_MIN_VIN_MSB_RESET);
1764 ack |= LTC2946_write_16_bits(LTC2946_I2C_ADDRESS, LTC2946_MAX_ADIN_MSB_REG, LTC2946_MAX_ADIN_MSB_RESET);
1765 ack |= LTC2946_write_16_bits(LTC2946_I2C_ADDRESS, LTC2946_MIN_ADIN_MSB_REG, LTC2946_MIN_ADIN_MSB_RESET);
1766 Serial.println();
1767 Serial.print(F("Min/Max Cleared.\n\n"));
1768 return(ack);
1769 }
1770
1771 //! Used to manipulate EEPROM data.
1772 union eeprom_data_union
1773 {
1774 struct data_struct_type //! EEPROM data structure
1775 {
1776 int16_t cal_key; //!< The key that keeps track of the calibration
1777 uint8_t alert1; //!< Used to store the ALERT1 settings
1778 uint8_t alert2; //!< Used to store the ALERT2 settings
1779 uint32_t max_power_threshold; //!< Used to store max power alert settings
1780 uint32_t min_power_threshold; //!< Used to store min power alert settings
1781 uint16_t max_delta_sense_thresh; //!< Used to store max delta sense alert settings
1782 uint16_t min_delta_sense_thresh; //!< Used to store min delta sense alert settings
1783 uint16_t max_Vin_thresh; //!< Used to store max Vin alert settings
1784 uint16_t min_Vin_thresh; //!< Used to store min Vin alert settings
1785 uint16_t max_adin_thresh; //!< Used to store adin max alert settings
1786 uint16_t min_adin_thresh; //!< Used to store adin min alert settings
1787 } data_struct; //!< Name of structure
1788
1789 char byte_array[sizeof(data_struct_type)]; //!< Array used to store the structure
1790 };
1791
1792 //! Read the alert settings from EEPROM
1793 int8_t restore_alert_settings()
1794 //! @return Return 1 if successful, 0 if not
1795 {
1796 int16_t cal_key;
1797
1798 // Read the cal key from the EEPROM
1799 eeprom_read_int16(EEPROM_I2C_ADDRESS, &cal_key, EEPROM_CAL_STATUS_ADDRESS);
1800
1801 if (cal_key == EEPROM_CAL_KEY)
1802 {
1803 // Calibration has been stored, read thresholds
1804
1805 eeprom_data_union eeprom;
1806
1807 eeprom_read_byte_array(EEPROM_I2C_ADDRESS, eeprom.byte_array, EEPROM_CAL_STATUS_ADDRESS, sizeof(eeprom_data_union));
1808 alert1_code = eeprom.data_struct.alert1; // Global variable used to communicate with loop()
1809 alert2_code = eeprom.data_struct.alert2; // Global variable used to communicate with loop()
1810 LTC2946_write(LTC2946_I2C_ADDRESS, LTC2946_ALERT1_REG, eeprom.data_struct.alert1);
1811 LTC2946_write(LTC2946_I2C_ADDRESS, LTC2946_ALERT1_REG, eeprom.data_struct.alert2);
1812 LTC2946_write_24_bits(LTC2946_I2C_ADDRESS, LTC2946_MAX_POWER_THRESHOLD_MSB2_REG, eeprom.data_struct.max_power_threshold);
1813 LTC2946_write_24_bits(LTC2946_I2C_ADDRESS, LTC2946_MIN_POWER_THRESHOLD_MSB2_REG, eeprom.data_struct.min_power_threshold);
1814 LTC2946_write_16_bits(LTC2946_I2C_ADDRESS, LTC2946_MAX_DELTA_SENSE_THRESHOLD_MSB_REG, eeprom.data_struct.max_delta_sense_thresh);
1815 LTC2946_write_16_bits(LTC2946_I2C_ADDRESS, LTC2946_MIN_DELTA_SENSE_THRESHOLD_MSB_REG, eeprom.data_struct.min_delta_sense_thresh);
1816 LTC2946_write_16_bits(LTC2946_I2C_ADDRESS, LTC2946_MAX_VIN_THRESHOLD_MSB_REG, eeprom.data_struct.max_Vin_thresh);
1817 LTC2946_write_16_bits(LTC2946_I2C_ADDRESS, LTC2946_MIN_VIN_THRESHOLD_MSB_REG, eeprom.data_struct.min_Vin_thresh);
1818 LTC2946_write_16_bits(LTC2946_I2C_ADDRESS, LTC2946_MAX_ADIN_THRESHOLD_MSB_REG, eeprom.data_struct.max_adin_thresh);
1819 LTC2946_write_16_bits(LTC2946_I2C_ADDRESS, LTC2946_MIN_ADIN_THRESHOLD_MSB_REG, eeprom.data_struct.min_adin_thresh);
1820
1821 Serial.println("Alert Settings Restored");
1822 return(1);
1823 }
1824 else
1825 {
1826 Serial.println("Alert Settings not found");
1827 return(0);
1828 }
1829 }
1830
1831 //! Store the alert settings to the EEPROM
1832 void store_alert_settings()
1833 {
1834 eeprom_data_union eeprom;
1835
1836 eeprom.data_struct.cal_key = EEPROM_CAL_KEY;
1837
1838 LTC2946_read(LTC2946_I2C_ADDRESS, LTC2946_ALERT1_REG, &eeprom.data_struct.alert1);
1839 LTC2946_read(LTC2946_I2C_ADDRESS, LTC2946_ALERT2_REG, &eeprom.data_struct.alert2);
1840 LTC2946_read_24_bits(LTC2946_I2C_ADDRESS, LTC2946_MAX_POWER_THRESHOLD_MSB2_REG, &eeprom.data_struct.max_power_threshold);
1841 LTC2946_read_24_bits(LTC2946_I2C_ADDRESS, LTC2946_MIN_POWER_THRESHOLD_MSB2_REG, &eeprom.data_struct.min_power_threshold);
1842 LTC2946_read_16_bits(LTC2946_I2C_ADDRESS, LTC2946_MAX_DELTA_SENSE_THRESHOLD_MSB_REG, &eeprom.data_struct.max_delta_sense_thresh);
1843 LTC2946_read_16_bits(LTC2946_I2C_ADDRESS, LTC2946_MIN_DELTA_SENSE_THRESHOLD_MSB_REG, &eeprom.data_struct.min_delta_sense_thresh);
1844 LTC2946_read_16_bits(LTC2946_I2C_ADDRESS, LTC2946_MAX_VIN_THRESHOLD_MSB_REG, &eeprom.data_struct.max_Vin_thresh);
1845 LTC2946_read_16_bits(LTC2946_I2C_ADDRESS, LTC2946_MIN_VIN_THRESHOLD_MSB_REG, &eeprom.data_struct.min_Vin_thresh);
1846 LTC2946_read_16_bits(LTC2946_I2C_ADDRESS, LTC2946_MAX_ADIN_THRESHOLD_MSB_REG, &eeprom.data_struct.max_adin_thresh);
1847 LTC2946_read_16_bits(LTC2946_I2C_ADDRESS, LTC2946_MIN_ADIN_THRESHOLD_MSB_REG, &eeprom.data_struct.min_adin_thresh);
1848
1849 eeprom_write_byte_array(EEPROM_I2C_ADDRESS, eeprom.byte_array, EEPROM_CAL_STATUS_ADDRESS, sizeof(eeprom_data_union));
1850
1851 Serial.println("Alert Settings Stored to EEPROM");
1852 }
1853
LTC2946_MIN_VIN_MSB_RESET
#define LTC2946_MIN_VIN_MSB_RESET
Definition: LTC2946.h:483
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
LTC2946_code_to_energy
float LTC2946_code_to_energy(int32_t adc_code, float resistor, float LTC2946_Power_lsb, float LTC2946_TIME_lsb)
Calculate the LTC2946 energy.
Definition: LTC2946.cpp:233
LTC2946_MIN_POWER_THRESHOLD_MSB2_REG
#define LTC2946_MIN_POWER_THRESHOLD_MSB2_REG
Definition: LTC2946.h:269
CLK_FREQ
const float CLK_FREQ
CLK Frequency.
Definition: DC2156.ino:123
setup
static void setup()
Initialize Linduino.
Definition: DC2156.ino:146
LTC2946_GPIOCFG_GPIO2_MASK
#define LTC2946_GPIOCFG_GPIO2_MASK
Definition: LTC2946.h:577
LTC2946_MIN_DELTA_SENSE_MSB_RESET
#define LTC2946_MIN_DELTA_SENSE_MSB_RESET
Definition: LTC2946.h:481
LTC2946_write_16_bits
int8_t LTC2946_write_16_bits(uint8_t i2c_address, uint8_t adc_command, uint16_t code)
Write a 16-bit code to the LTC2946.
Definition: LTC2946.cpp:93
menu_2_snapshot_mode_menu_2_ADIN
static int8_t menu_2_snapshot_mode_menu_2_ADIN(float scale)
ADIN - Snapshot Mode.
Definition: DC2156.ino:554
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_2_snapshot_mode
static int8_t menu_2_snapshot_mode(uint8_t VOLTAGE_SEL, float scale)
Snapshot Mode Menu.
Definition: DC2156.ino:453
LTC2946_POWER_MSB2_REG
#define LTC2946_POWER_MSB2_REG
Definition: LTC2946.h:257
LTC2946_MIN_ADIN_THRESHOLD_MSB_REG
#define LTC2946_MIN_ADIN_THRESHOLD_MSB_REG
Definition: LTC2946.h:303
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
LTC2946_GPIOCFG_GPIO1_MASK
#define LTC2946_GPIOCFG_GPIO1_MASK
Definition: LTC2946.h:576
LTC2946_code_to_power
float LTC2946_code_to_power(int32_t adc_code, float resistor, float LTC2946_Power_lsb)
Calculate the LTC2946 power.
Definition: LTC2946.cpp:222
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
LTC2946_DISABLE_ALERT_CLEAR
#define LTC2946_DISABLE_ALERT_CLEAR
Definition: LTC2946.h:463
LTC2946_CHANNEL_CONFIG_V_C_1
#define LTC2946_CHANNEL_CONFIG_V_C_1
Definition: LTC2946.h:453
LTC2946_GPIO3_OUT_HIGH_Z
#define LTC2946_GPIO3_OUT_HIGH_Z
Definition: LTC2946.h:545
VIN
#define VIN
Definition: LTC2492_original.h:64
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
LTC2946_MAX_VIN_MSB_RESET
#define LTC2946_MAX_VIN_MSB_RESET
Definition: LTC2946.h:482
user_command
unsigned char user_command
Definition: Serial_EEPROM_Test.ino:75
LTC2946_ENABLE_STUCK_BUS_RECOVER
#define LTC2946_ENABLE_STUCK_BUS_RECOVER
Definition: LTC2946.h:461
EEPROM_I2C_ADDRESS
#define EEPROM_I2C_ADDRESS
Definition: QuikEval_EEPROM.h:60
LTC2946_GPIO2_IN_ACC
#define LTC2946_GPIO2_IN_ACC
Definition: LTC2946.h:537
LTC2946_MAX_POWER_MSB2_RESET
#define LTC2946_MAX_POWER_MSB2_RESET
Definition: LTC2946.h:478
LTC2946_MAX_VIN_THRESHOLD_MSB_REG
#define LTC2946_MAX_VIN_THRESHOLD_MSB_REG
Definition: LTC2946.h:290
menu_3_alert_menu_3_set_vin_alerts
static int8_t menu_3_alert_menu_3_set_vin_alerts()
Set VIN Alert Thresholds.
Definition: DC2156.ino:766
LTC2946_ENABLE_MIN_I_SENSE_ALERT
#define LTC2946_ENABLE_MIN_I_SENSE_ALERT
Definition: LTC2946.h:493
store_alert_settings
static void store_alert_settings()
Store the alert settings to the EEPROM.
Definition: DC2156.ino:1832
LTC2946_DISABLE_MAX_POWER_ALERT
#define LTC2946_DISABLE_MAX_POWER_ALERT
Definition: LTC2946.h:489
print_title
static void print_title()
Print the title block.
Definition: DC2156.ino:232
LTC2946_ALERT2_REG
#define LTC2946_ALERT2_REG
Definition: LTC2946.h:306
LTC2946_DISABLE_ENERGY_OVERFLOW_ALERT
#define LTC2946_DISABLE_ENERGY_OVERFLOW_ALERT
Definition: LTC2946.h:520
LTC2946_DISABLE_GPIO_1_ALERT
#define LTC2946_DISABLE_GPIO_1_ALERT
Definition: LTC2946.h:511
menu_2_snapshot_mode_menu_4_Current
static int8_t menu_2_snapshot_mode_menu_4_Current()
Current - Snapshot Mode.
Definition: DC2156.ino:608
eeprom_data_union::data_struct_type::cal_key
int16_t cal_key
The key that keeps track of the calibration.
Definition: DC2692A.ino:164
LTC2946_ADIN_lsb
const float LTC2946_ADIN_lsb
Typical ADIN lsb weight in volts.
Definition: DC2156.ino:127
LTC2946_ENABLE_MIN_VIN_ALERT
#define LTC2946_ENABLE_MIN_VIN_ALERT
Definition: LTC2946.h:498
LTC2946_ENABLE_CHARGE_OVERFLOW_ALERT
#define LTC2946_ENABLE_CHARGE_OVERFLOW_ALERT
Definition: LTC2946.h:522
LTC2946_CTRLA_CHANNEL_CONFIG_MASK
#define LTC2946_CTRLA_CHANNEL_CONFIG_MASK
Definition: LTC2946.h:573
LTC2946_ADIN_INTVCC
#define LTC2946_ADIN_INTVCC
Definition: LTC2946.h:440
LTC2946_read
int8_t LTC2946_read(uint8_t i2c_address, uint8_t adc_command, uint8_t *adc_code)
Reads an 8-bit adc_code from LTC2946.
Definition: LTC2946.cpp:130
LTC2946_OFFSET_CAL_16
#define LTC2946_OFFSET_CAL_16
Definition: LTC2946.h:445
menu_5_settings_menu_3_configure_GPIO
static int8_t menu_5_settings_menu_3_configure_GPIO(uint8_t *GPIO_CFG, uint8_t *GPIO3_CTRL)
Configure GPIO pin States.
Definition: DC2156.ino:1582
LTC2946_MAX_ADIN_MSB_REG
#define LTC2946_MAX_ADIN_MSB_REG
Definition: LTC2946.h:297
LTC2946_write_24_bits
int8_t LTC2946_write_24_bits(uint8_t i2c_address, uint8_t adc_command, uint32_t code)
Write a 24-bit code to the LTC2946.
Definition: LTC2946.cpp:103
Linduino.h
Header File for Linduino Libraries and Demo Code.
LTC2946_ENABLE_MAX_VIN_ALERT
#define LTC2946_ENABLE_MAX_VIN_ALERT
Definition: LTC2946.h:497
LTC2946_read_16_bits
int8_t LTC2946_read_16_bits(uint8_t i2c_address, uint8_t adc_command, uint16_t *adc_code)
Reads a 16-bit adc_code from LTC2946.
Definition: LTC2946.cpp:155
demo_board_connected
static int8_t demo_board_connected
Set to 1 if the board is connected.
Definition: DC2156.ino:140
LTC2946_MAX_VIN_MSB_REG
#define LTC2946_MAX_VIN_MSB_REG
Definition: LTC2946.h:286
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
LTC2946_CHANNEL_CONFIG_A_V_C_1
#define LTC2946_CHANNEL_CONFIG_A_V_C_1
Definition: LTC2946.h:450
LTC2946_read_12_bits
int8_t LTC2946_read_12_bits(uint8_t i2c_address, uint8_t adc_command, uint16_t *adc_code)
Reads a 12-bit adc_code from LTC2946.
Definition: LTC2946.cpp:141
LTC2946_ENABLE_MAX_POWER_ALERT
#define LTC2946_ENABLE_MAX_POWER_ALERT
Definition: LTC2946.h:487
menu_2_snapshot_mode_menu_1_SENSE
static int8_t menu_2_snapshot_mode_menu_1_SENSE()
SENSE+ - Snapshot mode.
Definition: DC2156.ino:527
LTC2946_DISABLE_GPIO_2_ALERT
#define LTC2946_DISABLE_GPIO_2_ALERT
Definition: LTC2946.h:514
LTC2946_STATUS2_REG
#define LTC2946_STATUS2_REG
Definition: LTC2946.h:324
LTC2946_ENABLE_MIN_POWER_ALERT
#define LTC2946_ENABLE_MIN_POWER_ALERT
Definition: LTC2946.h:488
LTC2946_CHANNEL_CONFIG_SNAPSHOT
#define LTC2946_CHANNEL_CONFIG_SNAPSHOT
Definition: LTC2946.h:448
LTC2946_MAX_ADIN_MSB_RESET
#define LTC2946_MAX_ADIN_MSB_RESET
Definition: LTC2946.h:484
LTC2946_OFFSET_CAL_EVERY
#define LTC2946_OFFSET_CAL_EVERY
Definition: LTC2946.h:446
menu_5_settings_menu_2_configure_CTRLB_reg
static int8_t menu_5_settings_menu_2_configure_CTRLB_reg(uint8_t *CTRLB)
Configure CTRLB Register.
Definition: DC2156.ino:1440
LTC2946_TIME_COUNTER_MSB3_REG
#define LTC2946_TIME_COUNTER_MSB3_REG
Definition: LTC2946.h:309
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
menu_3_alert_menu_5_enable_disable_alerts_menu_2_ALERT2
static int8_t menu_3_alert_menu_5_enable_disable_alerts_menu_2_ALERT2()
Definition: DC2156.ino:984
LTC2946_GPIO2_IN_ACTIVE_HIGH
#define LTC2946_GPIO2_IN_ACTIVE_HIGH
Definition: LTC2946.h:533
LTC2946_VIN_lsb
const float LTC2946_VIN_lsb
Typical VIN lsb weight in volts.
Definition: DC2156.ino:129
LTC2946_DISABLE_MIN_I_SENSE_ALERT
#define LTC2946_DISABLE_MIN_I_SENSE_ALERT
Definition: LTC2946.h:495
LTC2946_CTRLA_VOLTAGE_SEL_MASK
#define LTC2946_CTRLA_VOLTAGE_SEL_MASK
Definition: LTC2946.h:572
menu_5_settings_menu_4_scaling_for_ADIN
static void menu_5_settings_menu_4_scaling_for_ADIN(uint8_t *scale)
Select duty cycle of measurments and channel configuration.
Definition: DC2156.ino:1737
eeprom_data_union::data_struct_type::min_power_threshold
uint32_t min_power_threshold
Used to store min power alert settings.
Definition: DC2156.ino:1780
LTC2946_ADIN_GND
#define LTC2946_ADIN_GND
Definition: LTC2946.h:441
LTC2946_GPIO2_IN_ACTIVE_LOW
#define LTC2946_GPIO2_IN_ACTIVE_LOW
Definition: LTC2946.h:534
menu_3_alert_menu_6_read_clear_faults
static int8_t menu_3_alert_menu_6_read_clear_faults()
Read Faults and Clear.
Definition: DC2156.ino:1109
eeprom_data_union::data_struct_type::max_power_threshold
uint32_t max_power_threshold
Used to store max power alert settings.
Definition: DC2156.ino:1779
LTC2946_DISABLE_STUCK_BUS_WAKE_ALERT
#define LTC2946_DISABLE_STUCK_BUS_WAKE_ALERT
Definition: LTC2946.h:517
LTC2946_ENERGY_MSB3_REG
#define LTC2946_ENERGY_MSB3_REG
Definition: LTC2946.h:319
LTC2946_GPIO3_OUT_REG_42
#define LTC2946_GPIO3_OUT_REG_42
Definition: LTC2946.h:542
LTC2946_CTRLB_REG
#define LTC2946_CTRLB_REG
Definition: LTC2946.h:252
menu_4_shutdown
static int8_t menu_4_shutdown(uint8_t *CTRLB, uint8_t *shutdown)
Toggle Shutdown Down Mode.
Definition: DC2156.ino:1143
LTC2946_MIN_POWER_MSB2_REG
#define LTC2946_MIN_POWER_MSB2_REG
Definition: LTC2946.h:263
LTC2946_GPIO3_IN_ACTIVE_LOW
#define LTC2946_GPIO3_IN_ACTIVE_LOW
Definition: LTC2946.h:541
LTC2946_FAULT2_REG
#define LTC2946_FAULT2_REG
Definition: LTC2946.h:325
LTC2946_CHANNEL_CONFIG_A_V_C_3
#define LTC2946_CHANNEL_CONFIG_A_V_C_3
Definition: LTC2946.h:452
LTC2946_DISABLE_CLEARED_ON_READ
#define LTC2946_DISABLE_CLEARED_ON_READ
Definition: LTC2946.h:465
LTC2946_code_to_time
float LTC2946_code_to_time(float time_code, float LTC2946_TIME_lsb)
Calculate the LTC2946 internal time base.
Definition: LTC2946.cpp:253
LTC2946_ENABLE_STUCK_BUS_WAKE_ALERT
#define LTC2946_ENABLE_STUCK_BUS_WAKE_ALERT
Definition: LTC2946.h:516
LTC2946_MAX_DELTA_SENSE_THRESHOLD_MSB_REG
#define LTC2946_MAX_DELTA_SENSE_THRESHOLD_MSB_REG
Definition: LTC2946.h:279
LTC2946_read_24_bits
int8_t LTC2946_read_24_bits(uint8_t i2c_address, uint8_t adc_command, uint32_t *adc_code)
Reads a 24-bit adc_code from LTC2946.
Definition: LTC2946.cpp:166
LTC2946_GPIO1_IN_ACTIVE_LOW
#define LTC2946_GPIO1_IN_ACTIVE_LOW
Definition: LTC2946.h:529
LTC2946_ADIN_code_to_voltage
float LTC2946_ADIN_code_to_voltage(uint16_t adc_code, float LTC2946_ADIN_lsb)
Calculate the LTC2946 ADIN voltage.
Definition: LTC2946.cpp:203
LTC2946_ADIN_DELTA_SENSE_lsb
const float LTC2946_ADIN_DELTA_SENSE_lsb
Typical sense lsb weight in V^2 *ADIN_lsb * DELTA_SENSE_lsb.
Definition: DC2156.ino:131
LTC2946_write
int8_t LTC2946_write(uint8_t i2c_address, uint8_t adc_command, uint8_t code)
Write an 8-bit code to the LTC2946.
Definition: LTC2946.cpp:81
LTC2946_GPIO3_IN_ACTIVE_HIGH
#define LTC2946_GPIO3_IN_ACTIVE_HIGH
Definition: LTC2946.h:540
LTC2946_MIN_VIN_THRESHOLD_MSB_REG
#define LTC2946_MIN_VIN_THRESHOLD_MSB_REG
Definition: LTC2946.h:292
LTC2946_CTRLB_ACC_MASK
#define LTC2946_CTRLB_ACC_MASK
Definition: LTC2946.h:574
LTC2946_ADIN_MSB_REG
#define LTC2946_ADIN_MSB_REG
Definition: LTC2946.h:295
LTC2946_GPIO1_IN_ACTIVE_HIGH
#define LTC2946_GPIO1_IN_ACTIVE_HIGH
Definition: LTC2946.h:528
LTC2946_INTERNAL_TIME_lsb
const float LTC2946_INTERNAL_TIME_lsb
Internal TimeBase lsb.
Definition: DC2156.ino:132
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
LTC2946_ENABLE_MIN_ADIN_ALERT
#define LTC2946_ENABLE_MIN_ADIN_ALERT
Definition: LTC2946.h:503
LTC2946_ENABLE_ADC_DONE_ALERT
#define LTC2946_ENABLE_ADC_DONE_ALERT
Definition: LTC2946.h:507
print_prompt
static void print_prompt()
Print the Prompt.
Definition: DC2156.ino:245
menu_5_settings_menu_1_configure_CTRLA_reg_menu_3_Voltage_Configuration
static void menu_5_settings_menu_1_configure_CTRLA_reg_menu_3_Voltage_Configuration(uint8_t *CTRLA, uint8_t *VOLTAGE_SEL)
Select the voltage measurement channel.
Definition: DC2156.ino:1337
LTC2946_SENSE_PLUS
#define LTC2946_SENSE_PLUS
Definition: LTC2946.h:346
LTC2946_GPIO3_OUT_LOW
#define LTC2946_GPIO3_OUT_LOW
Definition: LTC2946.h:544
LTC2946_MIN_DELTA_SENSE_MSB_REG
#define LTC2946_MIN_DELTA_SENSE_MSB_REG
Definition: LTC2946.h:277
menu_3_alert_menu_5_enable_disable_alerts_menu_1_ALERT1
static int8_t menu_3_alert_menu_5_enable_disable_alerts_menu_1_ALERT1()
Enable/Disable Alert in ALERT1 Register.
Definition: DC2156.ino:858
LTC2946_ENABLE_GPIO_1_ALERT
#define LTC2946_ENABLE_GPIO_1_ALERT
Definition: LTC2946.h:510
LTC2946_CTRLA_ADIN_MASK
#define LTC2946_CTRLA_ADIN_MASK
Definition: LTC2946.h:570
LTC2946_ENABLE_ENERGY_OVERFLOW_ALERT
#define LTC2946_ENABLE_ENERGY_OVERFLOW_ALERT
Definition: LTC2946.h:519
QuikEval_EEPROM.h
QuikEval EEPROM Library.
loop
static void loop()
Repeats Linduino loop.
Definition: DC2156.ino:168
restore_alert_settings
static int8_t restore_alert_settings()
Read the alert settings from EEPROM.
Definition: DC2156.ino:1793
menu_5_settings_menu_1_configure_CTRLA_reg_menu_1_ADIN_Configuration
static void menu_5_settings_menu_1_configure_CTRLA_reg_menu_1_ADIN_Configuration(uint8_t *CTRLA)
Configure the ADIN reference to GND/INTVCC.
Definition: DC2156.ino:1268
LTC2946_OFFSET_CAL_128
#define LTC2946_OFFSET_CAL_128
Definition: LTC2946.h:444
LTC2946_TIME_lsb
static float LTC2946_TIME_lsb
Static variable which is based off of the default clk frequency of 250KHz.
Definition: DC2156.ino:134
menu_5_settings
static int8_t menu_5_settings(uint8_t *CTRLA, uint8_t *CTRLB, uint8_t *VOLTAGE_SEL, uint8_t *GPIO_CFG, uint8_t *GPIO3_CTRL, float *scale)
Change Settings.
Definition: DC2156.ino:1169
menu_3_alert_menu_2_set_current_alerts
static int8_t menu_3_alert_menu_2_set_current_alerts()
Set Current Alert Thresholds.
Definition: DC2156.ino:738
LTC2946_ADIN
#define LTC2946_ADIN
Definition: LTC2946.h:345
menu_1_continuous_mode
static int8_t menu_1_continuous_mode(uint8_t CTRLA, uint8_t VOLTAGE_SEL, float scale)
Continuous Mode.
Definition: DC2156.ino:257
LTC2946_DISABLE_MIN_POWER_ALERT
#define LTC2946_DISABLE_MIN_POWER_ALERT
Definition: LTC2946.h:490
eeprom_data_union
Used to manipulate EEPROM data.
Definition: DC2692A.ino:160
EEPROM_CAL_STATUS_ADDRESS
#define EEPROM_CAL_STATUS_ADDRESS
Definition: QuikEval_EEPROM.h:58
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
LTC2946_MAX_POWER_THRESHOLD_MSB2_REG
#define LTC2946_MAX_POWER_THRESHOLD_MSB2_REG
Definition: LTC2946.h:266
menu_5_settings_menu_1_configure_CTRLA_reg
static int8_t menu_5_settings_menu_1_configure_CTRLA_reg(uint8_t *CTRLA, uint8_t *VOLTAGE_SEL)
Configure CTRLA Register.
Definition: DC2156.ino:1216
LTC2946_DISABLE_MIN_ADIN_ALERT
#define LTC2946_DISABLE_MIN_ADIN_ALERT
Definition: LTC2946.h:505
LTC2946_GPIO_CFG_REG
#define LTC2946_GPIO_CFG_REG
Definition: LTC2946.h:307
LTC2946_ENABLE_SHUTDOWN
#define LTC2946_ENABLE_SHUTDOWN
Definition: LTC2946.h:459
LTC2946_I2C_ADDRESS
#define LTC2946_I2C_ADDRESS
Definition: LTC2946.h:165
LTC2946_DISABLE_COUNTER_OVERFLOW_ALERT
#define LTC2946_DISABLE_COUNTER_OVERFLOW_ALERT
Definition: LTC2946.h:526
LT_SPI.h
LT_SPI: Routines to communicate with ATmega328P&#39;s hardware SPI port.
LTC2946_CHANNEL_CONFIG_V_C
#define LTC2946_CHANNEL_CONFIG_V_C
Definition: LTC2946.h:449
LTC2946_GPIO3_OUT_ALERT
#define LTC2946_GPIO3_OUT_ALERT
Definition: LTC2946.h:543
LTC2946_ENABLE_ALERT_CLEAR
#define LTC2946_ENABLE_ALERT_CLEAR
Definition: LTC2946.h:458
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
LTC2946_GPIO3_CTRL_REG
#define LTC2946_GPIO3_CTRL_REG
Definition: LTC2946.h:326
menu_3_alert_menu_5_enable_disable_alerts
static int8_t menu_3_alert_menu_5_enable_disable_alerts()
Enable/Disable Alert Menu.
Definition: DC2156.ino:822
LTC2946_ENABLE_MAX_I_SENSE_ALERT
#define LTC2946_ENABLE_MAX_I_SENSE_ALERT
Definition: LTC2946.h:492
LTC2946_ENABLE_COUNTER_OVERFLOW_ALERT
#define LTC2946_ENABLE_COUNTER_OVERFLOW_ALERT
Definition: LTC2946.h:525
LTC2946_RESET_ACC
#define LTC2946_RESET_ACC
Definition: LTC2946.h:473
LTC2946_DISABLE_CHARGE_OVERFLOW_ALERT
#define LTC2946_DISABLE_CHARGE_OVERFLOW_ALERT
Definition: LTC2946.h:523
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
LTC2946_DISABLE_ACC
#define LTC2946_DISABLE_ACC
Definition: LTC2946.h:469
LTC2946_MAX_DELTA_SENSE_MSB_REG
#define LTC2946_MAX_DELTA_SENSE_MSB_REG
Definition: LTC2946.h:275
LTC2946_ENABLE_AUTO_RESET
#define LTC2946_ENABLE_AUTO_RESET
Definition: LTC2946.h:474
LT_I2C.h
LT_I2C: Routines to communicate with ATmega328P&#39;s hardware I2C port.
LTC2946_GPIO2_OUT_HIGH_Z
#define LTC2946_GPIO2_OUT_HIGH_Z
Definition: LTC2946.h:535
LTC2946_FAULT1_REG
#define LTC2946_FAULT1_REG
Definition: LTC2946.h:255
LTC2946_DISABLE_AUTO_RESET
#define LTC2946_DISABLE_AUTO_RESET
Definition: LTC2946.h:475
LTC2946_ACC_PIN_CONTROL
#define LTC2946_ACC_PIN_CONTROL
Definition: LTC2946.h:468
LTC2946_CTRLB_RESET_MASK
#define LTC2946_CTRLB_RESET_MASK
Definition: LTC2946.h:575
demo_name
char demo_name[]
Demo Board Name stored in QuikEval EEPROM.
Definition: DC1880A.ino:97
UserInterface.h
eeprom
eeprom_data_union eeprom
Definition: DC2692A.ino:177
read_int
int32_t read_int()
Definition: UserInterface.cpp:93
LTC2946_CHANNEL_CONFIG_V_C_3
#define LTC2946_CHANNEL_CONFIG_V_C_3
Definition: LTC2946.h:455
CONTINUOUS_MODE_DISPLAY_DELAY
#define CONTINUOUS_MODE_DISPLAY_DELAY
The delay between readings.
Definition: DC2156.ino:120
read_float
float read_float()
Definition: UserInterface.cpp:78
LTC2946.h
LTC2946: 12-Bit Wide Range Power, Charge and Energy Monitor.
LTC2946_MIN_ADIN_MSB_RESET
#define LTC2946_MIN_ADIN_MSB_RESET
Definition: LTC2946.h:485
LTC2946_RESET_ALL
#define LTC2946_RESET_ALL
Definition: LTC2946.h:472
LTC2946_GPIOCFG_GPIO3_MASK
#define LTC2946_GPIOCFG_GPIO3_MASK
Definition: LTC2946.h:578
eeprom_data_union::byte_array
char byte_array[sizeof(data_struct_type)]
Array used to store the structure.
Definition: DC2692A.ino:174
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
LTC2946_DISABLE_MAX_VIN_ALERT
#define LTC2946_DISABLE_MAX_VIN_ALERT
Definition: LTC2946.h:499
LTC2946_VDD
#define LTC2946_VDD
Definition: LTC2946.h:344
LTC2946_ENABLE_CLEARED_ON_READ
#define LTC2946_ENABLE_CLEARED_ON_READ
Definition: LTC2946.h:460
LTC2946_GPIO1_OUT_LOW
#define LTC2946_GPIO1_OUT_LOW
Definition: LTC2946.h:531
alert1_code
static uint8_t alert1_code
Value stored or read from ALERT1 register.
Definition: DC2156.ino:141
LTC2946_CHANNEL_CONFIG_A_V_C_2
#define LTC2946_CHANNEL_CONFIG_A_V_C_2
Definition: LTC2946.h:451
eeprom_data_union::data_struct_type::alert1
uint8_t alert1
Used to store the ALERT1 settings.
Definition: DC2156.ino:1777
LTC2946_ENABLE_MAX_ADIN_ALERT
#define LTC2946_ENABLE_MAX_ADIN_ALERT
Definition: LTC2946.h:502
LTC2946_GPIOCFG_GPIO2_OUT_MASK
#define LTC2946_GPIOCFG_GPIO2_OUT_MASK
Definition: LTC2946.h:579
quikeval_I2C_init
void quikeval_I2C_init(void)
Initializes Linduino I2C port.
Definition: LT_I2C.cpp:394
LTC2946_OFFSET_CAL_LAST
#define LTC2946_OFFSET_CAL_LAST
Definition: LTC2946.h:443
ack_error
const char ack_error[]
Error message.
Definition: DC2156.ino:137
quikeval_I2C_connect
void quikeval_I2C_connect(void)
Switch MUX to connect I2C pins to QuikEval connector.
Definition: LT_I2C.cpp:401
eeprom_data_union::data_struct_type::alert2
uint8_t alert2
Used to store the ALERT2 settings.
Definition: DC2156.ino:1778
LTC2946_VIN_code_to_voltage
float LTC2946_VIN_code_to_voltage(uint16_t adc_code, float LTC2946_VIN_lsb)
Calculate the LTC2946 VIN voltage.
Definition: LTC2946.cpp:194
LTC2946_GPIO2_OUT_LOW
#define LTC2946_GPIO2_OUT_LOW
Definition: LTC2946.h:536
voltage
static float voltage
Definition: DC2289AA.ino:71
LTC2946_MIN_VIN_MSB_REG
#define LTC2946_MIN_VIN_MSB_REG
Definition: LTC2946.h:288
menu_3_alert
static int8_t menu_3_alert(uint8_t VOLTAGE_SEL, float scale)
Alert and Threshold Menu.
Definition: DC2156.ino:636
LTC2946_DISABLE_MAX_ADIN_ALERT
#define LTC2946_DISABLE_MAX_ADIN_ALERT
Definition: LTC2946.h:504
LTC2946_DISABLE_MIN_VIN_ALERT
#define LTC2946_DISABLE_MIN_VIN_ALERT
Definition: LTC2946.h:500
internalCLK
static bool internalCLK
Definition: DC2156.ino:143
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.
LTC2946_DELTA_SENSE_MSB_REG
#define LTC2946_DELTA_SENSE_MSB_REG
Definition: LTC2946.h:273
LTC2946_ENABLE_GPIO_2_ALERT
#define LTC2946_ENABLE_GPIO_2_ALERT
Definition: LTC2946.h:513
LTC2946_VIN_MSB_REG
#define LTC2946_VIN_MSB_REG
Definition: LTC2946.h:284
LTC2946_DISABLE_SHUTDOWN
#define LTC2946_DISABLE_SHUTDOWN
Definition: LTC2946.h:464
alert2_code
static uint8_t alert2_code
Value stored or read from ALERT2 register.
Definition: DC2156.ino:142
LTC2946_GPIO1_OUT_HIGH_Z
#define LTC2946_GPIO1_OUT_HIGH_Z
Definition: LTC2946.h:530
LTC2946_Power_lsb
const float LTC2946_Power_lsb
Typical POWER lsb weight in V^2 VIN_lsb * DELTA_SENSE_lsb.
Definition: DC2156.ino:130
menu_2_snapshot_mode_menu_3_VDD
static int8_t menu_2_snapshot_mode_menu_3_VDD()
VDD - Snapshot Mode.
Definition: DC2156.ino:581
LTC2946_MAX_POWER_MSB2_REG
#define LTC2946_MAX_POWER_MSB2_REG
Definition: LTC2946.h:260
LTC2946_code_to_current
float LTC2946_code_to_current(uint16_t adc_code, float resistor, float LTC2946_DELTA_SENSE_lsb)
Calculate the LTC2946 current with a sense resistor.
Definition: LTC2946.cpp:212
LTC2946_ENABLE_ACC
#define LTC2946_ENABLE_ACC
Definition: LTC2946.h:470
LTC2946_MIN_POWER_MSB2_RESET
#define LTC2946_MIN_POWER_MSB2_RESET
Definition: LTC2946.h:479
menu_5_settings_menu_1_configure_CTRLA_reg_menu_2_Offset_Configuration
static void menu_5_settings_menu_1_configure_CTRLA_reg_menu_2_Offset_Configuration(uint8_t *CTRLA)
Configure frequency of offset calibration.
Definition: DC2156.ino:1296
LTC2946_MAX_ADIN_THRESHOLD_MSB_REG
#define LTC2946_MAX_ADIN_THRESHOLD_MSB_REG
Definition: LTC2946.h:301
LTC2946_DISABLE_MAX_I_SENSE_ALERT
#define LTC2946_DISABLE_MAX_I_SENSE_ALERT
Definition: LTC2946.h:494
LTC2946_read_32_bits
int8_t LTC2946_read_32_bits(uint8_t i2c_address, uint8_t adc_command, uint32_t *adc_code)
Reads a 32-bit adc_code from LTC2946.
Definition: LTC2946.cpp:180
EEPROM_CAL_KEY
#define EEPROM_CAL_KEY
Definition: QuikEval_EEPROM.h:59
LTC2946_CHARGE_MSB3_REG
#define LTC2946_CHARGE_MSB3_REG
Definition: LTC2946.h:314
menu_3_alert_menu_4_set_adin_alerts
static int8_t menu_3_alert_menu_4_set_adin_alerts(float scale)
Set ADIN Alert Thresholds.
Definition: DC2156.ino:793
LTC2946_MIN_DELTA_SENSE_THRESHOLD_MSB_REG
#define LTC2946_MIN_DELTA_SENSE_THRESHOLD_MSB_REG
Definition: LTC2946.h:281
LTC2946_CHANNEL_CONFIG_V_C_2
#define LTC2946_CHANNEL_CONFIG_V_C_2
Definition: LTC2946.h:454
resistor
const float resistor
resistor value on demo board
Definition: DC2156.ino:122
LTC2946_MIN_ADIN_MSB_REG
#define LTC2946_MIN_ADIN_MSB_REG
Definition: LTC2946.h:299
LTC2946_CTRLA_REG
#define LTC2946_CTRLA_REG
Definition: LTC2946.h:251
LTC2946_MAX_DELTA_SENSE_MSB_RESET
#define LTC2946_MAX_DELTA_SENSE_MSB_RESET
Definition: LTC2946.h:480
LTC2946_GPIO3_CTRL_GPIO3_MASK
#define LTC2946_GPIO3_CTRL_GPIO3_MASK
Definition: LTC2946.h:580
LTC2946_code_to_coulombs
float LTC2946_code_to_coulombs(int32_t adc_code, float resistor, float LTC2946_DELTA_SENSE_lsb, float LTC2946_TIME_lsb)
Calculate the LTC2946 coulombs.
Definition: LTC2946.cpp:243
menu_3_alert_menu_1_set_power_alerts
static int8_t menu_3_alert_menu_1_set_power_alerts(uint8_t VOLTAGE_SEL, float scale)
Set Power Alert Thresholds.
Definition: DC2156.ino:703
menu_5_settings_menu_1_configure_CTRLA_reg_menu_4_Channel_Configuration
static void menu_5_settings_menu_1_configure_CTRLA_reg_menu_4_Channel_Configuration(uint8_t *CTRLA)
Select duty cycle of measurments and channel configuration.
Definition: DC2156.ino:1378
menu_6_clear_min_max
static int8_t menu_6_clear_min_max()
Clear Min/Max.
Definition: DC2156.ino:1753
LTC2946_ALERT1_REG
#define LTC2946_ALERT1_REG
Definition: LTC2946.h:253
LTC2946_DELTA_SENSE
#define LTC2946_DELTA_SENSE
Definition: LTC2946.h:343
LTC2946_CTRLA_OFFSET_MASK
#define LTC2946_CTRLA_OFFSET_MASK
Definition: LTC2946.h:571
LTC2946_DELTA_SENSE_lsb
const float LTC2946_DELTA_SENSE_lsb
Typical Delta lsb weight in volts.
Definition: DC2156.ino:128
LTC2946_DISABLE_STUCK_BUS_RECOVER
#define LTC2946_DISABLE_STUCK_BUS_RECOVER
Definition: LTC2946.h:466