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

Gaston said:
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.
48v controller is best for this battery voltage. That 6fet from pswpower works for me. Maybe they sell it cheaper on Aliexpress if only one unit order and you have more protection if it comes faulty.

http://s.aliexpress.com/3EZjIFrU?fromSns=Copy

I Confirm Geofft's recomendation of higher resisitance, if you will use 24/36v version. 48v version is running ok for me even at 14s battery (its hot, but works)
 
Great, count me on board !
I just ordered the other parts, so I unfortunately don't expect to have a running bike before April :(

The thing is on Ali are just available the 350W Controller (17A), but on their website are both the 350W P-KT36/48SVPRD-17A and the 500W P-KT36/48SVPRD-20A.
Not sure it's a big difference, but as the motor is 500W, will order the 20A one (in fact at same price, who would by 17A one??).
Or if you believe safe to have a spare one I should order 2?

I understood also need this ST-LINK/V2.
 
Gaston said:
Or if you believe safe to have a spare one I should order 2?

I understood also need this ST-LINK/V2.
Yes, order spare controllers and parts.
Follow the instructions here and see the material you need: https://opensourceebikefirmware.bitbucket.io/INSTALL_FIRMWARE.html
 
Gaston said:
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.
Thanks for the feedback!!

I think I am the only one planning to use regen when pedalling backwards. I am not using currently my direct drive motor ebike but I plan to do it soon and I will update the code for that feature and testing better :)
 
I increased max battery current and went to ride and discharge the battery, to see if the reducing duty_cycle for such that battery voltage never gets lower than ADC_BATTERY_VOLTAGE_MIN -- implemented by the following piece of firmware code:
Code:
  if (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--;
    }
  }

And works very well!!!!!!! And it is a great sensation to feel the motor support reducing when the battery gets near the ADC_BATTERY_VOLTAGE_MIN. The motor support reduces gradually, as I expected.

And I also found I bug, I think. My battery pack has 7 cells and I did configure ADC_BATTERY_VOLTAGE_MIN to be: 7 * 3.10 volts = 21.7 volts. But the LCD always did show to me as min voltage 21.0 volts..... here is the piece of firmware that defines that values:
Code:
#define BATTERY_LI_ION_CELLS_NUMBER 7
#define LI_ION_CELL_VOLTS_MIN 	3.10
#define ADC_BATTERY_VOLTAGE_MIN ((BATTERY_LI_ION_CELLS_NUMBER * LI_ION_CELL_VOLTS_MIN) / ADC_BATTERY_VOLTAGE_PER_ADC_STEP)
So, I guess the firmware is just considering 3 volts per cell and not 3.1 volts: 3 * 7 = 21 VERSUS 3.1 * 7 = 21.7

Me pedalling back to home, motor wasn't helping at that time :)

 
@Casainho - Great that it works and you like it!! :) have you tested the phase current limiting? I mean how different setting affects power at low to high speed..

Please take a look at the piece of log I sent few posts back. I hope its not my fault and waste of your time.

Btw now since the undervoltage works that well it should be settable in app, everyone will want different value. I'll go to 2.7v per cell
 
Gaston said:
Not sure it's a big difference, but as the motor is 500W, will order the 20A one (in fact at same price, who would by 17A one??).
Or if you believe safe to have a spare one I should order 2?

I understood also need this ST-LINK/V2.

You can ask seller on Ali to send you 20A but anyway its better to have more units so you can buy at pswpower. 17A vs 20A probably doesnt matter for us. Only mosfet type matters. I am safely pulling 25A from one stock 15A unit.... and planing to run modded 6fet at 50-60A :twisted:

STlink I bought cheapest on ali and works :wink:
 
honya96 said:
@Casainho - Great that it works and you like it!! :) have you tested the phase current limiting? I mean how different setting affects power at low to high speed..

Please take a look at the piece of log I sent few posts back. I hope its not my fault and waste of your time.

Btw now since the undervoltage works that well it should be settable in app, everyone will want different value. I'll go to 2.7v per cell
Yes, and did confuse me, as I didn't know the limiting was from motor or battery current. In the end, I put a big value for motor and I feel that is battery current that limits. I am using 12.5 amps of battery current. More than that and is more like a motor cycle (almost no need to make force on the pedals) when LCD assist power level is the max of 5.

Which log? Please post a link.

I have no time for the Java tool, better to go with config.h and main.h up to when I update the Java tool.
 
casainho said:
Which log? Please post a link.

I have no time for the Java tool, better to go with config.h and main.h up to when I update the Java tool.

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

I havent tried older versions of your fw now but flashing stancecoke's works
 
You need to use as reference config-example.h. Forget the java tool for now.
 
@Casainho - version from 30.1.2018 works as before (still lots of bugs known) on my table with gearmotor

But after the changes, sometimes no reaction to throtttle, if it starts it starts too fast so it almost falls from stand. Sometimes runs without throttle, sometimes blocks motor so hard so If I move it with my hand it pulls over 3A measured at one phase. It shows 700-950w at standby..... and more and more.

But somehow I still managed to feel it limiting power when low voltage so it looks like that works ok.

I'll wait with more testing until you try with direct motor, but I guess it will be good if someone else test on table too if he gets the same behavior.
 
honya96 said:
@Casainho - version from 30.1.2018 works as before (still lots of bugs known) on my table with gearmotor

But after the changes, sometimes no reaction to throtttle, if it starts it starts too fast so it almost falls from stand. Sometimes runs without throttle, sometimes blocks motor so hard so If I move it with my hand it pulls over 3A measured at one phase. It shows 700-950w at standby..... and more and more.

But somehow I still managed to feel it limiting power when low voltage so it looks like that works ok.

I'll wait with more testing until you try with direct motor, but I guess it will be good if someone else test on table too if he gets the same behavior.
On 2 Feb I started to add the PI controller.

You can try run without PI controller, just almost plain throttle -- you need to define EBIKE_THROTTLE_TYPE_THROTTLE_PAS_PWM_DUTY_CYCLE for that -- here is the piece of firmware that will apply:
Code:
void ebike_throttle_type_throttle_pas (void)
{
#if defined (EBIKE_THROTTLE_TYPE_THROTTLE_PAS_PWM_DUTY_CYCLE)
  uint8_t ui8_temp;
  float f_temp;

  f_temp = (float) (((float) ui8_throttle_value_filtered) * f_get_assist_level ());
  ui8_temp = (uint8_t) (map ((uint32_t) f_temp,
  			 (uint32_t) 0,
  			 (uint32_t) 255,
  			 (uint32_t) 0,
  			 (uint32_t) 255));
  motor_set_pwm_duty_cycle_target (ui8_temp);
  #endif

If you decided to define EBIKE_THROTTLE_TYPE_THROTTLE_PAS_CURRENT_SPEED, please test with P3 = 1, were PI controller will only control battery current and not wheel speed.

I think the issue of starting to fast, and probably after stop and then start again, is a PI controller oscillation. I did setup my KP and KI for my 24V S06S. The same ADC step for reading battery current, must be higher to your S12S, as it has bigger shunt so will have higher current. Also a step of duty_cycle on your 48V battery, also represent more output than on my 24v battery. So, in resume, please adjust KP and KI for battery current of PI controller.

Forget for now about shown LCD power value.
 
casainho said:
I think the issue of starting to fast, and probably after stop and then start again, is a PI controller oscillation. I did setup my KP and KI for my 24V S06S. The same ADC step for reading battery current, must be higher to your S12S, as it has bigger shunt so will have higher current. Also a step of duty_cycle on your 48V battery, also represent more output than on my 24v battery. So, in resume, please adjust KP and KI for battery current of PI controller.

Forget for now about shown LCD power value.

I am testing on 6fet first. At 36V

So now I was able to make it work kind of well without touching KP KI just by setting PWM rampup to 15, phase current 60 (lower than 20 oscilates)... etc. I dont know for sure what helped the most.

But still sometimes after releasing throttle and getting to low rpm it kind of kicked before stopping completly. No idea why.

Otherwise what still bothers me is the motor trying to pull power after releasing throttle - phases energized , current should be near zero, but when I block the motor fast it pulls 5A+ from battery.

now I understand more that its hard to avoid but I guess you will take a look at that more once you get to the direct drive?

You can think about or try how much slower the reaction will be if energizing the phases only while it gets input from throttle (as stock fw) and apply power then.

If it doesnt affect the reaction time too much it may be better?

I know we need backEMF but we can get it quite fast right?
 
honya96 said:
Otherwise what still bothers me is the motor trying to pull power after releasing throttle - phases energized , current should be near zero, but when I block the motor fast it pulls 5A+ from battery.

I think we should increase the slow loop frequency to at least 50Hz to improve that behaviour. If you let the phases float, you have to syncronize the PI-Controller to the wheel speed, if you enable the outputs again (when using a direct drive).

regards
stancecoke
 
stancecoke said:
If you let the phases float, you have to syncronize the PI-Controller to the wheel speed, if you enable the outputs again (when using a direct drive).
Float you mean energized or not? Can't we just watch the hall sensors output? Or see some feedback from phases even when they are completely off?

I'd prefer feeling completly no drag from motor (as when controller is off)

@Casainho - as I mentioned before, your fw blocks the wheel if you turn off the lcd while wheel rotates, stancecoke's does not. This can be a problem in case of lcd failure
 
honya96 said:
Float you mean energized or not?
Floating means, that the mosfets are not conducting, so you have the same behaviour, as the contoller is switched off. (of course the body diodes still rectify the Back EMF phase currents to the battery line)
Perhaps the wording is not exact, as normally you call a terminal floating, if it's not connected to a certain electrical potential.

honya96 said:
Can't we just watch the hall sensors output?
I'd prefer feeling completly no drag from motor (as when controller is off)

We have to find the right duty cycle to have zero battery/phase current when reactivating the PWM, this will take a certain time where you will feel braking or acceleration. So I think, it's better to have a fast current control (making the current going to zero very fast when releasing the throttle) in this way the PI controller is always up to date.

honya96 said:
@Casainho - as I mentioned before, your fw blocks the wheel if you turn off the lcd while wheel rotates, stancecoke's does not. This can be a problem in case of lcd failure

That's the only situation, when my code sets the phases floating: Undervoltage detection.

Code:
 else if(ui8_BatteryVoltage<BATTERY_VOLTAGE_MIN_VALUE){

      TIM1_CtrlPWMOutputs(DISABLE);
      uint_PWM_Enable=0; // highest priority: Stop motor for undervoltage protection
      ui32_setpoint=0;
      printf("Low voltage! %d\n",ui8_BatteryVoltage);
    }

regards
stancecoke
 
Now with 18fet controller - brake icon shows, throttle icon shows at startup, and if I add throttle it shows error message #6 - controller or motor has short circuit abnormality.

Can it be that I have 3 shunts in paralel? I am setting amps ~ 3 times lower than I would normally.

I also replaced original voltage regulator and resistor by dc-dc converter. (Worked with stock fw I think)
 
honya96 said:
Now with 18fet controller - brake icon shows, throttle icon shows at startup, and if I add throttle it shows error message #6 - controller or motor has short circuit abnormality.

Can it be that I have 3 shunts in paralel? I am setting amps ~ 3 times lower than I would normally.

I also replaced original voltage regulator and resistor by dc-dc converter. (Worked with stock fw I think)
That error message apears on LCD because you are applying throtttle but wheel is not moving / motor don't start up.

You can try comment the lines of duty_cyle++ and duty_cycle-- on PWM cycle code, that protects for under/over current and use the define option that setups direct throttle value to duty_cycle -- that way it should work or something on the hardware is missing.
 
I was testing (for now, only with wheel on the air) the firmware on my Q11 direct drive motor (rear wheel), 48V battery and S12S. I didn't changed anything about the PI controller.

First issue I had was that I exchanged the wires of throttle for PAS and vice-versa.

Then, the issue I found was that once I applied throttle and the motor was near the max duty_cycle, it would never stop. I solved by setup this values for regen current values (value of 0 or 1 would make motor never stop):
Code:
    motor_set_regen_current_max (2);
    ebike_app_battery_set_regen_current_max (2);

But maybe the issue would not happen when riding in real life, I am not sure. Anyway, it now seems to work as I expect.

With the wheel on the air, even if there is no throttle but I push the motor with the pedals, the duty_cyle target is zero (no throttle) but the duty_cycle (real duty_cycle applied to motor) increases in a way for the motor to not offer resistance to the force I apply to push the motor (because regen current is equal to a min value). I am curious to see what happens when I go down hill...

I could pedal up to max motor speed and then duty_cycle hits the max value, I then feel the motor blocking my force on the pedals and I see regen current flowing to battery on that situation, just as expected.

The code is on master branch and I wish I can ride tomorrow for testing....
 
I did some testing rides with the Q11 direct drive motor (rear wheel), 48V battery, S12S and torque sensor. I like the result!! For now, the only thing I miss from geared motor is the no vibrations -- this direct drive motor vibrates and I fell it, much better if they didn't exist like on geared motor.

I hope to test and ride my ebike more and after, add the code for the feature "Regen ebrake like coast brakes" that is in parallel branch and not on master branch.

Improvements:
- Because there was the issue of float operations on battery voltages, the motor was starting when I powered on the controller :-( -- I implemented the feature: Added protection for battery over voltage when firmware starts, to avoid unexpected motor starting
- Corrected float operations on battery voltage macros
- Found that my S12S has a different battery voltage ADC step: #define ADC_BATTERY_VOLTAGE_PER_ADC_STEP 0.262
S06S that I tested has a step of 0.272
- Improved current sent to LCD, so power seems to be correct (the LCD did show about 600W of motor at startup, with battery voltage of 57V and battery current limited to 12.5A --> 57*12.5 = 585W).
 
casainho said:
For now, the only thing I miss from geared motor is the no vibrations -- this direct drive motor vibrates and I fell it, much better if they didn't exist like on geared motor.

With high end controllers those vibrations doesnt exist and there is no resistance of the motor (you cant tell if controller is on or off) you cant guess by sound if you have throttle aplied or not, complete silence.

I have not tested yet after the last changes made but I was able to get it running kind of.

With 6 fet ok, with 18fet there is a kick when switching from 60 to 360° and when switching back to 60 at low rpm it spins faster for a while after the switch. (Without any throttle)

Tested same settings on both and also tried to compensate for different snesor. 18fet's phase hall sensor has 2.5v at zero current, but 6 fet has the one you said is 2V (not tested)
 
honya96 said:
Tested same settings on both and also tried to compensate for different snesor. 18fet's phase hall sensor has 2.5v at zero current, but 6 fet has the one you said is 2V (not tested)
@casainho: Where do you get this information from? From my experience and from internet informations the ACS712 has an output of 2.5V @Vcc=5V also....

regards
stancecoke
 
stancecoke said:
honya96 said:
Tested same settings on both and also tried to compensate for different snesor. 18fet's phase hall sensor has 2.5v at zero current, but 6 fet has the one you said is 2V (not tested)
@casainho: Where do you get this information from? From my experience and from internet informations the ACS712 has an output of 2.5V @Vcc=5V also....
I did measure with oscilloscope, I was looking at the phase current to measure the peak values and compare with valuea measured on shunt. I need to measure again and see!!!
 
honya96 said:
casainho said:
For now, the only thing I miss from geared motor is the no vibrations -- this direct drive motor vibrates and I fell it, much better if they didn't exist like on geared motor.

With high end controllers those vibrations doesnt exist and there is no resistance of the motor (you cant tell if controller is on or off) you cant guess by sound if you have throttle aplied or not, complete silence.
Thanks for the feedback. Maybe something is not correct... I hope we will understand what with time.

A friend that repairs electric bicycles and motor cycles, told me what Stancecoke also told recently - some motor cycle controllers, do regen a bit when user apply throttle and the motorcycle is moving, and I think we can do that with our hardware.
The thing is, if we release the motor phases then we don't have regen. Would you prefer to have no regen while riding an ebike?? Well, for motorcycles, my friend told me it can be like when user releases the throttle, it open motor phases and when user then apply regen, it starts regen -- maybe you are riding more like a motorcycle.
 
Back
Top