BAFANG M215 (BBS01 CAN bus), M315 (BBS02 CAN bus), M510, M560, M820, CR-A101 FOC Open Source EBiCS Firmware for GD32F303 processors

But as @Avatarkhorn already stated, the recalibration is triggered too often, the way I've implemented it.
Unfortunately, in this form, the automatic calibration undermines the usability of the firmware. This week, while actively riding, I turn the display on and off 20-30 times a day.
Because some user experienced thermal drift a couple of times :))
 
Is there any interest in including the simple PAS assistance in the M510/560 branch? I've implemented it in the M215 code anyway. You could set it for one assist level for example, to have a "bring me home" function in case of a torquesensor failure, or if you are completely exhausted...
 
Last edited:
On my M560 motor, it will also momentarily rotate on the Bafang firmware even if there are no perceived peddle movements ( I suspect there will be some rotation as your body when stood up off the seat maintains the lowest point of the peddle whilst the frame itself contours itself to the ground level which can mean rotation of the crank ) if the motor is being worked hard in difficult terrain. The Bafang firmware will almost cut power instantly with even a few degrees of rotating the pedals backward.

It‘s not everyone’s ideal but to advanced riders, that momentary power can be utilised and controlled.
 
Is there any interest in including the simple PAS assistance in the M510/560 branch? I've implemented it in the M820 code anyway. You could set it for one assist level for example, to have a "bring me home" function in case of a torquesensor failure, or if you are completely exhausted...
We have a number of motors that we cannot work out in a diagnostic way what the torque sensor is doing. Is there anyway we can have a diagnostic routine that changes the main display central large figure reporting say torque sensor, motor temp, board temp, volts, amps ( the small say calories display is too small to read whilst cycling ).
 
The Bafang firmware will almost cut power instantly with even a few degrees of rotating the pedals backward
The EBiCS firmware cuts the power after four upcounted backwards PAS pulses. The backwards counter is increased/decreased with every PAS pulse. If you move the pedals back and forth very slightly because of a tremor caused by exhaustion, the counter doesn't go up to four, since it always counts up by 1 and then immediately counts back down by 1.
Of course we could cut the power with the first backwards PAS pulse detected, but I guess then there will be a feedback, that the extended boost is aborted accidently, as you can't avoid to turn the pedals backwards a little when passing a rock or a step with an extended boost....

Is there anyway we can have a diagnostic routine
Sure, we can show what ever we want in the display fields. We just have to define a trigger to switch to the diagnostic mode. Maybe a similar "code" as used for the offroad mode.
 
Last edited:
Besides the config.h you have to edit the linker script also to set the right start address offset for the bootloader:

And of course, you have to add the 32byte header to the bin file by running the relating python script from the documentation folder.
Everything worked, thanks!
Could you please upload the source code for the latest version with the throttle exponent and other features for the M510/M560 on GitHub?
 
Could you please upload the source code for the latest version with the throttle exponent
The latest code is always on the repo. I recommend to use GitHub Desktop to syncronize your local files with the repo. If you want to change the code yourself, it would be even better if you fork the repo to your own GitHub account and commit your changes to your fork. If you think your changes are worth to be merged to the origin EBiCS repo, you can do a pull request.
There are several Git tools out there, but I think Github Desktop is the easiest for beginners, most common git commands are available per mouse click there.

You can check out any commit in the history, but you don't have to, as I've just commented out the autocalibration, so the recent state in the M510/560 branch includes all well tested improvements.

1787763526752.png
 
So simply don't use this version ;)
Perhaps it's better to delete it from the repo.
Of course, after the test, I went back to the release version 0.008. Comparing the release version with 0.0085, I can highlight the following points:
- The auto‑calibration is still causing issues.
- The throttle exponent is a great feature - I tried different variations and liked it.
- Increasing the torque sensor activation threshold in assist mode (v 0.0085) significantly reduces the number of errors on difficult terrain. It could be increased further, or the threshold could be made adjustable.
I assume that’s what @mk00 is working on — compiling their own version. :)
I filmed a short test of the M560 motor on EBiCS v0.0080 at 50 A/120 A. It’s fun and it works great! :) Unfortunately, my battery isn’t well‑suited for this because it’s built with low‑current cells.
 
Comparing the release version with 0.0085, I can highlight the following points:
- The auto‑calibration is still causing issues.
- The throttle exponent is a great feature
Hm, I don't understand your post.
V0.008 has no recalibration at runtime and no throttle exponent feature.
The throttle exponent feature is in 0.0083, that is still in the latest beta folder of the repo.
Is the auto-calibration at startup causing issues? There should be none, as long as you don't put load on the pedals when switching on the system. I've increased the delay to let the voltage stabilise before executing the calibration already, so it should be even more stable meanwhile.
Perhaps I should just put a 0.0086 from the recent code in the latest beta folder...

What is your suggestion?
 
Hm, I don't understand your post.
Yes, unfortunately I didn’t get around to learning English.
The throttle exponent feature is in 0.0083
Yes, it’s a good feature. I like it in versions 83+.
Is the auto-calibration at startup causing issues?
On startup — no. However, any short idle period causes incorrect calibration. Why? Because most riders rest their leading foot on the pedal while waiting. I’ve never had thermal drift. But due to recalibration, I had to restart the motor every time after a pause.
Summary of the comparison between the release version (80) and the new beta (85):
- Throttle exp. — great;
- Raising the torque sensor activation threshold - great, would be even better if it could be raised further;
Auto‑calibration - it’s ruining the firmware :)
 
Today, one of the e‑bike riders from the local Bafang chat ran into a problem: the M560 controller burned out completely while using EBiCS.
The timeline of events was roughly as follows:
- EBiCS was installed.
- Calibration was performed.
- The battery current was set to 30 A.
Then the user made a mistake by setting the “Override” activation threshold to 1 mV. After saving the settings, the motor started (without load) and caught fire. The apparent epicentre of the fire was the power transistors — it looks like a short circuit occurred. Before the fire, the motor had been making occasional clicking noises.
We can recall similar stories where fuses burned out. I also had an M560 controller burn out (though in that case, there are some questions regarding the display).
It seems there are some differences between the M510 and M560 motors that we didn’t notice. The only thing I personally observed is that the M560 motor is physically larger. There’s also the opposite situation, where the M560 motor is controlled perfectly and without any issues by the M510 controller with the corresponding firmware.
Conclusion — the M560 controller board hasn’t been fully analyzed by us.
 

Attachments

  • IMG_20260827_201510_705.jpg
    IMG_20260827_201510_705.jpg
    282.1 KB · Views: 18
  • IMG_20260827_201518_126.jpg
    IMG_20260827_201518_126.jpg
    141.4 KB · Views: 18
  • IMG_20260827_201523_755.jpg
    IMG_20260827_201523_755.jpg
    138.7 KB · Views: 17
  • IMG_20260827_201536_748.jpg
    IMG_20260827_201536_748.jpg
    120.9 KB · Views: 18
Last edited:
setting the “Override” activation threshold to 1 mV. After saving the settings, the motor started (without load) ... Before the fire, the motor had been making occasional clicking noises.
Of course, the motor will start with an Override threshold of 1mV, but without load nothing more should happen, the idle current is less than 1amp normally. So I guess the controller has been defective before already.
 
Looks like it is time for INNOTRACE M560 controller
I’ve read your thread and followed the dramatic debate about trademarks and the project overall. It’s an interesting project. But even if it were finished and fully functional, in my case it’d be much simpler to just buy a bunch of original controllers for $60 each.
Adapting the EBiCS project to a huge variety of motors and revisions is no easy task. But as a user, I already have the perfect solution: an M510 controller for next to nothing, and this firmware covers all my needs. It doesn’t burn out.
 
So I guess the controller has been defective before already.
I’m sure it’s not that simple, but I can’t prove it :)
Nonetheless, I know of several cases where the controller or fuse burned out on an M560 — including from my own experience. And there’s only one story with an M510 controller where the power transistors got shorted to the motor’s magnesium housing, with obvious consequences.
 
Then the user made a mistake by setting the “Override” activation threshold to 1 mV.
Hm, I don't know, if he read the Wiki. I think, if you read (and understand) it, you won't have the idea to set it lower than 750...
But I've added a warning anyway.
 
As far as I have analyzed, the controllers from the M510 and M560 are exactly the same. The main difference is the metal gear of the M560
I ask you not to take this lightly. When you started porting the EBiCS code to M560 controllers, we encountered many cases where fuses and BMS protections would suddenly trip.
Could it be that some M560 revisions use MOSFETs with a different “deadtime”? You know better than I do what happens if a power transistor doesn’t have time to turn off.
Could it be that the FOC algorithms are slightly different for a larger stator? Could the processor get the phases mixed up because of that? Theoretically.
That’s precisely why I went with the M510 controller for my experimental M560 build.
 
Could it be that some M560 revisions use MOSFETs with a different “deadtime”?
Maybe, as far as I remember I've increased the deadtime some day. Of course there are various hardware versions and they will differ a little. But the latest revision seems to share the same PCB at least, as M510 or M560 are marked manually on the PCB :) There is a very detailed thread in the EMTB forum:

1787942227831.png
 
Last edited:
It depends on how they track it. Those controllers are probably not intent for repair and they do not care about the PCB markings and manage things they need to manage in production through the MCU firmware only or maybe temporary stickers or something they remove before installing the controller in the motor. The PCB revision or version may stay the same since the PCB design has not been changed but the PCBA might be different due to different components and configuration. They may use stickers or engraving to reflect the PCBA configuration while the PCB silkscreen markings may stay the same for all the controllers if they did not change the PCB but changed PCBA and use different components.
 
and use different components.
This would be easy to check.
Maybe the motor current calibration is different (different feedback resistor on the opamp circuit), I guess I didn't rechecked that on the M560.
On the M820 the calibration factor is different. Strange that the weaker M820 has a higher calibration factor than the M510....
 
Is there a way to stop the display from showing 99 km/h in the Max Speed field? I tried hardcoding the value to 25 km/h, but it doesn't work.
Due to various interferences, almost right after resetting the display, it jumps to 99 km/h instead of showing the actual maximum speed achieved.
 

Attachments

  • 17884321641679199601138941365155.jpg
    17884321641679199601138941365155.jpg
    3.1 MB · Views: 3
Due to various interferences, almost right after resetting the display, it jumps to 99 km/h instead of showing the actual maximum speed achieved.
Have you tried to reset the trip in the display?
I guess the max speed is stored in the display itself and not in the controller.

1788435188827.png

Looking at the code of the Canable Tool, the command 0x6301 carries the max speed information,
C:
    static package1(packet) { // Data Block 1 (Mileage/Speed)
        if (!packet || !Array.isArray(packet.data) || packet.data.length < 8) {
             return { parseError: true, error: "Invalid data length for Display Data1" };
        }
        return {
            total_mileage: (packet.data[2] << 16) | (packet.data[1] << 8) | packet.data[0],
            single_mileage: (((packet.data[5] << 16) | (packet.data[4] << 8) | packet.data[3])) / 10,
            max_speed: ((packet.data[7] << 8) + packet.data[6]) / 10,
        };
    }

But this information is sent from the display to the controller only, not from the controller to the display.

If the trip reset doesn't solve the problem, we would have to check, whether we really send a value >99 kph with the recent speed accidently...
 
Last edited:
Back
Top