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

Are the values for cadence and torque from the original Tongsheng firmware?!

With a mountainbike of 20kg and a rider of 1.76 m hight and 100 kg weight you get a speed of appr. 24 km/h with no wind in the plain at 150W power and a cadence of 90/min. So you can estimate, if the shown power is in a realistic range, if assist level is zero. (and as you broke several BB axles already, I think your power is quite high :wink: )
You can play around on kreuzotter.de a little.

regards
stancecoke
 
stancecoke said:
Are the values for cadence and torque from the original Tongsheng firmware?!
Yes!! We found the RAM registers that hold the torque sensor value and cadence :) The other developer, also a German guy, had to make code to print to UART in real time RAM and so he could identify the variables for cadence...!!

stancecoke said:
With a mountainbike of 20kg and a rider of 1.76 m hight and 100 kg weight you get a speed of appr. 24 km/h with no wind in the plain at 150W power and a cadence of 90/min. So you can estimate, if the shown power is in a realistic range, if assist level is zero. (and as you broke several BB axles already, I think your power is quite high :wink: )
You can play around on kreuzotter.de a little.
That could be me and my bicycle :) -- so yes, that values makes sense to me.
 
This is the graph for the values on the big array, inside the TSDZ2 motor controler original firmware. I can't understand well... but yes, SVM waveform is there as we are doing on our firmware:

 
casainho said:
So, for your tests, the thing is FOC not working well.... some other ideas:

Find this piece of code on motor.c:
if (UI8_ADC_MOTOR_CURRENT > ui8_adc_motor_current_offset)
{
// motor mode
if (ui8_adc_id_current > ADC_PHASE_B_CURRENT_ZERO_AMPS_FOC_MAX) { ui8_angle_correction++; }
else if (ui8_adc_id_current < ADC_PHASE_B_CURRENT_ZERO_AMPS_FOC_MIN) { ui8_angle_correction--; }
}
else
{
// regen mode
if (ui8_adc_id_current > ADC_PHASE_B_CURRENT_ZERO_AMPS_FOC_MAX) { ui8_angle_correction--; }
else if (ui8_adc_id_current < ADC_PHASE_B_CURRENT_ZERO_AMPS_FOC_MIN) { ui8_angle_correction++; }
}
Using the firmware you did download and your needed changes on config.h, exchange the ++ for -- and vice-versa on that piece of code.

Even more deep is the next test, delete all that code and put there only this 2 lines:
if (ui8_adc_id_current > ADC_PHASE_B_CURRENT_ZERO_AMPS_FOC_MAX) { ui8_angle_correction++; }
else if (ui8_adc_id_current < ADC_PHASE_B_CURRENT_ZERO_AMPS_FOC_MIN) { ui8_angle_correction--; }
Also even if not working, try to exchange the ++ for -- and vice-versa.

I must say this is all strange because recently we tested with different motors and all did work. Myself, I tested with S06S controller and Q85 motor.

Sooooo... i found some time today again.
As expected the problem was the bridged current sensor. I guess block mode worked because it does not need the current sensor?
But still not sure how the F.. it worked with original firmware (running sinus!, i could hear it!)?!

Now next problem:
The motor spins up nice, then starts braking very hard, then spins up again

i had to remove this piece of code, now it runs smooth

Code:
if (ui8_adc_id_current > ADC_PHASE_B_CURRENT_ZERO_AMPS_FOC_MAX) { ui8_angle_correction--; }
else if (ui8_adc_id_current < ADC_PHASE_B_CURRENT_ZERO_AMPS_FOC_MIN) { ui8_angle_correction++; }

i have also exchanged ++ and -- but only in the regen mode part, then it was also running good.

Just to be sure i have also checked current sensor voltage. Its 2.495V idle, 2.480 with motor running at 1amp phase current. At 66mv/A of the ACS712 30A this seems the be a little bit off. Probably broken now?
 
stancecoke said:
Basia said:
On the custom firmware brake proportional? on my controller (kt36/48svpr) 3 wires for brakes.
In my fork, there is linear regen implemented, but you have so solder in an extra wire for that function.

Extra wire? I have three wires on the brake 🤔
 
dr_lulz said:
Now next problem:
The motor spins up nice, then starts braking very hard, then spins up again

i had to remove this piece of code, now it runs smooth

Code:
if (ui8_adc_id_current > ADC_PHASE_B_CURRENT_ZERO_AMPS_FOC_MAX) { ui8_angle_correction--; }
else if (ui8_adc_id_current < ADC_PHASE_B_CURRENT_ZERO_AMPS_FOC_MIN) { ui8_angle_correction++; }

i have also exchanged ++ and -- but only in the regen mode part, then it was also running good.

Just to be sure i have also checked current sensor voltage. Its 2.495V idle, 2.480 with motor running at 1amp phase current. At 66mv/A of the ACS712 30A this seems the be a little bit off. Probably broken now?
First, the signal wave on ACS712 can't be measured with a multimeter. The ~2.5V seems ok because should be the average value of the signal. I would say ACS712 is working ok.

The signal on ACS712 is this one on yellow line:
91-1.png

https://opensourceebikefirmware.bitbucket.io/development/Datasheets_and_application_notes--Endless-sphere.com_forum_messages--2017.10.23_-_FOC_and_no_FOC_comparison.html

I could not understand if it is working well or not and if so, what is the final code -- can you please explain? maybe step by step and numbering each step? I really want to understand and learn with your problem to see if I can improve the firmware.
 
First, the signal wave on ACS712 can't be measured with a multimeter. The ~2.5V seems ok because should be the average value of the signal. I would say ACS712 is working ok.

The signal on ACS712 is this one on yellow line:
91-1.png

https://opensourceebikefirmware.bitbucket.io/development/Datasheets_and_application_notes--Endless-sphere.com_forum_messages--2017.10.23_-_FOC_and_no_FOC_comparison.html

I could not understand if it is working well or not and if so, what is the final code -- can you please explain? maybe step by step and numbering each step? I really want to understand and learn with your problem to see if I can improve the firmware.

hmm you are right. Unfortunately i dont have an oscilloscope to measure this.

Right now i have 2 code versions that run the motor smooth:

"regen mode" disabled
Code:
		// minimum speed to do FOC
		if (ui16_motor_speed_erps > MOTOR_ROTOR_ERPS_START_INTERPOLATION_60_DEGREES)
		{
			// read here the phase B current: FOC Id current
			ui8_adc_id_current = UI8_ADC_MOTOR_PHASE_B_CURRENT;

			if (UI8_ADC_MOTOR_CURRENT > ui8_adc_motor_current_offset)
			{
				// motor mode
				if (ui8_adc_id_current > ADC_PHASE_B_CURRENT_ZERO_AMPS_FOC_MAX) { ui8_angle_correction++; }
				else if (ui8_adc_id_current < ADC_PHASE_B_CURRENT_ZERO_AMPS_FOC_MIN) { ui8_angle_correction--; }
			}
			/*else
			{
				// regen mode
				if (ui8_adc_id_current > ADC_PHASE_B_CURRENT_ZERO_AMPS_FOC_MAX) { ui8_angle_correction--; }
				else if (ui8_adc_id_current < ADC_PHASE_B_CURRENT_ZERO_AMPS_FOC_MIN) { ui8_angle_correction++; }
			}*/
		}

"regen mode" inverted, ++ and -- exchanged, not sure if this makes any sense at all

Code:
		// minimum speed to do FOC
		if (ui16_motor_speed_erps > MOTOR_ROTOR_ERPS_START_INTERPOLATION_60_DEGREES)
		{
			// read here the phase B current: FOC Id current
			ui8_adc_id_current = UI8_ADC_MOTOR_PHASE_B_CURRENT;

			if (UI8_ADC_MOTOR_CURRENT > ui8_adc_motor_current_offset)
			{
				// motor mode
				if (ui8_adc_id_current > ADC_PHASE_B_CURRENT_ZERO_AMPS_FOC_MAX) { ui8_angle_correction++; }
				else if (ui8_adc_id_current < ADC_PHASE_B_CURRENT_ZERO_AMPS_FOC_MIN) { ui8_angle_correction--; }
			}
			else
			{
				// regen mode
				if (ui8_adc_id_current > ADC_PHASE_B_CURRENT_ZERO_AMPS_FOC_MAX) { ui8_angle_correction++; }
				else if (ui8_adc_id_current < ADC_PHASE_B_CURRENT_ZERO_AMPS_FOC_MIN) { ui8_angle_correction--; }
			}
		}
 
casainho said:
We found the RAM registers that hold the torque sensor value and cadence :) The other developer, also a German guy, had to make code to print to UART in real time RAM and so he could identify the variables for cadence...!!

So it is not the original Tongsheng firmware but modified on assembler level!?

regards
stancecoke
 
dr_lulz said:
Right now i have 2 code versions that run the motor smooth:

"regen mode" disabled
"regen mode" inverted, ++ and -- exchanged, not sure if this makes any sense at all
So, when you say:
The motor spins up nice, then starts braking very hard, then spins up again
That was the ui8_angle_correction variable to go in the wrong direction (increasing or decreasing)... probably it start ok and then went to wrong values but after it wraps around and get's again on the correct value, etc, etc.

For some reason, when running in motor mode, the code was entering on the regen mode instead..... I need to see that.

If you can, please exchange this line:
Code:
if (UI8_ADC_MOTOR_CURRENT > ui8_adc_motor_current_offset)
to this:
Code:
if (UI8_ADC_BATTERY_CURRENT > ui8_adc_battery_current_offset)

The idea is to trigger regen mode only using battery current and not motor current. Battery current has a low pass filter on hardware and maybe that will help to not trigger the regen code on motor mode.
 
stancecoke said:
casainho said:
We found the RAM registers that hold the torque sensor value and cadence :) The other developer, also a German guy, had to make code to print to UART in real time RAM and so he could identify the variables for cadence...!!

So it is not the original Tongsheng firmware but modified on assembler level!?
Yes!! All started here, less than 3 weeks ago :)
casainho said:
Here is the TSDZ2 original firmware with an improvement to send motor current to LCD (still original LCD does not read motor current). This is mostly for developers/advanced users that may want to use LCD3 instead of the original LCD or some Arduino, etc.

TSDZ2_original_firmware-Flexible.zip

After disassembling we got good insights of some parts of the firmware do work. We could understand how data is sent to LCD and we could add our own function with the needed changes to send the current to the LCD.

Here is current disassembled file with our knowledge: https://docs.google.com/spreadsheets/d/1Zuv3ELZCQJf2eksGHNJ1gKZ7Hxlrk2OHaV0mXiXQ5Hs/edit?usp=sharing



 
casainho said:
If you can, please exchange this line:
Code:
if (UI8_ADC_MOTOR_CURRENT > ui8_adc_motor_current_offset)
to this:
Code:
if (UI8_ADC_BATTERY_CURRENT > ui8_adc_battery_current_offset)

that works! Motor running smooth. Seems like current is a little bit less as well
 
dr_lulz said:
casainho said:
If you can, please exchange this line:
Code:
if (UI8_ADC_MOTOR_CURRENT > ui8_adc_motor_current_offset)
to this:
Code:
if (UI8_ADC_BATTERY_CURRENT > ui8_adc_battery_current_offset)

that works! Motor running smooth. Seems like current is a little bit less as well
And how is regen working? It should work when you apply brakes, does the motor brake smooth or does it make vibrations?
 
casainho said:
Yes!! All started here, less than 3 weeks ago :)

OK, I saw that tables, but as I don't own a TSDZ2 any longer, I've not followed that topic.

Basia said:
Extra wire? I have three wires on the brake 🤔
Gives your brake lever a linear signal?!
I've modified a break lever to get a linear signal, see here.

index.php


You can use a thumbthrottle instead, also...

regards
stancecoke
 
dr_lulz said:
casainho said:
If you can, please exchange this line:
Code:
if (UI8_ADC_MOTOR_CURRENT > ui8_adc_motor_current_offset)
to this:
Code:
if (UI8_ADC_BATTERY_CURRENT > ui8_adc_battery_current_offset)

that works! Motor running smooth. Seems like current is a little bit less as well
Ok, I pushed that code to master branch.
 
stancecoke said:
Gives your brake lever a linear signal?!
I've modified a break lever to get a linear signal, see here.

index.php
Someday I hope to implement and use that brakes!!! Thanks for sharing.
 
casainho said:
And how is regen working? It should work when you apply brakes, does the motor brake smooth or does it make vibrations?

I am running a geared motor on my bench so its hard to tell if regen works. How to activate it? relase the throttle? Do i need the brake signal? Right now i did not notice any problems when releasing throttle.

Btw: is there active freewheeling implemented?
 
dr_lulz said:
casainho said:
And how is regen working? It should work when you apply brakes, does the motor brake smooth or does it make vibrations?

I am running a geared motor on my bench so its hard to tell if regen works. How to activate it? relase the throttle? Do i need the brake signal? Right now i did not notice any problems when releasing throttle.

Btw: is there active freewheeling implemented?
To get max regen, activate the brake signal (even if not mechanical braking). But release throttle will should not regen much.

Yes, freewheeling is implemented (I am almost sure. You can look at developement notes to see the PWM scheme used).
 
dr_lulz said:
I am running a geared motor on my bench so its hard to tell if regen works.
Oh wait, geared motor shouldn't regen due to the motor clutch. So, don't even use time about testing regen :)
 
I am thinking about running one of these controllers at 84V 100A and ~150-200 Phase amps so i will need at least 18 fet.
But i dont have space on my bike so i am thinking about building a little power stage on top of a 6fet version using 18x IRFB4110.
I will just remove the fets and caps and use the 6fet board as a logic provider only.

This is what i did so far

Schematic
schematic.JPG

Board Layout (55x90mm - same size as 6 fet board)
board.JPG

Fets will be placed backwards flat on the PCB so i can mount a nice heatsink like this on top
512Qih1MBrL._SY355_[1].jpg


I am still not sure where to place the big caps. My plan is to use at least 1000uF 100V caps which are HUGE! Hopefully they will somehow fit into the housing.
Its also not yet clear where to place the current sensor.... maybe i can use the smd variant and add a little solder bridge?

What do you think?
 
dr_lulz said:
using 18x IRFB4110
Why? Grab some CSD19536KCS instead, reduce RDSon by over a third. Might allow you to stick to 12 FETs too.

Or AOT290L. The 4110 are a pretty bad choice nowadays.
 
1N4001 said:
dr_lulz said:
using 18x IRFB4110
Why? Grab some CSD19536KCS instead, reduce RDSon by over a third. Might allow you to stick to 12 FETs too.

With both of these mosfets, use 20s li-ion max.

I tried 18fet swap to CSD mosfets and a 10A breaker trips when switching on the controller. (Without motor)

12fet stock fw and I think also this fw worked with these

I think that mosfet drivers may be too slow to sink the gate at 3 paralell (3x6), but I havent looked at it more.

If you plan to modify the drivers, please share.

You have 50A version of the current sensor, I think it will work up to 200A ok but there is 100,150, and 200A version too.
 
honya96 said:
1N4001 said:
dr_lulz said:
using 18x IRFB4110
Why? Grab some CSD19536KCS instead, reduce RDSon by over a third. Might allow you to stick to 12 FETs too.

With both of these mosfets, use 20s li-ion max.

I tried 18fet swap to CSD mosfets and a 10A breaker trips when switching on the controller. (Without motor)

12fet stock fw and I think also this fw worked with these

I think that mosfet drivers may be too slow to sink the gate at 3 paralell (3x6), but I havent looked at it more.

If you plan to modify the drivers, please share.

You have 50A version of the current sensor, I think it will work up to 200A ok but there is 100,150, and 200A version too.

honya96,

I have the same CSD mosfets I bought a while ago planning to replace them in the KT12 mosfet controller to get lower heating and higher power, on the paper CSD mosfets looked much better. Also I had thoughts of doubling them up to 24 MOSFET somehow, in the same controller. For this I guess gate resistor and gate sink resistors would need to be changed, providing that whatever is the gate driver can turn them on fast enough.

How is your 4110->CSD MOSFET swap going? I read few months ago it was not running well when you just swapped to CSD. Can you update?
 
1N4001 said:
dr_lulz said:
using 18x IRFB4110
Why? Grab some CSD19536KCS instead, reduce RDSon by over a third. Might allow you to stick to 12 FETs too.

Or AOT290L. The 4110 are a pretty bad choice nowadays.

well ... good point. I think i will go for the 12x CSD19536KCS. Much easier!
 
Who ever recorded the video process of the firmware on Windows 10? I can not install the firmware (((. direct drive motor.
 
Back
Top