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

@Stancecoke - I wasnt able to get your fw running, but I like the possibility of setting exact wheel circumference, throttle min max (regen lever min max will be good also) and undervoltage limit :wink:

I discovered more "bugs" on the main branch with bike on stand. now with direct motor, I doesnt start by throttle until PAS 3 or more (weird, should be 100% still, maybe only my case?) after motor stopping correction, it will brake hard (with direct motor) everytime you release throttle.
LVC behavior is better than original in shorter cut time, but it also brakes. will be great if it cut (not brake) and recover like 3 times a second, if not a smooth power decrease until lvc voltage at 0 power ouput. thats the best it can get.

btw, how to set to show the right speed on lcd3? P1 and wheel size works?
 
honya96 said:
@Stancecoke - I wasnt able to get your fw running,

Hmm, which board revision did you use? KTE-SVPxxx???
It is a little difficult to do a remote diagnosis, I guess it's a problem with the current measurement calibration.

regards
stancecoke
 
mtdr sent his KTE-SVP7-Board controller to me. It does'nt work with the master branch properly. I get the same behaviour that he described with my Shengyi-Middrive motor.
With the firmware from the torque-simulation branch, it works with no problems, after setting the right value for the battery current cal b value (-310 is right for this specific controller)

@honya96: you can try values between -312 and -320 to make your motor run with the torque simulation fork. And make sure, that you set the ride mode to "Throttle" first (and use throttle of course ;)), for the initial tests...

regards
stancecoke
 
I have svp5, will try. But my works with main branch kind of.. does the lcd connector have to be shorted by the original plug? Or just b+ to ignition.
 
honya96 said:
does the lcd connector have to be shorted by the original plug? Or just b+ to ignition.

You can use the LCD3 for switching on the system, but it will have no further function. Or just short b+ to ignition, that works too.

regards
stancecoke
 
casainho said:
stancecoke said:
geofft said:
Would it be possible point me (and others..) to the number(s) in the code that need to be changed so we can do our own calibrations to the wattmeter?

You would have to scale the read value in the ebike_app.c

Code:
i8_motor_current_filtered_10b = motor_get_current_filtered_10b ();
  i8_motor_current_filtered_10b -= 1; // try to avoid LCD display about 25W when motor is not running
  if (i8_motor_current_filtered_10b < 0) { i8_motor_current_filtered_10b = 0; } // limit to be only positive value, LCD don't accept regen current value
ui8_tx_buffer [8] = (uint8_t) (i8_motor_current_filtered_10b*120/100);

With the expression *120/100 you would increase the displayed value by 20%.
Casainho has already implemented an offset.
Almost there...
i8_motor_current_filtered_10b * 120 will overflow if
i8_motor_current_filtered_10b > 2, because that variables are 8 bits and just hold as max 255.

I needed to reduce the reading to 60% of that displayed. To my simple mind I thought that (......_10b * 6/10) might work without overflow, so I tried it - and it does..:shock:

Not sure if that makes any sense but like I say - it works for me.
 
geofft said:
to 60% of that displayed. To my simple mind I thought that (......_10b * 6/10) might work without overflow, so I tried it - and it does..:shock:

Not sure if that makes any sense but like I say - it works for me.
Maybe reding 50% will be ok, so would be:
Variable = variable >> 1;
 
stancecoke said:
@honya96: you can try values between -312 and -320

Tried -250 to -390. Stanby still 4.6w, very hard to turn wheel and clicks when turning. No response to throttle. Tried also lower cut off voltage, wider throttle range voltage.
 
Can you please implement an option to have 100% throttle whatever the PAS level at main branch? As geofft asked allready.. and pas speed limit later?

and probably just for me, :roll: would be great to have external switch for throttle limit (replacing original cruise wire for example) with configurable % power limitation.

It will be needed with higher power.
 
honya96 said:
Tried -250 to -390. Stanby still 4.6w, very hard to turn wheel and clicks when turning. No response to throttle. Tried also lower cut off voltage, wider throttle range voltage.
Hmm, strange. You can measure the voltage on pin 23 (AIN8), when the controller is switched on. Then we can make a better guess for the value of battery current cal b But be careful that you don't produce magic smoke with the probe tip :)
index.php


On the SVM7 board, the gain factor is diffent from the newer boards, too. The newer boards have 10 digits ADCvalue per ampere, the SVM7 has 9. I guess your board will have completely different values for battery current cal a and battery current cal b

regards
stancecoke
 
casainho said:
geofft said:
to 60% of that displayed. To my simple mind I thought that (......_10b * 6/10) might work without overflow, so I tried it - and it does..:shock:

Not sure if that makes any sense but like I say - it works for me.
Maybe reding 50% will be ok, so would be:
Variable = variable >> 1;

47/100 seems as close to reality as I am able to measure.. :) and shows 0w when stanby

Edit: shows 12w when turned on and 0 after running the motor.
 
@Casainho

P1 parameter is limiting my speed.

When set 46 I get 37km/h on display and not full rpm on motor
When set 92 I get 35km/h on display and twice the rpm on motor.

Edit: thats with P3: 1 and lcd speed limit 72

With P3: 0 I get the bugs I reported before.
 
honya96 said:
btw, how to set to show the right speed on lcd3? P1 and wheel size works?
Yes, on main branch, P1 and and wheel size works -- status project is here, you can read: https://opensourceebikefirmware.bitbucket.io/FLEXIBLE_OPENSOURCE_FIRMWARE.html#h1-3

honya96 said:
Can you please implement an option to have 100% throttle whatever the PAS level at main branch? As geofft asked allready.. and pas speed limit later?
I implemented after he explained -- see what I wrote to you can enable that feature.

honya96 said:
and probably just for me, :roll: would be great to have external switch for throttle limit (replacing original cruise wire for example) with configurable % power limitation.

It will be needed with higher power.
Currently there are base things that don't work correctly, that is my priority.

I wish I can find some free time to implement PI controller for current and speed controllers, as the current controllers don't well so well.
 
honya96 said:
@Casainho

P1 parameter is limiting my speed.

When set 46 I get 37km/h on display and not full rpm on motor
When set 92 I get 35km/h on display and twice the rpm on motor.

Edit: thats with P3: 1 and lcd speed limit 72

With P3: 0 I get the bugs I reported before.
P3 = 1; speed controller is set to max speed value set on LCD
P3 = 0; speed controller value is mapped to throttle value, where the max possible value is the max speed value set on LCD
 
honya96 said:
and probably just for me, :roll: would be great to have external switch for throttle limit (replacing original cruise wire for example) with configurable % power limitation.

It will be needed with higher power.
After thinking about it, I found would be easy to add this.

You just need to edit main.h:
Code:
#define THROTTLE_MIN_VALUE 0
#define THROTTLE_MAX_VALUE 255

If THROTTLE_MAX_VALUE = 127, throttle value will only be 50% of max possible value.

The code affected was this function:
Code:
void read_throotle (void)
{
  // read torque sensor signal
  ui8_adc_throttle_value = ui8_adc_read_throttle ();

  // map throttle value from 0 up to 255
  ui8_throttle_value = (uint8_t) (map (
		  ui8_adc_throttle_value,
		  (uint8_t) ADC_THROTTLE_MIN_VALUE,
		  (uint8_t) ADC_THROTTLE_MAX_VALUE,
		  (uint8_t) THROTTLE_MIN_VALUE,
		  (uint8_t) THROTTLE_MAX_VALUE));

  // low pass filter the torque sensor to smooth the signal
  ui16_throttle_value_accumulated -= ui16_throttle_value_accumulated >> 2;
  ui16_throttle_value_accumulated += ((uint16_t) ui8_throttle_value);
  ui8_throttle_value_filtered = ui16_throttle_value_accumulated >> 2;

  // setup ui8_is_throotle_released flag
  ui8_is_throotle_released = ((ui8_throttle_value > ((uint8_t) ADC_THROTTLE_MIN_VALUE)) ? 0 : 1);
}
 
@Casainho

P1 is not even mentioned working in the link you posted so I guess its as on original firmware.

100% throttle - spent 3 hours trying to get it (and other modifications) working, last thing to try will be compiling and flashing "manualy" by stancecoke's old pdf tomorow morning. If there us an easy way to flash modified config.h, please tell me. (Now I realize maybe by start compiling.bat in firmware folder)

Throttle Power switch - I know there are more important issues now, its just an idea I got which seemed easy to do.

As I understand your last post, editing it in config.h will limit it permanently, but you have not explained how to map it to switch by some wire. Anyway its not important now. :wink:

Can you please look again at my post about P1 setting vs. Speed? Why I get 37km/h max?

Thanks for your time
 
honya96 said:
100% throttle - spent 3 hours trying to get it (and other modifications) working, last thing to try will be compiling and flashing "manualy" by stancecoke's old pdf tomorow morning. If there us an easy way to flash modified config.h, please tell me. (Now I realize maybe by start compiling.bat in firmware folder)
Firmware configuration tool
The firmware configuration tool is a Java application that was developed to make easy the configuration of the firmware options. This tool does in background:
• generates the file config.h on the firmware folder, with the options selected by the user
• builds the firmware and flash it
• erase original firmware and flash the STM8 option bytes


So, the config.h file is generated by the configuration tool. But you can also edit by hand and execute that scritpt "Start_Compiling.bat" -- please note the script compile/builds and after also flashes the firmware. So in practice, you don't need to use the configuration tool.

Note that this options are already in main.h, you can edit them on that file (just like you would on config.h):
Code:
#define THROTTLE_MIN_VALUE 0
#define THROTTLE_MAX_VALUE 255

honya96 said:
As I understand your last post, editing it in config.h will limit it permanently, but you have not explained how to map it to switch by some wire. Anyway its not important now. :wink:
Some misunderstand -- I didn't mention that feature.

honya96 said:
Can you please look again at my post about P1 setting vs. Speed? Why I get 37km/h max?
There are 2 speed limits for the speed controller: the max speed value that is setup on LCD and the MOTOR_OVER_SPEED_ERPS. Are you hitting the MOTOR_OVER_SPEED_ERPS??

Code:
#define MOTOR_OVER_SPEED_ERPS 520 // motor max speed, protection max value | 30 points for the sinewave at max speed

Code:
// call every 100ms
uint8_t motor_speed_controller (void)
{
...
  i16_motor_speed_erps = (int16_t) ui16_motor_get_motor_speed_erps ();

  // if MOTOR_OVER_SPEED_ERPS, then limit for this value and not user defined ui16_target_erps
  if (ui16_target_erps > MOTOR_OVER_SPEED_ERPS) { i16_error = MOTOR_OVER_SPEED_ERPS - i16_motor_speed_erps; }
  else { i16_error = ui16_target_erps - i16_motor_speed_erps; }
...
 
honya96 said:
Its 3.788v. With the same board controller, 37.3v input.

Are you sure? Thats much higher than on other known boards...
with 3.788V the value for battery current cal b should be around -776 (5V-->1024, 3.788V-->776)

If you have an USB-UART-Adapter, you an look at the value with a terminal program at the PC. (Green wire of the display connector to Rx of the adapter, gnd to any black wire)

regards
stancecoke
 
@Casainho - edited config.h does not change it. I am far from hiting max erps, as I explained, I get 37km on display while set 72. Motor rpm is changing by P1 but still limits to about 37 on display

@Geofft - can you try the 100% throttle?

@Stancecoke - Thanks but I will stick with main branch, can test the value if you want, but I am not intersted because it does not work with lcd3.
 
honya96 said:
@Casainho - edited config.h does not change it. I am far from hiting max erps, as I explained, I get 37km on display while set 72. Motor rpm is changing by P1 but still limits to about 37 on display
Can you calc your motor ERPS for that 37km/h?
Please tell us:
- your wheel size
- motor gear reduction ratio (if any)
- motor number of magnets
 
24" x 3.0" tire so almost like 26". 46 magnets, no reduction. Firmware has some bugs for sure, I left my bike running on stand to drain battery and after about 2 minutes running with fixed throttle possition it started to accelerate to 78km/h on display and back to 35 and again. After releasing throttle it did once again and stopped, then after adding throttle just some sound but no turning. Had to flash again.
 
honya96 said:
24" x 3.0" tire so almost like 26". 46 magnets, no reduction. Firmware has some bugs for sure, I left my bike running on stand to drain battery and after about 2 minutes running with fixed throttle possition it started to accelerate to 78km/h on display and back to 35 and again. After releasing throttle it did once again and stopped, then after adding throttle just some sound but no turning. Had to flash again.
On that test, was the motor accelerating and keep always increasing the speed the the speed shown on LCD was wrong or do you think the speed shown on the LCD reflects the real value??

I must say I don't have a motor that fast, maybe there are some variable doing overflow with such high speed values. I need to think more about this. Every information about your tests is important, but please give detailed information!! Say in which conditions, which options the firmware and options on LCD like the values for P1, etc.

So, with 46 magnets, has 23 poles.

For the limit of 520 ERPS, would be:
- 520/23 = 22.6 RPS; 22.6*60 = RPMs = 1356

On this table, https://endless-sphere.com/forums/viewtopic.php?t=16114, 1356 RPMs would be 154km/h!!! So you are not hitting the MOTOR_OVER_SPEED_ERPS of 520.
 
honya96 said:
@Casainho - edited config.h does not change it. I am far from hiting max erps, as I explained, I get 37km on display while set 72. Motor rpm is changing by P1 but still limits to about 37 on display

@Geofft - can you try the 100% throttle?

Always 100% throttle works ok for me, after I requested it casainho added this line to config.h :-

#define EBIKE_THROTTLE_TYPE_THROTTLE_PAS_ASSIST_LEVEL_PAS_ONLY

...and it has worked ok since then. Maybe double check you have this exact line? There are a couple of other lines that are very similar.
 
geofft said:
honya96 said:
@Casainho - edited config.h does not change it. I am far from hiting max erps, as I explained, I get 37km on display while set 72. Motor rpm is changing by P1 but still limits to about 37 on display

@Geofft - can you try the 100% throttle?

Always 100% throttle works ok for me, after I requested it casainho added this line to config.h :-

#define EBIKE_THROTTLE_TYPE_THROTTLE_PAS_ASSIST_LEVEL_PAS_ONLY

...and it has worked ok since then. Maybe double check you have this exact line? There are a couple of other lines that are very similar.
That option, can be seen on config-example.h file on the firmware folder (should be added manually to config.h or main.h):

https://github.com/OpenSource-EBike-firmware/BMSBattery_S_controllers_firmware/blob/master/firmware/config-example.h
 
Back
Top