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

casainho said:
honya96 said:
My smaller "big" bike can take 50A battery regen current if overvoltage limited... just saying

VESC config looks good, would love to have same with kunteng :) and I hope the way you are implementing will do the job for this summer.
At slow loop 10Hz, using PI controller, only motor phase current is being controlled for the value defined by the rider, using for instance, the throttle.

The max values limits are controlled every PWM cycle. I think is easy to understand my implementation, because it seems "quick and dirty". And as you can see, controlling battery overvoltage is done

Consider adding under voltage also if its not done yet. So we dont get cut, but reduced power. :wink:

I hope I can test soon, expect real next level compared to last I tested (atleast for my application)
 
Forgot to say that battery undervoltage is done on slow loop: it just stops the motor and signals that state to LCD.

Don't know if is logic to have battery limits in different places and done at very different frequencies. Anyway, for now it is done like that and works for me.
 
casainho said:
I will consider that I read battery and motor currents.

"motor current" is a much better wording than "phase current" :) But I don't know, if it helps to avoid burning FETs, as we still don't know the phase current.... (except Phase B, where we have the additional ACS711/712 sensor).

Regards
stancecoke
 
Geoft has probably tested more than me so he can tell and say what Amp setting he used vs stock

I don't think I can help too much with this, current limiting isn't something I've needed to pay much attention to. I'm guessing that with my (relatively low powered) motor the current limit is more controlled by the saturation point of the motor windings than any firmware control.

I set the firmware limit to 20amps but never see the actual draw above about 17a so I'm presuming this is the motor maxed out. I'm happy to help with this though, if there's anything you want me to try just say..... :)
 
The code is now on master. I tested with some real rides and works well. Only one thing: on a geared motor, external speed sensor is a must other way motor blocked detection will fail.

Fast loop/PWM cycle limits:
// - limit battery overvoltage
// - limit battery max current
// - limit motor max current
// - limit battery max regen current
// - limit motor max regen current
// - limit motor max ERPS
Slow loop at 10Hz limits battery undervoltage.

Slow loop at 10Hz reads throttle/PAS/torque sensor and uses a PI controller to control battery current and wheel speed (P3 = 0). With P3 = 1, wheel speed is not controlled, only battery current. For this control, battery current and wheel speed are scaled based on LCD assist level value.
 
Does this work also with mid-drive motors like the Bafang BBSHD? I'd like to buy the S12S for a 48V battery pack.
 
racingame said:
Does this work also with mid-drive motors like the Bafang BBSHD? I'd like to buy the S12S for a 48V battery pack.
I think Stancecoke is the only one that tested on such motors.
 
@Casainho - I suggest adding battery low voltage to fast loop also if possible, tuned well, you will apreciate that when running out of juice with batteries that have noticeable voltage sag. (Actually the better ones-I can explain) overvoltage is less neccesary to have at fast loop than lowvoltage, if we cant do both. Curious if the stm8 can handle.
 
honya96 said:
@Casainho - I suggest adding battery low voltage to fast loop also if possible, tuned well, you will apreciate that when running out of juice with batteries that have noticeable voltage sag. (Actually the better ones-I can explain) overvoltage is less neccesary to have at fast loop than lowvoltage, if we cant do both. Curious if the stm8 can handle.
I don't really understand what you mean. Please give more details, how should be impleemented, etc. You can makesome drawings.
 
casainho said:
Fast loop/PWM cycle limits:
// - limit battery overvoltage
// - limit battery max current
// - limit motor max current
// - limit battery max regen current
// - limit motor max regen current
// - limit motor max ERPS
+limit battery undervoltage

As I understand in one pwm cycle if it senses overvoltage it lowers duty cycle - so it tries to hold max regen current set possible to maintain that voltage?

If yes, its more important to have this at undervoltage, but both is best if possible.

Is it enough explanation?
 
casainho said:
racingame said:
Does this work also with mid-drive motors like the Bafang BBSHD? I'd like to buy the S12S for a 48V battery pack.
I think Stancecoke is the only one that tested on such motors.

The firmware works with a Shengyi 48V Middrive Motor (used in 2016 "Fischer" - E-Bikes).
The testing with a yamaha middrive is ongoing but not satisfying yet.
We have not tested a Bafang middrive so far.

regards
stancecoke
 
What differences there are between displays? Dunno which one to take between S-LED890, S-LCD1, S-LCD3, S-LCD5, S-LCD6.
 
racingame said:
What differences there are between displays? Dunno which one to take between S-LED890, S-LCD1, S-LCD3, S-LCD5, S-LCD6. Also, is it ok if the original motor is sensorless (it has dedicated speed sensor cable)?
About the motor controller, please read which ones were tested:
https://opensourceebikefirmware.bitbucket.io/CHOOSE_MOTOR_CONTROLLER.html

About tested LCDs: https://opensourceebikefirmware.bitbucket.io/FLEXIBLE_OPENSOURCE_FIRMWARE.html
 
honya96 said:
As I understand in one pwm cycle if it senses overvoltage it lowers duty cycle - so it tries to hold max regen current set possible to maintain that voltage?

If yes, its more important to have this at undervoltage, but both is best if possible.
Overvoltage only happens when current is "negative", flowing to battery. So it is verified if is happening regen (negative current):
Code:
(ui8_adc_battery_current < ui8_adc_battery_current_offset)
And if voltage is overvoltage:
Code:
(UI8_ADC_BATTERY_VOLTAGE >= ((uint8_t) ADC_BATTERY_VOLTAGE_MAX))
Hmmm, so this means that I can improve by not checking if current is negative, as it is redundant.

When overvoltage happens, duty_cycle should be increased to reduce regen current. The inverse way you are suggesting for undervoltge, we should reduce duty_cyle.

There are some catchs here:
- if we start with battery with overvoltage, motor will accelerate to max speed!! Maybe start firmware by reading battery voltage e hang with an alert, never start the motor in this case.
- when testing/develop with a lab power supply and try do regen, the motor will accelerate to max speed, as the power supply capacitors charge and the voltage increases, etc.

Now I understand what you mean and I think is a good idea: battery current flowing to motor will be reduced if user ask more that what battery can give while maintain min safe voltage!! Seems a good idea, better than actual implemented behavior. I will test it!! :)
 
casainho said:
When overvoltage happens, duty_cycle should be increased to reduce regen current. The inverse way you are suggesting for undervoltge, we should reduce duty_cyle.

There are some catchs here:
- if we start with battery with overvoltage, motor will accelerate to max speed!! Maybe start firmware by reading battery voltage e hang with an alert, never start the motor in this case.
- when testing/develop with a lab power supply and try do regen, the motor will accelerate to max speed, as the power supply capacitors charge and the voltage increases, etc.

Now I understand what you mean and I think is a good idea: battery current flowing to motor will be reduced if user ask more that what battery can give while maintain min safe voltage!! Seems a good idea, better than actual implemented behavior. I will test it!! :)

Oh right, my fault.

I don't exactly undestand the part not quoted but dont think its necesary?

About the "catchs" you got

Edit: Now I see what you mean. That should be there for safety. But I dont know why would the motor start withou throttle input anyway.

You should set overvoltage slightly higher than your charger.

If your charger leaves battery siting with 4.16v per cell steady

Bms detects overcharge at 4.25v+ and balances at 4.18+ for most. (This varies)

Controller overcharge can be 4.2V+ (if your bms has higher or custom value, you can use overvoltage even 4.3V, then you can slightly regen even with "full battery" and it does not harm 18650's much. Believe me!

Regen will get stronger as the battery discharges

Above is actually as its done, for example Tesla regens well right off the charger. (You charge 80-90% mostly) same you can do with ebike if you want strong regen right from charger, most "better" chargers have voltage potenciometer inside.
 
Done about protecting battery undervoltage on fast loop only. I did a ride of 40 minutes but wasn't enough to discharge enough my battery (flat lands here) so I could not test this new feature.
Here is the relevant piece of code (it is now on master branch):
Code:
  /****************************************************************************/
  // PWM duty_cycle controller:
  // - limit battery overvoltage
  // - limit battery undervoltage
  // - limit battery max current
  // - limit battery max regen current
  // - limit motor max current
  // - limit motor max regen current
  // - limit motor max ERPS
  // - ramp up/down PWM duty_cycle value

  if ((UI8_ADC_BATTERY_CURRENT > ui8_adc_target_battery_current_max) || // battery max current, reduce duty_cycle
      (ui8_adc_battery_current > ui8_adc_target_motor_current_max) || // motor max current, reduce duty_cycle
      (ui16_motor_speed_erps > MOTOR_OVER_SPEED_ERPS) || // motor speed over max ERPS, reduce duty_cycle
      (UI8_ADC_BATTERY_VOLTAGE < ((uint8_t) ADC_BATTERY_VOLTAGE_MIN))) // battery voltage under min voltage, reduce duty_cycle
  {
    if (ui8_duty_cycle > 0)
    {
      ui8_duty_cycle--;
    }
  }
  // verify if there is regen current > 0 (if there is happening regen) and
  // if battery voltage is over or equal to absolute battery max voltage, and if so
  // reduce regen current -- the idea is to avoid overcharge the battery
  else if (((ui8_adc_battery_current < ui8_adc_motor_current_offset) &&
      (UI8_ADC_BATTERY_VOLTAGE >= ((uint8_t) ADC_BATTERY_VOLTAGE_MAX))) ||
      (UI8_ADC_BATTERY_CURRENT < ui8_adc_target_battery_regen_current_max) || // verify battery max regen current limit
      (ui8_adc_battery_current < ui8_adc_target_motor_regen_current_max)) // verify motor max regen current limit
  {
    if (ui8_duty_cycle < 255)
    {
      ui8_duty_cycle++;
    }
  }
 
A friendly user of the "pedelecforum" sent me a logfile of the communication between the Kunteng App and the controller.
See my first findings here.

regards
stancecoke
 
>>> Loading file main.ihx in PROGRAM MEMORY image in computer
(API) ERROR : No such file or directory

from both java tools

HighSpeed branch flashing works.

BTW @stancecoke - variable regen at x4 should be option in tool, I tested another 6fet and it does not run

edit: well its not the problem, I tried setting cal A,B etc. but dont remember how it was done....
sometimes starts itself but no reaction to throttle

I would like to stick with main branch. moving your functions there will be great. :wink:
 
honya96 said:
BTW @stancecoke - variable regen at x4 should be option in tool, I tested another 6fet and it does not run

You are right, with newer 6FET board revisions, you have to pull x4 to ground, as they have the external pull up too. So we should make regen switchable in the Java-tool.
Have you ever tried the "Thumb-Brake" on the road?

And yes, we should skip using different forks and concentrate on the master branch. I think we are proceeding in the right direction with the last changes, casinho made :)

regards
stancecoke
 
I have not tested, I was waiting for the current limiting because direct motor was still blowing mosfets :lol: but you tested it right?

Yes, if the last changes will work we basicaly have the most advanced controller on planet :lol: ,just missing the "true" FOC. But no stock controller does the under and overvoltage that well as this implementation should be.
 
honya96 said:
but you tested it right?

only on the workbench yet. We have -10°C here in Munich at the moment, brrrr. Far to cold to do a test ride :)
Burning mosfets may happen with a blocked wheel, :| as there is no active limitation of the phase current in my branch!

regards
stancecoke
 
stancecoke said:
honya96 said:
but you tested it right?

only on the workbench yet. We have -10°C here in Munich at the moment, brrrr. Far to cold to do a test ride :)
Burning mosfets may happen with a blocked wheel, :| as there is no active limitation of the phase current in my branch!

regards
stancecoke

Same temps here..

In my case its caused by too big/fast motor for 6fet,
60v mosfets, and happend at standstill everytime so I hope that current limiting will prevent that and enable us to use "any" motor. :) I upgraded one 6fet to stp80nf70 (stock) and one to csd19536kcs (for 72v at 3kw+!) mosfets so that should not be a problem anymore. :D
 
I just joined endless-sphere for this interesting project.
I'm building my first ebike and would use your firmware, I indeed love the idea of Regen commanded like roller brake (pedalling backward), it's such a great feature ! My bike will have FWD Mxus 500W motor & 48V (12S) battery.

BMSbattery do not sale de S06 in this voltage and the S12 is just horribly too big IMO.
What you think of pswpower.com? They have a compact 10A/20A.max controller "P-KT36/48SVPRD-20A", just 96x61x35mm.

If you confirm it might work, I will be happy to join you testing this promising project !
 
BMSbattery do not sale de S06 in this voltage and the S12 is just horribly too big IMO.
What you think of pswpower.com? They have a compact 10A/20A.max controller "P-KT36/48SVPRD-20A", just 96x61x35mm.

If you confirm it might work, I will be happy to join you testing this promising project !

I'm using the PSWpower controllers you mention and can confirm they work just fine with this firmware project. The pcb layout is slightly different from the BMS S06S versions but the connection points for the STlink are fairly obvious when you look at the pcb.

The only issue I had with these was the LM317 voltage regs running very hot when operated at 12s. I fit them with heatsinks which helps, may also try a slightly higher resistance series resistor sometime to drop the input voltage (to the LM317) a little more.
 
Back
Top