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

There's likely some interesting issue with the controller-display communication.
Hm, really strange finding. On my display there are no issues also. I see no software reason, if it works with one display and not with another with the identical software version. :unsure:
I'll have to sniff the communication with the original firmware. It's always difficult to debug things that do not happen on my system.
 
For now, I will postpone testing the M560 until the situation with the CAN protocol is clarified.
I've added various measures in this bin files:
- backwards cut out only after 5 PAS pulses in backwards direction, this should avoid the accidently interruption of the overdrive boost.
- much less cadence dependence of the motor power. I've set the exponent to (1/(1+10))=0.09. It's not user settable yet.
- sending an acknoledge on every write command from the display.
- sending the three IDs 0x3201,0x3200,0x3205 without request from the display.
- disable the debug messages on CAN

The code is the same for the M510 and M560, only the header differs.

For a constant torque on the crank we get this behavior in principle (no real numbers, just to show the characteristic):
1775995208333.png
 

Attachments

  • EBiCS_for_M510+M560_BL38_v0.0077.zip
    58.7 KB · Views: 6
Last edited:
It's not user settable yet.
I made it user settable now by the field "Expected Range on Full Charge". The system has to be restarted to make the change with the Canable Tool take effect, because the float exponent is only calculated once at startup.

I've added filtering for the speed information also. The more pulses per wheel revolution, the heavier the filtering. I haven't tested the code for more than one magnet. If we get positive user reports, I will release a new version on github.

And we have to start a Wiki, as it's getting more confusing, the more user settable features we are adding o_O

1776008599886.jpeg
 

Attachments

  • EBiCS_for_M510+M560_BL38_v0.0078.zip
    58.7 KB · Views: 7
Last edited:
I've added various measures in this bin files:
Testing #8
Bafang M510 FC 3.0 | Throttle – not used. | Battery – 52v (14S).
DPC245 Screen | FW - EBiCS_for_M510_BL38_v0.0077

I rode about 50 km through the city and through flat forest, most of the route with EBiCS v0.0077.

1) The new cadence/motor power algorithm seemed very good to me.
What should I set in the cadence exponent to get the same results as in v0.0077? 10?
2) I've developed an issue with the motor stalling abruptly. Any stop causes a clunking sound in the pedals. I'm not sure if this is good for the gearbox (other than rider comfort). Perhaps this has something to do with the new PAS Timeout algorithm.
3) Overrun is better, but still unusable. When I'm going up a steep climb, I don't have time to shift my weight to the front of the bike. The power is at maximum, and I flip over. I think I need to:
- Unlink overrun from override.
- Power depends on the rider's input power when they stop pedaling.
- Power is additionally adjustable for each support level. Five editable "Start Pulse (Signals)" (Assist) can be used. 0 = disabled, 100 = 100% power.
- The filtering parameters for the entire riding mode apply to overrun.
4) The voltage map for the charge indicator doesn't work correctly at voltages above 52-54V in the table for a 52V battery (14S).
5) Is it possible to create an algorithm to compensate for the voltage drop when the battery is discharged? That is, I set the maximum current to 18A and get ~18 x 58 = 1044W with a charged battery. When the voltage drops to 46V, the maximum current increases to 22A, and I still get ~1000W. The point is to stabilize the output power. This feature is dangerous for idiots, but they are unlikely to install EBiCS.
 
Last edited:
I've added filtering for the speed information also. The more pulses per wheel revolution, the heavier the filtering.
With 6 magnets, the filtering is too strong. The delay in receiving current information is more than 5 seconds. This means it takes 5+ seconds from the wheel stopping to the speedometer reading zero. The reading increases in a similar manner, but gradually increases to the current speed.

I downloaded v0.0078 on the M560. Everything works except for two of my three DPC245 displays :D (the same as before).
I was able to install the SW102T, which works fine and now displays the battery charge correctly (it just can't be turned off with the button, like before). There's no motor jerking at idle. Tomorrow I'll do a test drive with the logger.
 
Last edited:
You installed 6 magnets on the wheel? Did you put them on the spokes? For one magnet 5 seconds means 1 miles per hour threshold on 27.5" diameter wheel. What is the minimal speed you want to be able to see on the display? If you will decrease the delay time to 2.5 seconds for instance any speed below 2 miles per hour will be displayed as 0 miles per hour in 2.5 seconds after the last magnet passed the speed sensor event even it is not 0 (or actually any number between 0 and 2 regardless the actual speed depending on the algorithm) because of you want to know the speed sooner than the magnet passed the sensor.
 
You installed 6 magnets on the wheel?
Yes.
Did you put them on the spokes?
The sensor on my frame is installed in the brake disc area.
What is the minimal speed you want to be able to see on the display?
You can specify the number of magnets in the firmware. Let’s assume that with a value of “6”, the delay time could also be divided by this number.

The only reason this might be needed is for a more dynamic display of speed information. It’s possible that this was the case, but the display couldn’t handle the flow of information, and the data was hard to read. Therefore, the data update rate and its accuracy should still be limited.

And this is nothing more than an experiment. The quality of my life isn’t affected by having just one magnet on the wheel :D
 
Trend is to much higher optical reading of rear wheel speed to enable much better motor control at very low speeds, a 29” wheel covers a lot of distance in Mtb terms in one revolution.
 

Attachments

  • IMG_0187.jpeg
    IMG_0187.jpeg
    137.6 KB · Views: 9
Trend is to much higher optical reading of rear wheel speed to enable much better motor control at very low speeds, a 29” wheel covers a lot of distance in Mtb terms in one revolution.
Yeah, DJI’s made a bit of a revolution in how motors are controlled. It’s practically a cult among our local e‑bike riders. And that’s especially true given how affordable it is.
 
What should I set in the cadence exponent to get the same results as in v0.0077? 10?
Yes!
(1/(1+10))=0.09

I've developed an issue with the motor stalling abruptly.
Hm, nothing changed in the PAS timeout algorithm. We could try smoother PI-control parameters.

- Power depends on the rider's input power when they stop pedaling.
Thats exactly the way it is implemented. But the higher the threshold is set, the less range of torque on the crank can be used to scale the motor torque. See my graphs.
1776063537248.png

The voltage map for the charge indicator doesn't work correctly at voltages above 52-54V in the table for a 52V battery (14S).
A standard discharge curve is implemented. If you have a better suggestion, you are welcome!

Is it possible to create an algorithm to compensate for the voltage drop when the battery is discharged?
Sure, we can define a maximum electrical power (Ubat x Ibat) instead of a maximum battery current. But I fear, users won't understand, why their battery fuses fire on almost empty batteries then :)

With 6 magnets, the filtering is too strong.
OK, I will try a division instead of a right shift.

it just can't be turned off with the button, like before
Which fields can be shown on the SW102T? I would show the raw ADC value of the button input line on one field to see, how the value changes, if you press the on/off button. We can show it on the live data of the canable tool also, if the SW102T has no suitable field.
 
Last edited:
Yeah, DJI’s made a bit of a revolution in how motors are controlled. It’s practically a cult among our local e‑bike riders. And that’s especially true given how affordable it is.
if we could get anywhere near as good riding experience as DJI with @stancecoke ’s firmware then kudos to @stancecoke . Bare in mind that DJI have other sensors such as incline to play with and probably a much more powerful processor + a development budget of mega millions
 
A standard discharge curve is implemented. If you have a better suggestion, you are welcome!
The TSDZ2 project had the same problems, with each pack exhibiting different curves. In the end they ended up with a Couloumb counting option for the display. At this stage we have far more things to sort than be too worried on exact battery percentages ?
 
Trip, ODO, Time, Range, Max Speed, Avg Speed, Power.
Hm, perhaps Range can be used.

My main concern is the DPC245 problem.
That's still really strange. But showing the raw ADC value of the button may be helpful here also.
But there are more strange things, we have to analyze, for example why the headlight works with the bootloader and from a debug session from the IDE, but not from a restart without bootloader. I will have to check all port states directly after booting. This will take a little time...
 
Last edited:
At this stage we have far more things to sort than be too worried on exact battery percentages ?
Sure! I usually just jot down what I notice during testing. The idea is that the developer sets the priorities. :)
Overrun, for instance, isn’t a big deal for me. That said, I’m really impressed with how the firmware has progressed in recent weeks!
 
A standard discharge curve is implemented. If you have a better suggestion, you are welcome!
Honestly, this is some weird stuff. 3,7 V is right in the middle for a Li‑ion battery — definitely not 85%. Fans of high‑discharge cells will be like, “Wait, 3,0 V should't be 0%!”

What actually happens is that the percentage just hangs at 99, 98, 97 for ages, and then finally starts going down. The reasoning is simple: if it’s >3,8 V, it’s considered “high”. But I’m more used to seeing a linear relationship between voltage and SOC. :D
 
Last edited:
Honestly, this is some weird stuff
It's the result of an AI prompt ;)

We can adapt the curve from the FakeTaxi project.

But our main interest should be to solve the strange issues with the different displays at the moment. Would be great if some more Beta testers would share their experience!
 
Last edited:
Finally got around to repairing one of my M510 motors over the weekend, usual water ingress from the crank side seal and then damaged bearings putting water onto the small interface pcb. A real pain as every winter I get the same problems. Bosch and all the others have gone to multiple seals on that side and yet Bafang have one. The problem is somewhat UK winter conditions, we ride trails that are water logged and full of sand and grit, makes good grinding paste on that seal. Mmmm might have an idea on how to make a sacrificial seal that can be accessed from the outside by taking the spider off. I need to do something as its becoming an issue for me.

As soon as I have motor back in a frame and running I'll join in. My work battle continues, its all about a Great Crested Newt that could live in a 2m x 2m tin shed, the shed shows as a pond on the OS maps. Newts don't live in tin sheds. Talk about a beuracratic nightmare, I've literally spent 100's of hours, possibly into the high hundreds of work hours trying to find a siolution to what is purely a computer generated problem. It still continues. Mmmm.
 
Good afternoon. Today, I installed the firmware v0.0077 on two M560 motors equipped with DPC030 and DPC245 displays.
The firmware works magnificently. I was particularly impressed by how smoothly the bike rides using the standard settings.
At the same time, the firmware delivers high output power—registering around 2.2 kW on the display.
 
Both displays are working flawlessly?!
Yes, both displays work flawlessly.
What is your battery setup? Voltage and max current?
48v, 700ah standard battery from cef69 in the test rig

52v, 1270ah, 40а bms by bicycle. It was critical for me to set the battery's lower voltage limit in order to utilize the battery's full capacity. Your firmware allows me to do this.
 
Don't blame me, if you are burning your motor or your controller ;)

We can adapt the curve from the FakeTaxi project.
I've done that now. And the controller sends the raw ADC value to the "Range" field now.
Would be great to get some data which values are shown at which battery voltage with on/off button pressed and not pressed...

regards
stancecoke

Edit: the values on the range field have to be muliplicated by 100. I have updated the bin files, as my display shows only whole km... My value is about 650 with button released and about 630 with button pressed at about 53V.
 

Attachments

  • EBiCS_for_M510+M560_BL38_v0.0079.zip
    58.8 KB · Views: 3
Last edited:
Back
Top