Flexible OpenSource firmware for BMSBattery S/Kunteng KT motor controllers (0.25kW up to 5kW)

Electric Motors and Controllers
1N4001
1 µW
1 µW
Posts: 4
Joined: Nov 28, 2017 7:55 am

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by 1N4001 » Dec 01, 2017 5:00 am

casainho wrote:
Nov 30, 2017 8:47 pm
So, I own a S12S (S12P moded to S12S) and I it works very well with current firmware. The 72V version I don't know which changes are between the 48V and 72V versions, but I would say only the voltage resistor that reads the battery voltage (not counting with changes on capacitors, etc to handle the higher voltage). That difference I think you will be able to find using a multimeter.

I think someone will want to use the most powerful version of this controllers, and would be great to get knowledge on how to use them. I think Kunteng sells even an higher current version than BMSBattery sells. But go with BMSBattery if you can, because no BMSBattery versions may have some significant changes in hardware, mainly on the available cables/inputs to the microcontroller.
So if you're correct about the changes to the 72V version, adapting this firmware should be a no-brainer. Nice!

Your P-to-S mod and geofft's mention of the S09 has also piqued my interest. BMSB offers a S09PP 72V 1kW controller which comes in a smaller case, which would be perfect for me. So now I, too, wonder if that one can also be modded into a sine controller. Unlike the others, this one doesn't have an official sine version.

casainho
10 kW
10 kW
Posts: 953
Joined: Feb 14, 2011 2:43 pm

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by casainho » Dec 01, 2017 6:06 am

geofft wrote:
Dec 01, 2017 4:14 am
I also have been watching this thread with great interest and would like to add my congratulations to you guys on your efforts so far. Will definitely be trying your firmware sometime in the future, I'm no coder but can usually follow instructions to get these things loaded up and working.

Just a small question for casainho regarding the S12P to S12S mod you describe in the link. When this mod is done is the controller still run sensorless or do you add the three hall wires and run it sensored? I ask this as I have a S09P sensorless controller (ordered in error) that I would like to mod to S09S sinewave/sensored operation - is that possible? - unfortunately I have found that my Q128H does not run well in sensorless mode.
Hi Geoff.

Thanks for the feedback. Can you please share with us some information, so we can understand better your needs:
1. can you please tell us why are you interested to use the firmware?
2. what bicycle type do you have, what is the kind of usage?
3. which motor, battery pack voltage?
4. do you use throttle, PAS, torque sensor, regen brakes?

So I did the mistake to say it was an S12P while it was instead a Kunteng some version with mosfets but without the phase B current sensor/sinewave.
You can try to go ahead and try find if the circuit for the hall sensors is populated, like the resistors, capacitor... follow the schematic of the S06S!

You may have an Kunteng controller that have hall sensor cables but that does not do sinewave. I did mod this controller to a S12S version (sinewave control version). Seems the boards are equal but with one important missing component (and expensive one I think): phase B current sensor.
Developer of OpenSource firmware for EBike BMSBattery S/Kunteng KT motor controllers: https://opensourceebikefirmware.bitbucket.io/

geofft
10 mW
10 mW
Posts: 27
Joined: Nov 09, 2012 9:41 am
Location: Berkshire UK

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by geofft » Dec 01, 2017 7:09 am

Thanks for the feedback. Can you please share with us some information, so we can understand better your needs:
1. can you please tell us why are you interested to use the firmware?
2. what bicycle type do you have, what is the kind of usage?
3. which motor, battery pack voltage?
4. do you use throttle, PAS, torque sensor, regen brakes?
Thanks for your speedy reply, answers to your enquiries below:-

1. I'm using the PSWpower version of the S06S (17A) - although this controller works well it has a couple of issues which I'm hoping your firmware may allow me to 'adjust'.

a) Very non-linear reaction to throttle changes with a huge step in motor output at one point. The voltage output from the thumb throttle itself is correctly linear.

b) I'm using an LCD3 display with 5 power levels - the 5 steps are not even, levels 1-2-3-4 give nice even increases, but 4-5 gives a much larger increase in power level, almost like a step has been missed between 4-5. I often find on hills I'm having to switch 4-5-4-5 etc to get the right assist level.

....I don't know if these issues are normal or maybe peculiar to my controller - I have a further S06S (20a) on the way to check this out and use for trying your your firmware.

2. I'm using a mountain bike which I have converted to be a more comfortable 'street cruiser'. I do some off-road riding but only on relatively smooth tracks.

3. Q128H rear geared hub motor, 12s lipo (44-50v).

4. I use just PAS and throttle. Regen is not possible with the Q128H geared motor, torque sensing is something I may play with in the future.

The S09P I have is the BMS battery version, without hall wires. I think I will go ahead and try the mods I mentioned, I've nothing to lose in doing so. This probably won't happen until the new year but I'll let you guys know how it goes.

Geoff.
BBS02 V2 48v 750w, 12s lipo.
Q128H, S06S, slcd3, 48v 12s lipo.

casainho
10 kW
10 kW
Posts: 953
Joined: Feb 14, 2011 2:43 pm

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by casainho » Dec 01, 2017 12:39 pm

geofft wrote:
Dec 01, 2017 7:09 am
1. a) Very non-linear reaction to throttle changes with a huge step in motor output at one point. The voltage output from the thumb throttle itself is correctly linear.
For me my throttles are no linear - how did you verified that the output voltage is correctly linear?

Example of ADC value for throttle (purple lines) -- in the middle is kind of flat and on the final it jumps very fast to max value:
Image

Image
geofft wrote:
Dec 01, 2017 7:09 am
4. I use just PAS and throttle. Regen is not possible with the Q128H geared motor, torque sensing is something I may play with in the future.
Why do you use throttle if you also have PAS?
Developer of OpenSource firmware for EBike BMSBattery S/Kunteng KT motor controllers: https://opensourceebikefirmware.bitbucket.io/

geofft
10 mW
10 mW
Posts: 27
Joined: Nov 09, 2012 9:41 am
Location: Berkshire UK

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by geofft » Dec 01, 2017 2:09 pm

Hi, my method of checking the thumb throttle was pretty unscientific - just connected a voltmeter to the signal wire from the thumb throttle, operated it gradually and checked the signal voltage rose in a similar manner. Which it did - the sudden step in motor output at around 1/3 throttle was not present on the signal output from the thumb throttle. I have also tried another throttle with the same result.

I have always used PAS and throttle in combination, even with PAS I find the handlebar throttle is very useful for pulling away quickly from a standstill, temporarily adding a bit more power when the selected assist level isn't quite enough or simply adjusting power when I can't be bothered to keep the switching assist level up and down. I don't think I'm unique in riding this way, I'm sure many people ride PAS and throttle in combination.

As I said, I'm not completely sure as yet that these issues are a factor of the controller firmware, it may be be a feature of my individual setup. I suppose I'm thinking that a more configurable controller (like you guys are working on) could get round these sort of issues, often just personal preferences.

It's probably also true that I'd like to try your developing firmware "because I can" as we say - just idle curiosity really.... :wink:

Anyway good luck with your efforts, it looks like you're making great progress.

Geoff.
BBS02 V2 48v 750w, 12s lipo.
Q128H, S06S, slcd3, 48v 12s lipo.

rowbiker
10 W
10 W
Posts: 70
Joined: Jul 16, 2013 1:36 pm
Location: Saint Paul, Minnesota USA

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by rowbiker » Dec 01, 2017 7:13 pm

The "Copenhagen Wheel" ebike (unified rear wheel hub) uses pedaling in reverse to 'turn on' regen braking. In my limited experience riding this configuration, it works very well.

casainho
10 kW
10 kW
Posts: 953
Joined: Feb 14, 2011 2:43 pm

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by casainho » Dec 01, 2017 7:25 pm

rowbiker wrote:
Dec 01, 2017 7:13 pm
The "Copenhagen Wheel" ebike (unified rear wheel hub) uses pedaling in reverse to 'turn on' regen braking. In my limited experience riding this configuration, it works very well.
Great to know :-)
Developer of OpenSource firmware for EBike BMSBattery S/Kunteng KT motor controllers: https://opensourceebikefirmware.bitbucket.io/

honya96
10 mW
10 mW
Posts: 33
Joined: Mar 05, 2015 9:38 am

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by honya96 » Dec 02, 2017 2:59 am

Thats normal with these controllers on stock firmware, whatever you set at P3 its not toque control, theres still relation with speed, so at 1/3 its full from standstill. I am using 18Fet at almost 4Kw and with this power its a big problem. Planning to buy another controller and try this firmware.

Guys please, anyone knows what has to be done to get CSD19536KCS mosfets working while there was irfb4110z original? If the drivers need to be modified? Like some smd capacitors and resistors..

If I get it working, than with this firmware we can safely get 24Fet kunteng pulling 180A at 72v (6fet 45A) with upgraded traces and wires for sure.

casainho
10 kW
10 kW
Posts: 953
Joined: Feb 14, 2011 2:43 pm

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by casainho » Dec 02, 2017 3:24 am

honya96 wrote:
Dec 02, 2017 2:59 am
Guys please, anyone knows what has to be done to get CSD19536KCS mosfets working while there was irfb4110z original? If the drivers need to be modified? Like some smd capacitors and resistors..

If I get it working, than with this firmware we can safely get 24Fet kunteng pulling 180A at 72v (6fet 45A) with upgraded traces and wires for sure.
Maybe is better for you start a new thread specific about that mod, to improve hardware of the controller. Maybe you will get attention from hardware guys...

I would so see that mod!! :-) :-) and also the ebike that will be driven by that monster controller :-)
Developer of OpenSource firmware for EBike BMSBattery S/Kunteng KT motor controllers: https://opensourceebikefirmware.bitbucket.io/

honya96
10 mW
10 mW
Posts: 33
Joined: Mar 05, 2015 9:38 am

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by honya96 » Dec 02, 2017 3:44 am

It will be my 60kg Vector frame bike with qs205 v3 50H motor and both moto tires. Get ready to remove the 72km/h speed limit :D would be great if it shows 1 again after reaching 99.

User avatar
stancecoke
1 kW
1 kW
Posts: 301
Joined: Aug 02, 2017 2:56 pm

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by stancecoke » Dec 02, 2017 5:22 am

casainho wrote:
Nov 30, 2017 8:36 pm
I use both signals to get the direction and count how many steps, see the image:
OK, that's a simple way of encoding a quadrature signal, already. So, a quadrature PAS or the Thun torquesensor or the Sempu third generation torquesensor, that are using quadrature signals, should work with this code.
But for the most common simple PAS we have to add another function in the fast loop, something like this

Code: Select all

if (PAS_Pin = high) PAShigh_counter++;
else PASlow_counter++;

If (PAS_Pin=low && PAS_Pin_old = High){    //falling edge
If (PAShigh_counter>PASlow_counter) ... //you are pedaling forewards
If (PAShigh_counter<PASlow_counter)... // you are pedaling backwards

PASlow_counter=0;
PAShigh_counter=0;
}
regards
stancecoke

casainho
10 kW
10 kW
Posts: 953
Joined: Feb 14, 2011 2:43 pm

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by casainho » Dec 02, 2017 1:21 pm

stancecoke wrote:
Dec 02, 2017 5:22 am
OK, that's a simple way of encoding a quadrature signal, already.
So for torque sensor I did:
1º calculate PAS cadence (1º piece of code)
2º did a hack: added a another PAS (PAS2) to the torque sensor (2º piece of code). With the PAS2 I as able to implement that regen ebrake like coast brakes

1º is mainly for torque sensor, maybe it can be common to general PAS, I need to see. And yes, I understand that on general PAS we can find the direction by looking at with of ON time VS OFF time.
One way or other, I may out put #ifdefs and user can choose on the Java tool.

2º I like the result but since it involves an hack, maybe not much users will make and use it, so may no be useful to be on the main firmware... I don't know.

I want to install a PAS on one of my ebikes to develop the PAS code. I hope to do it next week.
Developer of OpenSource firmware for EBike BMSBattery S/Kunteng KT motor controllers: https://opensourceebikefirmware.bitbucket.io/

honya96
10 mW
10 mW
Posts: 33
Joined: Mar 05, 2015 9:38 am

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by honya96 » Dec 03, 2017 4:14 am

I found a good picture of all base kunteng controllers 6,9,12,18,24Fet. Its from Risunmotor.com they have best prices I found yet and duty free shipping, If you take whole kits, not just single controller.

Maybe you want to add this picture to the project page. :)
Attachments
risunmotor_controllers_1.jpg
(159.18 KiB) Not downloaded yet

User avatar
stancecoke
1 kW
1 kW
Posts: 301
Joined: Aug 02, 2017 2:56 pm

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by stancecoke » Dec 03, 2017 6:50 am

For having infinitely variable regen, I've modified a brake lever. With a linear hall sensor inside, it has an analogue output now. :D



Image
Image
Image

regards
stancecoke

User avatar
Alan B
100 GW
100 GW
Posts: 7025
Joined: Sep 11, 2010 7:43 am
Location: San Francisco Bay Area, USA
Contact:

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by Alan B » Dec 03, 2017 12:13 pm

When I made one of those I left the switch in, my controller requires a contact closure for ebrake enable and a variable voltage for variable regen.

User avatar
stancecoke
1 kW
1 kW
Posts: 301
Joined: Aug 02, 2017 2:56 pm

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by stancecoke » Dec 03, 2017 12:51 pm

Is there a documentation of your solution somewhere?

regards
stancecoke

User avatar
Alan B
100 GW
100 GW
Posts: 7025
Joined: Sep 11, 2010 7:43 am
Location: San Francisco Bay Area, USA
Contact:

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by Alan B » Dec 03, 2017 5:29 pm

It is in the Borg thread, linked in my sig, starting about here in the thread:

https://endless-sphere.com/forums/viewt ... 5#p1027591

User avatar
stancecoke
1 kW
1 kW
Posts: 301
Joined: Aug 02, 2017 2:56 pm

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by stancecoke » Dec 04, 2017 3:31 am

Thank you for that information.
here two more pictures with some details:

Image
Image

regards
stancecoke
Attachments
linear break lever drawing.jpg
(87.52 KiB) Not downloaded yet

dkmorb
1 mW
1 mW
Posts: 10
Joined: Nov 28, 2017 12:56 pm

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by dkmorb » Dec 04, 2017 6:51 am

@casainho
Nice to see you involved in stm32f1 firmware development on eggelectricunicycle project :-)
I like that kind of architecture...

Just few questions:
1) Can I obtain the raw 6 PWM signal from controller?
2) Can I disable hall sensor control and PAS but have a still working controller?

Sorry for my stupid questions...

casainho
10 kW
10 kW
Posts: 953
Joined: Feb 14, 2011 2:43 pm

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by casainho » Dec 04, 2017 7:22 am

dkmorb wrote:
Dec 04, 2017 6:51 am
@casainho
Nice to see you involved in stm32f1 firmware development on eggelectricunicycle project :-)
I like that kind of architecture...

Just few questions:
1) Can I obtain the raw 6 PWM signal from controller?
2) Can I disable hall sensor control and PAS but have a still working controller?
Thanks. Maybe someday I will be back to electric unicycles :-)

About your questions, I don't know if you are thinking in making your own controller. If so, you can buy the microcontroller from Ebay and a board here: https://www.waveshare.com/stm8s-discovery.htm

1. Yes, the raw 6 PWM signal are available -- see S06S schematic our the firmware source code file gpio.h

2. No and I don't know if you did understand already but the firmware needs a hall sensors, the motor must have hall sensors! No sensorless, not possible with this limited limited STM8 8 bits microcontroller. The SxxP controllers do sensorless but not sinewave, just 6 steps!!
You can read about it here: https://opensourceebikefirmware.bitbuck ... W-675.html
Hmmm, hall sensor control?
PAS: yes, the firmware is structured as motor controller (motor.c) + ebike app (ebike_app.c). The PAS code is on ebike app (the main code) and we can do another application other than ebike and still use the motor controller. For instance, we can do a generic motor controller, that is commanded by UART commands from an Arduino...
Developer of OpenSource firmware for EBike BMSBattery S/Kunteng KT motor controllers: https://opensourceebikefirmware.bitbucket.io/

dkmorb
1 mW
1 mW
Posts: 10
Joined: Nov 28, 2017 12:56 pm

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by dkmorb » Dec 04, 2017 10:58 am

Ok, I see, so no sensorless aproach by stm8 cpu...'cause we need to sample the zero crossing between interpolating phases, right?
Well, I order 2 little board with stm8 :oops:
And what about, in the future, porting the code to stm32fXXX and then implementing sensorless mode? :roll:
I need to put my hand in the code to understand!

casainho
10 kW
10 kW
Posts: 953
Joined: Feb 14, 2011 2:43 pm

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by casainho » Dec 04, 2017 11:23 am

dkmorb wrote:
Dec 04, 2017 10:58 am
Ok, I see, so no sensorless aproach by stm8 cpu...'cause we need to sample the zero crossing between interpolating phases, right?
Can't do that algorithm with sinewave/FOC.
dkmorb wrote:
Dec 04, 2017 10:58 am
And what about, in the future, porting the code to stm32fXXX and then implementing sensorless mode?
Do you need sensorless? Why sensorless?
Kunteng controllers go from 6 mosfets up to max of 24 mosfets. 24 mosfets --> 72V, 70 amps peak current, which is 5KW -- and they are cheap and widelly available controllers. The same knowledge and firmware we are building have all that potential, I don't think there are other controllers with this potential.
Developer of OpenSource firmware for EBike BMSBattery S/Kunteng KT motor controllers: https://opensourceebikefirmware.bitbucket.io/

User avatar
Alan B
100 GW
100 GW
Posts: 7025
Joined: Sep 11, 2010 7:43 am
Location: San Francisco Bay Area, USA
Contact:

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by Alan B » Dec 04, 2017 11:50 am

If you make a little PC board to convert zero crossings to 5V (three comparators) and feed those in where the hall sensors usually go, and adjust the angle to compensate, it should work in six step mode. Not in sinewave mode, so turn that off.

casainho
10 kW
10 kW
Posts: 953
Joined: Feb 14, 2011 2:43 pm

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by casainho » Dec 04, 2017 6:44 pm

Alan B wrote:
Dec 04, 2017 11:50 am
If you make a little PC board to convert zero crossings to 5V (three comparators) and feed those in where the hall sensors usually go, and adjust the angle to compensate, it should work in six step mode. Not in sinewave mode, so turn that off.
That is what SxxP controllers does:

The S06P controller don't do sine wave motor control but just 6 steps. When compared to the S06S controller:
• don't have the phase current sensor (the place is on the board but is empty)
• have a secondary board that connects to the same pins as hall sensors:
◇ have a STM8S003F3P6 (with available header to be programmed)
◇ have an LM339
◇ I would say this board does BEMF signal output to simulate the hall sensors signal, just like on the KU63 controller circuit

Image
Developer of OpenSource firmware for EBike BMSBattery S/Kunteng KT motor controllers: https://opensourceebikefirmware.bitbucket.io/

casainho
10 kW
10 kW
Posts: 953
Joined: Feb 14, 2011 2:43 pm

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by casainho » Dec 05, 2017 2:29 pm

Stancecoke,
I can use P3 for user choose a variantion of control mode.
Let's say I am implementing throotle:
P3 = 0: speed + current
P3 = 1: current

OR

P3 = 1: duty_cycle?

because with current only, motor will always run at max speed if wheel on the air...
Developer of OpenSource firmware for EBike BMSBattery S/Kunteng KT motor controllers: https://opensourceebikefirmware.bitbucket.io/

Post Reply