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

Electric Motors and Controllers
geofft
100 W
100 W
Posts: 117
Joined: Nov 09, 2012 9:41 am
Location: Berkshire UK

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

Post by geofft » Jan 16, 2018 12:12 pm

casainho wrote:
Jan 14, 2018 5:10 am
geofft wrote:
Jan 14, 2018 3:06 am
My estimate here is not scientific, the power maximum the motor draws (indicated on display) with the stock firmware is 800w, but the new firmware is showing 1150w. I can do some better tests with an ammeter in the battery supply if you prefer..?
That would be great, if you can confirm with an external meter.
Tried this 'on the road' today but found that both the readings (ammeter and lcd3 wattmeter) dance around so much that it wasn't possible to get any accurate results, it will need a better test setup than mine to do this.

Would it be possible to 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?

No rush, anytime will do... :)
Last edited by geofft on Jan 19, 2018 5:39 pm, edited 1 time in total.
BBS02 V2 48v 750w, 12s lipo.
Q128H (36v 201rpm), KT36/48SVPR 20amp, LCD3, 48v 12s lipo.

User avatar
stancecoke
1 kW
1 kW
Posts: 453
Joined: Aug 02, 2017 2:56 pm

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

Post by stancecoke » Jan 16, 2018 1:25 pm

geofft wrote:
Jan 16, 2018 12:12 pm
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: Select all

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.

Regards
stancecoke

casainho
100 kW
100 kW
Posts: 1220
Joined: Feb 14, 2011 2:43 pm

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

Post by casainho » Jan 16, 2018 1:36 pm

stancecoke wrote:
Jan 16, 2018 1:25 pm
geofft wrote:
Jan 16, 2018 12:12 pm
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: Select all

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 saw other tools to customize motor controllers, that user must input values in the form:
x / y.
x and y could be 8 bits and the result would need to be 16 bits variable, because the max of values 255 * 255 is 2^16, so that would be ok.

Sure we could go with floats, but they take a lot of memory space and processing time. I think this 16 bits multiply and division on the STM8 8bits only, without hardware multiply and division, will be better than even doing float operations.
Developer of the Flexible OpenSource firmware for EBike motor controllers: https://opensourceebikefirmware.bitbucket.io/

User avatar
stancecoke
1 kW
1 kW
Posts: 453
Joined: Aug 02, 2017 2:56 pm

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

Post by stancecoke » Jan 16, 2018 1:54 pm

casainho wrote:
Jan 16, 2018 1:36 pm
i8_motor_current_filtered_10b * 120 will overflow
upps, you are right, it's a little strange that you call it _10b, if it's just 8 bit :-)

It's easy to cast the variable into 16bit temporaribly to avoid floating points?!

Code: Select all

ui8_tx_buffer [8] = (uint8_t) (((uint16_t) i8_motor_current_filtered_10b)*120/100);
regards
stancecoke

edit: I wonder that you are using a signed integer for the 10 bit current value, as the maximum that this variable can keep is +12.7A only?!

honya96
100 W
100 W
Posts: 185
Joined: Mar 05, 2015 9:38 am
Location: Czech Republic

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

Post by honya96 » Jan 16, 2018 3:17 pm

@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?

User avatar
stancecoke
1 kW
1 kW
Posts: 453
Joined: Aug 02, 2017 2:56 pm

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

Post by stancecoke » Jan 17, 2018 8:01 am

honya96 wrote:
Jan 16, 2018 3:17 pm
@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

User avatar
stancecoke
1 kW
1 kW
Posts: 453
Joined: Aug 02, 2017 2:56 pm

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

Post by stancecoke » Jan 18, 2018 6:55 am

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

honya96
100 W
100 W
Posts: 185
Joined: Mar 05, 2015 9:38 am
Location: Czech Republic

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

Post by honya96 » Jan 18, 2018 10:42 am

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.

User avatar
stancecoke
1 kW
1 kW
Posts: 453
Joined: Aug 02, 2017 2:56 pm

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

Post by stancecoke » Jan 18, 2018 11:37 am

honya96 wrote:
Jan 18, 2018 10:42 am
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

geofft
100 W
100 W
Posts: 117
Joined: Nov 09, 2012 9:41 am
Location: Berkshire UK

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

Post by geofft » Jan 18, 2018 11:39 am

casainho wrote:
Jan 16, 2018 1:36 pm
stancecoke wrote:
Jan 16, 2018 1:25 pm
geofft wrote:
Jan 16, 2018 12:12 pm
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: Select all

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.
BBS02 V2 48v 750w, 12s lipo.
Q128H (36v 201rpm), KT36/48SVPR 20amp, LCD3, 48v 12s lipo.

casainho
100 kW
100 kW
Posts: 1220
Joined: Feb 14, 2011 2:43 pm

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

Post by casainho » Jan 18, 2018 11:48 am

geofft wrote:
Jan 18, 2018 11:39 am
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;
Developer of the Flexible OpenSource firmware for EBike motor controllers: https://opensourceebikefirmware.bitbucket.io/

honya96
100 W
100 W
Posts: 185
Joined: Mar 05, 2015 9:38 am
Location: Czech Republic

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

Post by honya96 » Jan 19, 2018 12:11 pm

stancecoke wrote:
Jan 18, 2018 6:55 am

@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.

honya96
100 W
100 W
Posts: 185
Joined: Mar 05, 2015 9:38 am
Location: Czech Republic

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

Post by honya96 » Jan 19, 2018 12:55 pm

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.

User avatar
stancecoke
1 kW
1 kW
Posts: 453
Joined: Aug 02, 2017 2:56 pm

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

Post by stancecoke » Jan 19, 2018 1:08 pm

honya96 wrote:
Jan 19, 2018 12:11 pm
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 :-)
Image

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

honya96
100 W
100 W
Posts: 185
Joined: Mar 05, 2015 9:38 am
Location: Czech Republic

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

Post by honya96 » Jan 19, 2018 1:28 pm

casainho wrote:
Jan 18, 2018 11:48 am
geofft wrote:
Jan 18, 2018 11:39 am
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.
Last edited by honya96 on Jan 19, 2018 1:41 pm, edited 1 time in total.

honya96
100 W
100 W
Posts: 185
Joined: Mar 05, 2015 9:38 am
Location: Czech Republic

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

Post by honya96 » Jan 19, 2018 1:35 pm

@stancecoke

Its 3.788v. With the same board controller, 37.3v input.

honya96
100 W
100 W
Posts: 185
Joined: Mar 05, 2015 9:38 am
Location: Czech Republic

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

Post by honya96 » Jan 19, 2018 1:48 pm

@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.

casainho
100 kW
100 kW
Posts: 1220
Joined: Feb 14, 2011 2:43 pm

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

Post by casainho » Jan 19, 2018 1:56 pm

honya96 wrote:
Jan 16, 2018 3:17 pm
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.bitbuck ... .html#h1-3
honya96 wrote:
Jan 19, 2018 12:55 pm
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 wrote:
Jan 19, 2018 12:55 pm
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.
Developer of the Flexible OpenSource firmware for EBike motor controllers: https://opensourceebikefirmware.bitbucket.io/

casainho
100 kW
100 kW
Posts: 1220
Joined: Feb 14, 2011 2:43 pm

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

Post by casainho » Jan 19, 2018 2:05 pm

honya96 wrote:
Jan 19, 2018 1:48 pm
@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
Developer of the Flexible OpenSource firmware for EBike motor controllers: https://opensourceebikefirmware.bitbucket.io/

casainho
100 kW
100 kW
Posts: 1220
Joined: Feb 14, 2011 2:43 pm

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

Post by casainho » Jan 19, 2018 4:42 pm

honya96 wrote:
Jan 19, 2018 12:55 pm
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: Select all

#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: Select all

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);
}
Developer of the Flexible OpenSource firmware for EBike motor controllers: https://opensourceebikefirmware.bitbucket.io/

honya96
100 W
100 W
Posts: 185
Joined: Mar 05, 2015 9:38 am
Location: Czech Republic

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

Post by honya96 » Jan 19, 2018 5:24 pm

@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

casainho
100 kW
100 kW
Posts: 1220
Joined: Feb 14, 2011 2:43 pm

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

Post by casainho » Jan 19, 2018 6:18 pm

honya96 wrote:
Jan 19, 2018 5:24 pm
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: Select all

#define THROTTLE_MIN_VALUE 0
#define THROTTLE_MAX_VALUE 255
honya96 wrote:
Jan 19, 2018 5:24 pm
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 wrote:
Jan 19, 2018 5:24 pm
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: Select all

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

Code: Select all

// 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; }
...
Developer of the Flexible OpenSource firmware for EBike motor controllers: https://opensourceebikefirmware.bitbucket.io/

User avatar
stancecoke
1 kW
1 kW
Posts: 453
Joined: Aug 02, 2017 2:56 pm

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

Post by stancecoke » Jan 20, 2018 4:15 am

honya96 wrote:
Jan 19, 2018 1:35 pm
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

honya96
100 W
100 W
Posts: 185
Joined: Mar 05, 2015 9:38 am
Location: Czech Republic

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

Post by honya96 » Jan 20, 2018 7:37 am

@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.

casainho
100 kW
100 kW
Posts: 1220
Joined: Feb 14, 2011 2:43 pm

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

Post by casainho » Jan 20, 2018 7:42 am

honya96 wrote:
Jan 20, 2018 7:37 am
@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
Developer of the Flexible OpenSource firmware for EBike motor controllers: https://opensourceebikefirmware.bitbucket.io/

Post Reply