Skip to content

Commit

Permalink
Debug formatting tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmpye committed Aug 29, 2023
1 parent a09edd3 commit a077e4d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 25 deletions.
38 changes: 16 additions & 22 deletions V10_BMS/src/bms.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,19 +343,14 @@ void bms_handle_discharging() {
//Reset the UART message counter;
serial_reset_message_counter();
//Brief pause to allow vac to wake up before we start sending serial data at it.
delay_ms(260);
}

while (1) {

#ifdef SERIAL_DEBUG
char message[40];
sprintf(message,"Discharging at %d mA \r\n", currentmA);
serial_debug_send_message(message);
sprintf(message, "Capacity %d\r\n", eeprom_data.total_pack_capacity);
serial_debug_send_message(message);
sprintf(message, "Level %d\r\n", eeprom_data.current_charge_level);
serial_debug_send_message(message);

#ifdef SERIAL_DEBUG
sprintf(debug_msg_buffer,"Discharging at %d mA, %d mAH, capacity %d mAH, Temp %d'C\r\n", currentmA*-1, eeprom_data.current_charge_level/1000, eeprom_data.total_pack_capacity/1000,
bq7693_read_temperature()/10);
serial_debug_send_message(debug_msg_buffer);
#endif
if (!port_pin_get_input_level(TRIGGER_PRESSED_PIN)) {
//Trigger released.
Expand Down Expand Up @@ -458,12 +453,9 @@ void bms_handle_charging() {
leds_flash_charging_segment((eeprom_data.current_charge_level*100) / eeprom_data.total_pack_capacity);

#ifdef SERIAL_DEBUG
sprintf(debug_msg_buffer,"Charging at %d mA \r\n", currentmA);
serial_debug_send_message(debug_msg_buffer);
sprintf(debug_msg_buffer, "Pack charge %d microAH : cap %d microAH\r\n", eeprom_data.current_charge_level, eeprom_data.total_pack_capacity);
serial_debug_send_message(debug_msg_buffer);
sprintf(debug_msg_buffer, "Pack temp %d 'C\r\n", bq7693_read_temperature()/10);
serial_debug_send_message(debug_msg_buffer);
sprintf(debug_msg_buffer,"Charging at %d mA, %d mAH, capacity %d mAH, Temp %d'C\r\n", currentmA, eeprom_data.current_charge_level/1000, eeprom_data.total_pack_capacity/1000,
bq7693_read_temperature()/10);
serial_debug_send_message(debug_msg_buffer);
#endif
if (!bms_is_safe_to_charge()) {
//Safety error.
Expand All @@ -487,15 +479,17 @@ void bms_handle_charging() {
}

if (bms_is_pack_full()) {
#ifdef SERIAL_DEBUG
sprintf(debug_msg_buffer, "Charging paused - cell full, attempt %d of %d\r\n", charge_pause_counter, FULL_CHARGE_PAUSE_COUNT);
serial_debug_send_message(debug_msg_buffer);
serial_debug_send_cell_voltages();
#endif
//Pause the charging.
port_pin_set_output_level(ENABLE_CHARGE_PIN, false);
bq7693_disable_charge();

//Delay for 30 seconds, then go and try again.
for (int i=0; i<30; ++i) {
#ifdef SERIAL_DEBUG
serial_debug_send_message("Charging paused because a cell hit capacity\r\n");
#endif
//This function takes a second.
leds_flash_charging_segment((eeprom_data.current_charge_level*100) / eeprom_data.total_pack_capacity);
//Check the charger hasn't been unplugged while we're waiting
Expand All @@ -513,8 +507,8 @@ void bms_handle_charging() {
bq7693_enable_charge();
}

if (charge_pause_counter == 10) {
//After 10 pauses, we are full.
if (charge_pause_counter == FULL_CHARGE_PAUSE_COUNT) {
//After FULL_CHARGE_PAUSE_COUNT pauses, we are full.
//Disable the charging
port_pin_set_output_level(ENABLE_CHARGE_PIN, false);
bq7693_disable_charge();
Expand All @@ -529,7 +523,7 @@ void bms_handle_charging() {
#ifdef SERIAL_DEBUG
serial_debug_send_message("Charging stopped - cells at capacity\r\n");
char message[40];
sprintf(message, "Total pack capacity %d\r\n", eeprom_data.total_pack_capacity);
sprintf(message, "Total pack capacity %dmAh\r\n", eeprom_data.total_pack_capacity/1000);
serial_debug_send_message(message);
#endif
return;
Expand Down
2 changes: 2 additions & 0 deletions V10_BMS/src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@

#define IDLE_TIME 60 * 15 // Idle time in seconds. Pack will go into SHIP/deep sleep mode if nothing happens in this duration

#define FULL_CHARGE_PAUSE_COUNT 10 //Once a cell reaches max charge volts, pause for 30 seconds and retry, this many times.

#define SERIAL_DEBUG 1

#endif /* CONFIG_H_ */
7 changes: 4 additions & 3 deletions V10_BMS/src/serial_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ void serial_debug_init() {
//Enable
usart_enable(&debug_usart);

//Initial debug blurb.
//Initial debug blurb
serial_debug_send_message("Dyson V10 BMS Aftermarket firmware init\r\n");
serial_debug_send_message("(C) David Pye davidmpye@gmail.com\r\n");
serial_debug_send_message("GNU GPL v3.0 or later\r\n");

serial_debug_send_cell_voltages();
//Need to pause 250mS before cell voltages are available from the BQ7693
delay_ms(250);
serial_debug_send_cell_voltages();
#endif

}
Expand Down

0 comments on commit a077e4d

Please sign in to comment.