Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't control MOSFETs with bms.set_0xE1_mosfet_control #2

Open
airy77 opened this issue Mar 6, 2022 · 1 comment
Open

Can't control MOSFETs with bms.set_0xE1_mosfet_control #2

airy77 opened this issue Mar 6, 2022 · 1 comment

Comments

@airy77
Copy link

airy77 commented Mar 6, 2022

I've called the function every way possible but I can't seem to turn off either FET.

bms.set_0xE1_mosfet_control(false,false); // My understanding is that this call should disable both FETs, but it doesn't
bms.set_0xE1_mosfet_control(false, true); // My understanding is that this call should disable the charge FET, but it doesn't
bms.set_0xE1_mosfet_control(true, false); // My understanding is that this call should disable the discharge FET, but it doesn't
bms.set_0xE1_mosfet_control(true, true); // My understanding is that this call should enable both FETs, but since I was never able to disable the FETs, I don't know if this actually turns them on

@airy77
Copy link
Author

airy77 commented Mar 6, 2022

Solved, the following functions are writing to m_0xE1_mosfet_control[0] when they should be writing m_0xE1_mosfet_control[1]

OverkillSolarBms2::set_0xE1_mosfet_control(bool charge, bool discharge)
OverkillSolarBms2::set_0xE1_mosfet_control_charge(bool charge)
OverkillSolarBms2::set_0xE1_mosfet_control_discharge(bool discharge)

I edited bms2.cpp in each of these functions to write m_0xE1_mosfet_control[1] and not m_0xE1_mosfet_control[0] and now I can control the charge FET and the discharge FET. Here is the new code that seems to work correctly. As always, use at your own risk.

// ###########################################################################
// 0xE1 Set MOSFET
// ###########################################################################

// bit 0: Set to disable charge FET
// bit 1: Set to disable discharge FET

void OverkillSolarBms2::set_0xE1_mosfet_control(bool charge, bool discharge) {
#ifdef BMS_OPTION_DEBUG
// Serial.println("Set 0xE1 MOSFET Control");
#endif
if (charge) {
m_0xE1_mosfet_control[1] &= 0b10; // Disable bit zero
}
else {
m_0xE1_mosfet_control[1] |= 0b01; // Enable bit zero
}
if (discharge) {
m_0xE1_mosfet_control[1] &= 0b01; // Disable bit 1
}
else {
m_0xE1_mosfet_control[1] |= 0b10; // Enable bit 1
}
write(BMS_WRITE, BMS_REG_CTL_MOSFET, m_0xE1_mosfet_control, 2);
}

void OverkillSolarBms2::set_0xE1_mosfet_control_charge(bool charge) {
if (charge) {
m_0xE1_mosfet_control[1] &= 0b10; // Disable bit zero
}
else {
m_0xE1_mosfet_control[1] |= 0b01; // Enable bit zero
}
write(BMS_WRITE, BMS_REG_CTL_MOSFET, m_0xE1_mosfet_control, 2);
}

void OverkillSolarBms2::set_0xE1_mosfet_control_discharge(bool discharge) {
if (discharge) {
m_0xE1_mosfet_control[1] &= 0b01; // Disable bit 1
}
else {
m_0xE1_mosfet_control[1] |= 0b10; // Enable bit 1
}
write(BMS_WRITE, BMS_REG_CTL_MOSFET, m_0xE1_mosfet_control, 2);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant