106 void menu_5_settings(int8_t *VDD_or_SENSE_monitoring, int8_t *ADIN_or_SENSE,
float *scale);
109 #define CONTINUOUS_MODE_DISPLAY_DELAY 1000 121 const char ack_error[] =
"Error: No Acknowledge. Check I2C Address.";
134 Serial.begin(115200);
139 Serial.println(F(
"Demo board not detected, will attempt to proceed"));
155 static int8_t VDD_or_SENSE_monitoring = 1;
156 static int8_t ADIN_or_SENSE = 1;
162 if (Serial.available())
165 if (user_command !=
'm')
166 Serial.println(user_command);
169 switch (user_command)
196 Serial.println(
"Incorrect Option");
201 Serial.print(F(
"*************************"));
211 Serial.println(F(
"\n*****************************************************************"));
212 Serial.print(F(
"* DC1697 Demonstration Program *\n"));
213 Serial.print(F(
"* *\n"));
214 Serial.print(F(
"* This program communicates with the LTC2945 12-Bit Wide Range *\n"));
215 Serial.print(F(
"* I2C Power Monitor found on the DC1697 demo board. *\n"));
216 Serial.print(F(
"* Set the baud rate to 115200 and select the newline terminator.*\n"));
217 Serial.print(F(
"* *\n"));
218 Serial.print(F(
"*****************************************************************\n"));
224 Serial.print(F(
"\n1-Continuous Mode\n"));
225 Serial.print(F(
"2-Snapshot Mode\n"));
226 Serial.print(F(
"3-Alert\n"));
227 Serial.print(F(
"4-Shutdown Mode\n"));
228 Serial.print(F(
"5-Settings\n"));
229 Serial.print(F(
"6-Clear Min/Max\n\n"));
230 Serial.print(F(
"Enter a command: "));
235 int8_t ADIN_or_SENSE,
242 if (VDD_or_SENSE_monitoring == 1)
244 if (ADIN_or_SENSE == 1)
250 if (ADIN_or_SENSE == 1)
252 Serial.print(F(
"*************************\n\n"));
254 int32_t power_code, max_power_code, min_power_code;
259 float power, max_power, min_power;
264 Serial.print(F(
"****Power: "));
265 Serial.print(power, 4);
266 Serial.print(F(
" W\n"));
268 Serial.print(F(
"Max Power: "));
269 Serial.print(max_power, 4);
270 Serial.print(F(
" W\n"));
272 Serial.print(F(
"Min Power: "));
273 Serial.print(min_power, 4);
274 Serial.print(F(
" W\n"));
278 Serial.print(F(
"*************************"));
282 int32_t power_code, max_power_code, min_power_code;
287 float power, max_power, min_power;
292 Serial.print(F(
"\n***ADIN Power: "));
293 Serial.print(power, 4);
294 Serial.print(F(
" W\n"));
296 Serial.print(F(
"Max ADIN Power: "));
297 Serial.print(max_power, 4);
298 Serial.print(F(
" W\n"));
300 Serial.print(F(
"Min ADIN Power: "));
301 Serial.print(min_power, 4);
302 Serial.print(F(
" W\n"));
305 uint16_t current_code, max_current_code, min_current_code;
310 float current, max_current, min_current;
315 Serial.print(F(
"\n****Current: "));
316 Serial.print(current, 4);
317 Serial.print(F(
" A\n"));
319 Serial.print(F(
"Max Current: "));
320 Serial.print(max_current, 4);
321 Serial.print(F(
" A\n"));
323 Serial.print(F(
"Min Current: "));
324 Serial.print(min_current, 4);
325 Serial.print(F(
" A\n"));
327 uint16_t VIN_code, max_VIN_code, min_VIN_code;
332 float VIN, max_VIN, min_VIN;
337 Serial.print(F(
"\n****VIN: "));
338 Serial.print(VIN, 4);
339 Serial.print(F(
" V\n"));
341 Serial.print(F(
"Max VIN: "));
342 Serial.print(max_VIN, 4);
343 Serial.print(F(
" V\n"));
345 Serial.print(F(
"Min VIN: "));
346 Serial.print(min_VIN, 4);
347 Serial.print(F(
" V\n"));
349 uint16_t ADIN_code, max_ADIN_code, min_ADIN_code;
354 float ADIN, max_ADIN, min_ADIN;
359 Serial.print(F(
"\n****ADIN: "));
360 Serial.print(ADIN, 4);
361 Serial.print(F(
" V\n"));
363 Serial.print(F(
"Max ADIN: "));
364 Serial.print(max_ADIN, 4);
365 Serial.print(F(
" V\n"));
367 Serial.print(F(
"Min ADIN: "));
368 Serial.print(min_ADIN, 4);
369 Serial.print(F(
" V\n"));
370 Serial.print(F(
"m-Main Menu\n\n"));
374 while (Serial.available() ==
false);
382 int8_t ADIN_or_SENSE)
387 Serial.print(F(
"*************************\n\n"));
388 Serial.print(F(
"Snapshot Mode\n"));
389 Serial.print(F(
"1-Current\n"));
390 Serial.print(F(
"2-VIN\n"));
392 Serial.print(F(
"3-ADIN\n"));
393 Serial.print(F(
"m-Main Menu\n"));
397 Serial.print(F(
"\n\nEnter a Command: "));
399 if (user_command ==
'm')
403 Serial.println(user_command);
405 if (user_command !=
'm')
407 Serial.print(F(
"*************************\n\n"));
408 Serial.print(F(
"Snapshot Mode\n"));
409 Serial.print(F(
"1-Current\n"));
410 Serial.print(F(
"2-VIN\n"));
411 Serial.print(F(
"3-ADIN\n"));
412 Serial.print(F(
"m-Main Menu\n"));
415 switch (user_command)
430 if (user_command !=
'm')
431 Serial.println(
"Incorrect Option");
435 while (!((user_command ==
'm') || (ack)));
441 int8_t ADIN_or_SENSE)
458 uint16_t current_code;
463 Serial.print(F(
"Current: "));
464 Serial.print(current, 4);
465 Serial.print(F(
" A"));
488 Serial.print(F(
"VIN: "));
489 Serial.print(VIN, 4);
490 Serial.print(F(
" V"));
514 Serial.print(F(
"ADIN: "));
515 Serial.print(ADIN, 4);
516 Serial.print(F(
" V"));
528 Serial.print(F(
"*************************\n\n"));
529 Serial.print(F(
"1-Set Power Alerts\n"));
530 Serial.print(F(
"2-Set Current Alerts\n"));
531 Serial.print(F(
"3-Set VIN Alerts\n"));
532 Serial.print(F(
"4-Set ADIN Alerts\n"));
533 Serial.print(F(
"5-Enable and Disable Alerts\n"));
534 Serial.print(F(
"6-Read and Clear Alerts\n"));
535 Serial.print(F(
"7-Store Alert Settings to EEPROM\n"));
536 Serial.print(F(
"m-Main Menu\n\n"));
537 Serial.print(F(
"Enter a command: "));
540 if (user_command ==
'm')
543 Serial.println(user_command);
545 switch (user_command)
576 if (user_command !=
'm')
577 Serial.println(
"Incorrect Option");
581 while (!((user_command ==
'm') || (ack)));
590 Serial.print(F(
"Enter Max Power Threshold:"));
592 float max_power_threshold;
594 Serial.println(max_power_threshold, 4);
596 int32_t max_power_threshold_code;
597 if (ADIN_or_SENSE == 1)
604 Serial.print(F(
"Enter Min Power Threshold:"));
606 float min_power_threshold;
608 Serial.println(min_power_threshold, 4);
610 int32_t min_power_threshold_code;
611 if (ADIN_or_SENSE == 1)
624 Serial.print(F(
"Enter Max Current Threshold:"));
626 float max_current_threshold;
628 Serial.println(max_current_threshold, 4);
630 int32_t max_current_threshold_code;
635 Serial.print(F(
"Enter Min Current Threshold:"));
637 float min_current_threshold;
639 Serial.println(min_current_threshold, 4);
641 int32_t min_current_threshold_code;
652 Serial.print(F(
"Enter Max VIN Threshold:"));
654 float max_VIN_threshold;
656 Serial.println(max_VIN_threshold, 4);
658 int32_t max_VIN_threshold_code;
662 Serial.print(F(
"Enter Min VIN Threshold:"));
664 float min_VIN_threshold;
666 Serial.println(min_VIN_threshold, 4);
668 int32_t min_VIN_threshold_code;
679 Serial.print(F(
"Enter Max ADIN Threshold:"));
681 float max_ADIN_threshold;
683 Serial.println(max_ADIN_threshold, 4);
685 int32_t max_ADIN_threshold_code;
689 Serial.print(F(
"Enter Min ADIN Threshold:"));
691 float min_ADIN_threshold;
693 Serial.println(min_ADIN_threshold, 4);
695 int32_t min_ADIN_threshold_code;
709 Serial.print(F(
"*************************\n\n"));
710 Serial.print(F(
"1-Enable/Disable Power Alerts\n"));
711 Serial.print(F(
"2-Enable/Disable Current Alerts\n"));
712 Serial.print(F(
"3-Enable/Disable VIN Alerts\n"));
713 Serial.print(F(
"4-Enable/Disable ADIN Alerts\n"));
714 Serial.print(F(
"m-Alert Menu\n\n"));
715 Serial.print(F(
"Enter a command:"));
717 if (user_command ==
'm')
720 Serial.println(user_command);
721 if (!(user_command == 0))
723 Serial.print(F(
"1-Enable, 2-Disable\n"));
725 switch (user_command)
729 Serial.print(F(
" Max Power:"));
731 if ((user_command > 2) || (user_command < 0))
733 Serial.println(user_command);
734 if (user_command == 1)
739 Serial.print(F(
" Min Power:"));
741 if ((user_command > 2) || (user_command < 0))
743 Serial.println(user_command);
744 if (user_command == 1)
751 Serial.print(F(
" Max Current:"));
753 if ((user_command > 2) || (user_command < 0))
755 Serial.println(user_command);
756 if (user_command == 1)
761 Serial.print(F(
" Min Current:"));
763 if ((user_command > 2) || (user_command < 0))
765 Serial.println(user_command);
766 if (user_command == 1)
773 Serial.print(F(
" Max VIN:"));
775 if ((user_command > 2) || (user_command < 0))
777 Serial.println(user_command);
778 if (user_command == 1)
783 Serial.print(F(
" Min VIN:"));
785 if ((user_command > 2) || (user_command < 0))
787 Serial.println(user_command);
788 if (user_command == 1)
795 Serial.print(F(
" Max ADIN:"));
797 if ((user_command > 2) || (user_command < 0))
799 Serial.println(user_command);
800 if (user_command == 1)
805 Serial.print(F(
" Min ADIN:"));
807 if ((user_command > 2) || (user_command < 0))
809 Serial.println(user_command);
810 if (user_command == 1)
816 if (user_command !=
'm')
817 Serial.println(
"Incorrect Option");
821 while (user_command !=
'm');
832 if (
alert_code & 0x80) Serial.print(F(
"Power Overvalue Fault Occurred\n\n"));
833 if (
alert_code & 0x40) Serial.print(F(
"Power Undervalue Fault Occurred\n"));
834 if (
alert_code & 0x20) Serial.print(F(
"Current Overvalue Fault Occurred\n"));
835 if (
alert_code & 0x10) Serial.print(F(
"Current Undervalue Fault Occurred\n"));
836 if (
alert_code & 0x08) Serial.print(F(
"VIN Overvalue Fault Occurred\n"));
837 if (
alert_code & 0x04) Serial.print(F(
"VIN Undervalue Fault Occurred\n"));
838 if (
alert_code & 0x02) Serial.print(F(
"ADIN Overvalue Fault Occurred\n"));
839 if (
alert_code & 0x01) Serial.print(F(
"ADIN Undervalue Fault Occurred\n"));
840 if (!
alert_code) Serial.print(F(
"No Alarms Were Present\n"));
851 Serial.print(F(
"LTC2945 Has Been Shutdown\n"));
857 int8_t *ADIN_or_SENSE,
861 Serial.print(F(
"VIN Monitor"));
862 Serial.print(F(
"\n0-VDD or 1-Sense+ Monitoring (Default=1)\n\n"));
863 *VDD_or_SENSE_monitoring =
read_int();
864 if ((*VDD_or_SENSE_monitoring < 0) || (*VDD_or_SENSE_monitoring > 1))
865 *VDD_or_SENSE_monitoring = 1;
866 Serial.println(*VDD_or_SENSE_monitoring);
867 Serial.print(F(
"Multiplier Select\n"));
868 Serial.print(F(
"0-ADIN or 1-SENS+/VDD (Default=1)"));
870 if ((*ADIN_or_SENSE < 0) || (*ADIN_or_SENSE > 1))
872 if (*ADIN_or_SENSE == 0)
874 Serial.print(F(
"\nresistor divider needs to be set such that New FS is 2.048v to ADIN\n"));
875 Serial.print(F(
"Enter in new full scale input voltage:"));
878 *scale = user_float / 2.048;
879 Serial.println(user_float);
880 Serial.print(F(
"Scale:"));
881 Serial.println(*scale);
906 struct data_struct_type
951 Serial.println(
"Alert Settings Restored");
956 Serial.println(
"Alert Settings not found");
980 Serial.println(
"Alert Settings Stored to EEPROM");
#define LTC2945_ENABLE_MAX_POWER_ALERT
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.
int32_t min_power_threshold
Used to store min power alert settings.
static int8_t menu_6_clear_min_max()
Clear Min/Max.
#define LTC2945_MIN_ADIN_MSB_RESET
uint16_t min_Vin_thresh
Used to store min Vin alert settings.
static void store_alert_settings()
Store the alert settings to the EEPROM.
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 LTC2945_DELTA_SENSE_SNAPSHOT
uint8_t alert
Used to store the alert settings.
uint16_t min_adin_thresh
Used to store adin min alert settings.
unsigned char user_command
#define EEPROM_I2C_ADDRESS
static int8_t menu_2_snapshot_mode(int8_t VDD_or_SENSE_monitoring, int8_t ADIN_or_SENSE)
Snapshot Mode Menu.
#define LTC2945_DISABLE_MAX_ADIN_ALERT
static void print_prompt()
Print the Prompt.
#define LTC2945_MIN_DELTA_SENSE_THRESHOLD_MSB_REG
int8_t LTC2945_write_16_bits(uint8_t i2c_address, uint8_t adc_command, uint16_t code)
Write a 16-bit code to the LTC2945.
float LTC2945_code_to_ADIN_power(int32_t adc_code, float resistor, float LTC2945_ADIN_DELTA_SENSE_lsb)
Calculate the LTC2945 power with the ADIN.
#define LTC2945_MAX_ADIN_MSB_REG
#define LTC2945_ENABLE_MIN_DELTA_SENSE_ALERT
#define LTC2945_DISABLE_MIN_VIN_ALERT
int16_t cal_key
The key that keeps track of the calibration.
#define LTC2945_DISABLE_MIN_POWER_ALERT
#define LTC2945_VIN_SNAPSHOT
#define CONTINUOUS_MODE_DISPLAY_DELAY
The delay between readings.
#define LTC2945_CONTROL_REG
float LTC2945_code_to_current(uint16_t adc_code, float resistor, float LTC2945_DELTA_SENSE_lsb)
Calculate the LTC2945 current with a sense resistor.
Header File for Linduino Libraries and Demo Code.
#define LTC2945_I2C_ADDRESS
int8_t LTC2945_read_16_bits(uint8_t i2c_address, uint8_t adc_command, uint16_t *adc_code)
Reads a 16-bit adc_code from LTC2945.
const float LTC2945_ADIN_lsb
Typical ADIN lsb weight in volts.
static int8_t menu_3_alert_menu_4_set_adin_alerts()
Set ADIN Alerts.
#define LTC2945_VIN_MSB_REG
static int8_t menu_2_snapshot_mode_menu_1_current(int8_t VDD_or_SENSE_monitoring, int8_t ADIN_or_SENSE)
Current - Snapshot mode.
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 LTC2945_MIN_VIN_MSB_REG
#define LTC2945_FAULT_CoR_REG
#define LTC2945_MAX_POWER_THRESHOLD_MSB2_REG
int8_t LTC2945_read(uint8_t i2c_address, uint8_t adc_command, uint8_t *adc_code)
Reads an 8-bit adc_code from LTC2945.
uint16_t max_delta_sense_thresh
Used to store max delta sense alert settings.
#define LTC2945_MAX_POWER_MSB2_REG
#define LTC2945_SENSE_MULTIPLIER
#define LTC2945_MAX_VIN_MSB_RESET
static void setup()
Initialize Linduino.
#define LTC2945_ENABLE_MIN_ADIN_ALERT
#define LTC2945_POWER_MSB2_REG
#define LTC2945_CONTINUOUS_MODE
#define LTC2945_ADIN_MSB_REG
#define LTC2945_MIN_ADIN_THRESHOLD_MSB_REG
static int8_t demo_board_connected
Set to 1 if the board is connected.
static void loop()
Repeats Linduino loop.
int8_t LTC2945_write(uint8_t i2c_address, uint8_t adc_command, uint8_t code)
Write an 8-bit code to the LTC2945.
#define LTC2945_MIN_VIN_MSB_RESET
static int8_t menu_3_alert(int8_t ADIN_or_SENSE)
Alert Menu.
float LTC2945_code_to_power(int32_t adc_code, float resistor, float LTC2945_Power_lsb)
Calculate the LTC2945 power.
#define LTC2945_MIN_DELTA_SENSE_MSB_RESET
uint16_t max_Vin_thresh
Used to store max Vin alert settings.
static int8_t menu_3_alert_menu_2_set_current_alerts()
Set Current Alerts.
static int8_t menu_3_alert_menu_1_set_power_alerts(int8_t ADIN_or_SENSE)
Set Power Alerts.
#define LTC2945_MIN_POWER_THRESHOLD_MSB2_REG
#define LTC2945_MAX_ADIN_MSB_RESET
#define LTC2945_DELTA_SENSE_MSB_REG
const float LTC2945_Power_lsb
Typical POWER lsb weight in V^2.
static void print_title()
Print the title block.
#define LTC2945_ENABLE_MAX_DELTA_SENSE_ALERT
#define LTC2945_MIN_ADIN_MSB_REG
Used to manipulate EEPROM data.
#define LTC2945_ENABLE_MAX_ADIN_ALERT
float LTC2945_ADIN_code_to_voltage(uint16_t adc_code, float LTC2945_ADIN_lsb)
Calculate the LTC2945 ADIN voltage.
#define EEPROM_CAL_STATUS_ADDRESS
#define LTC2945_ENABLE_MAX_VIN_ALERT
int8_t discover_demo_board(char *demo_name)
Read the ID string from the EEPROM and determine if the correct board is connected.
static int8_t menu_3_alert_menu_6_read_clear_alerts()
Read Alerts and Clear Alerts.
static int8_t menu_3_alert_menu_3_set_vin_alerts()
Set VIN Alerts.
#define LTC2945_SHUTDOWN_MODE
float LTC2945_VIN_code_to_voltage(uint16_t adc_code, float LTC2945_VIN_lsb)
Calculate the LTC2945 VIN voltage.
#define LTC2945_MIN_POWER_MSB2_RESET
#define LTC2945_DISABLE_MIN_ADIN_ALERT
LT_SPI: Routines to communicate with ATmega328P's hardware SPI port.
int32_t max_power_threshold
Used to store max power alert settings.
const float resistor
resistor value on demo board
#define LTC2945_DISABLE_MAX_VIN_ALERT
static int8_t menu_1_continuous_mode(int8_t VDD_or_SENSE_monitoring, int8_t ADIN_or_SENSE, float scale)
Continuous Mode.
uint16_t max_adin_thresh
Used to store adin max alert settings.
LT_I2C: Routines to communicate with ATmega328P's hardware I2C port.
#define LTC2945_MAX_DELTA_SENSE_MSB_REG
const float LTC2945_ADIN_DELTA_SENSE_lsb
Typical sense lsb weight in V^2 *ADIN_lsb * DELTA_SENSE_lsb.
static void menu_5_settings(int8_t *VDD_or_SENSE_monitoring, int8_t *ADIN_or_SENSE, float *scale)
change Settings
#define LTC2945_MAX_VIN_MSB_REG
char demo_name[]
Demo Board Name stored in QuikEval EEPROM.
const float LTC2945_VIN_lsb
Typical VIN lsb weight in volts.
static int8_t restore_alert_settings()
Read the alert settings from EEPROM.
#define LTC2945_MAX_DELTA_SENSE_THRESHOLD_MSB_REG
#define LTC2945_ADIN_SNAPSHOT
char byte_array[sizeof(data_struct_type)]
Array used to store the structure.
static int8_t menu_4_shutdown()
Shutdown Down Mode.
uint16_t min_delta_sense_thresh
Used to store min delta sense alert settings.
#define LTC2945_DISABLE_MAX_POWER_ALERT
#define LTC2945_DISABLE_MAX_DELTA_SENSE_ALERT
int8_t LTC2945_read_12_bits(uint8_t i2c_address, uint8_t adc_command, uint16_t *adc_code)
Reads a 12-bit adc_code from LTC2945.
static int8_t menu_2_snapshot_mode_menu_2_vin()
VIN - Snapshot Mode.
void quikeval_I2C_init(void)
Initializes Linduino I2C port.
#define LTC2945_MAX_POWER_MSB2_RESET
const float LTC2945_DELTA_SENSE_lsb
Typical Delta lsb weight in volts.
int8_t LTC2945_read_24_bits(uint8_t i2c_address, uint8_t adc_command, int32_t *adc_code)
Reads a 24-bit adc_code from LTC2945.
void quikeval_I2C_connect(void)
Switch MUX to connect I2C pins to QuikEval connector.
#define LTC2945_MAX_DELTA_SENSE_MSB_RESET
#define LTC2945_ALERT_REG
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 LTC2945_MIN_VIN_THRESHOLD_MSB_REG
LTC2945: 12-Bit Wide Range Power Monitor.
static uint8_t alert_code
Value stored or read from ALERT register.
const char ack_error[]
Error message.
#define LTC2945_MAX_ADIN_THRESHOLD_MSB_REG
#define LTC2945_ENABLE_MIN_VIN_ALERT
static int8_t menu_3_alert_menu_5_enable_disable_alerts()
Enable/Disable Alerts.
int8_t LTC2945_write_24_bits(uint8_t i2c_address, uint8_t adc_command, int32_t code)
Write a 24-bit code to the LTC2945.
#define LTC2945_MAX_VIN_THRESHOLD_MSB_REG
#define LTC2945_ENABLE_MIN_POWER_ALERT
#define LTC2945_MIN_DELTA_SENSE_MSB_REG
#define LTC2945_DISABLE_MIN_DELTA_SENSE_ALERT
static int8_t menu_2_snapshot_mode_menu_3_ADIN()
ADIN - Snapshot Mode.
#define LTC2945_MIN_POWER_MSB2_REG
#define LTC2945_SENSE_MONITOR