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

I use EggRider and yes it works with KT protocol. So i assume it can work also in this open source firmware ? Can i change assist levels, and settings (some c and p values?). EggRider uses just same settings than LCD3 display
 
I pedaled a little hard when the controller was turned on , without throttle and PAS. the motor maybe working,are there some setting to avoid that? :D
 
Nixunen said:
So i assume it can work also in this open source firmware ?
@Xnyle has implemented all parameters of the protocol in the display.c code, but as both of us don't like LCD displays very much, only very basic functions, like assist level, are really used. Just for showing speed, power and switching the assist levels, the EggRider will work with the open source firmware.


haiyi911 said:
I pedaled a little hard when the controller was turned on , without throttle and PAS. the motor maybe working,are there some setting to avoid that? :D
Can you explain again, please, I don't understand what the problem is.

regards
stancecoke
 
stancecoke said:
Nixunen said:
So i assume it can work also in this open source firmware ?
@Xnyle has implemented all parameters of the protocol in the display.c code, but as both of us don't like LCD displays very much, only very basic functions, like assist level, are really used. Just for showing speed, power and switching the assist levels, the EggRider will work with the open source firmware.
I think what you guys are missing here is that SW102/EggRider LCD is a small LCD AND Bluetooth communication.
You don't have this LCD fully working because you are missing the Bluetooth communication.

You can join us here to have the Bluetooth communication on the OpenSource firmware for KT motor controllers: https://github.com/OpenSource-EBike-firmware/Color_LCD/wiki/Bafang-LCD-SW102
 
Regarding C and P Parameters, they are being processed, but not bound. Wheelsize currently can not be bound, cause its one of the few options not yet changable at runtime. P1 could be bound now. The remaining P and C values have limited value ranges (you have to look at the logical and shift operators) and could be bound to something. But as long as people don't come up with suggestions on what to bind them to, nothing will happen ;)

Code:
			lcd_configuration_variables.ui8_assist_level = ui8_rx_buffer [1] & 7;
			lcd_configuration_variables.ui8_max_speed = 10 + ((ui8_rx_buffer [2] & 248) >> 3) | (ui8_rx_buffer [4] & 32);
			lcd_configuration_variables.ui8_wheel_size = ((ui8_rx_buffer [4] & 192) >> 6) | ((ui8_rx_buffer [2] & 7) << 2);

			lcd_configuration_variables.ui8_p1 = ui8_rx_buffer[3];
			lcd_configuration_variables.ui8_p2 = ui8_rx_buffer[4] & 0x07;
			lcd_configuration_variables.ui8_p3 = ui8_rx_buffer[4] & 0x08;
			lcd_configuration_variables.ui8_p4 = ui8_rx_buffer[4] & 0x10;
			lcd_configuration_variables.ui8_p5 = ui8_rx_buffer[0];

			lcd_configuration_variables.ui8_c1 = (ui8_rx_buffer[6] & 0x38) >> 3;
			lcd_configuration_variables.ui8_c2 = (ui8_rx_buffer[6] & 0x37);
			lcd_configuration_variables.ui8_c4 = (ui8_rx_buffer[8] & 0xE0) >> 5;
			lcd_configuration_variables.ui8_c5 = (ui8_rx_buffer[7] & 0x0F);
			lcd_configuration_variables.ui8_c12 = (ui8_rx_buffer[9] & 0x0F);
			lcd_configuration_variables.ui8_c13 = (ui8_rx_buffer[10] & 0x1C) >> 2;
			lcd_configuration_variables.ui8_c14 = (ui8_rx_buffer[7] & 0x60) >> 5;
 
stancecoke said:
[
Can you explain again, please, I don't understand what the problem is.
the controller was powered off,rotating motor was easy.
the controller was powered on, i felt resistance when i rotated motor by hand ,
so i think the motor should be rotated smoothly without resistance even thought the controller was powered on(didnot rotate throttle).
I had tested,but :(
//#define DISABLE_PWM_CHANNELS_1_3 rotating resistance,throttle was valid
#define DISABLE_PWM_CHANNELS_1_3 rotating easy, throttle was invalid
 
@Xnyle has implemented the experimental function PWM off in the Java-tool.
You can try this setting. But rotating the wheel by hand is not a normal use case, while riding or pushing your bike you won't recognize a resistance, as the control loop will keep the current at zero fast enough.

regards
stancecoke
 
Hi stancecoke,

You mention using a Buck converter to power the HC-05 bluetooth module, which needs around 30ma at 5v. My current meter shows 40ma from the controller and I have only a PAS running directly from the battery, so would it be ok to run the bluetooth module if it's the only 5v sensor and no display?

Thanks for your work on the project and support!
 
You can try it of course, but I don't recomment to do it. The big resistor and the voltage regulator will get very hot. Perhaps the voltage will drop and you'll get a very strange behaviour of the whole system.

regards
stancecoke
 
Display is not running on 5V rail, so there is no current you're saving if you don't have it. For every mA the BT mod uses, the regulator will burn 10 times more, not a good idea.
 
stancecoke said:
@Xnyle has implemented the experimental function PWM off in the Java-tool.
You can try this setting. But rotating the wheel by hand is not a normal use case, while riding or pushing your bike you won't recognize a resistance, as the control loop will keep the current at zero fast enough.

I can recongnize a obvious resistance while riding or pushing my bike(the controller was powered on) .
i exchanged another controller and the motor without resitance(the controller was powered on).
So i choose “diagnosis” mode to konwn the controller state,when the controller was powered on and the bike was standstill,
the information was 17,0,0,321,0,7 ,17 were PAS RAMP and throttle/torquesensor currently override.
if the 17 affected the resistance?
when the controller powered on ,should the controller state be 0 not 17???
 
stancecoke said:
You can try it of course, but I don't recomment to do it. The big resistor and the voltage regulator will get very hot. Perhaps the voltage will drop and you'll get a very strange behaviour of the whole system.

regards
stancecoke

Thanks, i've ordered a little DCDC.

I'm all set and ready to flash the controller, but was a little confused by these instructions:

"Before deleting, please find out the correct phase and Hall sensor assignment on the complete system with the original firmware. This ensures that the controller in principle harmonizes with the engine."

Does this simply mean finding the right cable combinations for the phase and halls, or does it relate to some software parameters?
 
Xnyle said:
Besides: I think we desperately are in need for someone to create a "how to get this thing running" flowchart /cheat sheet/youtube tutorial, something like that. So anyone who want's to contribute is welcome. What's not so welcome are ppl that produce a constant stream of support requests :)

I'm up for putting some work into this, like updating the documentation perhaps, or maybe a simple video.
 
davideserin said:
"Before deleting, please find out the correct phase and Hall sensor assignment on the complete system with the original firmware. This ensures that the controller in principle harmonizes with the engine."

Does this simply mean finding the right cable combinations for the phase and halls, or does it relate to some software parameters?

This is, as you suspect, simply making sure that the phase/hall combo is correct before flashing the new firmware. If your motor runs cleanly with the stock fw you should be ok.. :wink:
 
haiyi911 said:
the controller was powered off,rotating motor was easy.
You are lucky that the motor stops after releasing the throttle stick :). In my case (9-fet hailong-integrated controller) when you release the throttle (without pressing the brake lever), the motor never stops completely and rotates at a speed of 2.4 km/h with sufficient power (do not stop with your hands). Of course, if the switch inside brake lever has been activated, the motor stops completely. But still this is a problem. I remembered the old "bad workaround"
https://endless-sphere.com/forums/viewtopic.php?f=30&t=87870&p=1387010&hilit=workaround#p1387010

and changed
Code:
adc.c
79:  ui16_current_cal_b -= 1: 
to
ui16_current_cal_b -= 2:

Now the motor (MXUS XF15R) stops completely without brake switch, but kt-lçd3 shows 9W power instead of 0W, when the controller is turned on and after the motor is completely stopped.

https://github.com/stancecoke/BMSBattery_S_controllers_firmware/commit/27827598a908c4df540ed54eb387770c313f9baf

Regarding the latest commits: I discovered a strange problem - with active driving, my stupid "throttle pressed when power on" protection

Code:
main.c

while (ui8_adc_read_throttle ()> = ADC_THROTTLE_MIN_VALUE);

         // ITC_SetSoftwarePriority (ITC_IRQ_TIM1_OVF, ITC_PRIORITYLEVEL_2);

is triggered, and I have to turn off the controller and turn it on again.

I could not understand what was the matter, until I realized that it was the watchdog that was triggered by restarting the firmware. Programmers know better, but I suppose that the processor is already a bit "overloaded" by interrupt handling or something similar..
Latest version without this trouble i checked (and may be +1-2 commts "up", not tested)
https://github.com/stancecoke/BMSBattery_S_controllers_firmware/commits/27827598a908c4df540ed54eb387770c313f9baf
Who can get debug logs when traveling - please check if there are "System initialized" messages if you didn’t turn off and on the controller again
Regarding the resonances of the rear gear motors ... I replaced the unnamed Chinese hall sensors (marked "613" on the case) in XF15R with Infineon TLE4935L (latch), the best option for motors with an unstable magnetic field (different gaps between magnets, chipped magnets and etc)). And shortened the signal wires from the hall PCB.
https://photos.app.goo.gl/1n3eJMYQQB9qTJN78
The result ... Not so much. The peaks of the resonance at a speed of 7.2 km/h and 11.4 km/h have decreased, but only that. There is almost no difference with the Bafang SWX02 motor ...
Friends who ask to ride my bike with the original or open source KT firmware, exclaim "Wow, did you buy at the nearest sex shop?". I take offense, install a cheap Chinese DMHC controller (STM8S903K3, "unprotected" (downloadable from controller) firmware) with its poor and primitive LCD display, and go further... Without vibrations and resonances ...
 
different gaps between magnets, chipped magnets and etc

The OS FW already has options for compensating "different gaps". I had this last year and can tell you it feels completely different than the resonances. So maybe you fixed some additional problem with the motor.

But the main problem seems to be a resonant circuit with certain controller/motor combinations, not software related. If the original FW has resonances and our own which shares zero code as well, there is a high probability it's simply a hardware "bug" with the KT controller setup.

I'm starting to wonder if XF15 is maybe working fine with KT 6FET controllers but not with 12FET (which are mostly sold for use with direct drive motors)
 
Regarding controller reset:

could you comment out the GPIO_Write in gpio.c and try again:

Code:
// added by DerBastler - Light
void light_pin_set (void)
{
  GPIO_WriteHigh(LIGHT__PORT, LIGHT__PIN);
}
// added by DerBastler - Light
void light_pin_reset (void)
{
  GPIO_WriteLow(LIGHT__PORT, LIGHT__PIN);
 }

Maybe it's not a good idea to constantly GPIO_Write in fast loop.
 
Hi guys, I'm a new user from Italy. :thumb:

I followed silently this thread a for months, since I had the idea to build an ebike from scratch by myself.

My goal was to build a pedelec with just some assistance (not exceding EU legal power), minimizing weight, and experimenting ways to maximize trip distance.

I finally succedeed to build a lightweight 13kg 26" ebike, based on a Xiongda YTW 06 front motor powered by a 7Ah bottle battery.
I added a Sempu T2 3d gen TS, that's the (first) reason I began to follow this thread, because the stock controller FW obviously doesn't manage it.

In these days, I'm getting familiar with OSEC and BluOsec setup: thank you for the fantastic work, and I would like to (try to) contribute a little.

Since from the beginning, for distance maximizing I wanted to experiment with automatic gear shifting, so I built the bike only with rear derailleur (it's a 1x10 config, with a HUGE&SEXY Sunrace 11-46 cassette :D ).

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.

I noticed, in fact, that many ebike drivers tend to underuse the gear shifters, insisting in higher gears than usual and asking the motor to balance it.

The mechanical part is ready: derailleur is driven by a 25KG digital servo, fixed on a 3D printed PLA support.
The servo has its standard 20 mm diameter round alu pulley which wind up the shift cable: I was VERY lucky when I realizedthat the 172° servo travel + pulley diameter cover perfectly the travel needed by my Shimano SLX derailleur!

I verified briefly the forces involved, a standard derailleur needs about 12kg to retain position, and some more to move. For position keeping, I've noticed that most of the 12kg are sustained by the internal reduction gears of the servo, so it doesn't need too much current to stay in idle in some gear.

Initially I imagined to use a separate Arduino Mega platform to drive the servo, sharing sensors (cadence, speed, torque at least) with the KT controller...until I opened my spare KT controller I bought and compared to the STM8S datasheet: the KT board (at least my revision) is plenty of free pads other than famous X4 one, which could be used to my needs...yeah!

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.

The algorithm could be simple at the beginning, I think I'll create a Optimal cadence parameter (typically 90 rpm) and an Overlapping parameter to manage gears shifts, but it could be made more omplex...I'm thinking about torque value, but also parameters, for example, from BlueOsec: clinometer, FC from a HRM, etc...

I hope there will be some headroom left in STM8S resources... :lol:

(I think that in future BlueOsec could be the gate to share other async sensed values to controller, provided by a common phone: otherwise, most of the sensing modules on the market are I2C or UART based, but the first is not avaible in KT controller, the second is busy...)

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

Long post sorry, I don't want to bother you anymore: if you want some detail/photos/etc...just ask!

Thank you all!
:D
 
Thank you for your detailed report! Of course I am interested in some photos and your software implementation! :)

regards
stancecoke
 
Do you have found that the waveform is asymmetrical?
 

Attachments

  • Asymmetrical.jpg
    Asymmetrical.jpg
    50.2 KB · Views: 2,874
vulcanears said:
FedeleC said:
[...] auto-shifting [...]

This might be interesting to you:
https://www.archercomponents.com/
(Electronic wireless shifter over bluetooth)

Thank you, I didn't knew this specific vendor, interesting resource!

I know there are suppliers of electronic gear shift systems, both integrated with derailleurs (Sram, Shimano and Campagnolo) and some new productors of independent systems, like this one.

These systems are electronic but not automated, and many muscolar bike drivers (like me) don't catch the benefit from spending so much money to switch from robust mechanical levers to a system based on buttons&batteries...on a full mechanical bike could be a non sense! :wink:

On a ebike, we have already a battery to carry around, and an electronic that acquire cadence, speed and torque...so it could be more interesting to integrate such a sub system.

The only similar system I know is the one made of Bosch Steps and Shimano DI2 integrated...but at a huge cost! :shock:

A digital servo from China costs 14 €, it's worth a try to integrate in OSEC! :D

Obviously, I'm thinking also about a manual shift mode to operate the servo, so I need a "device" with at least 3 buttons (up, down, mode switch)...I have some ideas, I'll tell you... :wink:

Bye!
 
Hi all
Anyone got any insight on Regen blowing these controllers. My mate has been through 3 40amp controllers all dying on Regen.
13s li-ion battery, 500w DD motor, 40amp kt controller with lcd3 display. Regen set to 70% to hopefully prevent big spikes.
It seems Regen on a full battery is killing the controller with mosfet blowing L, R and center!
Is this a known issue? Don't want to put in yet another one only to have it pop.
Thanks!
 
haiyi911 said:
Do you have found that the waveform is asymmetrical?
You will get even more distortion if FOC is not working. That waveform seems very good to me from what I saw when experimenting / developing the FOC for KT controllers.

Try to disable FOC and increase motor speed and current and then take the screen shoots and show to us.
 
Back
Top