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

Electric Motors and Controllers
User avatar
KingQueenWong   100 mW

100 mW
Posts: 39
Joined: Dec 18 2016 7:07am

Re: OpenSource firmware BMSBattery Sxxx motor controllers ST

Post by KingQueenWong » Jun 02 2017 9:00am

20170602149641168359316e23d2087.jpg
The latest connected wires,but it fail to rotate too. The power supply volatage is adjusted to 24V.

casainho   100 MW

100 MW
Posts: 2738
Joined: Feb 14 2011 2:43pm

Re: OpenSource firmware BMSBattery Sxxx motor controllers ST

Post by casainho » Jun 02 2017 9:03am

KingQueenWong wrote:
20170602149641168359316e23d2087.jpg
The latest connected wires,but it fail to rotate too. The power supply volatage is adjusted to 24V.
But are you trying to run the original controller, with the original firmware or trying my OpenSource firmware?
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

User avatar
KingQueenWong   100 mW

100 mW
Posts: 39
Joined: Dec 18 2016 7:07am

Re: OpenSource firmware BMSBattery Sxxx motor controllers ST

Post by KingQueenWong » Jun 02 2017 9:07am

I am trying to run the original controller,next i will try your firmware,finally i will change your firmware.

casainho   100 MW

100 MW
Posts: 2738
Joined: Feb 14 2011 2:43pm

Re: OpenSource firmware BMSBattery Sxxx motor controllers ST

Post by casainho » Jun 02 2017 9:22am

KingQueenWong wrote:I am trying to run the original controller,next i will try your firmware,finally i will change your firmware.
Good plan!! :-)

I see that you are not using the LCD -- I bought the LCD and is useful as it shows some error code and motor do not runs. What I know for my case:
- need to connect the hall sensors, without that motor will not run and LC will show an error
-- seems you are shunting that wires to avoid using the LCD
- I use the throttle, never tested with PAS

If you can't make it working, maybe it is faster to flash the firmware!! The instructions:
- wire first the STLinkV2 and explained here: https://opensourceebikefirmware.bitbuck ... oller.html

- install the usual development software, at least to build the firmware and flash it using "stm8flash"
-- https://opensourceebikefirmware.bitbuck ... s-gdb.html
-- https://opensourceebikefirmware.bitbuck ... mming.html

- Unlock the memory (just need to make first time):
echo "00 00 ff 00 ff 00 ff 00 ff 00 ff 00 ff 00 ff" | xxd -r -p > factory_defaults.bin
stm8flash -c stlinkv2 -p stm8s105?6 -s opt -w factory_defaults.bin
-- more info: https://opensourceebikefirmware.bitbuck ... emory.html

- Get the firmware, build it, flash it and profit: https://github.com/OpenSource-EBike-fir ... s_firmware (master branch, on the commit with log: Motor now runs with 6 steps. Also break coast the motor)
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

User avatar
KingQueenWong   100 mW

100 mW
Posts: 39
Joined: Dec 18 2016 7:07am

Re: OpenSource firmware BMSBattery Sxxx motor controllers ST

Post by KingQueenWong » Jun 03 2017 1:44am

Maybe you are right,i try to hack the controller's schematic.

Type Component Package Publisher
Mosfet: TK150E09NE (TO-220AB) Toshiba
Current Sensor: ACS711 (QFN) Allegro
LDO: LM317 (TO-220) ST
MCU: STM8S105C6T6 (LQFP48) ST
Operational Amplifier: LM358 (SO8) ST
Attachments
201706031496470531593254039329f.jpg
201706031496470869593255557e197.jpg
201706031496470758593254e6ecba5.jpg
201706031496471031593255f72df98.jpg
201706031496470945593255a15054a.jpg
elschema_kathmandu - 01 - Main circuit - Rev B-Model.pdf
(139.53 KiB) Downloaded 155 times

casainho   100 MW

100 MW
Posts: 2738
Joined: Feb 14 2011 2:43pm

Re: OpenSource firmware BMSBattery Sxxx motor controllers ST

Post by casainho » Jun 03 2017 3:51am

KingQueenWong wrote:Maybe you are right,i try to hack the controller's schematic.
Please reuse all th information I already got, like the pins that goes to microcontroller: https://opensourceebikefirmware.bitbuck ... -S06S.html

And I will complement my notes with the information you just shared!! :-)
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

casainho   100 MW

100 MW
Posts: 2738
Joined: Feb 14 2011 2:43pm

Re: OpenSource firmware BMSBattery Sxxx motor controllers ST

Post by casainho » Jun 03 2017 4:30am

One note: the metal case can be open just on the top side!! this is great for keep the controller open for development/testing and still have the needed heat sink working!! Also for the complete assembly.
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

User avatar
KingQueenWong   100 mW

100 mW
Posts: 39
Joined: Dec 18 2016 7:07am

Re: OpenSource firmware BMSBattery Sxxx motor controllers ST

Post by KingQueenWong » Jun 04 2017 2:20am

I am trying to draw the s06s controller's schematic. :)
Attachments
2017060414965605115933b37fe8ee0.jpg
S06S-Controller.PDF
(517.44 KiB) Downloaded 140 times

casainho   100 MW

100 MW
Posts: 2738
Joined: Feb 14 2011 2:43pm

Re: OpenSource firmware BMSBattery Sxxx motor controllers ST

Post by casainho » Jun 04 2017 3:06am

KingQueenWong wrote:I am trying to draw the s06s controller's schematic. :)
That's great!!!! I would like to the the source files for the schematic on your GitHub ;-) even better if was designed with KiCad because is OpenSource.

There is one issue I have: my board with my firmware just works when I have the STLinkV2 connected and powered. Seems it controls the reset line of the STM8. Can you please look to this part of schematic and see what the hardware does for reset line???
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

User avatar
KingQueenWong   100 mW

100 mW
Posts: 39
Joined: Dec 18 2016 7:07am

Re: OpenSource firmware BMSBattery Sxxx motor controllers ST

Post by KingQueenWong » Jun 04 2017 4:16am

001.jpg
001.jpg (11.23 KiB) Viewed 2997 times
The NRST pin just connect a 100K pull up Resistor to 5V and a 0.1uf Capacitor to GND.
The SWIM pin just connect a 10K pull up Resistor to 5V.
Last edited by KingQueenWong on Jun 04 2017 4:41am, edited 1 time in total.

casainho   100 MW

100 MW
Posts: 2738
Joined: Feb 14 2011 2:43pm

Re: OpenSource firmware BMSBattery Sxxx motor controllers ST

Post by casainho » Jun 04 2017 4:25am

KingQueenWong wrote:
001.jpg
The NRST pin just connect a 100K pull up Resistor to 5V and a 0.1uf Capacitor t0 GND.
The SWIM pin just connect a 10K pull up Resistor to 5V.
Thanks. Seems it is ok. I don't know if there is any special flag on configuration bits of STM8S105 that can cause this behavior I did refer...

I just added you to https://github.com/OpenSource-EBike-firmware so you can put your repo there, if you prefer. Also for future firmware development.

When you have the schematic finalized, please tell me so I can put it on the notes file!!! :-)
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

casainho   100 MW

100 MW
Posts: 2738
Joined: Feb 14 2011 2:43pm

Re: OpenSource firmware BMSBattery Sxxx motor controllers ST

Post by casainho » Jun 06 2017 3:17am

Found a bug on firmware and finally I implemented the firmware that does 4 quadrant bipolar PWM and tested it on an electric unicycle motor. I know this motor and I am having this one as a comparison with Q85 motor. When I decelerate, the motor regen and the power supply voltage increases as it is supposed. Unlike my latest tries when the firmware had a bug and with Q85 motor, the power supply voltage do no increase when I accelerate the motor nor the motor asks to much current -- it is running very well.
I didn't tested yet this firmware of Q85 motor.

Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

User avatar
KingQueenWong   100 mW

100 mW
Posts: 39
Joined: Dec 18 2016 7:07am

Re: OpenSource firmware BMSBattery Sxxx motor controllers ST

Post by KingQueenWong » Jun 06 2017 6:06am

Good Procedures!
1.Disconnect the ST-link's wires(includes GND,5V,SWIM,NRST) to s06s board,it can solve the problem that firmware run unsuccessfully.
2.The wires needs to be inserted deeper.(The last days,I just insert half of depth :( )
20170606149674668359368abb04214.jpg

casainho   100 MW

100 MW
Posts: 2738
Joined: Feb 14 2011 2:43pm

Re: OpenSource firmware BMSBattery Sxxx motor controllers ST

Post by casainho » Jun 06 2017 9:14am

Another experiment, the same firmware and controller as on the last video but this time with that Q85 Ebike motor, which is very small, light and less powerful (200W) when compared to the EUC motor. And this motor runs bad, with noise, asking a lot of current (motor heats)!!

And why so different this motor VS the EUC motor??
I think the main different is that this small and light motor have much less coils inductance and resistance:

http://www.diyelectriccar.com/forums/sh ... 76770.html
There are many low inductance motors around these days. By low I mean 5μH and lower. These are coreless or compact outrunners.
The problem is that the inductance is so low, that it is unable to integrate the PWM and current ripple blows the controller or overheats a motor. Or significantly lowers motor's maximum useful current at least.

Seems that this low inductance motors are more hard/expensive to control... and seems that one way is to lower the voltage supply to minimum so the current peaks will be lower... but on EUC motor can be different and that is also one reason for them to have high voltage supply??
I will keep thinking if there is a way to improve the current way to control this motor...

Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

casainho   100 MW

100 MW
Posts: 2738
Joined: Feb 14 2011 2:43pm

Re: OpenSource firmware BMSBattery Sxxx motor controllers ST

Post by casainho » Jun 09 2017 1:14pm

I finished the 4Q bipolar PWM with motor current control and I think is the most advanced PWM scheme I know. Although motor max current is controlled, the motor makes noise, don't rotate so quick as original firmware and also the mosfets do heat a lot.
Took me a lot of time to develop this firmware and I had to make some code with bit shifting operations because processing power is very limited. At some time, I could not make a division of a uint32_t and had to make a workaround...

Current motor control schemes:
- 6 steps: works very well but should not work for regen/breaking. The code is on this branch:
https://github.com/OpenSource-EBike-fir ... ee/6_steps

- 4Q bipolar PWM SVM: most advanced PWM scheme that should work for regen/breaking. Includes max motor current control. The code is on this branch:
https://github.com/OpenSource-EBike-fir ... e/tree/SVM

I will now try to replicate the original PWM scheme as it do not heat the mosfets, should work for regen/breaking BUT makes more noise than 6 step WPM scheme. The code will be on this branch:
https://github.com/OpenSource-EBike-fir ... l_sinewave
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

casainho   100 MW

100 MW
Posts: 2738
Joined: Feb 14 2011 2:43pm

Re: OpenSource firmware BMSBattery Sxxx motor controllers ST

Post by casainho » Jun 10 2017 8:21pm

KingQueenWong wrote:I am trying to draw the s06s controller's schematic. :)
Seems that you did finish the schematic, which is great!! Can you please push to github and export to PDF and PNG file??
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

User avatar
KingQueenWong   100 mW

100 mW
Posts: 39
Joined: Dec 18 2016 7:07am

Re: OpenSource firmware BMSBattery Sxxx motor controllers ST

Post by KingQueenWong » Jun 10 2017 9:46pm

Attachments
S06S-Controller.PDF
(595.66 KiB) Downloaded 143 times

casainho   100 MW

100 MW
Posts: 2738
Joined: Feb 14 2011 2:43pm

Re: OpenSource firmware BMSBattery Sxxx motor controllers ST

Post by casainho » Jun 10 2017 9:55pm

What is the signal "LEARN"?? I didn't found a documentation for the black and blue wires on the S controller...

I can't understand the signal "AN8"... is that the inverted of "OC" signal?? Can you please explain??
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

User avatar
KingQueenWong   100 mW

100 mW
Posts: 39
Joined: Dec 18 2016 7:07am

Re: OpenSource firmware BMSBattery Sxxx motor controllers ST

Post by KingQueenWong » Jun 11 2017 12:46am

I have updated the schematic.I am sure the schematic is correct.
I am not sure that the "BLUE" and "BLACK" whether LEARN or not(It seem that the old version s06s board have this function).
The LM358's two channel operational amplifiers seem that both just for measures current(only over current?).
201706111497159306593cd68a600db.jpg
Attachments
S06S-Controller.PDF
(600.57 KiB) Downloaded 103 times

casainho   100 MW

100 MW
Posts: 2738
Joined: Feb 14 2011 2:43pm

Re: OpenSource firmware BMSBattery Sxxx motor controllers ST

Post by casainho » Jun 11 2017 7:03pm

Thanks for the schematic!! I just added to my notes here: https://opensourceebikefirmware.bitbuck ... -S06S.html
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

MisterMint   1 mW

1 mW
Posts: 19
Joined: Aug 12 2015 2:42am
Location: Germany

Re: OpenSource firmware BMSBattery Sxxx motor controllers ST

Post by MisterMint » Jun 13 2017 1:04pm

Nice to see someone taking care of the cheap stuff from the land of china.
Been reading along on ES/vedder/esk8 and you really seem to be serious about the open source.
Big thumbs up! I really hope some hassle free firmware useable for people that know nothing about FOC and sh*t will grow out of the effort taken. Yes, it will never be on the same level as VESC, BUT it will take 13S for sure without any magic smoke - and IF it smokes it does cost only a little.

So, this is the sine wave controller I have inside my bike:
https://endless-sphere.com/forums/downl ... &mode=view
Its taken from the bottle battery from BMS Battery and I modified it to take XT90 input
from my homemade 13S5P 18650 instead.

I've got a second of these laying around which will power the front wheel soon and
I am very willing to flash some custom firmware that would allow to sync them in a way
that will stop the front wheel from spinning free in case its lifted. Any other kind of
improvement is for sure welcome as well. Will solder anything beside SMD.

I chose these controllers as they come with the nice waterproof plugs.
I question myself how close they are to the "boxed" BMS battery sine wave controllers.
I can shoot some better close up of the circuits if needed.

Here is a link to the original (incomplete) build tread:

https://endless-sphere.com/forums/viewt ... =2&t=71810

Best wishes for your investigation!

casainho   100 MW

100 MW
Posts: 2738
Joined: Feb 14 2011 2:43pm

Re: OpenSource firmware BMSBattery Sxxx motor controllers ST

Post by casainho » Jun 13 2017 3:35pm

MisterMint wrote:Nice to see someone taking care of the cheap stuff from the land of china.
Thank you for your words. Talking by myself, I would like to give some love to this cheap and widely available EBike motor controller and technology. Even if we don't get a better firmware than original, at least sharing knowledge about them is important for repair and modding/hacking.

Your controller, seems to me, that is equal to S06x. I think you can consider S06x schematic: https://opensourceebikefirmware.bitbuck ... .html#h1-1

I put your pictures on the documentation page - thanks: https://opensourceebikefirmware.bitbuck ... oller.html
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

casainho   100 MW

100 MW
Posts: 2738
Joined: Feb 14 2011 2:43pm

Re: OpenSource firmware BMSBattery Sxxx motor controllers ST

Post by casainho » Jun 14 2017 3:14am

I asked to a moderator, Alan B (that was very helpful), to moved this thread from "Electric Bicycles ‹ E-Bike Technical" to "Electric Vehicle Technology ‹ Motor Technology" as this last one seems where the discussion about other motor controllers happen, even the user developed ones.
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

User avatar
Alan B   100 GW

100 GW
Posts: 7490
Joined: Sep 11 2010 7:43am
Location: San Francisco Bay Area, USA
Contact:

Re: OpenSource firmware BMSBattery Sxxx/Kuteng controllers S

Post by Alan B » Jun 14 2017 11:28am

Great project here. Good work!

casainho   100 MW

100 MW
Posts: 2738
Joined: Feb 14 2011 2:43pm

Re: OpenSource firmware BMSBattery Sxxx/Kuteng controllers S

Post by casainho » Jun 17 2017 6:42pm

Ok I got the 4 quadrant bipolar PWM and tested it on the Q85 motor. Seems very near the performance of original firmware.

Next step should be limit max current and try to put current at +90º of hall sensors signal. The idea is to have a god and robust motor control firmware.

Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

Post Reply