Master CAN module for Hankzor balancers

Topics concerning OEM and open source BMSes
arber333
Posts: 3337
Joined: Mon Dec 24, 2018 1:37 pm
Location: Slovenia
Has thanked: 84 times
Been thanked: 262 times
Contact:

Re: Master CAN module for Hankzor balancers

Post by arber333 »

It seems i did the modules injustice. Its sensory part is very precise IF you calibrate it beforehand. It seems to look to AD differences between cells and takes complete scale with respect to that. Whrn you use a good multimeter ti measure module voltage you insert that in the application and it will then follow that value.

But regarding longevitl i would say it ran for over a year with balancers allways on. Then mosfets failed and consecutively resistor fuses. Now mosfets failed on 24S wired models not 16S. Those are still running strong.
This leads me to believe it shouldnt be used as 24S. Maybe rather 20S. Transistor gap is too small for 90V and mosfets are 100V rated. We need more margin...
tom91
Posts: 1449
Joined: Fri Mar 01, 2019 9:15 pm
Location: Bristol
Has thanked: 120 times
Been thanked: 266 times

Re: Master CAN module for Hankzor balancers

Post by tom91 »

Ah okay, quite a shame to have to run it under capacity. It does say its rated at 100V which of course literally will be the max voltage of a package and not the design itself.

Did you publish your decoding and control publicly?
Founder Volt Influx https://www.voltinflux.com/
Webstore: https://citini.com/
tom91
Posts: 1449
Joined: Fri Mar 01, 2019 9:15 pm
Location: Bristol
Has thanked: 120 times
Been thanked: 266 times

Re: Master CAN module for Hankzor balancers

Post by tom91 »

Sorry answered my own question.

A bit bulky code, will look into making a bit more "dynamic" as in not fixed and fully configurable.

https://github.com/arber333/ESP32-VCU/b ... 32BMSa.ino
Founder Volt Influx https://www.voltinflux.com/
Webstore: https://citini.com/
arber333
Posts: 3337
Joined: Mon Dec 24, 2018 1:37 pm
Location: Slovenia
Has thanked: 84 times
Been thanked: 262 times
Contact:

Re: Master CAN module for Hankzor balancers

Post by arber333 »

tom91 wrote: Fri Jan 20, 2023 6:30 pm Sorry answered my own question.

A bit bulky code, will look into making a bit more "dynamic" as in not fixed and fully configurable.

https://github.com/arber333/ESP32-VCU/b ... 32BMSa.ino
Yes i am no coder... i changed it multiple times. I want to use flags as i need the code selectively turn on.

For my first objective i tried to turn balancers on and off as i drive or charge.
For second objective i want to get all cell values and store them in an array. There i can compare them and choose the highest and lowest cell and its position.
For third objective i will take temp values and make some alarms from all data.
For rest of steps i would like to put filtered data to Wifi or Bluetooth.

Would you need one sample board for testing?
tom91
Posts: 1449
Joined: Fri Mar 01, 2019 9:15 pm
Location: Bristol
Has thanked: 120 times
Been thanked: 266 times

Re: Master CAN module for Hankzor balancers

Post by tom91 »

I will first get it working on my SimpBMS Teensy 3.2 probably starting with VW code base.

Then I will look at working out how to best share this with others, dont want to go rewriting your whole code as I do not know the "I/O functions".
Founder Volt Influx https://www.voltinflux.com/
Webstore: https://citini.com/
arber333
Posts: 3337
Joined: Mon Dec 24, 2018 1:37 pm
Location: Slovenia
Has thanked: 84 times
Been thanked: 262 times
Contact:

Re: Master CAN module for Hankzor balancers

Post by arber333 »

tom91 wrote: Fri Jan 20, 2023 8:42 pm I will first get it working on my SimpBMS Teensy 3.2 probably starting with VW code base.

Then I will look at working out how to best share this with others, dont want to go rewriting your whole code as I do not know the "I/O functions".
Ah ok BMS is just sensing ENABLE and PP signals and possibly 12V level on AD rest are outputs for interfacing with the car.

When you test your code and it works please report back on how it works as i may copy your hard work.
tom91
Posts: 1449
Joined: Fri Mar 01, 2019 9:15 pm
Location: Bristol
Has thanked: 120 times
Been thanked: 266 times

Re: Master CAN module for Hankzor balancers

Post by tom91 »

First draft created. https://github.com/Tom-evnut/SimpBMS-JK

It reads the info and can command balancing.


Balancing is done here, they need to be set once so using a simple integer to do this.

Code: Select all

      if (balancecells == 1)
      {
        if (SetBal == 2 || SetBal == 0)
        {
          bms.balanceCells(1, 0); //1 is debug
          SetBal = 1;
        }
      }
      else
      {
        if (SetBal == 1 || SetBal == 0)
        {
          bms.balanceCells(0, 0); //1 is debug
          SetBal = 2;
        }
      }
BMS section handles the sending of the can message, it first checks which modules are known to exist.

Code: Select all

void BMSModuleManager::balanceCells(bool balance, int debug)
{
  for (int y = 1; y < MAX_MODULE_ADDR; y++)
  {
    if (modules[y].isExisting() == 1)
    {
      OUTmsg.id  = y;
      OUTmsg.len = 2;
      OUTmsg.ext = 0;

      OUTmsg.buf[0] = 0xF6;
      OUTmsg.buf[1] = balance;
      Can0.write(OUTmsg);

      delay(1);
    }
  }
}
Requesting info, currently is just a shotgun approach not cyclic like you probally want to implement it.
The variable settings.NumModules is a setting to assign amount of modules that should be requested.

Code: Select all

void sendcommand()
{
  for (int I = 1; I < (settings.NumModules + 1); I++)
  {
    msg.id  = I;
    msg.len = 1;
    msg.buf[0] = 0xFF;
    Can0.write(msg);
    delay(1);
  }
}
The decoding happens as follows. It merely looks for a message in the right range and passes it on.

Code: Select all

 if (inMsg.id < 0x00F)//Can Messages from modules
  {
    if (candebug == 1)
    {
      bms.decodecan(inMsg, 1); //Can Messages from modules
    }
    else
    {
      bms.decodecan(inMsg, 0); //Can Messages from modules
    }
  }
Again a simple pass along to the right section using the message id as the module id.

Code: Select all

void BMSModuleManager::decodecan(CAN_message_t &msg, int debug)
{
  int CMU, Id = 0;

  CMU = msg.id;

  if (debug == 1)
  {
    Serial.println();
    Serial.print(CMU);
    Serial.print(" | ");
  }

  modules[CMU].setExists(true);
  modules[CMU].setReset(true);
  modules[CMU].decodecan(msg);

}
Here is how I decode the message, it puts all the variables into the right places to allow it to function in the SimpBMS code frame work.

Code: Select all

void BMSModule::decodecan(CAN_message_t &msg)
{
  uint8_t Id = 0;

  Id = msg.buf[0];

  switch (Id)
  {
    case 1:
      temperatures[0] = msg.buf[2] + msg.buf[1] * 256;
      break;

    case 2:
      balstat = msg.buf[3];
      break;

    case 4:
      cellVolt[msg.buf[1]] = (msg.buf[3] + msg.buf[2] * 256) * 0.001;
      cellVolt[msg.buf[1] + 1] = (msg.buf[5] + msg.buf[4] * 256) * 0.001;
      cellVolt[msg.buf[1] + 2] = (msg.buf[7] + msg.buf[6] * 256) * 0.001;
      break;

    default:
      break;
  }
}
Founder Volt Influx https://www.voltinflux.com/
Webstore: https://citini.com/
arber333
Posts: 3337
Joined: Mon Dec 24, 2018 1:37 pm
Location: Slovenia
Has thanked: 84 times
Been thanked: 262 times
Contact:

Re: Master CAN module for Hankzor balancers

Post by arber333 »

I think in the past i promised the DIP switch address table:
image.png
image.png (8.65 KiB) Viewed 7604 times
Riwi
Posts: 43
Joined: Wed Jun 12, 2019 5:50 pm
Has thanked: 1 time
Been thanked: 8 times

Re: Master CAN module for Hankzor balancers

Post by Riwi »

tom91 wrote: Sat Jan 21, 2023 2:14 pm First draft created. https://github.com/Tom-evnut/SimpBMS-JK

It reads the info and can command balancing.


Balancing is done here, they need to be set once so using a simple integer to do this.

Code: Select all

      if (balancecells == 1)
      {
        if (SetBal == 2 || SetBal == 0)
        {
          bms.balanceCells(1, 0); //1 is debug
          SetBal = 1;
        }
      }
      else
      {
        if (SetBal == 1 || SetBal == 0)
        {
          bms.balanceCells(0, 0); //1 is debug
          SetBal = 2;
        }
      }
BMS section handles the sending of the can message, it first checks which modules are known to exist.

Code: Select all

void BMSModuleManager::balanceCells(bool balance, int debug)
{
  for (int y = 1; y < MAX_MODULE_ADDR; y++)
  {
    if (modules[y].isExisting() == 1)
    {
      OUTmsg.id  = y;
      OUTmsg.len = 2;
      OUTmsg.ext = 0;

      OUTmsg.buf[0] = 0xF6;
      OUTmsg.buf[1] = balance;
      Can0.write(OUTmsg);

      delay(1);
    }
  }
}
Requesting info, currently is just a shotgun approach not cyclic like you probally want to implement it.
The variable settings.NumModules is a setting to assign amount of modules that should be requested.

Code: Select all

void sendcommand()
{
  for (int I = 1; I < (settings.NumModules + 1); I++)
  {
    msg.id  = I;
    msg.len = 1;
    msg.buf[0] = 0xFF;
    Can0.write(msg);
    delay(1);
  }
}
The decoding happens as follows. It merely looks for a message in the right range and passes it on.

Code: Select all

 if (inMsg.id < 0x00F)//Can Messages from modules
  {
    if (candebug == 1)
    {
      bms.decodecan(inMsg, 1); //Can Messages from modules
    }
    else
    {
      bms.decodecan(inMsg, 0); //Can Messages from modules
    }
  }
Again a simple pass along to the right section using the message id as the module id.

Code: Select all

void BMSModuleManager::decodecan(CAN_message_t &msg, int debug)
{
  int CMU, Id = 0;

  CMU = msg.id;

  if (debug == 1)
  {
    Serial.println();
    Serial.print(CMU);
    Serial.print(" | ");
  }

  modules[CMU].setExists(true);
  modules[CMU].setReset(true);
  modules[CMU].decodecan(msg);

}
Here is how I decode the message, it puts all the variables into the right places to allow it to function in the SimpBMS code frame work.

Code: Select all

void BMSModule::decodecan(CAN_message_t &msg)
{
  uint8_t Id = 0;

  Id = msg.buf[0];

  switch (Id)
  {
    case 1:
      temperatures[0] = msg.buf[2] + msg.buf[1] * 256;
      break;

    case 2:
      balstat = msg.buf[3];
      break;

    case 4:
      cellVolt[msg.buf[1]] = (msg.buf[3] + msg.buf[2] * 256) * 0.001;
      cellVolt[msg.buf[1] + 1] = (msg.buf[5] + msg.buf[4] * 256) * 0.001;
      cellVolt[msg.buf[1] + 2] = (msg.buf[7] + msg.buf[6] * 256) * 0.001;
      break;

    default:
      break;
  }
}
Hi Tom!

What’s the status on the Jkbms/balancer integration to simpbms? Do you have it up and running?

Thanks

Rikard
tom91
Posts: 1449
Joined: Fri Mar 01, 2019 9:15 pm
Location: Bristol
Has thanked: 120 times
Been thanked: 266 times

Re: Master CAN module for Hankzor balancers

Post by tom91 »

Riwi wrote: Sat Apr 15, 2023 8:10 pm Hi Tom!

What’s the status on the Jkbms/balancer integration to simpbms? Do you have it up and running?

Thanks

Rikard
It literally is in the github link.
Founder Volt Influx https://www.voltinflux.com/
Webstore: https://citini.com/
Riwi
Posts: 43
Joined: Wed Jun 12, 2019 5:50 pm
Has thanked: 1 time
Been thanked: 8 times

Re: Master CAN module for Hankzor balancers

Post by Riwi »

tom91 wrote: Sat Apr 15, 2023 8:53 pm It literally is in the github link.
Ok, so loading the evsbms with SimpJK.ino.TEENSY32.hex would do it?

When using more than 24s I guess that the jk-balancers needs to be connected like this in order for all cells to be balanced evenly?
Image
tom91
Posts: 1449
Joined: Fri Mar 01, 2019 9:15 pm
Location: Bristol
Has thanked: 120 times
Been thanked: 266 times

Re: Master CAN module for Hankzor balancers

Post by tom91 »

Riwi wrote: Mon Apr 17, 2023 6:29 am Ok, so loading the evsbms with SimpJK.ino.TEENSY32.hex would do it?
NO that is for the SimpBMS as it says and the previous posts mention. If you need it to work on EVS-BMS hardware that can be looked at too, do you have an EVS-BMS?
Founder Volt Influx https://www.voltinflux.com/
Webstore: https://citini.com/
Riwi
Posts: 43
Joined: Wed Jun 12, 2019 5:50 pm
Has thanked: 1 time
Been thanked: 8 times

Re: Master CAN module for Hankzor balancers

Post by Riwi »

tom91 wrote: Mon Apr 17, 2023 8:38 am NO that is for the SimpBMS as it says and the previous posts mention. If you need it to work on EVS-BMS hardware that can be looked at too, do you have an EVS-BMS?
Ok, I haven’t decided on the bms to use yet, still looking though options.

Thanks
thomaa
Posts: 8
Joined: Tue Feb 06, 2024 3:55 pm
Location: Melbourne, Australia
Has thanked: 9 times
Been thanked: 1 time

Re: Master CAN module for Hankzor balancers

Post by thomaa »

I've been looking around for BMS options and have landed on this project. I'm trying to prioritize cost and this seems most effective.

Have been in contact with JK-bms sales reps to try to aks more details out of them. Basically the same info that we already have.
From what ive told, the CAN option doesnt support more than one connection?? Whats the point of going CAN then. Anyways from this I assumed they meant the units don't have isolated CAN, so the GND of each of the units is the bottom most cell in that group. Can anyone confirm if this is the case? If so what did you do for isolation?

Is this still being developed?
arber333
Posts: 3337
Joined: Mon Dec 24, 2018 1:37 pm
Location: Slovenia
Has thanked: 84 times
Been thanked: 262 times
Contact:

Re: Master CAN module for Hankzor balancers

Post by arber333 »

thomaa wrote: Wed Jun 26, 2024 2:17 am I've been looking around for BMS options and have landed on this project. I'm trying to prioritize cost and this seems most effective.

Have been in contact with JK-bms sales reps to try to aks more details out of them. Basically the same info that we already have.
From what ive told, the CAN option doesnt support more than one connection?? Whats the point of going CAN then. Anyways from this I assumed they meant the units don't have isolated CAN, so the GND of each of the units is the bottom most cell in that group. Can anyone confirm if this is the case? If so what did you do for isolation?

Is this still being developed?
I am working on this its just that i dont have much spare time.
I have some problems with ESP32 randomly freezing on receiving from more than 4 modules

Like i said those JK modules are not BMS but rather independent balancers with cell parameters reporting. That reporting can be done via Bluetooth or CAN.
CAN protocol is determined and it works really good. The issue is that those modules need to be set for unique ID number. Normaly this is set via DIP swithes by the balancer side. Table of values i posted here.
When IDs are determined each module needs to be pinged for it to reply with package of values. Those values i intend to package into a cell array and i can do lots with those values.

My intention is simple BMS report via 8byte CAN telegram:
- Pack voltage
- Pack temperature
- Vmax cell
- Vmax position in pack
- Vmin
- Vmin position in pack
- Balancer Error state
- ID Balancer in error

Error states would include:
- Cell UV
- Cell OV
- Balancer Overtemp
- any other error state reported from balancers

After that would work i intend to use an LILYGO® T-Display-S3 AMOLED ESP with CAN bus to display data from BMS and possible other inputs from CAN
User avatar
midway
Posts: 87
Joined: Mon Feb 15, 2021 3:52 pm
Location: Ural
Has thanked: 6 times
Been thanked: 10 times

Re: Master CAN module for Hankzor balancers

Post by midway »

thomaa wrote: Wed Jun 26, 2024 2:17 am I've been looking around for BMS options and have landed on this project. I'm trying to prioritize cost and this seems most effective.

Have been in contact with JK-bms sales reps to try to aks more details out of them. Basically the same info that we already have.
From what ive told, the CAN option doesnt support more than one connection?? Whats the point of going CAN then. Anyways from this I assumed they meant the units don't have isolated CAN, so the GND of each of the units is the bottom most cell in that group. Can anyone confirm if this is the case? If so what did you do for isolation?

Is this still being developed?
The Kan bus in the balancers is isolated, according to the datasheet up to 1000 Volts
arber333
Posts: 3337
Joined: Mon Dec 24, 2018 1:37 pm
Location: Slovenia
Has thanked: 84 times
Been thanked: 262 times
Contact:

Re: Master CAN module for Hankzor balancers

Post by arber333 »

midway wrote: Wed Jun 26, 2024 9:03 am The Kan bus in the balancers is isolated, according to the datasheet up to 1000 Volts
Just so that there is no doubt; I get traffic from modules, its just that after some 4th module report my ESP32 goes tits up and watchdog resets. As of yet I couldnt solve this issue.
Does anyone know of why such reset would happen? Allways at similar range....

I am leaning on to try with different chip, maybe STM32, but i need to build my board first...
User avatar
uhi22
Posts: 793
Joined: Mon Mar 14, 2022 3:20 pm
Location: Ingolstadt/Germany
Has thanked: 112 times
Been thanked: 481 times

Re: Master CAN module for Hankzor balancers

Post by uhi22 »

The usual suspects when the ESP crashes are
- bad power supply of the ESP (unlikely in your situation I guess)
- bad espressif "CAN" driver software. Had some "nice" hours debugging, roughly documented here: https://github.com/uhi22/wifican/blob/m ... rashlog.md and came to the conclusion, that using ESP32 for CAN is like gambling, you may win or you may loose.
- bad espressif "CAN" hardware. This runs in undefined state when it gets the messages faster than the controller reads it. Fine for some single messages, bad for fast bursts. In my case this did not lead to crash, just the CAN reception was dead until restart.
- Finally a reset could also be triggered if you write some data into memory and declared the variable too small, so that you overwrite stack or OS data. E.g. if you declare an array of 10 bytes and write 100 bytes into it.
thomaa
Posts: 8
Joined: Tue Feb 06, 2024 3:55 pm
Location: Melbourne, Australia
Has thanked: 9 times
Been thanked: 1 time

Re: Master CAN module for Hankzor balancers

Post by thomaa »

Thanks for the prompt updates!

It looks like the sales rep I was speaking to didn't really know what they were talking about, so the inbuilt CAN is isolated. Does anyone have the datasheet?

I've ordered a few of these units, different vendor (directly off JK taobao store, JK B2A24S) and would love to help with the development of this once I get them. I had the same idea as arber for what the final product would be with the MCU master putting data onto the vehicle CAN, to be read by a cell status display and possibly VCU to impose power limits.

Is this project documented in more depth elsewhere? I saw the github links tom and arber have put up so far but that seems to be for software side. Sorry if this info is already here and im misinterpreting but is the BMS host/master integrated into the ESP32 VCU hardware that arber has designed?
arber333
Posts: 3337
Joined: Mon Dec 24, 2018 1:37 pm
Location: Slovenia
Has thanked: 84 times
Been thanked: 262 times
Contact:

Re: Master CAN module for Hankzor balancers

Post by arber333 »

uhi22 wrote: Wed Jun 26, 2024 1:32 pm The usual suspects when the ESP crashes are
- bad power supply of the ESP (unlikely in your situation I guess)
- bad espressif "CAN" driver software. Had some "nice" hours debugging, roughly documented here: https://github.com/uhi22/wifican/blob/m ... rashlog.md and came to the conclusion, that using ESP32 for CAN is like gambling, you may win or you may loose.
- bad espressif "CAN" hardware. This runs in undefined state when it gets the messages faster than the controller reads it. Fine for some single messages, bad for fast bursts. In my case this did not lead to crash, just the CAN reception was dead until restart.
- Finally a reset could also be triggered if you write some data into memory and declared the variable too small, so that you overwrite stack or OS data. E.g. if you declare an array of 10 bytes and write 100 bytes into it.
Thanks for the thoughts.
For a while now i suspected MCP2515 controler is not up to the task with code from Collin Kidder. After a brief discusion with him i decided to replace 2515 with MCP2517FD chip. It seems that is more supported with his code.

After some time fiddling with circuit i sent some new boards to be made to JLPCB. After soldering i tested the new board. Inbuilt CAN works great, but external SPI module wouldnt start. It all came down to oscillator. I use 20Mhz crystal and in code i had SPI speed set to 20Mhz. It seems that is not ideal. 10Mhz is better i guess. After i played with the settings in header file i set "#define FD_SPI_SPEED 10000000"

I also tweaked my Watchdog code so that it will observe shorter period of 2s. It seems this works better.
Now both CAN bus lines work at different speeds. CAN0 meant for BMS operates at 250kbaud and CAN1 meant to transmitt 0x285 telegram will work at 500kbaud. I need to test this for integration... will get back to you. 8-)

EDIT: Seems the best crystal to use with Collin Kidders code would be 40Mhz. I just need to get one crystal to test...
User avatar
midway
Posts: 87
Joined: Mon Feb 15, 2021 3:52 pm
Location: Ural
Has thanked: 6 times
Been thanked: 10 times

Re: Master CAN module for Hankzor balancers

Post by midway »

thomaa wrote: Wed Jun 26, 2024 2:04 pm Thanks for the prompt updates!

It looks like the sales rep I was speaking to didn't really know what they were talking about, so the inbuilt CAN is isolated. Does anyone have the datasheet?

I've ordered a few of these units, different vendor (directly off JK taobao store, JK B2A24S) and would love to help with the development of this once I get them. I had the same idea as arber for what the final product would be with the MCU master putting data onto the vehicle CAN, to be read by a cell status display and possibly VCU to impose power limits.

Is this project documented in more depth elsewhere? I saw the github links tom and arber have put up so far but that seems to be for software side. Sorry if this info is already here and im misinterpreting but is the BMS host/master integrated into the ESP32 VCU hardware that arber has designed?
The balancer has a VP1050 chip installed
Attachments
0e04cae0a3a92de461730477.pdf
(1.19 MiB) Downloaded 23 times
Post Reply