• Hello ES! We could use some help to get us past the finish line on building the new knowledgebase for the forum.
    Can you donate? Please see our fundraising page. Thank you!

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

Today, i rode my bike about 3 h( it was bikepark like terrain) and twice happened the situation on which the motor was acting like i was using throttle but I did not. I had to restart the motor to stop that action. Once it occured after uphill and once after downhill. Besides it worked flawlessly.
 
In my case, the torque sensor drift went up to over 900, though that rarely happened. Right now, I've set the pedal threshold to 850
 
Hm, I think we should add a recalibration at runtime, if the idle value (cadence zero and PWM off for example) is not plausible.

We have a double check in resetting the torque counter. The torque has to be greater than the threshold and the PAS counter has to be smaller than the PAS timeout.

C:
    if(MS.torque_on_crank>tq_threshold&&PAS_counter<MP.PAS_timeout)torque_counter=0;//reset counter, if pressure on pedal and pedals rotating


So if you stop pedaling, the assistance will stop also. But especially when riding off-road, it's difficult to keep the pedals completely still enough to prevent a PAS pulse from being triggered. So the assistance is not switched off, if the idle signal is drifting above the threshold.
 
Last edited:
Hm, I think we should add a recalibration at runtime
I've added that feature to the v0.0084 now. The new calibration is executed, if the cadence is zero, the PWM is switched off and the idle value is more than 40mV off the first calibration at startup. Maybe the calibration is triggered, if you rest your leg on the pedal at a red traffic light, you have to try it, I have no M560 on my test bike at the moment. You can check the recent torque value in the calories field
https://github.com/EBiCS/BAFANG_GD3...0/latest_beta/EBiCS_for_M560_BL38_v0.0084.bin
 
Last edited:
Thank you for the feedback. Which version did you use? Can you look at the calories field, before switching off the system next time?
V0.0083
Question: dose this soft work with other display than dpc 245 because I want to change for dpc080? I bought dz41 and motor makes klicking sounds ...
 
I still have the “faulty” sensor. I’ll be able to prepare the motor for testing this issue within a week. It will be an M560 motor with an M510 controller. I assume the mechanical part from the M560 won’t interfere with reproducing the problem.
Hi, @stancecoke
I wasn’t able to assemble the motor last week. I only received the controller for the build yesterday, and I assembled the motor today. Then something totally unexpected happened - the controller turned out to have the BL3 bootloader.
I tried changing the header of the current firmware to match BL3 and managed to flash it onto the controller, but it doesn’t work (the display doesn’t turn on). Next, I tried using your binary file processing script from the repository, but that didn’t help either.
Could you tell me if there’s any way to adapt the latest version of your firmware for the BL3 bootloader?
So far, I’ve successfully managed to flash the older BL3 release:
 
Last edited:
Could you tell me if there’s any way to adapt the latest version of your firmware for the BL3 bootloader?
As the BL3 uses a different start address for the interrupt vector table, you have to recompile the code with different settings. You have to change two files. It's just a matter of a few seconds, if you have installed the tool chain.
I will provide a version later.
Files to edit:
config.h
gd32f30x_flash.ld
 
Last edited:
There should be no impact of the used display on the motor behaviour. As long as the display uses the known CAN protocol.
I installed dz41 display to M600 and it is ok but with m560 , the motor produced that clicking sound and it was felt a sort of stuggering. Can you explain this - are there different can bus protocols for m600 and 560?
 
I installed dz41 display to M600 and it is ok but with m560 , the motor produced that clicking sound and it was felt a sort of stuggering. Can you explain this - are there different can bus protocols for m600 and 560?
I just need to know that there’s a strange menu option in the DZ41 settings, after which the M560 controller burned out, turning to ash with minimal motor activity. I’m actually working on restoring it right now.
I can’t even guess what happened, but I’m not using that display anymore. Especially since there’s a great alternative - the SW‑102T display in the CAN version.
I’d guess that EBICS CAN communication methods still differ from the original ones. I have an SW102‑T that works with EBiCS on one motor but not on another, even though the motors are identical (M510 FC 3.0). Also, my original DPC245 displays (I have three of them) behave inconsistently on the same motor with EBiCS. Please keep in mind that EBiCS is not a fully finished release at the moment.
 
I’d guess that EBICS CAN communication methods still differ from the original ones
The commands that are implemented in EBiCS yet are identical to the original Bafang ones, otherwise they won't work with the display and the Canable tool. Maybe some commands from the original systems are still missing or are not documented at all since now. To see what is different in the DZ41 communication, we would have to sniff on the traffic on the CAN bus with the Canable and a tool like Cangaroo.
 
I compared this motor with another M510 running on EBiCS. I found that the controllers are completely identical, so I didn’t touch them.
However, there’s a slight difference in the torque sensor’s marking. After replacing the torque sensor, I got a motor that works fully with EBiCS. Let me remind you again that the “non‑working” torque sensor worked perfectly with the stock firmware.
I can also recall another strange thing about this torque sensor. There were 2–3 cases when, after calibration and a few runs in “Walk Mode,” the motor’s calibration got reset. But this didn’t happen again after multiple calibrations.
So, I installed the “problematic” torque sensor on the new M510 controller - the one with the BL3 bootloader. The issue repeated exactly: with EBiCS, I have no problems with Walk Mode and the throttle, but the assistance fades out right after startup. The cadence is displayed correctly on the screen.
I’m observing rather unusual voltage readings from the torque sensor - both in the Canable interface and on the display. In the default state, the voltage is around 750 mV, which is within the normal range. When I press the pedal, there’s a sharp voltage spike that almost immediately drops back to ~750 mV - even though the pressure on the pedal is maintained.
If I give a quick, strong press, after the spike the voltage readings can “bounce” almost down to zero before returning to the default value. The maximum value I’ve seen is 2600 mV, although usually the torque sensor can be pressed relatively easily up to 3400 mV (the typical maximum for a torque sensor).
This explains what’s happening during pedaling, but it doesn’t explain why the stock firmware has no issues processing these readings.
 
So, I installed the “problematic” torque sensor on the new M510 controller
Did you test with the v0.0084? If yes, please try the official v0.008 from the latest release first. The 0.0084 will do exactly what you are showing in the video. If the cadence is the zero and the PWM is off, the output will be set back to 740mV.
The best would be, if you could read the voltage on the torque output wire of the sensor with a multimeter.
 
The best would be, if you could read the voltage on the torque output wire of the sensor with a multimeter.
Lol, I couldn’t solder the wires to the controller with my Chinese soldering iron - obviously, they used high‑melting lead‑free solder there. 😅
I had to strip the wire insulation. In my opinion, the readings I’m getting are completely normal.
 
The readings in the “calories” field match the multimeter readings
Then the bike works without issues with the v0.008?

I've switched to a longer standstill duration for triggering the recalibration. But maybe, if you are riding offroad for a longer period, you will never have the situation with four seconds of standstill, so the recalibration will not be triggered before the drift reaches the threshold value 🤷‍♂️

 
Last edited:
Then the bike works without issues with the v0.008?
The bike works the same way as on all subsequent EBiCS versions:
Throttle - works fine.
Walk Mode - works fine.
Assist - starts normally, but the support cuts off almost immediately and stays disabled until the torque sensor is fully unloaded. Then, on the next start, the same thing happens again.
The same issue occurred on the torque sensor’s “native” controller (BL38) with a different motor, the M510. The key point is that this torque sensor works perfectly fine on the original firmware.
I could just put this torque sensor aside and use another one. But we want to get to the bottom of this, right? 😉

Could it be, for example, that cadence sensors are polled differently in the stock firmware?
 
Last edited:
But we want to get to the bottom of this, right?
This is related to exact this one single torque sensor?! Strange. If the torque readings are OK in the calories field on v0.008, it must be an issue with the PAS signal... Is the cadence shown correctly, if the motor stops? The PAS signals are strange on this bafang sensors, as we have 3 wires with PAS information. The "normal" quadrature PAS on pins 1+2 and the processed signal with double frequency on pin 4.
EBiCS uses the quadrature signal.
 
Back
Top