Skip to content

Commit

Permalink
Disable precharge bit if not precharging.
Browse files Browse the repository at this point in the history
  • Loading branch information
mvgalen committed Jan 13, 2025
1 parent 7a52024 commit f9132df
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Software/src/battery/MEB-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1600,8 +1600,8 @@ void transmit_can_battery() {
if (MEB_503.data.u8[3] == BMS_TARGET_HV_OFF) {
logging.printf("MEB Requesting HV\n");
}
MEB_503.data.u8[1] = 0xB0;
MEB_503.data.u8[3] = BMS_TARGET_AC_CHARGING; //TODO, should we try AC_2 or DC charging?
MEB_503.data.u8[1] = 0x30 | (datalayer.battery.status.bms_status == ACTIVE ? 0x00 : 0x80); // Disable precharing if ACTIVE
MEB_503.data.u8[3] = BMS_TARGET_HV_ON; //TODO, should we try AC_2 or DC charging?
MEB_503.data.u8[5] = 0x82; // Bordnetz Active
MEB_503.data.u8[6] = 0xE0; // Request emergency shutdown HV system == 0, false
} else if (first_can_msg > 0 && currentMillis > first_can_msg + 2000 && BMS_mode != 0 &&
Expand Down
5 changes: 4 additions & 1 deletion Software/src/communication/can/comm_can.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@ void transmit_can_frame(CAN_frame* tx_frame, int interface) {
#ifdef CANFD_ADDON
CANFDMessage MCP2518Frame;
if (tx_frame->FD) {
MCP2518Frame.type = CANFDMessage::CANFD_WITH_BIT_RATE_SWITCH;
if (tx_frame->BRS)
MCP2518Frame.type = CANFDMessage::CANFD_WITH_BIT_RATE_SWITCH;
else
MCP2518Frame.type = CANFDMessage::CANFD_NO_BIT_RATE_SWITCH;
} else { //Classic CAN message
MCP2518Frame.type = CANFDMessage::CAN_DATA;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
enum State { PRECHARGE_IDLE, START_PRECHARGE, PRECHARGE, PRECHARGE_OFF, COMPLETED };
State prechargeStatus = PRECHARGE_IDLE;

#define MAX_ALLOWED_FAULT_TICKS 1000
#define MAX_PRECHARGE_TIME_MS 15000 // Maximum time precharge may be enabled

#define Precharge_default_PWM_Freq 22000
#define Precharge_min_PWM_Freq 18000
#define Precharge_default_PWM_Freq 11000
#define Precharge_min_PWM_Freq 5000
#define Precharge_max_PWM_Freq 34000
#define PWM_Res 8
#define PWM_OFF_DUTY 0
Expand Down Expand Up @@ -58,6 +57,8 @@ void handle_precharge_control() {
prechargeStartTime = currentTime;
prechargeStatus = PRECHARGE;
logging.printf("Precharge: Starting sequence\n");
digitalWrite(POSITIVE_CONTACTOR_PIN, HIGH);

break;

case PRECHARGE:
Expand Down Expand Up @@ -90,18 +91,21 @@ void handle_precharge_control() {
datalayer.system.settings.equipment_stop_active) {
pinMode(PRECHARGE_PIN, OUTPUT);
digitalWrite(PRECHARGE_PIN, LOW);
digitalWrite(POSITIVE_CONTACTOR_PIN, LOW);
prechargeStatus = PRECHARGE_IDLE;
logging.printf("Precharge: Disabling Precharge bms not standby/active or equipment stop\n");
} else if (currentTime - prechargeStartTime >= MAX_PRECHARGE_TIME_MS) {
pinMode(PRECHARGE_PIN, OUTPUT);
digitalWrite(PRECHARGE_PIN, LOW);
digitalWrite(POSITIVE_CONTACTOR_PIN, LOW);
prechargeStatus = PRECHARGE_OFF;
datalayer.battery.status.bms_status = FAULT;
logging.printf("Precharge: Disabled (timeout reached) -> PRECHARGE_OFF\n");
// Add event
} else if (datalayer.system.status.battery_allows_contactor_closing) {
pinMode(PRECHARGE_PIN, OUTPUT);
digitalWrite(PRECHARGE_PIN, LOW);
digitalWrite(POSITIVE_CONTACTOR_PIN, LOW);
prechargeStatus = COMPLETED;
logging.printf("Precharge: Disabled (contacts closed) -> COMPLETED\n");
}
Expand Down
1 change: 1 addition & 0 deletions Software/src/devboard/utils/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ enum led_color { GREEN, YELLOW, RED, BLUE, RGB };
/* CAN Frame structure */
typedef struct {
bool FD;
bool BRS;
bool ext_ID;
uint8_t DLC;
uint32_t ID;
Expand Down

0 comments on commit f9132df

Please sign in to comment.