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

Aeron said:
I have quite the same question but the other way around : I have a 36/48V version, but I want to run it at 52V.
The FETs and caps were changed to their 80V counterparts to accomodate higher voltage (and I am thinking about changing the LM317 regulator*), but is there any hardware modification to make this controller work with 14S battery ? (voltage limits or other)

*edit : original LM317T replaced by TL783CKCSE3.

Noone knows ?
 
I don't have a good understanding of the electronics behind LVC so I thought it would be a good idea to ask first.
If I were using a lower voltage, I guess I'd still be in the mesurement range of the LVC circuit.
But when overvolting, isn't there a risk of falling out of that range and saturate the chip ?

The answer I'm looking for is whether or not the LVC circuit needs any modification (in addition to a setting change in the firmware), like change a resistor value, to shift this range (hence adjusting to a slightly higher battery voltage). Wouldn't it be "too easy" if it were already compatible with higher voltages ? Maybe it is already good enough to set LVC to 42-44V, but I thought I'd check.

bushido said:
+1

i would also love to have higher voltage on a small 6FET/9FET controller. because i will use it with high geared hub motors, i would max out @ ~45km/h. i dont need more power (A), just higher voltage.

i just want to know if its an "easy" mod. if i have to replace one third of the components its not worth it

If you are interested, I'll let you know how the 6fet I have behaves @52V (stock amps, I'm like you and don't want to up the amps for now).
 
Aeron said:
I don't have a good understanding of the electronics behind LVC so I thought it would be a good idea to ask first.
If I were using a lower voltage, I guess I'd still be in the mesurement range of the LVC circuit.
But when overvolting, isn't there a risk of falling out of that range and saturate the chip ?

The answer I'm looking for is whether or not the LVC circuit needs any modification (in addition to a setting change in the firmware), like change a resistor value, to shift this range (hence adjusting to a slightly higher battery voltage). Wouldn't it be "too easy" if it were already compatible with higher voltages ? Maybe it is already good enough to set LVC to 42-44V, but I thought I'd check.

bushido said:
+1

i would also love to have higher voltage on a small 6FET/9FET controller. because i will use it with high geared hub motors, i would max out @ ~45km/h. i dont need more power (A), just higher voltage.

i just want to know if its an "easy" mod. if i have to replace one third of the components its not worth it

If you are interested, I'll let you know how the 6fet I have behaves @52V (stock amps, I'm like you and don't want to up the amps for now).

thanks, but its to late, i have just bought 2x S12SNN 72V from BMS Battery. initially i have planned a stealthy build with DIY bottle batteries. but after thinking through how to best setup the cells configuration , i have decided its not worth it, and i know myself, the limit of 45-50kph (48V) with the Bafang RM G310 & FM G370 would annoy me and i would probably upgrade it later anyway for higher V.

in the end i will build somethink like this

https://endless-sphere.com/forums/viewtopic.php?f=3&t=47631

or this

https://i.pinimg.com/originals/2d/2d/45/2d2d45be094676cb773d592892eddc07.jpg

and place my battery(20S11P NCR18650PF) and controllers there. i will just put a ~40A phase current limit to the controllers so i don't overload the nylon gears with to much torque. anyway, with 2 motors i should still have good torque. with oil cooling and maybe some heatsinks in the future, i should have no problems running like 2000-2500W continuously. although i will end up with like 1000W most of the time.

its like with the internet speed. sure 20mbit might be good enough for the most time, but there will be times when you need more speed for a short period of time.
 
Hi KT gurus
Before I destroy another kt controller :( I thought I'd ask first this time!!
The output on the controller that is at battery voltage, I'm assuming it is for lights. Is this regulated at all? Am I safe to chuck in any old led (rated for 6-60v) front and rear combo or do I have to worry about current draw etc
Thanks in advance
 
kdog said:
Hi KT gurus
Before I destroy another kt controller :( I thought I'd ask first this time!!
The output on the controller that is at battery voltage, I'm assuming it is for lights. Is this regulated at all? Am I safe to chuck in any old led (rated for 6-60v) front and rear combo or do I have to worry about current draw etc
Thanks in advance

Kt controllers light output (that output which can control on-off using display etc) has battery voltage, like you say, but current you can draw only 100mA so in 52v it is only 5.2W. I simply use that output to control relay, so i can use any led's / lights after that.
 
Hi,

This is my first post so I'm not sure if I'm doing this right.

So, thanks to the efforts of many people on this site I have managed to:
• Convert a square wave controller to sine wave
• Flash it with the OSEC firmware
• Run the BluOsec app
This is all running successfully on a leaf bike 48v, 1000w, hub motor kit. The variable regen function is fantastic since in town I frequently have to slow down for traffic lights and standard bike brakes are not designed for multiple stops from 45 kph!
I have a few outstanding questions on items I don’t understand:
• Cruise control appears to be supported, but it is not clear how it is activated (I cannot find a pin assignment in the code)
• Phase current B – this is measured by the ACS712. It is not clear whether the absolute value of this is important. Does it need to be calibrated or is the firmware just looking at relative values. There is a comment in the code to the effect that for FOC ‘this needs to be regulated to zero’ in which case the absolute value is unimportant. Since the zero current output of the ACS712 sits at VCC/2 I would have expected to find an ADC_value -511 or 512 but I cannot.
In an effort to contribute, I noticed a number of posts saying the BluOsec app frequently crashes. I experienced this as well, but found that moving the HC-05 further away from the controller made a huge difference. It may well be as a result of electromagnetic interference from the switchers.
Also, I have been using my turbo trainer as a dyno to look at currents and voltages under different load conditions via BluOsec logging, current clamp and scope, ammeter, at 5A and 10A battery currents.
 
mercamg said:
• Cruise control appears to be supported, but it is not clear how it is activated (I cannot find a pin assignment in the code)
Casainho implemented the function in the code, but I never set it active. I don't know, if Xnyle has done it. There's no hardware pin for activating, it's automatically activated, if you hold the throttle at a constant value for a certain period of time. It's deactivated by breaking or by turning the throttle.

mercamg said:
• Phase current B – this is measured by the ACS712. It is not clear whether the absolute value of this is important. Does it need to be calibrated or is the firmware just looking at relative values. There is a comment in the code to the effect that for FOC ‘this needs to be regulated to zero’ in which case the absolute value is unimportant. Since the zero current output of the ACS712 sits at VCC/2 I would have expected to find an ADC_value -511 or 512 but I cannot.

We are reading the phase B current just with 8 bit resolution, so the FOC algorithm tries to keep the value at 127. We are just looking at the zero crossing, not at the absolute value. The motor current is calculatet from Battery Current / duty cycle internally.

regards
stancecoke
 
Thanks that's perfect.
By the way, given the additional switching that's going on, would you expect a sine controller to get hotter than a square wave controller for the same load conditions?
 
mercamg said:
would you expect a sine controller to get hotter than a square wave controller for the same load conditions?

yes, especially the fact that the pwm is always active, even if the motor is at standstill, the controller gets handwarm even without load. But that's no problem in the normal use of the system.
You can disable PWM at standstill with the experimental option, but we have no feedback, if it causes any problem. There's a certain risk to kill your mosfets with this function.

regards
stancecoke
 
I was trying to use this firmware but I get an error when using stm8flash as per this link: https://opensourceebikefirmware.bitbucket.io/INSTALL_FIRMWARE--Tools_build_and_flash_firmware--How_to_erase_and_unlock_protected_read_memory.html

Determine OPT area
Due to its file extension (or lack thereof), "option_bytes_pwm_n_channels_enabled.bin" is considered as RAW BINARY format!
15 bytes at 0x4800... Tries exceeded

Any ideas? I confirmed I'm using the correct connections, tried on a couple of different controllers, tried external power etc. At this point I'm thinking it's most likely an issue with the stlink or stm8flash. Note that I'm using Linux. I don't currently have any Windows PCs around.

BTW I made a simple web app yesterday to interface to stock Kunteng controllers from any mobile/tablet/pc via a HM-10 Bluetooth LE module. In theory it should work with almost any controller/firmware with a few changes. In my case it was not necessary to change any HM-10 module settings or use any extra circuitry. Some here might find it useful. https://endless-sphere.com/forums/viewtopic.php?f=30&t=95633&p=1484041#p1484041
 
flangefrog said:
Note that I'm using Linux. I don't currently have any Windows PCs around.
Perhaps casainho or Xnyle can give you a hint, I don't use linux.

flangefrog said:
BTW I made a simple web app yesterday to interface to stock Kunteng controllers from any mobile/tablet/pc via a HM-10 Bluetooth LE module. In theory it should work with almost any controller/firmware with a few changes.

nice work, but can you explain some details. You have to run a local web server on your device, if you want to use it offline? How do you pair the HM10 with your web-application?

I can find the function "connect" in the source code, but nothing happens at my android phone with the chrome browser, if I click the BT-button on the website. :-(
Code:
        function connect() {
            exponentialBackoff(8 /* max retries */ , 1 /* seconds delay */ ,
                function toTry() {
                    time('Connecting to Bluetooth Device... ');
                    document.getElementById("connectBtn").textContent = "bluetooth_searching";
                    return bluetoothDevice.gatt.connect();
                },
                function success(server) {
                    time('Bluetooth Device connected');
                    document.getElementById("connectBtn").textContent = "bluetooth_connected";
                    onConnected(server);
                },
                function fail() {
                    time('Failed to reconnect.');
                    document.getElementById("connectBtn").textContent = "bluetooth";
                });
        }

you can use a high side switch on a GPIO Pin of the HM-10 to switch on/off the controller by the app, I've done this for a Lishui controller:
https://www.pedelecforum.de/forum/index.php?threads/nachbau-lishui-bluetooth-modul.45072/

regards
stancecoke
 
flangefrog said:
I was trying to use this firmware but I get an error when using stm8flash as per this link: https://opensourceebikefirmware.bitbucket.io/INSTALL_FIRMWARE--Tools_build_and_flash_firmware--How_to_erase_and_unlock_protected_read_memory.html

Determine OPT area
Due to its file extension (or lack thereof), "option_bytes_pwm_n_channels_enabled.bin" is considered as RAW BINARY format!
15 bytes at 0x4800... Tries exceeded

Any ideas? I confirmed I'm using the correct connections, tried on a couple of different controllers, tried external power etc. At this point I'm thinking it's most likely an issue with the stlink or stm8flash. Note that I'm using Linux. I don't currently have any Windows PCs around.
Make sure you have permissions to write to device, maybe you need to use sudo??

Another alternative to stm8flash is OpenOCD. I use OpenOCD because it alsoet me debug, which needed for development.
 
stancecoke said:
flangefrog said:
BTW I made a simple web app yesterday to interface to stock Kunteng controllers from any mobile/tablet/pc via a HM-10 Bluetooth LE module. In theory it should work with almost any controller/firmware with a few changes.
nice work, but can you explain some details. You have to run a local web server on your device, if you want to use it offline? How do you pair the HM10 with your web-application?
Do you plan to publish the source?

you can use a high side switch on a GPIO Pin of the HM-10 to switch on/off the controller by the app, I've done this for a Lishui controller:
https://www.pedelecforum.de/forum/index.php?threads/nachbau-lishui-bluetooth-modul.45072/
No local web servers needed. I will simply use a JavaScript Service Worker. It only requires a few lines of code for a simple offline implementation. The other way it can be done is with the Application Cache but that's now deprecated.

It's even possible to make it add an icon to the home screen on a mobile device and launch the app in a windowless browser (e.g. will seem like any other native app). You might be interested in this site: https://whatwebcando.today/

Bluetooth is done via Web Bluetooth. See Implementation Status for supported platforms and browsers. Note it only supports Bluetooth LE not Bluetooth Classic (although that may be supported in the future through Web Serial). Currently to connect you just click the Bluetooth icon on the header (ux could be better). You should see a Bluetooth device chooser dialog. I haven't implemented any error messages yet so if your device doesn't support Web Bluetooth or Bluetooth is disabled then it won't do anything. You can check in the console (F12) for any messages.

Web Bluetooth with offline support is the same solution I've used for the energy monitor in my signature.

The source is available by right clicking the page and clicking view source or Ctrl+U. Everything is on that single file although the code is not very clean as I just quickly hacked it together.

I did see that post of yours at this link. I didn't have any high side switches/suitable p channel fets on hand though. I'm also not using the ADC for voltage measurement yet.

casainho said:
flangefrog said:
I was trying to use this firmware but I get an error when using stm8flash
Make sure you have permissions to write to device, maybe you need to use sudo??

Another alternative to stm8flash is OpenOCD. I use OpenOCD because it alsoet me debug, which needed for development.
Permissions should be fine, I've added the udev rule and also tried using sudo.

I installed OpenOCD 0.10.0 but it seems the scripts for stlink/stm8 weren't compatible with that version. I'll try it again later and post the errors I got.
 
flangefrog said:
Currently to connect you just click the Bluetooth icon on the header (ux could be better). You should see a Bluetooth device chooser dialog.

Hm, that only works on my newest android tablet. With my older android mobile and on IPhone and Windows10 it doesn't work.

Perhaps you can write a small tutorial, how to make it work offline?!

Regards
stancecoke
 
As per https://github.com/WebBluetoothCG/web-bluetooth/blob/gh-pages/implementation-status.md
The Windows implementation is available in Chrome 70.0.3526.0 and requires Windows 10 version 1703 (Creators Update).
Android: Requires Android 6.0 Marshmallow or later.
WebBLE is an app for iOS that supports the GATT Communication API

See also https://caniuse.com/#search=web%20bluetooth

You can also use Chromium or Opera on Windows. Of course the PC will need to support Bluetooth LE. Most Bluetooth 4/5 adaptors are dual mode and support LE. Or you can buy one of these: https://www.ebay.com/itm/Mini-USB-Bluetooth-Adapter-V-4-0-Dual-Mode-Wireless-Dongle-CSR-4-0-Win7-8-XP-L/252848510670

On Android you need Opera Mobile, Samsung Internet, Android Browser or Chrome. Make sure you use the browser and the link isn't opening inside an app like Gmail for example, as that will use the WebView where Web Bluetooth isn't yet supported.

On iOS webBLE is a browser that implements the Web Bluetooth API as the iOS WKWebView component used by Chrome doesn't yet support it.

There are already thousands of tutorials on how to use Service Workers. You generally use them as a proxy and supply resources from a local cache rather than a remote server.
https://css-tricks.com/serviceworker-for-offline/
https://developers.google.com/web/fundamentals/codelabs/offline/
https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps/Offline_Service_workers

I'll add offline support when I have some time.
 
flangefrog said:
I'll add offline support when I have some time.

Hm, I think this will be necessary. I am already very IT-affine, but such headstands to get an app running offline is not a good prerequisite for a wide use of such applications...

regards
stancecoke
 
Hi, anyone working on making the sw102 display compatible with the kt open source firmware ? Lot of useful infos here: https://github.com/OpenSource-EBike-firmware/Color_LCD/wiki/Bafang-LCD-SW102
I'd join the effort but my knowledge is not deep enough to do everything by myself.
 
Sorry, but both of the main developers don't like any display. (Xnyle prefers his BlueOsec App for the android cell phone, I prefer to have no device at my handlebar at all :wink: )

Of course everbody is invited to implement the stock Bafang-protocol to our firmware. I think it could be done by copy and paste from the "Forumscontroller" code. As long as there is no possibility to flash the sw102 without destroying the housing, a custom firmware for the display is no alternative...

regards
stancecoke
 
stancecoke said:
Sorry, but both of the main developers don't like any display. (Xnyle prefers his BlueOsec App for the android cell phone, I prefer to have no device at my handlebar at all :wink: )

Cool! I get that there is no need for all the hype stuff, bu how do you check batt level and how do you control power / temperature to make sure it doesn't overheat ?

stancecoke said:
Of course everbody is invited to implement the stock Bafang-protocol to our firmware. I think it could be done by copy and paste from the "Forumscontroller" code. As long as there is no possibility to flash the sw102 without destroying the housing, a custom firmware for the display is no alternative...

Ok, thanks for the heads up.
 
qwerkus said:
how do you check batt level and how do you control power / temperature to make sure it doesn't overheat ?

I know quite exactly, how far I can ride with a fully charged battery. I use the motor only for commuting, not for trips in the mountains. The power is controlled by my legs, I have a torque- and cadence-sensor installed. Overheat is no problem with 10 amps maximum current and no long/steep inclines.

regards
stancecoke
 
FedeleC said:
I want to investigate on my thought that in some situations (hilly journeys), the power saved by auto shift (letting the driver legs/motor work with the most adequate gear) is more than the power consumption of this sub-system.


So, I rerouted/created some input/output of my KT36/48SVPR-HRD01:
  • Rearranged some wires to power the Sempu T2 @ 36 V
  • Draw current directly from Vbat +36V pad to a DC/DC Step Down Converter to 6,8V, to power the servo. I reached to connect and enclose it inside the controller box
  • Attached Servo signal output to a pad connected (via a 2,2K resistor) to PIN 43 of STM8S: I want try to use it as a PWM output of Timer 3, not used yet by OSEC, @ about 50 Hz. I've to check if i'll need to short circuit the 2,2 K resistor, I hope not :wink:
  • Attached a passive buzzer output to a pad connected (via 2,2 K resistor, again) to PIN 45: it would be sooo nice to notice the driver of an imminent gear shift...This PIN has to be reconfigured with the STM8 S Option byte to work as a Beep source.

After finishing optimizing the OSEC to my motor (it worked at first start!), next days I'll work on FW to create the automatic gear shift function: altough I'm not a programmer I have a past experience in motor controllers...so let's try! :D

Hi FedeleC, I'm very interested to Your project! Do You make any progress?

I don't know if putting the servo on the derailleur is the best thing because of its weight on the gearbox. It would probably be easier to use with any derailleur if it operated the stock cable (much shorter, since the servo can be put on the dropout).
But the principle is the same.
I'm dreaming of connecting a bluetooth remote control for the gears to the SW102 display and controlling the derailleur with the KT or TSDZ2 controller (but I don't think there is a pwm free output on this), so we can no authorise gear change if cadence < 10, or pedal torque > 30Nm, automatic gear change, and a lot of more stuff ...

Thanks You!
 
Hi,
When I start to ride under PAS mode, the motor works intermittently, with a creaking sound. Yet when I speed the pedaling up, the abnomal sound disappear and it goes smoothly.Do I have to worry about parameters?
PAS magnets:5
timeout:3125
ramp end :1500 or 18750(10rpm)
ramp start:64000
pas threshold:1.1
Thanks in advance.
 
Back
Top