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

Electric Motors and Controllers
User avatar
stancecoke
1 kW
1 kW
Posts: 305
Joined: Aug 02, 2017 2:56 pm

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by stancecoke » Dec 06, 2017 2:50 am

Hm, I would prefer a switch between torque-simulation- and torquesensor-mode. There are many people with physical disabilities who want to excercise their body (in torquesensor-mode) but need to have the possibility to switch to "pseudo-pedaling", if they get exhausted on a tour.
I think a throttle is quite exotic on a "pedelec", if I look at all the bikes that are selled at discounters or cycle dealers (in Germany, I have no international experience).

regards
stancecoke

User avatar
Alan B
100 GW
100 GW
Posts: 7027
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 06, 2017 3:09 am

That's because of the rules there, in the US most ebikes were throttle until recently, now more pedelecs are coming out.

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

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by casainho » Dec 06, 2017 3:51 am

I am very confused right now.

Let's assume I have only a throttle installed on my ebike.
P3 = 0: throttle position define a value for the current controller + a value for the speed controller
P3 = 1: throttle position defines what?? a value for the PWM duty_cycle value or a value for the current controller?

After having this defined, I will apply the same for PAS and torque sensor.
Developer of OpenSource firmware for EBike BMSBattery S/Kunteng KT motor controllers: https://opensourceebikefirmware.bitbucket.io/

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

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by honya96 » Dec 06, 2017 1:46 pm

I dont know how the duty cycle control feels but I think adaptto and others use current. As you said, wheel spins at max rpm when it has enough amps set by throttle to do it. For me there is no need to even have that current+speed setting. Current only just feels to be the right way. Kunteng stock firmware throttle is so bad on street and unusable when riding off-road

But with PAS only their "torque simulation" is good.

Few questions

As I understand you can use only 1 or 0 because of the display firmware, will you also modify it in future?

With current firmware can you do unlimited max speed when set lowest limit on lcd or unlimited when 72 is set or so?

Thank you.

User avatar
Alan B
100 GW
100 GW
Posts: 7027
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 06, 2017 1:54 pm

PWM throttle (duty cycle) is so poor, why bother with that? Speed throttle is basically the same thing, and not all that useful either.

Torque or torque + speed is nearly equal on the street and trail. The only time it is different is when the wheel is off the ground.

Keep it simple, choose torque throttle and be done with it.

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

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by honya96 » Dec 06, 2017 3:12 pm

Torque and torque+speed is no way near the same. Atleast with stock kunteng. Torque +speed means you get full powet at 1/3 or even less throttle from standstill(its trying to get to set speed by full torque), but you get no power until you reach 2/3 or more at high speeds (its allready over set speed so it does not work). Even worse is that with 18fet stock kunteng you can regen from 65km/h to 10km/h on like 100meters by holding a bit of throttle because torque+speed is trying to get to the set speed by braking. May sound good for street but its not, and offroad Its even dangerous. Maybe you have to try to know what I mean.

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

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by honya96 » Dec 06, 2017 3:17 pm

And it feels the same with kelly kls controllers, only difference is it does not brake that much by throttle. All Kelly software makes their products trash.

User avatar
Alan B
100 GW
100 GW
Posts: 7027
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 06, 2017 3:42 pm

OK, I would say they didn't do it right. Torque + Speed should always be limited by torque and the speed part ignored except when the wheel is off the ground, then the speed part keeps it from running to max speed at low torques. But they've clearly done something else with it.

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

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by honya96 » Dec 07, 2017 4:10 am

I dont understand how it can work the way you say when I want 300w helping me to keep 70km/h downhill. but it doesnt matter, torque only is the way to go.

So if possible try P3-0 phase amp throttle and P3-1 battery amp throttle. Just to see the difference

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

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by casainho » Dec 07, 2017 4:50 am

So I think I will implement:
1. PWM duty_cycle (someone may prefer BUT is also important for development and debug purposes)
2. torque/current control
3. torque/current control + speed

And I think I will make this options as ifdefs, meaning the options will be selected when building the firmware.
honya96 wrote:
Dec 07, 2017 4:10 am
So if possible try P3-0 phase amp throttle and P3-1 battery amp throttle. Just to see the difference
For now I can't read phase amps and I think firmware original also don't do it.
honya96 wrote:
Dec 06, 2017 1:46 pm
Few questions
1. As I understand you can use only 1 or 0 because of the display firmware, will you also modify it in future?
2. With current firmware can you do unlimited max speed when set lowest limit on lcd or unlimited when 72 is set or so?
1. I will not develop the display firmware, I would develop instead an Android app as it would have all the flexibility needed
2. Sure, I don't see why it wouldn't be possible. On current firmware, that value is used for the speed controller meaning if you are using only the current/torque controller, that max speed from LCD don't take effect.
Developer of OpenSource firmware for EBike BMSBattery S/Kunteng KT motor controllers: https://opensourceebikefirmware.bitbucket.io/

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

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by stancecoke » Dec 07, 2017 8:10 am

casainho wrote:
Dec 07, 2017 4:50 am
For now I can't read phase amps and I think firmware original also don't do it.
??? We read phase B current already, but we just use it for simplified FOC.
But I agree with @honya96, I would like to know the difference in bike behaviour.
The difference between battery current and phase current is discussed often, but I have not seen any comparing measurements yet...

regards
stancecoke

User avatar
Alan B
100 GW
100 GW
Posts: 7027
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 07, 2017 10:08 am

At low speed battery current gets multiplied many times by the stepdown in voltage, so low speed control is less precise with battery current control. At a small fraction of full battery current the motor current maxes out and the rest of the throttle rotation is wasted. Motor current control is torque control, and that gives the most predictable response and full range of the throttle mechanism can be used.

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

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by stancecoke » Dec 07, 2017 11:41 am

Of course I know this theoretical interdependencies. But I've never seen real measurements of battery current and phase current vs. rpm and mechanical load for a BLDC.

regards
stancecoke

User avatar
Alan B
100 GW
100 GW
Posts: 7027
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 07, 2017 1:07 pm

The ebikes.ca simulator has been upgraded and is quite accurate, you can infer motor current from the torque graph and they show the battery current curve as well, as well as RPM and load.

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

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by stancecoke » Dec 07, 2017 3:43 pm

Yes, but the mathematical model behind this just says, that I bat = dutycycle * I mot. But the reality is not that simple.
I played around with LTspice a little.

regards
stancecoke

Image
Attachments
LTspice_battery_and_motor_current.JPG
(127.15 KiB) Not downloaded yet

User avatar
Alan B
100 GW
100 GW
Posts: 7027
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 07, 2017 3:47 pm

A good sim like ebikes.ca's goes beyond that.

User avatar
usertogo
100 mW
100 mW
Posts: 35
Joined: Nov 19, 2014 9:31 am

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by usertogo » Dec 08, 2017 7:02 am

Thanks guys for this open source effort! I have to admit I haven't read the whole thread and don't quite understand yet what has been accomplished and what is the final goal. I have a Chinese controller https://www.aliexpress.com/item/High-Qu ... 486.Y9WYKc and found the circuit diagram that Albert von Dalen pulled from a KU63 controller, and see that it has a lot of similarities! The controller is great and on my 72V setup (with a Crystalite 2500W direct drive motor) I have seen uphill performance up to 48A which calculates to way more than 3000W! Its fast and smooth and quiet, but there are some things I need to figure out, most importantly regenerative braking!
So I wonder is this a controller that can be used with some alternative firmware?
GREENTIME 15 Mosfets 48-84V 1500W 45Amax Dual mode SensorSensorless Brushless DC Motor Controller1.jpg
Controller plus wires
GREENTIME 15 Mosfets 48-84V 1500W 45Amax Dual mode SensorSensorless Brushless DC Motor Controller1.jpg (140.68 KiB) Viewed 210 times
GREENTIME 15 Mosfets 48-84V 1500W 45Amax Dual mode SensorSensorless Brushless DC Motor Controller2.jpg
Controller Table of Connections
GREENTIME 15 Mosfets 48-84V 1500W 45Amax Dual mode SensorSensorless Brushless DC Motor Controller2.jpg (139.92 KiB) Viewed 210 times
FYI I am currently working on a Arduino Nano based wire eliminator / internal overlord (open source) that goes inside the controller so I can figure out and test things, do some diagnostics and find the hidden features, I bet you guys can help me out a lot :P

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

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by casainho » Dec 08, 2017 7:05 pm

usertogo wrote:
Dec 08, 2017 7:02 am
So I wonder is this a controller that can be used with some alternative firmware?
Go ahead and investigate if the microcontroller is the same as also the schematic. On the project page you can find the links to buy controllers to where this firmware runs.
Developer of OpenSource firmware for EBike BMSBattery S/Kunteng KT motor controllers: https://opensourceebikefirmware.bitbucket.io/

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

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by casainho » Dec 08, 2017 7:35 pm

About throotle/PAS, torque sensor and motor control with motor current/torque + speed

I improved the PAS code, as stancecoke did mention, to count the both ON and OFF time of PAS signal and this way know when the pedals are rotating backwards and zeroing the cadence on that case -- the following part of the code runs every PWM cycle:
Image

And the slow loop code that calcs PAS cadence (every 100ms):
Image

Now the ebike_app_controller () calls the function for throotle and PAS or torque sensor. Firmware need to be build with one of that both options:
Image

And the logic for throotle and PAS is:
1. cadence is mapped from 0 to 255, where 255 is the PAS_MAX_CADENCE_RPM
2. throttle is also mapped from 0 to 255
3. the max value of both throotle and PAS is used and multiplied by (1/5) * LCD assist level
4. now the value is mapped from 0 up to motor controller max current and is applied to the motor current controller
5. if LCD P3 = 1, the same value is also mapped from 0 to LCD max wheel speed and is applied to the motor speed controller, else, the motor speed controller is configured with the LCD max wheel speed

Image

The torque sensor have the same logic, with LCD P3 also configuring the option to have motor current controller/torque or motor current controller/torque + speed.
But there is also a ifdef to choose to use human power or simple torque signal: EBIKE_THROTTLE_TYPE_TORQUE_SENSOR_NO_HUMAN_POWER

The bad news is that I didn't test the code... but I tested most of this code before, in parts. Stancecoke, can you please help testing?
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: 7027
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 08, 2017 9:18 pm

I hope your test bikes have really convenient kill switches, in case something goes bad, to cut power quick.

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

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by geofft » Dec 09, 2017 3:46 am

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.
....with the stock firmware I have since discovered this throttle 'surge' only happens when riding with PAS and some throttle is added to increase assist. When throttle is used alone motor response is correct, it would seem that the stock firmware implementation of this PAS/throttle combination is not good.

It will be interesting to see if your code does this better, maybe this situation is worth adding to your testing.... :wink:
BBS02 V2 48v 750w, 12s lipo.
Q128H, S06S, slcd3, 48v 12s lipo.

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

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

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

casainho wrote:
Dec 08, 2017 7:35 pm
About throotle/PAS, torque sensor and motor control with motor current/torque + speed
So still you have not implemented the classical "torque-simulation" mode, see the picture in the old post on page 20.
casainho wrote:
Dec 08, 2017 7:35 pm
The bad news is that I didn't test the code... but I tested most of this code before, in parts. Stancecoke, can you please help testing?
I don't have a simple PAS that has this assymetrical output. So I can't test if the direction detection works, sorry.

Have you put all the #defines into the config.h? Then perhaps it's time to update the Java-Tool of the master branch.

regards
stancecoke

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

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by casainho » Dec 09, 2017 7:18 am

stancecoke wrote:
Dec 09, 2017 6:03 am
casainho wrote:
Dec 08, 2017 7:35 pm
About throotle/PAS, torque sensor and motor control with motor current/torque + speed
So still you have not implemented the classical "torque-simulation" mode, see the picture in the old post on page 20.
Image
I just put this graph and your notes, on the project notes files as this is important to understand the "torque-simulation" mode.

Here is the code:

Image

Let's consider throttle is not connect (ui8_throttle_value_filtered will be zero).
1. PAS cadence is mapped from 0 to 255, where 255 is the PAS_MAX_CADENCE_RPM
Seems that on your image, PAS_MAX_CADENCE_RPM = 45
2. the max value of both throotle and PAS is used, in this case, PAS cadence is the only one that will have effect
3. is multiplied by (1/5) * LCD assist level (at max level 5, the output will be max of 255)
4. now the value is mapped from 0 up to motor controller max current and is applied to the motor current controller (with LCD assist level of 5, this will represent the top line of your graphic; with level 1, the bottom line of the graph)
5. if LCD P3 = 1, the same value is also mapped from 0 to LCD max wheel speed and is applied to the motor speed controller, else, the motor speed controller is configured with the LCD max wheel speed

The extra here is P3 = 0, were with above all of that, will also set different wheel speed with the same logic as the motor current.

What do you think?
stancecoke wrote:
Dec 09, 2017 6:03 am
I don't have a simple PAS that has this assymetrical output. So I can't test if the direction detection works, sorry.

Have you put all the #defines into the config.h? Then perhaps it's time to update the Java-Tool of the master branch.
So I think we should consider it works until someone tries and say it is not working :-)
Maybe I will test it later, as I have one of that PAS.

I didn't put any the #define in config.h. I am not working yet on there and on the Java tool. Can you do that? -- but see if there is any advantage to do that right now, as I could understand, maybe you are the only one using that tool for now. I prefer to do it manually as I need to know very well which options I am selecting and see the source code being disabled/enable when I change that options.

But if you test and agree with the throotle/PAS and torque sensor control schemes, I think they should not change much and will keep that #define options. So will be a good investment to add to Java tool.

I want to put all my ebikes with torque sensor, I have 3 ebikes and 2 torque sensor installed, I just need to buy another one.
This torque sensor detects torque when press the pedals to the ground, my small soon can cheat the system like that. With human power enable it is ok as depends on the cadence but I would like to have motor assist without need to pedaling at startup. Maybe I can implement the walk speed limit of 6km/h when cadence = 0.
Developer of OpenSource firmware for EBike BMSBattery S/Kunteng KT motor controllers: https://opensourceebikefirmware.bitbucket.io/

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

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by casainho » Dec 09, 2017 7:29 am

In the case you guys didn't noticed this new thread:

Double MOSFET in your controler. Kuteng 12FET to 24FET
Developer of OpenSource firmware for EBike BMSBattery S/Kunteng KT motor controllers: https://opensourceebikefirmware.bitbucket.io/

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

Re: OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Post by honya96 » Dec 09, 2017 10:55 am

Just sharing some interesting stuff:

Seat tube controller
http://www.szktdz.com/en/news_show.php?article_id=550

Overpriced Kunteng with current based "3speed switch" on stock firmware? (I would like to have 1st speed 25km/h 1000w, second 50% battery,phase? current, third 100%)

http://e4bike.ru/collection/kontrollery ... ii?lang=en

Attached screenshots are the best deal I found to get 4kw at 14s 52v nominal 70km/h+ topspeed. lcd3 or 6 included. Duty free shipping and you can add more things without much increase in shipping price. www.Risunmotor.com
Hope its interesting for someone
Attachments
Screenshot_2017-12-09-16-41-01.png
20171209_165434.png
20171209_165434.png (238.76 KiB) Viewed 131 times

Post Reply