Bafang M500 and M600 motors

casainho

Active member
May 27, 2022
44
142
Portugal
I just got the M500 second hand motor, it was fast, thanks to Thomas H.

First thing I did were to remove the cover and original motor controller, and cut the motor wires on the original controller and solder to VESC. Took me only 1 minute to get the motor running:


As you can see, I only needed to connect the 3 phase wires and it is running sensorless.

See also that there is a generous space where the original motor controller was, meaning the DIY EBike control board can probably be installed there and the only external board will be the VESC controller. The wires will need to be:
- 3 thick motor phase wires, as seen on the video
- 2 thin UART wires, for communication with VESC
- 2 thin wires, 5V and GND, from VESC to power the DIY EBike control board


I did draw the schematic for the DIY version I plan to implement - all that was already tested on previous projects. The power to this board will be provided by the 5V output from VESC.

As can be seen, mostly is only wires. There are only 3 basic resistors + the CAN module (to communicate with the torque sensor) + the NRF52840 board. This board is connected by USB to PC, to be programmed with the (CircuitPython) Python application of EBike, yet to be developed. The debug of this python EBike application is done by serial port that is implemented on top of the USB connection.
The various sensors connections are really basic.

The communication for the display will also be UART and the power to the display will be the dame 5V from VESC.

ebike.png


And here is the schematic for the Easy DIY display - really basic:



For now, I have a very simple Python code that is sending data to UART1, to be connected to VESC. My plan for next days is to make a code that reads the throttle value and setup a motor speed and current based on the throttle values. It needs to read the throttle ADC as also to read and send by UART commands to the VESC -- here is the Github repository with current code and schematics:

 

TeoElFeo

Member
Apr 13, 2022
185
63
Tallinn
This is difficult to grasp but very interesting! 😄 I take my hat off before you. Also do you know if stock controller uses FOC? If not there might be some efficiency gain as well!
 

casainho

Active member
May 27, 2022
44
142
Portugal
This is difficult to grasp but very interesting! 😄 I take my hat off before you. Also do you know if stock controller uses FOC? If not there might be some efficiency gain as well!
Almost for sure original firmware on the original motor controller, implements FOC.

For me, even lowest assist level produces to much motor power so I will win once I can setup it to lower -- my fitness will be improved and I will be able to use a smaller and lighter battery.
 

TeoElFeo

Member
Apr 13, 2022
185
63
Tallinn
I would say this issue was resolved in m510 that allows you with the help of Besst Pro to regulate max current on each assist level. If you set it to 10-15% you get a very gentle assist
 

casainho

Active member
May 27, 2022
44
142
Portugal
I would say this issue was resolved in m510 that allows you with the help of Besst Pro to regulate max current on each assist level. If you set it to 10-15% you get a very gentle assist
I understand your suggestion, but I bought my M500 only 8 months ago and If I would need to buy M510, I would need to pay 1000€!! Paying 1000€ just to have the assist levels factor customized??

But even that would be not enough, because I really want to focus on my fitness and I need full control of the motor, as I did explain here on the other forum:

I am now more fit, I use my ebike with Bafang M500 and I use a gravel bike (a regular bicycle, no motor). I really care about my health and the bicycles / ebikes are strategic health and pleasure machines I use, other than small trail runs and swimming.
I am now more fit, I use my ebike with Bafang M500 and I use a gravel bike (a regular bicycle, no motor). I really care about my health and the bicycles / ebikes are strategic health and pleasure machines I use, other than small trail runs and swimming.

On both bicycles, I have the same Garmin pedals XC100 that measures my pedal power. My average regular pedal power is around 200 watts and I like to pedal at that level on my rides. But I can also give peaks of like 400W for 30 seconds, etc - see my power curve bellow measured by my pedals.

Although I am looking to do fitness, I still need to use the ebike for that step and long hills, on days with 80 kms and that I take like at least 6 hours to do it. This long day rides and this power, have a big positive impact on my diabetes and fat loss!

I do not like my M500 because the lowest assist level 1 is still to much for me, I wish it was way lower! But it is not only that, I wish to be force to always give my average 200W pedal power and only after that, the motor assist would turn on. See this graph:



So looking at the graph, I would like:
1. Green line: configure a constant min value of motor power, like 75W, that is the one to compensate the the extra friction on the pedals due to the motor and extra weight on the bicycle due to the motor and battery.
2. Green line: configure the pedal power value after which the motor would start to give assistance / motor power on top of 1., and ramp up it based on the pedal power.

This is a dream, as the original firmware does net let us configure such advanced modes. If we could develop our own firmware, we could do it. The pedal power value could be measured by the Bafang M500 torque sensor.

My power curve recorded by my pedals:


On both bicycles, I have the same Garmin pedals XC100 that measures my pedal power. My average regular pedal power is around 200 watts and I like to pedal at that level on my rides. But I can also give peaks of like 400W for 30 seconds, etc - see my power curve bellow measured by my pedals.

Although I am looking to do fitness, I still need to use the ebike for that step and long hills, on days with 80 kms and that I take like at least 6 hours to do it. This long day rides and this power, have a big positive impact on my diabetes and fat loss!

I do not like my M500 because the lowest assist level 1 is still to much for me, I wish it was way lower! But it is not only that, I wish to be force to always give my average 200W pedal power and only after that, the motor assist would turn on. See this graph:



So looking at the graph, I would like:
1. Green line: configure a constant min value of motor power, like 75W, that is the one to compensate the the extra friction on the pedals due to the motor and extra weight on the bicycle due to the motor and battery.
2. Green line: configure the pedal power value after which the motor would start to give assistance / motor power on top of 1., and ramp up it based on the pedal power.

This is a dream, as the original firmware does net let us configure such advanced modes. If we could develop our own firmware, we could do it. The pedal power value could be measured by the Bafang M500 torque sensor.

My power curve recorded by my pedals:
 

casainho

Active member
May 27, 2022
44
142
Portugal
I got the Bafang M500 motor running using a throttle. The code I did, reads the throttle value and maps that value to a motor current value, that I send to VESC using command COMM_SET_CURRENT.


Here is the current EBike board. Black and red wires powers the EBike board from the VESC. Yellow and white wires are UART tx and rx, for communication with VESC.
The throttle has 3 wires. The blue is the throttle output analog signal and the others are GND and 3.3V that powers the throttle. There is one resistor of 100K, as seen on the following schematic:

image.png




And this is the current Python code of the EBike board:

 

Waynemarlow

E*POWAH Master
Dec 6, 2019
1,126
902
Bucks
Casainho, there are a number of VESC boards available ( I think the one you are using is for higher voltages and more current than needed ), are there any small VESC Boards of lower amp specs enough to shoe horn into the void left by taking out the Bafang controller ?

Edit: A quick look on the internet throws up this little beastie at 65mm x 18mm. It only has a burst amps of 40A and rated at 20A constant which is right in the ball park
 
Last edited:

casainho

Active member
May 27, 2022
44
142
Portugal
Casainho, there are a number of VESC boards available ( I think the one you are using is for higher voltages and more current than needed ), are there any small VESC Boards of lower amp specs enough to shoe horn into the void left by taking out the Bafang controller ?
The one I use on the video can not support 13S battery, only 12S. So I decided to go with other that supports up to 75V, that should be plenty for my 14S / 52V battery.

Yes, I agree would be better to have smaller board but I do not think that exists. The only option if is someone desing, build and test a custom board. There is a developer doing just that! In fact this step of DIY is important to develop and validate before having the final board, still, there are disadvantages that custom board will be hard to assembly and be tested, as also will only for a specific motor model.
 

Mida

Member
Oct 23, 2022
7
1
ČR
Hi,
I noticed that on github this text is listed in the firmware folder:


1668803729185.png


How should I understand it?
Is it possible to change something on certain addresses in the firmware in the hex editor?
 

Kyokushin

Active member
Mar 28, 2021
332
195
Sol
No, M510 have different controller than M500 and M600.
M510 controller do not work with M500/600 engines and firmware is not interchangable.
 

Dado

Active member
Jun 28, 2022
701
471
Bratislava
Casainho, good job! Just to put it all together and make from it workable and reliable system will be hard. Torque sensor will be a little problem to make it smooth.
If that small VESC can be placed into motor that would be great. The one from Sparkfun is really small - RC guys have still the smallest boards. ;)
 

captainhightop

Active member
Feb 26, 2021
136
143
UK
I have m510 48v ,can i install 36v firmware on it?
Yes, I've been running this for months as the torque sensor works better for me in this mode. You need to have the correct 36V firmware for your version of controller though for it to flash correctly. Your battery level indicator won't be much use as it will stay very high all the time, so don't rely on it.
 

Waynemarlow

E*POWAH Master
Dec 6, 2019
1,126
902
Bucks
s it then possible to use a 43v or 48v battery on a 36v motor?
Something to consider. I finally for the first time ran my battery fully out, as in the bike turned off due to a low battery. My M600 is Ver 46.7 on supposedly 48 volts. I have run it on 52 volts from new without problem and assumed due to the higher voltage, that it would be the BMS that would shut the battery down, a 48 volt low battery should be around 38 volts.

That is clearly not the case. The motor some how knows the battery is a 52 volt battery and shut the motor down at 3.0V a cell 42 volts. Now that’s way earlier than expected and possibly it means that the Controller has switched into 52 volt mapping. Interesting also that the percentage meter on the display also accurately mapped down to 1% as it shut down.

If nothing else its a tad annoying as I still had about 80Whs left in the battery.
 

Dado

Active member
Jun 28, 2022
701
471
Bratislava
yes but you need to flash the firmware
Sava, please dont spread untrue, we have lot of this in the World now, no? ;)

You can not use 48V battery on 36V firmware. You will get Error 7.
You can use only one level up with battery. So if you flash 43V firmware u can use 48V battery. (And this is the best option for power tuning - you just would have wrong SOC %, but you will get to deeper voltage cutoff, so would use whole battery energy)
 

Dado

Active member
Jun 28, 2022
701
471
Bratislava
Something to consider. I finally for the first time ran my battery fully out, as in the bike turned off due to a low battery. My M600 is Ver 46.7 on supposedly 48 volts. I have run it on 52 volts from new without problem and assumed due to the higher voltage, that it would be the BMS that would shut the battery down, a 48 volt low battery should be around 38 volts.

That is clearly not the case. The motor some how knows the battery is a 52 volt battery and shut the motor down at 3.0V a cell 42 volts. Now that’s way earlier than expected and possibly it means that the Controller has switched into 52 volt mapping. Interesting also that the percentage meter on the display also accurately mapped down to 1% as it shut down.

If nothing else its a tad annoying as I still had about 80Whs left in the battery.


Hello mate.

Have not experimented yet with 52V battery. Just form my experience, motor is not auto detecting number of serial cells (unless u have Bafang battery with BMS CAN protocol). Firmware just checking actual range of voltage.

Is true Bafang cutoff voltage is set quite high - cca 3V per cell. So then cutoff voltage will be 39V for 48V FW. If you use 52V battery should not matter and you should be able to go deeper here - 39/14 = 2.78V per cell.

And BMSes usually have cutoff set to 2.6V per cell.
 

savas

Member
Oct 16, 2018
137
57
sofia
Sava, please dont spread untrue, we have lot of this in the World now, no? ;)

You can not use 48V battery on 36V firmware. You will get Error 7.
You can use only one level up with battery. So if you flash 43V firmware u can use 48V battery. (And this is the best option for power tuning - you just would have wrong SOC %, but you will get to deeper voltage cutoff, so would use whole battery energy)
Hi Dado
what i meant was that he needs to flash the firmware to 48v in order to use the correct battery(48v).I am getting my besst tool next week and will try from 48v firmware to 36v firmware.
 

Waynemarlow

E*POWAH Master
Dec 6, 2019
1,126
902
Bucks
Hello mate.

Have not experimented yet with 52V battery. Just form my experience, motor is not auto detecting number of serial cells (unless u have Bafang battery with BMS CAN protocol). Firmware just checking actual range of voltage.

Is true Bafang cutoff voltage is set quite high - cca 3V per cell. So then cutoff voltage will be 39V for 48V FW. If you use 52V battery should not matter and you should be able to go deeper here - 39/14 = 2.78V per cell.

And BMSes usually have cutoff set to 2.6V per cell.
Correct in theory and I had expected that as well, but the motor shut down at 42 volts. That means the motor has auto detected a 52 volt battery and shut down accordingly.

Bit of a pain as I ended up riding 8 km with nearly 100m rise on a dead motor. The only upside was that it is possible to pedal the bike unlike a friends latest Bosch which is almost impossible to pedal when the motor is off.
 

Dado

Active member
Jun 28, 2022
701
471
Bratislava
And when did you measure voltage? During high power draw?

When I drain battery almost to end, at home I am measuring 46V (with 48V battery) .
 

Waynemarlow

E*POWAH Master
Dec 6, 2019
1,126
902
Bucks
And when did you measure voltage? During high power draw?

When I drain battery almost to end, at home I am measuring 46V (with 48V battery) .
Yup the cells will recover pretty quickly with a surface charge that can fool you. The cells I’m using should be fine as I was only pulling very low amps when the battery shut down and according to their test specifications, well within limits.

Out of interest next time I have a lowish battery I’ll put it on test load and check just exactly what is going on.
 

Mida

Member
Oct 23, 2022
7
1
ČR
Hi,
Do you know where FLX.bike sends its goods?

I wanted to order this controller, but it can't be sent to the Czech Republic...
I would have it forwarded from one of the countries that FLX ships to...

Kyokushin:​

you may try myus.com, i used their services once, however i see Czechia on FLX list.


FLX really says in its information that it ships to the Czech Republic, but when I filled in the Czech address in the basket, I received information that it is not possible to send the goods to the Czech Republic.
I don't know why that was.
I finally solved it by ordering the controller from AliExpress in the November festival at a similar price:
 

casainho

Active member
May 27, 2022
44
142
Portugal
Finally I have the display working, here is the current status:

Before start doing the EBike application, here is what is working and what is missing:
- [x] Throotle read
- [x] Torque sensor read
- [x] Brake sensor read
- [x] Wheel speed sensor read
- [x] VESC motor control
- [x] Display
- [ ] EBike application
- [ ] Install this system and this Bafang M500 on my EBike, test and make the final developments

Current Pyhton code: github.com/EBike_EScooter_app_pyhton/firmware/main.py

My next step is start thinking on the EBike application. I will use my EBike on an event this weekend so I will keep the original motor up to next Monday, after that and up to January 2023, I should finalize this project in a way I can ride my EBike on next events. As I can develop and program by Bluetooth, with a PC or my phone, the EBike application software, I will always be able to fine tune anything at laEBike_EScooter_app_pyhton/blob/main/firmware/main.pyst minute before any riding or even during a ride -- because I am pretty sure it will take time to fine tune the motor torque curve response, throttle curve, etc.

As you can see on the video, the battery voltage, battery current and motor power, can be seen on the display. Note that this values are read from the VESC and so they are slightly different from the ones seen on the lab power supply.

 
Last edited:

EMTB Forums

Since 2018

The World's largest electric mountain bike community.

559K
Messages
28,287
Members
Join Our Community

Latest articles


Top