Bafang BBSHD BBS02 mid drive -- Flexible OpenSource firmware

casainho

10 GW
Joined
Feb 14, 2011
Messages
6,043
I just started to gather information and seems possible to develop our own firmware, that would be mainly based on our current OpenSource firmware for TSDZ2 and that implements FOC. This would also would mean support for the displays 850C color and SW102 Bluetooth, also running our OpenSource firmware.

The information I have and I will keep updating on this wiki page: https://github.com/OpenSource-EBike-firmware/Bafang_BBS02_BBSHB/wiki

- Does anyone knows what are the other ICs references other than the microcontroller?
- Can someone please shared more detailed pictures of the motor controller from both sides?

BBSHD motor controller

Motor controller (unpotted):
BBSHD%20unpotted%20Display%20Power%20Line.jpg


This motor controller hardware seems very similar to the TSDZ2 one, except that it has not the torque sensor part. There are power resistors to read the battery current and the microcontroller can control the 6 PWM channels that controls the power mosfets. Also there are the 3 motor hall sensors connections.

Since the microcontroller has only 32 kbytes of flash memory and the hardware is similar to the TSDZ2, the firmware for Bafang could be mostly based on our OpenSource firmware for TSDZ2 that implements FOC motor control. This would also mean that this Bafang motor would support the displays 850C color and SW102 Bluetooth, also running our OpenSource firmware.

Microcontroller

Microcontroller is the STC15W4K32S4, based on a 8051 CPU, runs at 35 MHz and has 32 kbytes of flash memory.

* Product page: https://www.stcmicro.com/STC/STC15W4K32S4.html
* Datasheet: STC15W4K32S4-en.pdf
* Available free OpenSource SDDC compiler and flasher stcgal, as also working firmware with makefile, see here: https://github.com/YaoFei509/stc_diyclock
* There is a cheap 3€ development board available on Aliexpress, search for "system board IAP15W4K58S4 core board STC15W4K56S4"

BBS02 motor controller

This motor controller seems similar to BSSHD motor controller. Probably the firmware would be the same with minor differences.

DIY torque sensor

Bafang DIY motors miss a torque sensor. Maybe a torque sensor could be added to the pedal cranks like this:
- Youtube: V3 Power Meter - Introduction to the Build and V3–Power Meter–The Complete How To
- Youtube: https://www.youtube.com/watch?v=ZZnG135o4ZQ and ESPeedo an ESP8266 Bicycle "Power" Sensor
 
Another alternative to the torque sensor (for people who are riding for fitness/fun) would be "ideal cadence mode" where you adjust the motor power output to keep the users cadence between 85-95 RPM (or whatever) - even as the user goes through hills.

Or use the bluetooth in the SW102 to do "heart rate mode" where you slowly adjust the motor output to try and keep the user's heart rate in the range they want for training (i.e. a heart rate zone of 3.5 or 4.2 or whatever the user is trying to target for this workout).
 
I know there is a second MCU on the board, here is some info on what it could be: https://electrotransport.ru/ussr/index.php?topic=18823.msg1324810#msg1324810

D79F9211

But I guess it might not be related to the motor control and it's doing something else.
 
BotoXbz said:
I know there is a second MCU on the board, here is some info on what it could be: https://electrotransport.ru/ussr/index.php?topic=18823.msg1324810#msg1324810

D79F9211

But I guess it might not be related to the motor control and it's doing something else.
Thanks!!

That IC is more near the power mosfets driver so for sure it is working as a motor controller.

I would say that this motor controller does not implement FOC. TSDZ2 original firmware do no implement FOC. The old motor controllers based on X8M06 worked for hub motors and I am sure they also do not implement FOC.

And here more information about it:

stancecoke said:
I think this is a chinese clone of the Renesas (formerly NEC) D79F9211, sometimes branded as a X8M06, well known from the old KU63 controllers. 44 Pin LQFP package.
https://de.aliexpress.com/item/Elec...ntroller-X8M06-C-Battery-Car/32826350022.html

https://github.com/stancecoke/Param...b/master/related-documents/UPD79F9211-NEC.pdf

There is no cheap programmer available for this processor. I tried to build one on my own some month ago, but I stopped that project.
https://github.com/stancecoke/Parameter-Setting-Tool-for-EBike-Controller

regards
stancecoke
 
Hm, the STC µC can be flashed via the display connector with a quite strange flash tool, see here:
https://endless-sphere.com/forums/viewtopic.php?f=28&t=100064

But if you want to implement FOC you have to deal with the X8M06 :-(

First you would have to do a Reverse Engineering of the schematic of the PCB to understand the circuit.

I don't know, if it's worth the work, as you can set many of relevant parameters with the Bafang-Tool already...

regards
stancecoke
 
stancecoke said:
Hm, the STC µC can be flashed via the display connector with a quite strange flash tool, see here:
https://endless-sphere.com/forums/viewtopic.php?f=28&t=100064

But if you want to implement FOC you have to deal with the X8M06 :-(

First you would have to do a Reverse Engineering of the schematic of the PCB to understand the circuit.

I don't know, if it's worth the work, as you can set many of relevant parameters with the Bafang-Tool already...

regards
stancecoke
Yes, by now I already think it is a dead end road due to X8M06 -- I saw your messages and of other Russian guys try to program it... there is no C compiler nor programmer to it.

But yes, at least I would like to look at PCB to understand how the things are connected. I wish I could find some donor for this motor controllers, I mean broken/damaged controllers.

In the case of KU controllers using the X8M06, since they work for any hub motor, I think they simple do not implement FOC as it would need to be like on TSDZ2, where we previous know the motor inductance and resistance. In this case, since the motor is fixed, I hope they did implement FOC -- however, since they did 2 microcontrollers and the X8M06 specifically for motor controller, I guess they did not, probably they just went with the "old" proven technology used on KU controllers and others and used the second microcontroller to implement the specific of their LCD, etc.
 
casainho said:
Yes, by now I already think it is a dead end road due to X8M06

That's a real shame, I was really hoping you guys would turn your attention to the BBS02/HD at some point. I've got a couple of these, great drives that would be even better with some more capable firmware and a torquesensor.

Would there be any mileage in replacing the internal controller with an external unit that is easier to work with? Although I guess the hardware mods required may be a step too far for many users... :(
 
geofft said:
casainho said:
Yes, by now I already think it is a dead end road due to X8M06

That's a real shame, I was really hoping you guys would turn your attention to the BBS02/HD at some point. I've got a couple of these, great drives that would be even better with some more capable firmware and a torquesensor.

Would there be any mileage in replacing the internal controller with an external unit that is easier to work with? Although I guess the hardware mods required may be a step too far for many users... :(
Yes, go with VESC that is OpenSource motor controller, high technology and costs 60€ on eBay. Handles 48V 13S battery packs and 50 amps continuous.

Theo torque sensor must also be DIY.
 
i think a "rocky mountain system" to relevate the torque it's better. Place sensor in the red square... place the same hall of tsdz2 and use the tsdz2 controller :D

rocky mountain.JPG
The advantage is that the rotating winding of the tsdz2 is not needed

some mechanical complications but electronics already exist :D
 
That is an idea.

The electronics: small battery, strain gauges, amplifier strain gauges and NRF51 bluetooh board -- all available on ebay for a total of 20 euros!! very cheap for prototyping. Later someone could design a PCB with all this integrated and user would need to glue the 4 strain gauges to the crank, solder the wires to PCB and finally glue and put silicone to protect against the water. I wish charging could be wireless.

I already bought the components, I hope I will find time to prototype this.
 
I also considered using strain gages to measure pedalling power.
I found these "wireless power supply" https://aliexpi.com/e2X1
It could be used instead of battery to power up the module on cranks.

(i never have nor used it, just want to give You an idea)

HTB1KYWqXELrK1Rjy1zbq6AenFXaJ.jpg
 
:)

I used this wireless power module for contact- and wireless torque sensing by strain gauges, two years ago.

index.php

index.php

index.php

index.php


Of course for a middrive, the strain gauges have to be placed on the crank, not on the chainring.

see the german forum:
https://www.pedelecforum.de/forum/index.php?threads/drehmomentsensor-eigenbau-v5.44335/

[youtube]vrCHON44dXc[/youtube]


regards
stancecoke
 
I saw other removing original controller and 3D print with black plastic a case for another external motor controller.

I wish I could go with KT motor controller S12, but it handles only 30A and his big and heavy for that. I think I will go with VESC that I can buy on Ebay for 42 euros that can handles 50A continuous, is small and has the OpenSource firmware and board.

For tor PAS and torque sensor, I would do like that other guys did, with the strain gauses and IMU for PAS signal. I would start using a battery like them, to simplify at start.

Current TSDZ2 firmware evaluates torque sensor signal and PAS cadence every 100ms, not less. This means if we can receive their values from SW102, it will work. And the Bluetooth latency is lower, I think we will get near the 100ms so I think it will work, the sending the data over Bluetooh to SW102 and then send to VESC.

Other sensors like throttle, motor temperature sensor or brakes can be connected to VESC directly or by Bluetooth to SW102. The throttle and brakes are also evaluated every 100 ms, not less, on TSDZ2 firmware.

The torque and PAS sensor could be an external project as it is general enough to be installed in any cranks and send the data by Bluetooth to SW102 or other device. And SW102 with our firmware already integrates with Strava app.
 
casainho said:
I saw other removing original controller and 3D print with black plastic a case for another external motor controller.

I wish I could go with KT motor controller S12, but it handles only 30A and his big and heavy for that. I think I will go with VESC that I can buy on Ebay for 42 euros that can handles 50A continuous, is small and has the OpenSource firmware and board.

For tor PAS and torque sensor, I would do like that other guys did, with the strain gauses and IMU for PAS signal. I would start using a battery like them, to simplify at start.

Current TSDZ2 firmware evaluates torque sensor signal and PAS cadence every 100ms, not less. This means if we can receive their values from SW102, it will work. And the Bluetooth latency is lower, I think we will get near the 100ms so I think it will work, the sending the data over Bluetooh to SW102 and then send to VESC.

Other sensors like throttle, motor temperature sensor or brakes can be connected to VESC directly or by Bluetooth to SW102. The throttle and brakes are also evaluated every 100 ms, not less, on TSDZ2 firmware.

The torque and PAS sensor could be an external project as it is general enough to be installed in any cranks and send the data by Bluetooth to SW102 or other device. And SW102 with our firmware already integrates with Strava app.

Do you think VESC 4.12 is a good option? I've read that it fails with 13s (i.e. 48V) quite often
 
guancio said:
Do you think VESC 4.12 is a good option? I've read that it fails with 13s (i.e. 48V) quite often
I don't know but I think for regen it may fail sooner and here we don't have regen.
 
I was looking again to the S12S motor controller I have here. The case says 40A. This controller is big but the PCB uses about 2/3 of the case and I think I can cut with a metal saw the 1/3 and let the case to be smaller and lighter.

S12S has the advantage that there are versions up to 72V at least and the hardware is very easy to tweak if needed, including for sure our OpenSource firmware that implements FOC with at least the same quality as on TSDZ2.
BMSBattery.com sells S12S for 30€.

The S12S has input for PAS signal so we can use the original BBSxx PAS signal. We just need to implement the torque sensor and send the data to SW102 display by Bluetooth.
 
casainho said:
I was looking again to the S12S motor controller I have here. The case says 40A. This controller is big but the PCB uses about 2/3 of the case and I think I can cut with a metal saw the 1/3 and let the case to be smaller and lighter.

S12S has the advantage that there are versions up to 72V at least and the hardware is very easy to tweak if needed, including for sure our OpenSource firmware that implements FOC with at least the same quality as on TSDZ2.
BMSBattery.com sells S12S for 30€.

The S12S has input for PAS signal so we can use the original BBSxx PAS signal. We just need to implement the torque sensor and send the data to SW102 display by Bluetooth.

The Kunteng (S12S) type controllers would have a lot of advantages and make life much easier for the developers - if the size can be reduced a little these seem like the best option. I see that PSWpower are now marketing a "20amp" version of the KT36/48svpr (6fet), I'm wondering if for the lower powered BBS02's and people with lower power requirements these might also be an option?

I like the look of that Paltorc crank, looks expensive though, couldn't see a price anywhere.... :shock:
 
geofft said:
The Kunteng (S12S) type controllers would have a lot of advantages and make life much easier for the developers - if the size can be reduced a little these seem like the best option. I see that PSWpower are now marketing a "20amp" version of the KT36/48svpr (6fet), I'm wondering if for the lower powered BBS02's and people with lower power requirements these might also be an option?
BMSBattery is a good source for this controllers, they have the S06S, S09S and S12S.

Also maybe the ones looking to use the S06S for the size and weight, maybe can tweak it with better mosfets and stronger PCB traces??
 
casainho said:
geofft said:
The Kunteng (S12S) type controllers would have a lot of advantages and make life much easier for the developers - if the size can be reduced a little these seem like the best option. I see that PSWpower are now marketing a "20amp" version of the KT36/48svpr (6fet), I'm wondering if for the lower powered BBS02's and people with lower power requirements these might also be an option?
BMSBattery is a good source for this controllers, they have the S06S, S09S and S12S.

Also maybe the ones looking to use the S06S for the size and weight, maybe can tweak it with better mosfets and stronger PCB traces??

My thinking was that if the KT36/48SVPR really is capable of 20A then it could be used without modification for the lower power setups. I always used these previously and they seem to run the open source firmware just the same as the S06S.

Just a detail really though, I guess KT36/48, S06S, S12S, would all do the job... :)
 
Thanks to an user that did show this picture:

file.php


I was able to find and write on the wiki this new informationan:

Mosfets driver
OnSemi FAN7388

FAN7388: 625V, 3.3/5V input logic compatible, 0.65/0.35A sink/source current, 3-Phase Half-Bridge Gate-Drive IC.
 
Few month ago I decided to install a BBS02B on my bike. It's a great motor but I was a bit disapointed with the PAS and I'm confident we can have something better

As I really like the VESC, I am thinking to integrate it in place of the original controller, but it needs a complete redesign and a custom firmware

If you are interested into this integration, I will do the redesign of the electronics, but I'm going to need some help for the firmware..
 
Back
Top