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

Just out of curiosity this is what Google AI came up with:

27,000 eRPM (electrical revolutions per minute) for a geared hub motor is a high, typical operating speed, usually translating to a very fast physical wheel RPM (often 1,000–1,500+ RPM). It indicates high power, with the motor likely spinning fast to achieve top speeds often exceeding 30–40 mph, especially on 1000W-3000W+ systems.

Understanding 27,000 eRPM:
  • eRPM vs. RPM: The geared hub motor's internal motor spins much faster than the hub shell (wheel). The 27,000 eRPM is the speed of the magnetic field switching, not the wheel's rotation speed.
  • Calculation: The formula is eRPM=RPM (physical) × Pole Pairs × Gear Ratio. A high eRPM like 27,000 is common in smaller, fast-spinning, high-pole-count brushless motors found in e-bikes.
  • Performance: A geared motor spinning this fast suggests high-voltage, high-performance setups (e.g., 52V-72V batteries).
  • Limits: If the motor is small, 27,000 eRPM might approach the limit of its internal nylon planetary gears, potentially causing faster wear.
 
the shelf mid drive product that offers this out of the box
There are now several hub motor systems available for OEMs and DIY bicycles. Even in the low-cost bicycle segment, they are now state-of-the-art. And of course the Bafang CR101.C hub motor controller that I'm using here, supports the Bafang BB torque sensor out of the box.

Examples:


 
Last edited:
I will try if the original firmware works with this motor and if yes, if this rattle appears with this also.
I just checked it, it's exactly the same with the original firmware. The original firmware needs slightly more voltage to reach the critical speed, but the symptoms are the same, rattling and high current draw. I checked the critical speed, it's a cadence of about 124/min with the gear ratio of the Shengyi, so nothing really relevant. I won't put any more effort on searching the cause of this issue.
 
Last edited:
There are now several hub motor systems available for OEMs and DIY bicycles
Ok, truckrun RN04 is really really good, I was looking for something like it but in the 750w nominal range. The only motor that comes close is grin all axle but its very expensive. Truckrun rw28 does not support through axle and that's a requirement for me.
 
The max battery current control is implemented in a quite simple way now, it works but may need improvement.
I did a lot of testing on the testbench today.
The algorithm controls the motor torque (motor current iq) in all levels. The battery current limit is the same in all levels.
In this test, I set the display to Eco first, so the motor current limit is reached (green curve stays about 130 (ADC value for iq, calibration factor is 60, 130*60=7800 mA motor current)
Then I switched to Sport level and the battery current limit (set to 8000mA, black curve) kicks in.

1769284498814.png

This chart shows flipping through the assist levels on the display while the torque sensor emulator simulates a constant human power.

1769285090874.png

So I'm ready to test on a real bike now, but I think I will use the roller trainer first, as it's too cold outside to do test rides on the road 🥶
 
Last edited:
I will use the roller trainer first
First test on the roller trainer with the real torquesensor was successful. :cool:
Black: Battery current
Red: speed in kph*100
Blue: human power
Green: iq setpoint

On the roller trainer the mass inertia is much lower than on a real ride, so the curves will be a little smoother on the road, but it works as expected. I set a decreasing assistfactor with the speed for the Eco mode, as you can see in the graph, the human power is higher in proportion to the motor current at high speed...

So now I can prepare the first release, even though many things such as the battery indicator, trip indicator, etc. are not yet working. And of course my "old favorite bug", that I control the torque proportional to the human power leads to the effect, that the assist factor increases linear with speed. I would have the divide the setpoint by the speed to have the motor power proportional to the human power, but I still like this increasing assist factor :)

1769349339593.png

1769349780885.png
 
Last edited:
So now I can prepare the first release
It's done, I've just released the V0.001 on github! 🥳


I'm not expecting very much feedback, as the CR101.C controller is not very common, but of course every feedback is highly welcome!

I will start to port the improvements to the M510 branch now, as I guess, that there are much more potential users for the middrive out there...

regards
stancecoke
 
Last edited:
I'm not expecting very much feedback, as the CR101.C controller is not very common, but of course every feedback is highly welcome!
The sad thing is 6 month ago i sold a fully functioning (older) E-bike with still a good battery and front motor for 150 Euro lol. That could have been a candidate to put a CR101 and bottom bracket torque sensor in and test the code. I'm looking around now for a cheap non functioning one. Which is the item number for the torque sensor you used? Is it this one?
 
It's done, I've just released the V0.001 on github! 🥳


I'm not expecting very much feedback, as the CR101.C controller is not very common, but of course every feedback is highly welcome!

I will start to port the improvements to the M510 branch now, as I guess, that there are much more potential users for the middrive out there...

regards
stancecoke
That's right, owners of m500 carriage motors,510,560,600,400,300,820,420,300,200,210,410,430 a huge amount. But of course, you can ignore most of the engines presented and focus on the newest and most popular m510,560,820, the rest of the models are outdated unfortunately. Perhaps someday you will join our ranks, who knows, having received all the advantages and benefits of using it.
 
It's done, I've just released the V0.001 on github! 🥳


I'm not expecting very much feedback, as the CR101.C controller is not very common, but of course every feedback is highly welcome!

I will start to port the improvements to the M510 branch now, as I guess, that there are much more potential users for the middrive out there...

regards
stancecoke
The one Bafang mid drive unit that has become popular is the M820. It is probably the poorest firmware of the mid drive units for some reason. It has probably the most number of people swapping in new firmwares, perhaps if we could get this controller tuneable with the firmware you’ll get plenty of feedback. Has anyone had one of these controllers in hand to see what processor it has ?
 
Last edited:
Thanks @stancecoke, I hope it is as thats the one motor that is really the most dissatisfying for us EMtbers. Shame really as it could be a good relatively small light weight motor. The M510 series is a lot better in the way the App and BESST is able to tune the motor.

A question, I still haven't really got my head around the speed tabs on the Cannable programme. Are you going to let the user set these speed tabs ? For my use the speed at a set point in time is almost irrelevant, I just need to be able to adjust how the motor reacts to torque from the peddle at any speed. Sure low end speed at say moving off uphill shouldn't allow max Watts.
 
Are you going to let the user set these speed tabs ?
Sure, this is already implemented. But not in the way Bafang does it. See the ReadMe of the repo.

You can limit the max torque and the max speed for each level. Then you can define the assist factor for each level in speed depencence and a global muliplyer.

At the moment there is a hardcoded filter on the torque signal to avoid a pulsating assitance. This may be too sluggish for use in real mountain biking, @TPEHAK has implemented it in a different way, he always takes the maximum value directly and then lets the signal fade away. My experience with such direct assistance philosophies on public roads is poor. The bike jumps forward like a wild goat when you start from a standstill, because you are used to pedaling harder when starting off to get momentum. If you want to start off gently with this philosophy, you can only lightly touch the pedals...

But we can try any behaviour we want, as long as there is an idea how to calculate the iq setpoint from the sensor data.
 
Last edited:
having received all the advantages
I had a big grin on my face reading this comment on the broken clutch of the M560 middrive :ROFLMAO:

I have a suggestion for you.
Very strong low RPM torque = the nightmare of a clutch
....
Of course on a DD hub the real limit for phase amps is if you can stay on the bike or not after hitting the throttle.
 
I will start to port the improvements to the M510 branch now
No port since now, but I tested the last commit of the M510 branch on the roller trainer now. Sadly I have no idea if the efficiency is OK, as in idle run all the drivetrain has to be moved so the current with no load is much higher than I know from hubmotors....
The video shows the current under load of the roller trainer of course.
 
Портирование пока не проводилось, но я протестировал последний коммит ветки M510 на велотренажёре. К сожалению, я понятия не имею, насколько хороша эффективность, поскольку на холостом ходу приходится перемещать всю трансмиссию, поэтому ток без нагрузки намного выше, чем я знаю по мотор-колесам...
На видео, разумеется, показан текущий режим работы велотренажёра под нагрузкой.
Прежде всего, большое спасибо за этот проект и за участие в других, от всего мирового сообщества. Пожалуйста, сообщите, когда можно будет принять участие в бета-тестировании, например, на моем m420 или на m510 у других пользователей? Я уже могу использовать его на m420, а потом, если понадобится, вернуться к нативной прошивке? Надеюсь, вам не надоест и вы не бросите этот проект, подозреваю, это ваше любимое хобби, которое не приносит денег, но доставляет удовольствие?
 
Last edited:
Please let me know when it is possible to participate in the beta test, for example, on my m420 or other people on the m510?
This firmware runs not on the M420, as it uses a NXP processor, not the GD32F303. But of course M510 users are highly welcome for beta testing. Today I've merged the improvements of the Master branch to the M510. The motor is running, the display is working. I don't know, if my torquesensor on the M510 is defective, as the cadence reading from the Speed/Direction line doesn't work. I'm reading the cadence from the PAS2 signal on PC11 now, this works.
I have to optimize the algorithm, as long as I'm accelerating or keeping a steady speed, it works quite fine, but if I reduce the effort to get slower, there is a scattering. I have to check, if I find a UART Tx pin available somewhere for debugging, this would make things much easier. Of course I could use CAN for debugging also, but this would be an additional effort ...
As I have no external speed sensor yet, the speed is not displayed correctly at the moment.

I suspect it's your favorite hobby that doesn't bring money
Indeed. I'm happy if there are some users, but I do all the development just for fun and most interesting for me is the FOC motor control itself. All the stuff to make the project user friendly is quite boring :ROFLMAO:
 
I have a controller from a bafang hub motor kit that's a year old. This motor hits 30mph on 52v, so i imagine it is an unlimited model.

I attempted to disassemble it to find out what chip drives it, only to find the FETs are glued to the case, making removing the board a bit dangerous. I decided to not perform that operation.

It looks an awful lot like the controller in the first page. Is there a good way to tell if this is a controller your firmware could run on?

suspected controller.jpg
 
I send debug messages via CAN now. It's just one FrameID, so it is limited to 8 Bytes payload. The advantage of CAN is the possibility to set ID filters, so it's very easy to print the debug data to a python terminal window and you can use the Canable cable, see the screenshot. The display communication works in parallel without problems.
I've switched to an active battery current control at the battery current limit, as the simple downscaling of the iq setpoint caused a jerky behavior near the battery current limit. Now the external speed sensor is the last thing missing before I'm ready to publish the first beta for the M510 :cool:

1770151129355.png
 
Super! And yep brakes are essential in a test setup on the road. Maybe you can implement a brake sensor to stop the motor in case it thinks it has to run full steam ahead :)
 
Back
Top