mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-05 10:49:42 +02:00
Add second contactor closing function
This commit is contained in:
parent
7f16ee6fb0
commit
cb4a830a57
3 changed files with 42 additions and 26 deletions
|
@ -151,16 +151,14 @@ unsigned long timeSpentInFaultedMode = 0;
|
|||
|
||||
void set(uint8_t pin, bool direction, uint32_t pwm_freq = 0xFFFFFFFFFF) {
|
||||
#ifdef PWM_CONTACTOR_CONTROL
|
||||
if(pwm_freq != 0xFFFFFFFFFF)
|
||||
{
|
||||
if (pwm_freq != 0xFFFFFFFFFF) {
|
||||
ledcWrite(pin, pwm_freq);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (direction == 1) {
|
||||
digitalWrite(pin, HIGH);
|
||||
}
|
||||
else{ // 0
|
||||
} else { // 0
|
||||
digitalWrite(pin, LOW);
|
||||
}
|
||||
}
|
||||
|
@ -537,10 +535,16 @@ void init_contactors() {
|
|||
pinMode(PRECHARGE_PIN, OUTPUT);
|
||||
set(PRECHARGE_PIN, OFF);
|
||||
#endif //CONTACTOR_CONTROL
|
||||
#ifdef CONTACTOR_CONTROL_DOUBLE_BATTERY
|
||||
pinMode(SECOND_POSITIVE_CONTACTOR_PIN, OUTPUT);
|
||||
set(SECOND_POSITIVE_CONTACTOR_PIN, OFF);
|
||||
pinMode(SECOND_NEGATIVE_CONTACTOR_PIN, OUTPUT);
|
||||
set(SECOND_NEGATIVE_CONTACTOR_PIN, OFF);
|
||||
#endif //CONTACTOR_CONTROL_DOUBLE_BATTERY
|
||||
// Init BMS contactor
|
||||
#ifdef HW_STARK // TODO: Rewrite this so LilyGo can also handle this BMS contactor
|
||||
pinMode(BMS_POWER, OUTPUT);
|
||||
set(BMS_POWER, ON);
|
||||
digitalWrite(BMS_POWER, HIGH);
|
||||
#endif //HW_STARK
|
||||
}
|
||||
|
||||
|
@ -800,6 +804,15 @@ void handle_contactors() {
|
|||
if (!datalayer.system.status.inverter_allows_contactor_closing) {
|
||||
contactorStatus = DISCONNECTED;
|
||||
}
|
||||
#ifdef CONTACTOR_CONTROL_DOUBLE_BATTERY
|
||||
if (datalayer.system.status.battery2_allows_contactor_closing) {
|
||||
set(SECOND_NEGATIVE_CONTACTOR_PIN, ON);
|
||||
set(SECOND_POSITIVE_CONTACTOR_PIN, ON);
|
||||
} else {
|
||||
set(SECOND_NEGATIVE_CONTACTOR_PIN, OFF);
|
||||
set(SECOND_POSITIVE_CONTACTOR_PIN, OFF);
|
||||
}
|
||||
#endif //CONTACTOR_CONTROL_DOUBLE_BATTERY
|
||||
// Skip running the state machine below if it has already completed
|
||||
return;
|
||||
}
|
||||
|
@ -831,8 +844,8 @@ void handle_contactors() {
|
|||
case PRECHARGE_OFF:
|
||||
if (currentTime - negativeStartTime >= POSITIVE_CONTACTOR_TIME_MS) {
|
||||
set(PRECHARGE_PIN, OFF);
|
||||
set(NEGATIVE_CONTACTOR_PIN, PWM_HOLD_DUTY);
|
||||
set(POSITIVE_CONTACTOR_PIN, PWM_HOLD_DUTY);
|
||||
set(NEGATIVE_CONTACTOR_PIN, ON, PWM_HOLD_DUTY);
|
||||
set(POSITIVE_CONTACTOR_PIN, ON, PWM_HOLD_DUTY);
|
||||
contactorStatus = COMPLETED;
|
||||
datalayer.system.status.contactor_control_closed = true;
|
||||
}
|
||||
|
|
|
@ -53,13 +53,16 @@
|
|||
//#define HW_STARK
|
||||
//#define HW_3LB
|
||||
|
||||
/* Contactor settings. If you have a battery that does not activate contactors via CAN, configure this section */
|
||||
//#define CONTACTOR_CONTROL //Enable this line to have the emulator handle automatic precharge/contactor+/contactor- closing sequence (See wiki for pins)
|
||||
//#define CONTACTOR_CONTROL_DOUBLE_BATTERY //Enable this line to have the emulator hardware control secondary set of contactors for double battery setups (See wiki for pins)
|
||||
//#define PWM_CONTACTOR_CONTROL //Enable this line to use PWM for CONTACTOR_CONTROL, which lowers power consumption and heat generation. CONTACTOR_CONTROL must be enabled.
|
||||
//#define NC_CONTACTORS //Enable this line to control normally closed contactors. CONTACTOR_CONTROL must be enabled for this option. Extremely rare setting!
|
||||
|
||||
/* Other options */
|
||||
//#define DEBUG_VIA_USB //Enable this line to have the USB port output serial diagnostic data while program runs (WARNING, raises CPU load, do not use for production)
|
||||
//#define DEBUG_CAN_DATA //Enable this line to print incoming/outgoing CAN & CAN-FD messages to USB serial (WARNING, raises CPU load, do not use for production)
|
||||
//#define INTERLOCK_REQUIRED //Nissan LEAF specific setting, if enabled requires both high voltage conenctors to be seated before starting
|
||||
//#define CONTACTOR_CONTROL //Enable this line to have pins 25,32,33 handle automatic precharge/contactor+/contactor- closing sequence
|
||||
//#define PWM_CONTACTOR_CONTROL //Enable this line to use PWM for CONTACTOR_CONTROL, which lowers power consumption and heat generation. CONTACTOR_CONTROL must be enabled.
|
||||
//#define NC_CONTACTORS //Enable this line to control normally closed contactors. CONTACTOR_CONTROL must be enabled for this option. Extremely rare setting!
|
||||
//#define DUAL_CAN //Enable this line to activate an isolated secondary CAN Bus using add-on MCP2515 chip (Needed for some inverters / double battery)
|
||||
#define CRYSTAL_FREQUENCY_MHZ 8 //DUAL_CAN option, what is your MCP2515 add-on boards crystal frequency?
|
||||
//#define CAN_FD //Enable this line to activate an isolated secondary CAN-FD bus using add-on MCP2518FD chip / Native CANFD on Stark board
|
||||
|
|
|
@ -52,9 +52,9 @@
|
|||
#define NEGATIVE_CONTACTOR_PIN 33
|
||||
#define PRECHARGE_PIN 25
|
||||
|
||||
#define 2ND_POSITIVE_CONTACTOR_PIN 13
|
||||
#define 2ND_NEGATIVE_CONTACTOR_PIN 16
|
||||
#define 2ND_PRECHARGE_PIN 18
|
||||
#define SECOND_POSITIVE_CONTACTOR_PIN 13
|
||||
#define SECOND_NEGATIVE_CONTACTOR_PIN 16
|
||||
#define SECOND_PRECHARGE_PIN 18
|
||||
|
||||
// SMA CAN contactor pins
|
||||
#define INVERTER_CONTACTOR_ENABLE_PIN 36
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue