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);
120 #define CONTINUOUS_MODE_DISPLAY_DELAY 2000 137 const char ack_error[] =
"Error: No Acknowledge. Check I2C Address.";
152 Serial.begin(115200);
157 Serial.println(F(
"Demo board not detected, will attempt to proceed"));
178 static uint8_t shutdown = 0;
181 static float scale = 102.4/2/046;
185 if (Serial.available())
188 if (user_command !=
'm')
189 Serial.println(user_command);
192 switch (user_command)
211 menu_5_settings(&CTRLA, &CTRLB, &VOLTAGE_SEL, &GPIO_CFG, &GPIO3_CTRL, &scale);
219 Serial.println(
"Incorrect Option");
224 Serial.print(F(
"*************************"));
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"));
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: "));
262 uint8_t LTC2946_mode;
266 LTC2946_mode = CTRLA;
278 Serial.print(F(
"*************************\n\n"));
280 uint32_t power_code, max_power_code, min_power_code;
286 float power, max_power, min_power;
291 Serial.print(F(
"****Power: "));
292 Serial.print(power, 4);
293 Serial.print(F(
" W\n"));
295 Serial.print(F(
"Max Power: "));
296 Serial.print(max_power, 4);
297 Serial.print(F(
" W\n"));
299 Serial.print(F(
"Min Power: "));
300 Serial.print(min_power, 4);
301 Serial.print(F(
" W\n"));
305 Serial.print(F(
"*************************"));
309 uint32_t power_code, max_power_code, min_power_code;
314 float power, max_power, min_power;
319 Serial.print(F(
"\n***ADIN Power: "));
320 Serial.print(power, 4);
321 Serial.print(F(
" W\n"));
323 Serial.print(F(
"Max ADIN Power: "));
324 Serial.print(max_power, 4);
325 Serial.print(F(
" W\n"));
327 Serial.print(F(
"Min ADIN Power: "));
328 Serial.print(min_power, 4);
329 Serial.print(F(
" W\n"));
332 uint16_t current_code, max_current_code, min_current_code;
337 float current, max_current, min_current;
342 Serial.print(F(
"\n****Current: "));
343 Serial.print(current, 4);
344 Serial.print(F(
" A\n"));
346 Serial.print(F(
"Max Current: "));
347 Serial.print(max_current, 4);
348 Serial.print(F(
" A\n"));
350 Serial.print(F(
"Min Current: "));
351 Serial.print(min_current, 4);
352 Serial.print(F(
" A\n"));
354 uint16_t VIN_code, max_VIN_code, min_VIN_code;
359 float VIN, max_VIN, min_VIN;
364 Serial.print(F(
"\n****VIN: "));
365 Serial.print(VIN, 4);
366 Serial.print(F(
" V\n"));
368 Serial.print(F(
"Max VIN: "));
369 Serial.print(max_VIN, 4);
370 Serial.print(F(
" V\n"));
372 Serial.print(F(
"Min VIN: "));
373 Serial.print(min_VIN, 4);
374 Serial.print(F(
" V\n"));
376 uint16_t ADIN_code, max_ADIN_code, min_ADIN_code;
381 float ADIN, max_ADIN, min_ADIN;
386 Serial.print(F(
"\n****ADIN: "));
387 Serial.print(ADIN, 4);
388 Serial.print(F(
" V\n"));
390 Serial.print(F(
"Max ADIN: "));
391 Serial.print(max_ADIN, 4);
392 Serial.print(F(
" V\n"));
394 Serial.print(F(
"Min ADIN: "));
395 Serial.print(min_ADIN, 4);
396 Serial.print(F(
" V\n"));
400 uint32_t energy_code;
403 uint32_t charge_code;
411 float energy,charge,time;
426 Serial.print(F(
"**********Accumulators**********\n"));
428 Serial.print(F(
"\n****Energy: "));
429 Serial.print(energy, 4);
430 Serial.print(F(
" J\n"));
432 Serial.print(F(
"****Charge: "));
433 Serial.print(charge, 4);
434 Serial.print(F(
" C\n"));
436 Serial.print(F(
"****Time: "));
437 Serial.print(time, 4);
438 Serial.print(F(
" s\n\n"));
440 Serial.print(F(
"********************************\n"));
443 Serial.print(F(
"m-Main Menu\n\n"));
447 while (Serial.available() ==
false);
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"));
469 Serial.print(F(
"\n\nEnter a Command: "));
471 if (user_command ==
'm')
475 Serial.println(user_command);
477 if (user_command !=
'm')
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"));
488 switch (user_command)
505 if (user_command !=
'm')
506 Serial.println(
"Incorrect Option");
510 if (user_command !=
'm')
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"));
522 while (!((user_command ==
'm') || (ack)));
542 uint16_t voltage_code;
547 Serial.print(F(
"SENSE+: "));
548 Serial.print(voltage, 4);
549 Serial.print(F(
" V\n\n"));
574 Serial.print(F(
"ADIN: "));
575 Serial.print(ADIN, 4);
576 Serial.print(F(
" V\n\n"));
601 Serial.print(F(
"VDD: "));
602 Serial.print(VDD, 4);
603 Serial.print(F(
" V\n\n"));
623 uint16_t current_code;
628 Serial.print(F(
"Current: "));
629 Serial.print(current, 4);
630 Serial.print(F(
" A\n\n"));
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: "));
657 if (user_command ==
'm')
660 Serial.println(user_command);
662 switch (user_command)
693 if (user_command !=
'm')
694 Serial.println(
"Incorrect Option");
698 while (!((user_command ==
'm') || (ack)));
708 Serial.print(F(
"Enter Max Power Threshold:"));
710 float max_power_threshold;
712 Serial.println(max_power_threshold, 4);
714 int32_t max_power_threshold_code;
722 Serial.print(F(
"Enter Min Power Threshold:"));
724 float min_power_threshold;
726 Serial.println(min_power_threshold, 4);
728 int32_t min_power_threshold_code;
742 Serial.print(F(
"Enter Max Current Threshold:"));
744 float max_current_threshold;
746 Serial.println(max_current_threshold, 4);
748 int32_t max_current_threshold_code;
753 Serial.print(F(
"Enter Min Current Threshold:"));
755 float min_current_threshold;
757 Serial.println(min_current_threshold, 4);
759 int32_t min_current_threshold_code;
770 Serial.print(F(
"Enter Max VIN Threshold:"));
772 float max_VIN_threshold;
774 Serial.println(max_VIN_threshold, 4);
776 int32_t max_VIN_threshold_code;
780 Serial.print(F(
"Enter Min VIN Threshold:"));
782 float min_VIN_threshold;
784 Serial.println(min_VIN_threshold, 4);
786 int32_t min_VIN_threshold_code;
798 Serial.print(F(
"Enter Max ADIN Threshold:"));
800 float max_ADIN_threshold;
802 Serial.println(max_ADIN_threshold, 4);
804 int32_t max_ADIN_threshold_code;
805 max_ADIN_threshold_code = ((1.0/scale)*max_ADIN_threshold) /
LTC2946_ADIN_lsb;
808 Serial.print(F(
"Enter Min ADIN Threshold:"));
810 float min_ADIN_threshold;
812 Serial.println(min_ADIN_threshold, 4);
814 int32_t min_ADIN_threshold_code;
815 min_ADIN_threshold_code = ((1.0/scale)*min_ADIN_threshold) /
LTC2946_ADIN_lsb;
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"));
833 if (user_command ==
'm')
836 Serial.println(user_command);
837 switch (user_command)
846 if (user_command !=
'm')
847 Serial.println(
"Incorrect Option");
852 while (user_command !=
'm');
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:"));
874 if (user_command ==
'm')
877 Serial.println(user_command);
878 if (!(user_command == 0))
880 Serial.print(F(
"1-Enable, 2-Disable\n"));
882 switch (user_command)
886 Serial.print(F(
"Max Power :"));
888 if ((user_command > 2) || (user_command < 0))
890 Serial.println(user_command);
891 if (user_command == 1)
896 Serial.print(F(
"Min Power :"));
898 if ((user_command > 2) || (user_command < 0))
900 Serial.println(user_command);
901 if (user_command == 1)
908 Serial.print(F(
"Max Current :"));
910 if ((user_command > 2) || (user_command < 0))
912 Serial.println(user_command);
913 if (user_command == 1)
918 Serial.print(F(
"Min Current :"));
920 if ((user_command > 2) || (user_command < 0))
922 Serial.println(user_command);
923 if (user_command == 1)
930 Serial.print(F(
"Max VIN :"));
932 if ((user_command > 2) || (user_command < 0))
934 Serial.println(user_command);
935 if (user_command == 1)
940 Serial.print(F(
"Min VIN :"));
942 if ((user_command > 2) || (user_command < 0))
944 Serial.println(user_command);
945 if (user_command == 1)
952 Serial.print(F(
"Max ADIN :"));
954 if ((user_command > 2) || (user_command < 0))
956 Serial.println(user_command);
957 if (user_command == 1)
962 Serial.print(F(
"Min ADIN :"));
964 if ((user_command > 2) || (user_command < 0))
966 Serial.println(user_command);
967 if (user_command == 1)
973 if (user_command !=
'm')
974 Serial.println(
"Incorrect Option");
978 while (user_command !=
'm');
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:"));
1003 if (user_command ==
'm')
1004 Serial.println(
'm');
1006 Serial.println(user_command);
1007 if (!(user_command == 0))
1009 Serial.print(F(
"1-Enable, 2-Disable\n"));
1011 switch (user_command)
1015 Serial.print(F(
"ADC Conv Done: "));
1017 if ((user_command > 2) || (user_command < 0))
1019 Serial.println(user_command);
1020 if (user_command == 1)
1027 Serial.print(F(
"GPIO1 Input Alert: "));
1029 if ((user_command > 2) || (user_command < 0))
1031 Serial.println(user_command);
1032 if (user_command == 1)
1039 Serial.print(F(
"GPIO2 Input Alert: "));
1041 if ((user_command > 2) || (user_command < 0))
1043 Serial.println(user_command);
1044 if (user_command == 1)
1051 Serial.print(F(
"Stuck-Bus Timeout Wake-Up Alert: "));
1053 if ((user_command > 2) || (user_command < 0))
1055 Serial.println(user_command);
1056 if (user_command == 1)
1063 Serial.print(F(
"Energy Overflow Alert: "));
1065 if ((user_command > 2) || (user_command < 0))
1067 Serial.println(user_command);
1068 if (user_command == 1)
1075 Serial.print(F(
"Charge Overflow Alert: "));
1077 if ((user_command > 2) || (user_command < 0))
1079 Serial.println(user_command);
1080 if (user_command == 1)
1087 Serial.print(F(
"Time Counter Overflow Alert: "));
1089 if ((user_command > 2) || (user_command < 0))
1091 Serial.println(user_command);
1092 if (user_command == 1)
1098 if (user_command !=
'm')
1099 Serial.println(
"Incorrect Option");
1103 while (user_command !=
'm');
1113 uint8_t fault_code = 0;
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"));
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"));
1152 Serial.print(F(
"LTC2946 Has Been Shutdown\n\n"));
1159 Serial.print(F(
"LTC2946 Is No Longer in Shutdown\n\n"));
1171 uint8_t *VOLTAGE_SEL,
1173 uint8_t *GPIO3_CTRL,
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:"));
1190 if (user_command ==
'm')
1191 Serial.println(
'm');
1193 Serial.println(user_command);
1194 switch (user_command)
1205 if (user_command !=
'm')
1206 Serial.println(
"Incorrect Option");
1211 while (user_command !=
'm');
1217 uint8_t *VOLTAGE_SEL)
1223 Serial.println(*CTRLA);
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:"));
1235 if (user_command ==
'm')
1236 Serial.println(
'm');
1238 Serial.println(user_command);
1239 switch (user_command)
1254 if (user_command !=
'm')
1255 Serial.println(
"Incorrect Option");
1259 while (user_command !=
'm');
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:"));
1277 if ((user_command > 2) || (user_command < 1))
1279 Serial.println(user_command);
1280 if (user_command == 1)
1284 Serial.print(F(
"CTRLA set to measure ADIN with respect to INTVCC\n"));
1290 Serial.print(F(
"CTRLA set to measure ADIN with respect to GND\n"));
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:"));
1306 Serial.println(user_command);
1307 switch (user_command)
1312 Serial.print(F(
"Offset Calibration set to use last calibrated result\n"));
1317 Serial.print(F(
"Offset Calibration set to once every 128 conversions\n"));
1322 Serial.print(F(
"Offset Calibration set to once every 16 conversions\n"));
1327 Serial.print(F(
"Offset Calibration set to once every conversion\n"));
1330 if (user_command !=
'm')
1331 Serial.println(
"Incorrect Option");
1338 uint8_t *VOLTAGE_SEL)
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:"));
1346 if ((user_command > 3) || (user_command < 0))
1348 Serial.println(user_command);
1350 switch (user_command)
1356 Serial.print(F(
"SENSE+ selected\n"));
1362 Serial.print(F(
"ADIN selected\n"));
1368 Serial.print(F(
"VDD selected\n"));
1371 if (user_command !=
'm')
1372 Serial.println(
"Incorrect Option");
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:"));
1392 Serial.println(user_command);
1393 switch (user_command)
1395 Serial.print(F(
"Selected Mode = "));
1399 Serial.print(F(
"Voltage Once Followed by Current Indefinetly\n"));
1404 Serial.print(F(
"ADIN,Voltage, Current at 1/256, 1/256 and 254/256 Duty Cycle, Respectively\n"));
1409 Serial.print(F(
"ADIN,Voltage, Current at 1/32, 1/32 and 30/32 Duty Cycle, Respectively\n"));
1414 Serial.print(F(
"Aleternate ADIN, Voltage and Current Measurement\n"));
1419 Serial.print(F(
"Voltage and Current at 1/128 and 127/128 Duty Cycle, Respectively\n"));
1424 Serial.print(F(
"Voltage and Current at 1/16 and 15/16 Duty Cycle, Respectively\n"));
1429 Serial.print(F(
"Alternate Voltage and Current Measurement\n\n"));
1432 if (user_command !=
'm')
1433 Serial.println(
"Incorrect Option");
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:"));
1458 if (user_command ==
'm')
1459 Serial.println(
'm');
1461 Serial.println(user_command);
1463 switch (user_command)
1467 Serial.print(F(
"1-Enable, 2-Disable\n"));
1469 Serial.print(F(
" Alert Clear Enable:"));
1471 if ((user_command > 2) || (user_command < 0))
1473 Serial.println(user_command);
1474 if (user_command == 1)
1480 Serial.print(F(
"1-Enable, 2-Disable\n"));
1481 Serial.print(F(
" Shutdown:"));
1483 if ((user_command > 2) || (user_command < 0))
1485 Serial.println(user_command);
1486 if (user_command == 1)
1492 Serial.print(F(
"1-Enable, 2-Disable\n"));
1493 Serial.print(F(
" Cleared On Read Control:"));
1495 if ((user_command > 2) || (user_command < 0))
1497 Serial.println(user_command);
1498 if (user_command == 1)
1504 Serial.print(F(
"1-Enable, 2-Disable\n"));
1505 Serial.print(F(
" Stuck Bus Timeout Auto Wake Up:"));
1507 if ((user_command > 2) || (user_command < 0))
1509 Serial.println(user_command);
1510 if (user_command == 1)
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:"));
1521 Serial.println(user_command);
1522 switch (user_command)
1537 Serial.println(
"Incorrect Option");
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:"));
1547 Serial.println(user_command);
1548 switch (user_command)
1567 Serial.println(
"Incorrect Option");
1571 if (user_command !=
'm')
1572 Serial.println(
"Incorrect Option");
1576 while (user_command !=
'm');
1583 uint8_t *GPIO3_CTRL)
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:"));
1601 if (user_command ==
'm')
1602 Serial.println(
'm');
1604 Serial.println(user_command);
1606 switch (user_command)
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"));
1614 if (user_command ==
'm')
1615 Serial.println(
'm');
1617 Serial.println(user_command);
1618 switch (user_command)
1637 Serial.println(
"Incorrect Option");
1639 Serial.println(*GPIO_CFG);
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"));
1648 if (user_command ==
'm')
1649 Serial.println(
'm');
1651 Serial.println(user_command);
1652 switch (user_command)
1675 Serial.println(
"Incorrect Option");
1677 Serial.println(*GPIO_CFG);
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"));
1686 if (user_command ==
'm')
1687 Serial.println(
'm');
1689 Serial.println(user_command);
1690 switch (user_command)
1717 Serial.println(
"Incorrect Option");
1719 Serial.println(*GPIO_CFG);
1720 Serial.println(*GPIO3_CTRL);
1723 if (user_command !=
'm')
1724 Serial.println(
"Incorrect Option");
1730 while (user_command !=
'm');
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"));
1746 *scale = user_value/2.048;
1747 Serial.print(user_value);
1748 Serial.print(F(
"Scale = "));
1749 Serial.print(*scale);
1767 Serial.print(F(
"Min/Max Cleared.\n\n"));
1774 struct data_struct_type
1821 Serial.println(
"Alert Settings Restored");
1826 Serial.println(
"Alert Settings not found");
1851 Serial.println(
"Alert Settings Stored to EEPROM");
#define LTC2946_MIN_VIN_MSB_RESET
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.
float LTC2946_code_to_energy(int32_t adc_code, float resistor, float LTC2946_Power_lsb, float LTC2946_TIME_lsb)
Calculate the LTC2946 energy.
#define LTC2946_MIN_POWER_THRESHOLD_MSB2_REG
const float CLK_FREQ
CLK Frequency.
static void setup()
Initialize Linduino.
#define LTC2946_GPIOCFG_GPIO2_MASK
#define LTC2946_MIN_DELTA_SENSE_MSB_RESET
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.
static int8_t menu_2_snapshot_mode_menu_2_ADIN(float scale)
ADIN - Snapshot Mode.
int32_t min_power_threshold
Used to store min power alert settings.
static int8_t menu_2_snapshot_mode(uint8_t VOLTAGE_SEL, float scale)
Snapshot Mode Menu.
#define LTC2946_POWER_MSB2_REG
#define LTC2946_MIN_ADIN_THRESHOLD_MSB_REG
uint16_t min_Vin_thresh
Used to store min Vin alert settings.
#define LTC2946_GPIOCFG_GPIO1_MASK
float LTC2946_code_to_power(int32_t adc_code, float resistor, float LTC2946_Power_lsb)
Calculate the LTC2946 power.
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.
#define LTC2946_DISABLE_ALERT_CLEAR
#define LTC2946_CHANNEL_CONFIG_V_C_1
#define LTC2946_GPIO3_OUT_HIGH_Z
uint16_t min_adin_thresh
Used to store adin min alert settings.
#define LTC2946_MAX_VIN_MSB_RESET
unsigned char user_command
#define LTC2946_ENABLE_STUCK_BUS_RECOVER
#define EEPROM_I2C_ADDRESS
#define LTC2946_GPIO2_IN_ACC
#define LTC2946_MAX_POWER_MSB2_RESET
#define LTC2946_MAX_VIN_THRESHOLD_MSB_REG
static int8_t menu_3_alert_menu_3_set_vin_alerts()
Set VIN Alert Thresholds.
#define LTC2946_ENABLE_MIN_I_SENSE_ALERT
static void store_alert_settings()
Store the alert settings to the EEPROM.
#define LTC2946_DISABLE_MAX_POWER_ALERT
static void print_title()
Print the title block.
#define LTC2946_ALERT2_REG
#define LTC2946_DISABLE_ENERGY_OVERFLOW_ALERT
#define LTC2946_DISABLE_GPIO_1_ALERT
static int8_t menu_2_snapshot_mode_menu_4_Current()
Current - Snapshot Mode.
int16_t cal_key
The key that keeps track of the calibration.
const float LTC2946_ADIN_lsb
Typical ADIN lsb weight in volts.
#define LTC2946_ENABLE_MIN_VIN_ALERT
#define LTC2946_ENABLE_CHARGE_OVERFLOW_ALERT
#define LTC2946_CTRLA_CHANNEL_CONFIG_MASK
#define LTC2946_ADIN_INTVCC
int8_t LTC2946_read(uint8_t i2c_address, uint8_t adc_command, uint8_t *adc_code)
Reads an 8-bit adc_code from LTC2946.
#define LTC2946_OFFSET_CAL_16
static int8_t menu_5_settings_menu_3_configure_GPIO(uint8_t *GPIO_CFG, uint8_t *GPIO3_CTRL)
Configure GPIO pin States.
#define LTC2946_MAX_ADIN_MSB_REG
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.
Header File for Linduino Libraries and Demo Code.
#define LTC2946_ENABLE_MAX_VIN_ALERT
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.
static int8_t demo_board_connected
Set to 1 if the board is connected.
#define LTC2946_MAX_VIN_MSB_REG
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.
#define LTC2946_CHANNEL_CONFIG_A_V_C_1
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.
#define LTC2946_ENABLE_MAX_POWER_ALERT
static int8_t menu_2_snapshot_mode_menu_1_SENSE()
SENSE+ - Snapshot mode.
#define LTC2946_DISABLE_GPIO_2_ALERT
#define LTC2946_STATUS2_REG
#define LTC2946_ENABLE_MIN_POWER_ALERT
#define LTC2946_CHANNEL_CONFIG_SNAPSHOT
#define LTC2946_MAX_ADIN_MSB_RESET
#define LTC2946_OFFSET_CAL_EVERY
static int8_t menu_5_settings_menu_2_configure_CTRLB_reg(uint8_t *CTRLB)
Configure CTRLB Register.
#define LTC2946_TIME_COUNTER_MSB3_REG
uint16_t max_delta_sense_thresh
Used to store max delta sense alert settings.
static int8_t menu_3_alert_menu_5_enable_disable_alerts_menu_2_ALERT2()
#define LTC2946_GPIO2_IN_ACTIVE_HIGH
const float LTC2946_VIN_lsb
Typical VIN lsb weight in volts.
#define LTC2946_DISABLE_MIN_I_SENSE_ALERT
#define LTC2946_CTRLA_VOLTAGE_SEL_MASK
static void menu_5_settings_menu_4_scaling_for_ADIN(uint8_t *scale)
Select duty cycle of measurments and channel configuration.
uint32_t min_power_threshold
Used to store min power alert settings.
#define LTC2946_GPIO2_IN_ACTIVE_LOW
static int8_t menu_3_alert_menu_6_read_clear_faults()
Read Faults and Clear.
uint32_t max_power_threshold
Used to store max power alert settings.
#define LTC2946_DISABLE_STUCK_BUS_WAKE_ALERT
#define LTC2946_ENERGY_MSB3_REG
#define LTC2946_GPIO3_OUT_REG_42
#define LTC2946_CTRLB_REG
static int8_t menu_4_shutdown(uint8_t *CTRLB, uint8_t *shutdown)
Toggle Shutdown Down Mode.
#define LTC2946_MIN_POWER_MSB2_REG
#define LTC2946_GPIO3_IN_ACTIVE_LOW
#define LTC2946_FAULT2_REG
#define LTC2946_CHANNEL_CONFIG_A_V_C_3
#define LTC2946_DISABLE_CLEARED_ON_READ
float LTC2946_code_to_time(float time_code, float LTC2946_TIME_lsb)
Calculate the LTC2946 internal time base.
#define LTC2946_ENABLE_STUCK_BUS_WAKE_ALERT
#define LTC2946_MAX_DELTA_SENSE_THRESHOLD_MSB_REG
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.
#define LTC2946_GPIO1_IN_ACTIVE_LOW
float LTC2946_ADIN_code_to_voltage(uint16_t adc_code, float LTC2946_ADIN_lsb)
Calculate the LTC2946 ADIN voltage.
const float LTC2946_ADIN_DELTA_SENSE_lsb
Typical sense lsb weight in V^2 *ADIN_lsb * DELTA_SENSE_lsb.
int8_t LTC2946_write(uint8_t i2c_address, uint8_t adc_command, uint8_t code)
Write an 8-bit code to the LTC2946.
#define LTC2946_GPIO3_IN_ACTIVE_HIGH
#define LTC2946_MIN_VIN_THRESHOLD_MSB_REG
#define LTC2946_CTRLB_ACC_MASK
#define LTC2946_ADIN_MSB_REG
#define LTC2946_GPIO1_IN_ACTIVE_HIGH
const float LTC2946_INTERNAL_TIME_lsb
Internal TimeBase lsb.
uint16_t max_Vin_thresh
Used to store max Vin alert settings.
#define LTC2946_ENABLE_MIN_ADIN_ALERT
#define LTC2946_ENABLE_ADC_DONE_ALERT
static void print_prompt()
Print the Prompt.
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.
#define LTC2946_SENSE_PLUS
#define LTC2946_GPIO3_OUT_LOW
#define LTC2946_MIN_DELTA_SENSE_MSB_REG
static int8_t menu_3_alert_menu_5_enable_disable_alerts_menu_1_ALERT1()
Enable/Disable Alert in ALERT1 Register.
#define LTC2946_ENABLE_GPIO_1_ALERT
#define LTC2946_CTRLA_ADIN_MASK
#define LTC2946_ENABLE_ENERGY_OVERFLOW_ALERT
static void loop()
Repeats Linduino loop.
static int8_t restore_alert_settings()
Read the alert settings from EEPROM.
static void menu_5_settings_menu_1_configure_CTRLA_reg_menu_1_ADIN_Configuration(uint8_t *CTRLA)
Configure the ADIN reference to GND/INTVCC.
#define LTC2946_OFFSET_CAL_128
static float LTC2946_TIME_lsb
Static variable which is based off of the default clk frequency of 250KHz.
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.
static int8_t menu_3_alert_menu_2_set_current_alerts()
Set Current Alert Thresholds.
static int8_t menu_1_continuous_mode(uint8_t CTRLA, uint8_t VOLTAGE_SEL, float scale)
Continuous Mode.
#define LTC2946_DISABLE_MIN_POWER_ALERT
Used to manipulate EEPROM data.
#define EEPROM_CAL_STATUS_ADDRESS
int8_t discover_demo_board(char *demo_name)
Read the ID string from the EEPROM and determine if the correct board is connected.
#define LTC2946_MAX_POWER_THRESHOLD_MSB2_REG
static int8_t menu_5_settings_menu_1_configure_CTRLA_reg(uint8_t *CTRLA, uint8_t *VOLTAGE_SEL)
Configure CTRLA Register.
#define LTC2946_DISABLE_MIN_ADIN_ALERT
#define LTC2946_GPIO_CFG_REG
#define LTC2946_ENABLE_SHUTDOWN
#define LTC2946_I2C_ADDRESS
#define LTC2946_DISABLE_COUNTER_OVERFLOW_ALERT
LT_SPI: Routines to communicate with ATmega328P's hardware SPI port.
#define LTC2946_CHANNEL_CONFIG_V_C
#define LTC2946_GPIO3_OUT_ALERT
#define LTC2946_ENABLE_ALERT_CLEAR
int32_t max_power_threshold
Used to store max power alert settings.
#define LTC2946_GPIO3_CTRL_REG
static int8_t menu_3_alert_menu_5_enable_disable_alerts()
Enable/Disable Alert Menu.
#define LTC2946_ENABLE_MAX_I_SENSE_ALERT
#define LTC2946_ENABLE_COUNTER_OVERFLOW_ALERT
#define LTC2946_RESET_ACC
#define LTC2946_DISABLE_CHARGE_OVERFLOW_ALERT
uint16_t max_adin_thresh
Used to store adin max alert settings.
#define LTC2946_DISABLE_ACC
#define LTC2946_MAX_DELTA_SENSE_MSB_REG
#define LTC2946_ENABLE_AUTO_RESET
LT_I2C: Routines to communicate with ATmega328P's hardware I2C port.
#define LTC2946_GPIO2_OUT_HIGH_Z
#define LTC2946_FAULT1_REG
#define LTC2946_DISABLE_AUTO_RESET
#define LTC2946_ACC_PIN_CONTROL
#define LTC2946_CTRLB_RESET_MASK
char demo_name[]
Demo Board Name stored in QuikEval EEPROM.
#define LTC2946_CHANNEL_CONFIG_V_C_3
#define CONTINUOUS_MODE_DISPLAY_DELAY
The delay between readings.
LTC2946: 12-Bit Wide Range Power, Charge and Energy Monitor.
#define LTC2946_MIN_ADIN_MSB_RESET
#define LTC2946_RESET_ALL
#define LTC2946_GPIOCFG_GPIO3_MASK
char byte_array[sizeof(data_struct_type)]
Array used to store the structure.
uint16_t min_delta_sense_thresh
Used to store min delta sense alert settings.
#define LTC2946_DISABLE_MAX_VIN_ALERT
#define LTC2946_ENABLE_CLEARED_ON_READ
#define LTC2946_GPIO1_OUT_LOW
static uint8_t alert1_code
Value stored or read from ALERT1 register.
#define LTC2946_CHANNEL_CONFIG_A_V_C_2
uint8_t alert1
Used to store the ALERT1 settings.
#define LTC2946_ENABLE_MAX_ADIN_ALERT
#define LTC2946_GPIOCFG_GPIO2_OUT_MASK
void quikeval_I2C_init(void)
Initializes Linduino I2C port.
#define LTC2946_OFFSET_CAL_LAST
const char ack_error[]
Error message.
void quikeval_I2C_connect(void)
Switch MUX to connect I2C pins to QuikEval connector.
uint8_t alert2
Used to store the ALERT2 settings.
float LTC2946_VIN_code_to_voltage(uint16_t adc_code, float LTC2946_VIN_lsb)
Calculate the LTC2946 VIN voltage.
#define LTC2946_GPIO2_OUT_LOW
#define LTC2946_MIN_VIN_MSB_REG
static int8_t menu_3_alert(uint8_t VOLTAGE_SEL, float scale)
Alert and Threshold Menu.
#define LTC2946_DISABLE_MAX_ADIN_ALERT
#define LTC2946_DISABLE_MIN_VIN_ALERT
static uint16_t current
the current measurement from the LTC3335's counter test mode.
struct eeprom_data_union::data_struct_type data_struct
Name of structure.
#define LTC2946_DELTA_SENSE_MSB_REG
#define LTC2946_ENABLE_GPIO_2_ALERT
#define LTC2946_VIN_MSB_REG
#define LTC2946_DISABLE_SHUTDOWN
static uint8_t alert2_code
Value stored or read from ALERT2 register.
#define LTC2946_GPIO1_OUT_HIGH_Z
const float LTC2946_Power_lsb
Typical POWER lsb weight in V^2 VIN_lsb * DELTA_SENSE_lsb.
static int8_t menu_2_snapshot_mode_menu_3_VDD()
VDD - Snapshot Mode.
#define LTC2946_MAX_POWER_MSB2_REG
float LTC2946_code_to_current(uint16_t adc_code, float resistor, float LTC2946_DELTA_SENSE_lsb)
Calculate the LTC2946 current with a sense resistor.
#define LTC2946_ENABLE_ACC
#define LTC2946_MIN_POWER_MSB2_RESET
static void menu_5_settings_menu_1_configure_CTRLA_reg_menu_2_Offset_Configuration(uint8_t *CTRLA)
Configure frequency of offset calibration.
#define LTC2946_MAX_ADIN_THRESHOLD_MSB_REG
#define LTC2946_DISABLE_MAX_I_SENSE_ALERT
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.
#define LTC2946_CHARGE_MSB3_REG
static int8_t menu_3_alert_menu_4_set_adin_alerts(float scale)
Set ADIN Alert Thresholds.
#define LTC2946_MIN_DELTA_SENSE_THRESHOLD_MSB_REG
#define LTC2946_CHANNEL_CONFIG_V_C_2
const float resistor
resistor value on demo board
#define LTC2946_MIN_ADIN_MSB_REG
#define LTC2946_CTRLA_REG
#define LTC2946_MAX_DELTA_SENSE_MSB_RESET
#define LTC2946_GPIO3_CTRL_GPIO3_MASK
float LTC2946_code_to_coulombs(int32_t adc_code, float resistor, float LTC2946_DELTA_SENSE_lsb, float LTC2946_TIME_lsb)
Calculate the LTC2946 coulombs.
static int8_t menu_3_alert_menu_1_set_power_alerts(uint8_t VOLTAGE_SEL, float scale)
Set Power Alert Thresholds.
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.
static int8_t menu_6_clear_min_max()
Clear Min/Max.
#define LTC2946_ALERT1_REG
#define LTC2946_DELTA_SENSE
#define LTC2946_CTRLA_OFFSET_MASK
const float LTC2946_DELTA_SENSE_lsb
Typical Delta lsb weight in volts.
#define LTC2946_DISABLE_STUCK_BUS_RECOVER