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

you have to try all possible combinations of Hall and motor wires
Tkank you,
I wrote a code that allows to remap pins without physically soldering wires and I tried all 36 combinations, found a few more that the wheel spins on, and only one that works with an angle 20. (I checked all options with angles of 235 and 20)
nothing has changed, the bike goes fast enough, but in small jerks as feels like rotor is stuck for a short time, like on an old moped, even the phone is trembling on the steering))
I checked with interpolation turned on, if I turn it off - it goes much worse and makes noise. interpolation 360 and anti-jitter do not affect in any way.
could it be a burnt mosfet? but when the controller is off, the wheel spins easily,and it spins just as easily with TIM1_CtrlPWMOutputs(Disable)
what else should I check?
perhaps the halls in the motor are installed somehow unusually and the angles do not fit? How can I check this without disassembling it?
also I have tons of Blueosec app logs but nothing useful in them
 
Tkank you,
I wrote a code that allows to remap pins without physically soldering wires and I tried all 36 combinations, found a few more that the wheel spins on, and only one that works with an angle 20.
I'm curious about how you went about remapping the output phases (mine rotated motor angle by -120, 0 or 120 degrees (-85,0,85 units) and optionally swapped phases A and C in the PWM output.)
(EDIT: It's notable that phase B has the current sensor, and you cant move the sensor around, so ... mind that, i just adjusted the wires physically correct before moving on with the finetuning with the current sensor, below.)

Anyways, First I'd double-check that the hall state order when spinning forwards is correct (motor.c +ACAcommons.c records that in uint8_t_hall_order[]) (462315 or a rotation thereof, but 6 after 4 etc)
After this you'd only have the 6 permutations of phase wires to check btw, sorry that you went through all 36 :|

Then I'd check that you have proper phase B current sensor readings (do not enable "Enable rotor angle correction" + interpolation before that... you can have interpolation without the current sensor, just not the rotor angle correction) - those are recorded in uint8_t_hall_case[] by motor.c, just make sure it kinda sinewaves around 128 while operating.

If the phase B current sensor works, you can use that to finetune the motor specific angle (i made it possible to adjust it by one unit either way via uart, that was handly) - see where ui8_position_correction_value goes while running with interpolation and rotor angle correction, and adjust motor angle so it the correction value stays near 127. For my DYU D3F the motor specific angle (in the units used by the configurator) seems to be about 200, which i was surprised about (237 was functional but so far forwards that it had trouble getting started and ui8_position_correction_value just clamped down to 111 to try to fix it.)

After this, you can check the uint8_t_60deg_pwm_cycles[] recorded by motor.c to check how much time is spent in each hall state. Mine were withing an unit or two of eachother so i was like that seems good enough, but basically in theory if your hall sensors have unequal spacing that's where it would show, and you could adjust the hall state angles accordingly.

EDIT: Unrelated recommendation, after it otherwise works: do actually check how much current your controller pulls vs. what you thought you configured it for. For my KT24/36 it seems to be about 1.5x of what you'd expect from the raw value - that is, a cal_a of about 67, but cal_a is used only for display purposes (literally, in display.c etc), you still need to account for it in the battery, phase and regen current variables. The wiki does tell you this how it is, but it's just... i wasn't expecting that big of a discrepancy.

(Sidenote: this configurator is way too coder-oriented to be a proper end-user tool, nobody wants to configure times in units of 64 microseconds, angles in units of 360/256 degrees, currents in raw ADC readouts, etc.)
 
Last edited:
I'm curious about how you went about remapping the output phases
Thanks for the aswer,
I seem to have made a mistake here. I changed only here
TIM1_SetCompare1((uint16_t) (ui8_value_new_A << 1)); // C
TIM1_SetCompare2((uint16_t) (ui8_value_new_B << 1)); // B
TIM1_SetCompare3((uint16_t) (ui8_value_new_C << 1)); // A
but looks like I have to change angles as well
ui8_temp = fetch_table_value((uint8_t) (ui8_sinetable_position + 85 /* 120° */)); right?
this approach should work, because with interpolation and angle correction turned off, measuring the phase current does not affect anything.
in general I didn't get any further than that, I couldn't get the motor to spin more or less normally with interpolation and angle correction turned off.
before I got into it, this controller worked perfectly, soft and smooth when moving forward. but regeneration that I need did not work (we have a very hilly area here)
it is also strange that when I find a combination in which the motor spins forward and turns on interpolation, it stops and starts to twitch. It seems to me that the halls in the motor are located somehow incorrectly, but I have no idea how to find out their actual position without disassembling the motor.
about the current consumed - there are combinations in which it takes 5 amperes at idle, this is of course wrong. on others it takes 0.5A - I was happy when I found it, but under load the motor trembles noticeably
 
So, I have spend a day trying to get this to work, but with no success.

I have a KT36/48SVPRD-ffF10L controller, PCB is marked as KT-6S5-C 2018-1-8, fresh from AliExpress, didn't even test it out before flashing it :-/ It seems to be a standard S06S controller, where the only visible difference is the MCU is not an original STM, and seem to be marked as (AS)STMS105. although it's hard to read. But no ST logo. It accepts the firmware from my STLink V2 just fine, and I don't get any errors on compile either.

No matter what settings I try, I can't get it to spin my geared hub motor, either by pedaling or activating walk assist mode. No stuffering, increase in the wattage shown on the LCD, heatup of MOSFETs or anything. I tried measuring the output of the phase wires with an oscilloscope, but don't get any output (measuring between battery ground and each phase, is that the correct way?). Setting the controller to use an external speed sensor (this would be correct for a geared hub anyway?), it does attempt to show the speed on the display (KT-LCD3), but it is way too high, showing around 60 km/h when I just lift the wheel and spin it. Changing the wheel circumference to a much lower or higher value does not seem to affect that. But it does show that the MCU is running and communicating with the display.

I think the next thing to try is measuring the MOSFETs directly, but I would like to know if it is safe to run the controller without the MOSFETs being mounted to the case? And what else should I try?
 
Is the MCU generating gate drive signals to the FETs? (IIRC the leftmost pin of each FET is gate, if pins are "down" and you are facing the printed side of the FETs).

Is the MCU receiving hall signals from the motor?

As long as you don't allow the PCB to short on anything, and the FETs are still mounted to the heatsink / mounting bar (in case the controller does something that causes enough current flow to heat them up rapidly), you can run the controller without it's casing for testing/etc.
 
Thanks amberwolf. I don't see any signals on the gate pins. All six stay at 0 volts, measured against battery negative, when I try walk assist or stick some 1k resistors in the throttle connector to simulate a throttle. The hall sensors sends out signals when I spin the motor backwards, and the motor also work with my other controller (exactly the same, but original firmware). I will try enabling serial debugging tomorrow, that should tell me if the controller is trying to drive the MOSFETs.
 
If there's no gate drive, then the MCU probably isn't doing anythign to drive the motor.

Assuming the system is set to the right assist level to respond to the input being given, then the usual reason for that is a limit being exceeded within the MCU somewhere, like HVC, LVC, overcurrent, etc. Those should be programmable with the setup program or within the display, if they haven't already been set.

Or there could just be something wrong with the controller in general.

But it is also possible that there are differences between the MCU on this controller and the one the FW was written for so that the FW isn't correctly operating the controller. Or (less likely) there could be other hardware differences, such as having different MCU pins wired to the various I/O lines inside the controller, so the OSFW is telling the MCU to read or write the wrong signals to/from the wrong parts of the controller.
 
Well, that was what I was thinking. I have some experience with the STM32 bluepill boards, that often use STM32 clones or semi defective chips, and have some weird quirks. I guess that lead me to believe the answer would be something related to that. But, but, but, the real reason why it didn't work was much simpler. I forgot to set the right undervoltage value! It's like the only configuration value I didn't mess around with and I deserve to be a bit ashamed. According to what the java configurator has saved as experimental settings, I have compiled and uploaded the firmware around 20 times. I have taken the controller apart 5 times, desoldered the phase and hall effect wires to try different combinations, made a makeshift heatsink for the MOSFETs to be able to measure the board, and probably gotten a few new gray hairs in the process. But at least it works now, and I know the controller hardware well enough to reassemble it blindfolded. You're all welcome to point and laugh, but also anyone coming across this should learn from my mistake. And I'm sorry for wasting your very competent help on something so obvious.
 
I have not actually tried riding the bike yet, only confirmed the motor spins. I have to make all the wires look nice and clean and reassemble it before I want to do that. But I do hope I can make it work, because I have 3 of these controllers, and one that's the same, but with 9 FETs, and want to fine tune settings for all my bikes using the opensource firmware if possible. Mainly, the difference in power output between PAS levels on stock firmware is way too big for my liking, having me using PAS 4 most of the time, and 5 for climbing hills- It would be nice to have PAS 1 be enough for flat terrain, and use the higher levels to fine tune power output to adjust for hills, tired legs, headwind and added weight.

Edit: Just took it for a few quick test runs. There's definitely some jerkyness at lower speeds/startup, which seems to stop when it reaches 15 km/h and above. But right now I'm running it on my very big and heavy fatbike, and it may become more obvious on my other, lighter, bikes. There's lots of details to tune in before I'm satisfied, but I'm really happy it's working :-D

Edit2: Everything works great on my MTB conversion, also with a geared hub motor. No stuttering or anything. Have anyone tried modding the source code to add a brake light? I'm thinking about having the lights always be on, with the rear one going through an extra resistor, and then change the code to activate the light output when the brake signal is active, bypassing the resistor, if that makes sense.
 
Last edited:
where the only visible difference is the MCU is not an original STM, and seem to be marked as (AS)STMS105. although it's hard to read. But no ST logo. It accepts the firmware from my STLink V2 just fine, and I don't get any errors on compile either.
That's just how Kunteng does this stuff lately. I've purchased some controllers from different vendors and all had the "new (as) mcu".
Like you, I haven't met any real differences in software so I suppose that it may just be a "good clone". But we may find that out sooner or later :LOL:
 
at the end I could not get my motor to go without jerking. can someone help me interpret the screenshots?
if I turn on dc_static_zero and spin the wheel, I don't see any graph. some kind of wave is visible only when you first turn it on. Is this normal, or is this some kind of malfunction?
then, while there is some speed, the graph is almost straight, but you can see that it changes a little.
Is there any other way to determine the angle of the motor?
also, at starting, incorrect switching is clearly felt, it seems to stick, as if braking on a scooter to 0 speed, it feels like the magnets come off poles with such a specific click
 

Attachments

  • Screenshot_20230715-172936.png
    Screenshot_20230715-172936.png
    377.5 KB · Views: 17
  • Screenshot_20230716-160707.png
    Screenshot_20230716-160707.png
    337.5 KB · Views: 18
if I turn on dc_static_zero and spin the wheel, I don't see any graph. some kind of wave is visible only when you first turn it on. Is this normal, or is this some kind of malfunction?
then, while there is some speed, the graph is almost straight, but you can see that it changes a little.
Yeah the righthand display is consistent with it never being spun at all (the points at zero in the graph are at zero because the controller has not written to those points in the graph yet, because the motor has not been in those hall sensor orientations).

Basically, if there's not a significant swing even under motor power --- the left one says to me nope, but i'm not 100% sure if that's fast enough because i have not used the app yet --- then you don't have a working phase current sensor, but the input pin is sitting at half-Vcc (2.5V), which to me sounds like the sensor is physically installed - maybe it has been solder-blobbed over?

---
Anyways, i arrived here just to make a fundamentally pointless question about the firmware. The F does ACA mean?
(Seriously, this thing should come with a glossary... i'm not sure if even ERPS was/is written out anywhere -- i've figured out it's (roughly) electrical rotations per second, but like i had to dig deep in the code to see how the value was computed to figure that out.)
 
Hi All,

I am working on getting my two KT controllers working with the "Hubmonster" motor. The motor has dual phase windings & dual sets of hall sensors. Two controllers to run it properly.

I can get the motor to spin in the right direction at low rpm smoothly however once it gets to a certain RPM say est 35ish KPH the motor changes its tone and sounds terrible, also with the higher current draw once it switch's over the controller will loose throttle response (i believe the controller senses something is wrong and stops all power to motor until the throttle is turned again)

Regardless of settings i try on the LCD8H display, nothing changes.

I have tried to unlock these 18 Mosfet controllers however, i have not been successful. (Model KT48SVPRK-LCD-C&D)

I've tried unlocking them but it seems it will not work, here is the closest I got using the st-link v2 to flashing but i get the following error (see photo)

(Tried connecting with the HC-05 bluetooth module, even though i connected to the BT module, nothing is showing on the blue0sec app as far as data/settings

some of the resources i used:



 

Attachments

  • IMG_7111.jpg
    IMG_7111.jpg
    7.5 MB · Views: 11
Hi All,

I am working on getting my two KT controllers working with the "Hubmonster" motor. The motor has dual phase windings & dual sets of hall sensors. Two controllers to run it properly.

I can get the motor to spin in the right direction at low rpm smoothly however once it gets to a certain RPM say est 35ish KPH the motor changes its tone and sounds terrible, also with the higher current draw once it switch's over the controller will loose throttle response (i believe the controller senses something is wrong and stops all power to motor until the throttle is turned again)

Regardless of settings i try on the LCD8H display, nothing changes.

I have tried to unlock these 18 Mosfet controllers however, i have not been successful. (Model KT48SVPRK-LCD-C&D)

I've tried unlocking them but it seems it will not work, here is the closest I got using the st-link v2 to flashing but i get the following error (see photo)

(Tried connecting with the HC-05 bluetooth module, even though i connected to the BT module, nothing is showing on the blue0sec app as far as data/settings

some of the resources i used:



I discovered I wired pins to the st link v2 incorrectly. Not sure how I managed to do it, I confused which side the pins where on. Luckly everything still works.

I managed to get one controller working correctly on one set of phase wires and halls with low power settings. Working on getting the second controller working with the second set of hall/phase wires. Im not sure what motor angle setting works best, but the first controller like 220. Second wont work correctly and high current slow motor speed results. Tried 220, 230, 240, 250 with similar issues
 
I discovered I wired pins to the st link v2 incorrectly. Not sure how I managed to do it, I confused which side the pins where on. Luckly everything still works.

I managed to get one controller working correctly on one set of phase wires and halls with low power settings. Working on getting the second controller working with the second set of hall/phase wires. Im not sure what motor angle setting works best, but the first controller like 220. Second wont work correctly and high current slow motor speed results. Tried 220, 230, 240, 250 with similar issues
Update 2

Turns out with my particular application dual winding motor requiring two controllers to run, will programming or testing one controller i need to disconnect the second controller. The back emf i believe its called while testing on stand was causing the controller thats not powered up to act like a regen brake. Even with battery at 53 v the emf voltage spikes where so high it damaged all caps in the second controller (63v stock caps) will upgrade them to 100v

So if using a dual winding motor, program and test one controller at a time. Then connect them both and always run them in parallel turned on or risk damaging a controller. Will update once everything works 100%
 
I felt like I needed to do something fun, so I added reverse to my DYU D3F ;)

(Yeah the code is slightly jank and there are some debug artifacts etc left, but it works, I have full interpolation etc also in reverse (and speed limit to 2 km/h))
 
Edit:

I have fixed my issue by copying part of the main code on ACAcommons, I have no idea what I'm doing but seems to work.
Now I have no clue on how to get it to work on LCD11, Some people had changed the display code to include some lines, will experiment by adding more values. I have no clue what is xor and how to determine this.


Hi all, I wanted to try torque sensor, and opted to try the firmware and its amazing but I have some issues I'm not sure how to solve:

My problem is when I stop to pedal for the first time the motor doesn't shut down completely, it stops when I disconnect the torque sensor, and throttle has no effect. The Target Current is -0.3 for some reason and it resist spinning it backwards and slowly accelerates. (its a geared hub)

I have opted to use x4 torque sensor since I wanted to use throttle for 6kph (that is allowed), and i have installed the torque sensor

I used a resistor to ground on x4 to bring it down to 1.1v from 5v then realized I had to change the x4value to a lower value so it could work.
(I don't have a clue about programing) Torque sensor is "T9" and it generates 1.5v to 3v, but when connected it is generating 1.3v.

Calibration went reasonably fine, not sure how it calculates the assistance, I would like that to be a % of what I'm putting out but not sure how it is calculated.
 
Last edited:
Is it possible to use a kt36/48SVPR-EP028B from pswpower with 48v battery? I am having trouble using it with 48v while using with 36v battery goes without any problems. On 48v battery the throttle and pas randomly completly stops working during riding. When I turn off and on its works but again it stops after some time.
Can I flash the firmware and then be able to use the controller with 48v battery?
 
The wiki seems to be lacking in the aspect of the regenerative breaking function of the firmware. How should I determine the safe or maximum regen value for my battery? What's important to take into consideration when defining the "regen current max" value in the java tool?

I suppose the regenerative breaking activates upon triggering the break signal. Do I need to enable it with the "Regen Digital (no 4x throttle" parameter? Or is it enabled by default and "Regen Digital" is something else?

The wiki states "regen is activated by the brake lever switch, otherwise linear regen via an analog voltage on pad X4, you can use an additional thumb throttle for example" which I understand as "Activate this to use regen while breaking or do X4 instead". Is that correct?

Also, does the "Speed influences Regen Rate" parameter confine within the defined max regen value? Or does it just do it's own thing and goes outside of the defined max?

Sorry for the amount of questions, I've gotten everything to work and I'm not really fond of the idea to burning something.
 
Okay but then is it PAS irrelevant at all. I though cadence is affecting the power calculation ? so then i am looking for the reson why sometimes the motor does not star from idle. It may takie few to 10 seconds before it start again from coasting or idle. Appreciate your response.

PS The torque output is OK. Could it be something obout P and I settings?
Hello, I have the same problem with starting after a standstill. I can rule out that with a strong voltage drop.

During this time, the marked symbol appears in the BluOSec app. After a short activation of the brake the motor starts immediately.
Best Regards
IMG_20230901_154437.jpg
 
Hi all! Tell me, is it possible to read the firmware from the MCU of the KT36/48SVPRL-ffF10AL controller? Is it read-proof? The problem is that the firmware is configured and does not work correctly: 1. When the engine starts smoothly, an unpleasant hum and rattle is emitted; 2. A sharp increase in current consumption >5 amperes, even when turning the accelerator knob 1/4 full turn. I want to write the KT firmware to a file, then erase the memory and flash it with your open-source firmware. But to be able to go back to the KT firmware. And don't buy a new KT controller.
 
So, I have spend a day trying to get this to work, but with no success.

... where the only visible difference is the MCU is not an original STM, and seem to be marked as (AS)STMS105. although it's hard to read. But no ST logo. ...
Found the same MCU on KT36/48SVPRM-EP01X1 , in addition the white motor wire (speed / temperature sensor) is connected to X5 pin instead of X4. I will try to find proper controller with original STI MCU. Otherwise could it be the end of KT OSF flashing - hope not. Hovewer Lishui controllers offer more with slightly different process: Lishui "Open Source Firmware" project / KingMeter 5S ....
 

Attachments

  • IMG20231006191405 m.jpg
    IMG20231006191405 m.jpg
    403.5 KB · Views: 5
  • IMG20231006191110 m.jpg
    IMG20231006191110 m.jpg
    357.7 KB · Views: 5
Last edited:
Edit:
.......
I used a resistor to ground on x4 to bring it down to 1.1v from 5v then realized I had to change the x4value to a lower value so it could work.
(I don't have a clue about programing) Torque sensor is "T9" and it generates 1.5v to 3v, but when connected it is generating 1.3v.

.....
The situation is that torque signal is trying to pull it to 1,5V idle but its cannot overcome existing on this pin power supply.
You actually need to desolder the pull-up resistor that is connecting X4 to 5V supply. So X4 when disconnected from torque signal should show Perfect 0V. Hope you have used something like 100Kohm resitor?
 
Back
Top