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

ui16_time_ticks_between_pas_interrupt only gets updated when ui8_PAS_Flag == 1 otherwise it keeps it's initial value of 64000L.
ui8_PAS_Flag only gets to 1 if there was an interrupt on the PAS__PORT which is GPIOD which is address GPIOD_BaseAddress which is 0x500F

For what you describe to happen you PAS__PORT might be floating. Otherwise ui16_time_ticks_between_pas_interrupt_smoothed should be always 64000L>>3 which is also >timeout.

But what do I know, maybe someone else can debug :wink:
 
Xnyle said:
ui16_time_ticks_between_pas_interrupt only gets updated when ui8_PAS_Flag == 1 otherwise it keeps it's initial value of 64000L.
ui8_PAS_Flag only gets to 1 if there was an interrupt on the PAS__PORT which is GPIOD which is address GPIOD_BaseAddress which is 0x500F

For what you describe to happen you PAS__PORT might be floating. Otherwise ui16_time_ticks_between_pas_interrupt_smoothed should be always 64000L>>3 which is also >timeout.

But what do I know, maybe someone else can debug :wink:

Ahh yes! That makes sense, remember I was getting switching noise on my ADC inputs. On a high speed Input with an interrupt this could be the issue! PAS flag must be getting set when the PWM first gets enabled
I will confirm later today. Thank you for the help btw :thumb:

Also, should I just be running in Torque mode if I only have a throttle? Does this solve my issues altogether?

EDIT:
I still stand by my statement that time_ticks_smoothed starts at 0 and works it's way up. Just run the following and see what I mean. Or ignore it and we'll all just move on.
Code:
#include <stdio.h>

int PAS_is_active = 0;
int ui16_time_ticks_between_pas_interrupt = 64000;
int ui16_s_ramp_start = 1500;
int ui16_aca_flags = 0;
int TQ_SENSOR_MODE = 0;
static int ui32_time_ticks_between_pas_interrupt_accumulated = 0;
static int ui16_time_ticks_between_pas_interrupt_smoothed = 0;
int ui8_i;

int main(void) {
  for (ui8_i = 0; ui8_i < 8; ui8_i++) {
  if ((!PAS_is_active||(ui16_time_ticks_between_pas_interrupt > ui16_s_ramp_start)) && ((ui16_aca_flags & TQ_SENSOR_MODE) != TQ_SENSOR_MODE)) {
    ui32_time_ticks_between_pas_interrupt_accumulated += ui16_s_ramp_start;
  } else {
    ui32_time_ticks_between_pas_interrupt_accumulated += ui16_time_ticks_between_pas_interrupt;
  }
  ui16_time_ticks_between_pas_interrupt_smoothed = ui32_time_ticks_between_pas_interrupt_accumulated >> 3;//smoothed is defined in ACAcontrollerState as = 0
  printf("time_ticks = %u\r\n", ui16_time_ticks_between_pas_interrupt);
  printf("Smoothed = %u\r\n", ui16_time_ticks_between_pas_interrupt_smoothed);
  }
  return 0;
}
 
It doesn't, it starts at ui32_time_ticks_between_pas_interrupt_accumulated>>3 which starts at timeout, not at 0 as in your code.

You can let it start at timeout <<3 which would be more correct but I doubt that solves your problem.
 
Xnyle said:
It doesn't, it starts at ui32_time_ticks_between_pas_interrupt_accumulated>>3 which starts at timeout, not at 0 as in your code.

You can let it start at timeout <<3 which would be more correct but I doubt that solves your problem.

Ah, yes you are correct accumulated starts at Timeout, thanks for that :wink: . Changing that in the example I provided above actually helps my case and shows that it matches up with my debugging.

Code:
#include <stdio.h>

int PAS_is_active = 0;
int ui16_time_ticks_between_pas_interrupt = 64000;
int ui16_s_ramp_start = 64000;
int ui16_aca_flags = 0;
int TQ_SENSOR_MODE = 0;
static int ui32_time_ticks_between_pas_interrupt_accumulated = 3125;
static int ui16_time_ticks_between_pas_interrupt_smoothed = 0;
int ui8_i;

int main(void) {
  for (ui8_i = 0; ui8_i < 8; ui8_i++) {
      ui32_time_ticks_between_pas_interrupt_accumulated -= ui32_time_ticks_between_pas_interrupt_accumulated >> 3;
  if ((!PAS_is_active||(ui16_time_ticks_between_pas_interrupt > ui16_s_ramp_start)) && ((ui16_aca_flags & TQ_SENSOR_MODE) != TQ_SENSOR_MODE)) {
    ui32_time_ticks_between_pas_interrupt_accumulated += ui16_s_ramp_start;
  } else {
    ui32_time_ticks_between_pas_interrupt_accumulated += ui16_time_ticks_between_pas_interrupt;
  }
  ui16_time_ticks_between_pas_interrupt_smoothed = ui32_time_ticks_between_pas_interrupt_accumulated >> 3;//smoothed is defined in ACAcontrollerState as = 0
  printf("time_ticks = %u\r\n", ui16_time_ticks_between_pas_interrupt);
  printf("Smoothed = %u\r\n", ui16_time_ticks_between_pas_interrupt_smoothed);
  }
  return 0;
}

Code:
ui16_current_cal_b = 324
System initialized
PAS_is_active = 0
PAS_timetickacc = 66735
PAS_timetick = 64000
PAS_timetick smooth = 8341
ui8_temp = 2
battcurrmax = 800
current target = 16
float_temp = 25
ui16_time_ticks_between = 8341
ui16_s_ramp_end = 1500
ui16_s_ramp_start =  64000
Current Target = 338
cutoffSP in = 5
cutoffSP out = 5
update setpoint 5
PAS_is_active = 0
PAS_timetickacc = 122394
PAS_timetick = 64000
PAS_timetick smooth = 15299
ui8_temp = 5
battcurrmax = 800
current target = 40
float_temp = 22
ui16_time_ticks_between = 15299
ui16_s_ramp_end = 1500
ui16_s_ramp_start =  64000
Current Target = 354
cutoffSP in = 6
cutoffSP out = 6
update setpoint 6
PAS_is_active = 0
PAS_timetickacc = 171095
PAS_timetick = 64000
PAS_timetick smooth = 21386
ui8_temp = 8
battcurrmax = 800
current target = 64
float_temp = 19
ui16_time_ticks_between = 21386
ui16_s_ramp_end = 1500
ui16_s_ramp_start =  64000
Current Target = 367
cutoffSP in = 6
cutoffSP out = 6
update setpoint 6
PAS_is_active = 0
PAS_timetickacc = 213709
PAS_timetick = 64000
PAS_timetick smooth = 26713


You need to understand that what causes the wheel rotation at startup is the setpoint being written to. It gets written to via float_temp, which is determined by ui16_time_ticks_between_pas_interrupt_smoothed not ui16_time_ticks_between_pas_interrupt

ui16_time_ticks_between_pas_interrupt_smoothed starts at 0 and after 8 samples reaches 64000 after a total of 64 iterations of the first code snip I posted above.

I have patched my code to work by setting
Code:
static int ui32_time_ticks_between_pas_interrupt_accumulated = 8*64000;
My motor works perfectly now that the smoothing is initialized to the correct value, no more jogging on startup.
 
Wiki: https://github.com/stancecoke/BMSBattery_S_controllers_firmware/wiki
Controller should both work, read wiki for info on pimping square wave (ACS712) :)
Regen braking working fine on direct drive including overvoltage protection, 5 step adjustable via app or additional regen throttle.
again, read wiki :)

If you want to improve the wiki, make it easier to understand for newcomers that would be greatly appreciated.

For the time being, make sure, you read the complete wiki twice, that should answer a lot of "stupid" questions.
 
I just flashed latest firmwire and set in config offroad speed, limit and without PAS to 50 kph but no change in speed. i do nat have pas it is electric scooter.

system is 36v with 250w motor.

Is there anybody who can help me?

Thanks

Žiga
 
Can't write for anyone else, but I won't until you don't prove you read

https://github.com/stancecoke/BMSBattery_S_controllers_firmware/wiki

by posting some kind of useful information.
 
Hi!

I was thinking that there is some kind of limit that does not allow me to go over 25 but i think i am limited with KV value of motor.

Am I right?

https://drive.google.com/open?id=1YMAPp_oPF0nFRUqq4wt5RT-dm3O_hVzp (motor)
https://drive.google.com/open?id=1QMSh8SQHg54idE_SiE8d0wnSn1ioV4ou (controller)
 
stancecoke said:
I'm using the BionX IGH3 with our firmware. It's completely quiet except small resonance vibrations in the range of 12-14 km/h.
stancecoke

hi,stancecoke
with my direct motor the small resonance vibrations in the range of 11-12km/h,could it be fixed?
 
Hello,
I have KT36/48SVPRK-SLS02G version of KT controller (45A, 18 mosfets) with reverse function.
I am considering changing software to increase the maximum current but I have to use reverse function witch unfortunately wasn't probably implemented in the OpenSource firmware.
I have not analyzed the source code yet, but can you tell me if it would be difficult to add such functionality?
 
You'd have to change interpolation in motor.c and also disable or rework angle correction there. Also you'd have to implement something in display.c or BOdisplay.c to set or reset the new reverse flag you will have to introduce.

If you write nice code and don't just hack it in some way, we might be able to merge a pull request.
 
uploader18 said:
i think i am limited with KV value of moto
Yes, you have to use a battery with higher voltage or you have to use field weakening (not recommented)

haiyi911 said:
with my direct motor the small resonance vibrations in the range of 11-12km/h,could it be fixed?
It's a mecanical problem, you can try to increase/decrease the tension of the spokes, but that might just shift the resonance range...

Xnyle said:
You'd have to change interpolation in motor.c

not only the interpolation, but the angle assorted to the hall events, too. In reverse direction, 60° is followed by 0°, not 120°.

regards
stancecoke
 
Xnyle said:
You'd have to change interpolation in motor.c and also disable or rework angle correction there. Also you'd have to implement something in display.c or BOdisplay.c to set or reset the new reverse flag you will have to introduce.

If you write nice code and don't just hack it in some way, we might be able to merge a pull request.

Thank you for the information, I will take a closer look at it and maybe try to do some tests to find out how it all works.
 
stancecoke said:
It's a mecanical problem, you can try to increase/decrease the tension of the spokes, but that might just shift the resonance range...
regards
stancecoke

Thanks for your infomation, :D i tried other controller and the motor run well,so i think that the problem can be fixed by some way.
 
stancecoke said:
Was the other controller a square wave or a sinosodial one?

regards
stancecoke

it was sinosodial controller.And there was a strange phenomenon the throttle was full but the motor kept standstill,just like the motor stopped at special position,the motor couldnot be started.
 
So those resonances seem to be a commutation issue after all, although I have no idea what might cause them.

not only the interpolation, but the angle assorted to the hall events, too. In reverse direction, 60° is followed by 0°, not 120°.

Ofc iterpolation has to go backwards then and maybe also you'd have to add -120° (or -60°?) to the table lookup (also not sure if motor angle would be the same for forward and backward rotation)

But the (virtual) angle itself assorted to the hall events doesn't change!?
 
stancecoke said:
It's a mecanical problem, you can try to increase/decrease the tension of the spokes, but that might just shift the resonance range...

No, this is not a "mechanical" problem, it is absolutely exactly a software problem. Or, perhaps, hardware problems (signal filtering, interference) of the KT controllers themselves.
I tested the original KT firmware (sine and square version) on 7 different gear (rear :)) motors - Bafang, Mxus, and Shengyi. They all had the same problem - the resonances and vibrations of the bike frame and equipment of the bike at a speed of 5-8 km / h, and at a speed of 11-13 km / h. Exactly the same problem with open source firmware. Which is a bit strange.
BTW - Mxus XF15R has good mechanics and an absolute lack of even the slightest vibrations and resonances on a cheap "trapezoid" chinese DMHC controller (I quoted the link above). My other motors also work smoothly without vibration. All this is easy to check - just take another (not KT) controller and check the operation of the motors. Vibration will not be
All this is very sad.
P.S. My KT controllers s have 25 kOhm resistors, instead of "standard" 2.2-2.5 kOhm between + 5V and the signal output of the hall sensors(open collectors). Perhaps - the problem is this, the signals are too "dirty" - the pulses from the motor windings can distort the signals from the hall sensors....
 
Does this cheap "trapezoid" even do PWM?

I recently added a trapezoid wavetable, you could test that by changing a few lines in motor.c

But ofc this "trapeziod" ist still generated via PWM. Maybe it's simply the PWM frequency on the KT controllers.

Can we change that at all? Edit yes we can and we did, high speed setting, which btw. doesn't change anything as well :(

So many questions, so few answers ;)

Edit: You can almost certainly exclude hall sensor problems. I experimented a lot, tested 360° interpolation (basically disabling them), logged jitter, implemented anti jitter. All this had minimal to zero effect. There isn't much jitter btw.

Edit2: anyone tested PWM dead times >1us? the comment "hardware nees a dead time of 1us" might be for a 24V 6fet controller? Dead time distortion shouldn't become a problem, if dead time is < 1% of PWM frequency, right?
 
kkm said:
No, this is not a "mechanical" problem, it is absolutely exactly a software problem. Or, perhaps, hardware problems (signal filtering, interference) of the KT controllers themselves.

OK, but it can't be a software problem. I have a buck converter for supplying the head- and rearlights on my bike. Even if the battery is not installed at all and the controller is switched off, the resonaces appear when the lights are switched on. The direct drive motor is working as a generator via the body diodes of the mosfets in this case. So it can't be a matter of PWM or commutation.

This leaves only a hardware problem as the cause of the resonances.
Capacity and inductivity may be in an unfavourable relation.

regards
stancecoke
 
Then the remaining question is: Can we do something about it via software.

If we can that would be great, because then we're better than the original FW in yet another area.

I don't have the equipment to even figure out what's going on. If someone has a fancy oscilloscope he could probably just hook up a motor to it (3 phases and hall sensor signals), apply some resistance to the motor, twist and fix the throttle until resonances appear and then create a few dumps/screenshots so we at least know what might be going on.
 
Hi Folks,

I'm very interested in the KT controller specially if it can support the Bafang SW102 display device (also have G310 rear hub motor).

https://www.amazon.com/BAFANG-Display-Available-Electric-Bicycle/dp/B07MW261M8/ref=sr_1_11?keywords=bafang+display&qid=1551420497&s=gateway&sr=8-11

Does someone know if this display is or could be supported by a KT controller ?
 
Hi, i'm trying to set this software up and finding it super confusing. I've followed the links in the website linked at the beginning of this thread and can't find what is mentioned for a few links. Where are the most up to date and simple step by step instructions for getting set up? I can use Mac, Windows XP or Windows 10, whichever is better for this. Thanks!

I've had trouble finiding the correct SDCC files. I download the linked files and the setup Install.txt file tells me to click sdcc-3.9.0-setup.exe but it's not in the downloaded files.

I've installed Java Runtime, but can't launch OSEC Parameter Configurator.jar

Thanks!
 
davideserin said:
Hi, i'm trying to set this software up and finding it super confusing. I've followed the links in the website linked at the beginning of this thread and can't find what is mentioned for a few links. Where are the most up to date and simple step by step instructions for getting set up? I can use Mac, Windows XP or Windows 10, whichever is better for this. Thanks!

I've had trouble finiding the correct SDCC files. I download the linked files and the setup Install.txt file tells me to click sdcc-3.9.0-setup.exe but it's not in the downloaded files.

I've installed Java Runtime, but can't launch OSEC Parameter Configurator.jar

Thanks!

I was trying to install in XP and failed. Tried in Wiindows 10 and it was straight forward. Solved!
 
Pegazus said:
if it can support the Bafang SW102 display device

You can use a eggrider display, it uses the same hardware and is available with Kunteng protocol, as far as I know.


davideserin said:
Where are the most up to date and simple step by step instructions for getting set up?

See my signature.

regards
stancecoke
 
Back
Top