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

OK, thank you for the feedback! Are the power drops solved with this value
Testing #5.1
Bafang M510 FC 3.0 | Throttle – not used. | Battery – 52v (14S).
DPC245 Screen | FW - EBiCS_for_M510_BL38_v0.0071

1) The motor was calibrated multiple times using EBiCS. Calibration debug values are 63-65.
2) The motor still loses power at high cadence, but to a lesser extent. Up to 600-700W. This is probably the maximum positive result for a calibration with a +60 offset.

Incidentally, calibration in the original Bafang firmware occurs at a current above 1A. The sensors record ~65-75 RPM on the chainring. However, before this, a brief but loud shift in the chainring is observed.
 

Attachments

  • Testing #5.1 CSV.zip
    1.3 MB · Views: 2
Last edited:
The motor still loses power at high cadence
Yes, looking at your logs, the new calibration value has not fixed the issue, U_d is still much too high.
1775293716079.png

It's not easy to debug, as my motor behaves different obviously.
Using higher current for the calibration is very easy. But it will not solve the problem I guess...
I have to review the algorithm. 🧐
 
It's not easy to debug, as my motor behaves different obviously.
We still have slightly different controllers. Maybe if I burn out my FC 3.0, I'll have to install a controller from the M560 or FC 2.0 :D (I don't see FC 3.0 in the quick access list).
 
I have to review the algorithm.
Hm, there is a bug in the logic, indeed. The rotor position is calculated from the timer2 value times the angle increment for one encoder step in normal motor operation. If the z-pulse is fired, the timer2 is reset to the value that was found in the calibration procedure for the z-pulse position.
But I took the z-position from the timer2 value, not from the absolute angle before. So there was a shift in it.
I have to test the new logic on Monday :)

 
I have to test the new logic on Monday
OK, the effect of the different way of setting the calibration value is, that I have 180 deg offset now, so the motor is turning in the other direction. :ROFLMAO:
I've added an autotune algorithm now, that starts the motor in closed loop, after the open loop z-position detection has finshed. The motor runs in idle speed now and tunes the found z-position until u_d is slightly negative. You can follow this procedure by watching the calories field. After this tuning, the motor stops and the calibration is finished.
I don't know, why this fine tunig is needed, perhaps the encoder has a certain delay, that needs to be accounted in the rotor angle estimation.

As always, I can test only with my own motor, if you are executing the calibration, make sure, that you have a fuse between battery and controller and have the possibility to cut the supply, if the motor doesn't stop the calibration process...

Before running the position sensor calibration, set the motor directon to the other direction, or do a factory settings reset!

I'll attach the bin file with the latest improvements later!

1775487283057.png
 
I'll attach the bin file with the latest improvements later!
Here is a video of the calibration process, the calibration value (encoder offset) is shown in the field "Calories". During the open loop calibration, there is no display communication, therefor the display shows an error. The error disappears when the closed loop part of the calibration starts.


After this calibration, U_d is near zero at idle run. Of course without load, the battery current stays near zero also:

1775492550683.png

When pedaling with load on the roller trainer, U_d stays in a range, that doesn't hit the U_d max limit at high cadence and high power.

1775492793462.png

@Avatarkhorn: I'm really curious to see if your logs will look similar now!
 

Attachments

  • EBiCS_for_M510_BL38_v0.0072.zip
    27.2 KB · Views: 4
Last edited:
@Avatarkhorn: I'm really curious to see if your logs look similar now
I'll do the calibration, but the field test might have to wait until tomorrow. Yesterday was an epic pig-ride in the mud, and I won't have time to get the bike ready for firmware testing today.

Upd.
@stancecoke: I got a rather disappointing result: strange readings, a roaring motor, and currents up to 2.6A. This was true both in one direction and the other, i.e., from the motor to the battery.
 
Last edited:
I got a rather disappointing result:
Hm, your system has a negative Z-position. I have to check, if my calculation fails for negative values :unsure:.
But first I will check, if something went wrong with merging the code for compiling it on my other computer.

It took me over 10 calibrations to get stable readings in the 63-65 range. The starting value was 124, then 140+, then 90+, and then gradually decreased to the stable values described above.

1) The motor was calibrated multiple times using EBiCS. Calibration debug values are 63-65.
2) The motor still loses power at high cadence, but to a lesser extent. Up to 600-700W. This is probably the maximum positive result for a calibration with a +60 offset.
Hm, I have no idea why your offset readings are that random. With the new logic (without the hardcoded 60 offset) the initial value should be about -180 deg, but your video shows about -128 deg. ((65243-2^16)*0,439)

I can't find an obvious bug in the calculation. Can you repeat the calibration a few times, to see if you get the same (bad) result always? I've increased the current during the open loop run already in V0.0072, it should be about 5 amps now...
For my motor I find a calibration value of about 82, 82*0,439=36 deg.

1775558272440.png
 
Last edited:
We still have slightly different controllers.
Can someone provide a flash dump of the Bootloader 38 for the M510? I tried a modified file from the hubmotor controller, but my mod doesn't work.
For the M820 we will have to check, if we can flash a custom firmware with the same strategy. I did a flash dump from the M820 controller and can see, that it uses a different bootloader, the start address has a different offset.
But perhaps, here the guys from the Fake Taxi project like @rekrezeb can help, as they obviously know, how the bin file has to be structured, to be able to flash it with the BESST tool.
 
Last edited:
But first I will check, if something went wrong with merging the code for compiling it on my other computer.
Hm, I've checked the bin file (for bootloader 3) and it works as expected for me. 🤷‍♂️
I allways get very similar resulte of 82-84 for the calibration value...

But I've calibrated at least five times with the same result.
So I really wonder, what's going wrong with your motor :unsure:
More Beta users would be helpful, to see if it is a lucky punch with my controller, or if your controller is the exot :)

Ah, I just have an idea, maybe the timer can't be preloaded with a negative value, I have to check that, but this should be quite easy to solve...
 
Last edited:
So I really wonder, what's going wrong with your motor
My motor is fine. FC 3.0 works almost perfectly. There are just a couple of minor issues due to the proprietary firmware. And that annoying fact of it being proprietary :D.
I reset the settings just in case and recalibrated several times: the results are stable, the same as above.
 
Would be glad, if you could test it!
It looks like you did everything correctly! Of course, I'm getting a different value than you. The engine sound and current consumption at idle are adequate.
I'll try to get out on the bike today. Especially since it's not raining yet.
 
Would be glad, if you could test it!
Testing #6
Bafang M510 FC 3.0 | Throttle – not used. | Battery – 52v (14S).
DPC245 display | FW - EBiCS_for_M510_BL38_v0.0073

1) The motor runs perfectly: very quiet, smooth, and powerful. Calibrated successfully on the first try. Perhaps the current calibration algorithm is perfect; more testers are needed.
2) The adequate range of assistance levels on my motor is quite small. Roughly speaking, ~30-100 units. At 75, I can easily reach maximum power (factor *1).
3) CANable Pro algorithms interfere with adjusting the Torque Sensor filter. It is forbidden to set the acceleration in ECO mode higher than in more powerful riding modes. And since In EBiCS, the higher the value, the stronger the filtering, so it's impossible to make ECO smoother.
4) All other comments concern features that haven't been implemented yet; I hope we can move forward now.

I think I can now use this build permanently on my M510.
 

Attachments

  • Testing #6.zip
    949.3 KB · Views: 3
Sounds like a rly great progress here !

I could also test but at the moment I only own a m560 so it's not helping right ?
 
CANable Pro algorithms interfere with adjusting the Torque Sensor filter.
I hope @mdi will disable the value check in the Canable tool, I don't want to have an extra tool.
The adequate range of assistance levels on my motor is quite small.
Hm, of course I can reduce the output. As I don't know, how much torque one amp of motor current produces, I can't really calculate the mechanical power. I would simply reduce it by factor four, then you have a bigger number range for fine tuning.

All other comments concern features that haven't been implemented yet;
We can add any gimmick we want, but we have to prioritise: is it more helpful to make other motors like the M820 work, or to add more functions to the M510?

I could also test but at the moment I only own a m560 so it's not helping right ?
We had the statement, that in the M560 exactly the same controller is used as in the M510 from @Avatarkhorn. But we got a report about melted battery contacts on the M560 also.

I have no M560, so I can't test.
 
is it more helpful to make other motors like the M820 work, or to add more functions to the M510?
Of course, I'd love to get functional firmware for my motor faster. But more motors = more testers. And there aren't that many popular models: M510, M560, M820.
We had the statement, that in the M560 exactly the same controller is used as in the M510 from @Avatarkhorn.
I didn't say that :D.
They are identical and the first versions of the controllers used the same board.
However, I would like to test it first through the fuse. I already have that capability.
 
Back
Top