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

Electric Motors and Controllers
casainho
100 kW
100 kW
Posts: 1485
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 » Apr 08, 2018 10:09 am

geofft wrote:
Apr 08, 2018 9:13 am
casainho wrote:
Apr 08, 2018 8:47 am
Between sun and rain, today I did a good ride of 1h30 betweem home and near beachs.
The firmware was built with SDCC 3.7.0.
Will you be making this latest version be available on github sometime? I just wondered if it may have any effect on the (windows users) compiling issue?
The version I am using is on master branch of github. I just updated the compiler version to 3.7.0 and I found that the compiled firmware was about 40% smaller but still works the same.
The issue is thay the SDCC developers didn't put online a Windows version for 3.7.0 unlike on version 3.6.0. On Linux, I had to compile/build the version 3.7.0 but it is a regular way of doing it, we are used already to compile some of the software, mainly when we want the latest versions.

Please search on Google, maybe some one already compiled SDCC 3.7.0 and is sharing the executables.
Developer of the Flexible OpenSource firmware for EBike motor controllers:
- Kunteng/BMSBattery VLR FOC motor controller: https://opensourceebikefirmware.bitbucket.io/
- TongSheng TSDZ2 mid drive motor controller: https://opensourceebikefirmware.bitbuck ... ment_tsdz2

geofft
100 W
100 W
Posts: 151
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 » Apr 08, 2018 12:40 pm

casainho wrote:
Apr 08, 2018 10:09 am
geofft wrote:
Apr 08, 2018 9:13 am
Will you be making this latest version be available on github sometime? I just wondered if it may have any effect on the (windows users) compiling issue?
The version I am using is on master branch of github. I just updated the compiler version to 3.7.0 and I found that the compiled firmware was about 40% smaller but still works the same.
The issue is thay the SDCC developers didn't put online a Windows version for 3.7.0 unlike on version 3.6.0. On Linux, I had to compile/build the version 3.7.0 but it is a regular way of doing it, we are used already to compile some of the software, mainly when we want the latest versions.

Please search on Google, maybe some one already compiled SDCC 3.7.0 and is sharing the executables.
Ah - ok, my lack of developer knowledge showing here, I was forgetting that the firmware has to be built into executable (in windows or linux) in the final stage.. :roll:
BBS02 V2 48v 750w, 12s lipo.
Q128H (36v 201rpm), KT36/48SVPR 20amp, LCD3, 48v 12s lipo.

nieles
10 kW
10 kW
Posts: 641
Joined: Jul 14, 2008 5:39 pm
Location: The Netherlands

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

Post by nieles » Apr 09, 2018 2:20 am

i might have the solution for windows users, i found and document describing how to build the SDCC binary using visual C++ (http://sdcc.sourceforge.net/doc/sdccman.pdf)

i am pretty sure i have almost all required software installed on my PC so will give this a try tonight.

casainho
100 kW
100 kW
Posts: 1485
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 » Apr 09, 2018 3:24 am

I bought the TSDZ2, shipping from EU,from http://www.pswpower.com/
My plan is to first take some good pictures; try to measure PWM frequency looking at motor phases; understand how torque sensor and how we can read it; understand how we can connect wires or such on the board knowing that it is potted.
Developer of the Flexible OpenSource firmware for EBike motor controllers:
- Kunteng/BMSBattery VLR FOC motor controller: https://opensourceebikefirmware.bitbucket.io/
- TongSheng TSDZ2 mid drive motor controller: https://opensourceebikefirmware.bitbuck ... ment_tsdz2

User avatar
stancecoke
10 kW
10 kW
Posts: 562
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 » Apr 09, 2018 5:19 am

Finally, I've managed do figure out which files of cygwin are necessary to run the windows release of 3.7.0

Code: Select all

09.04.2018  12:08    <DIR>          ..
27.01.2017  21:13           739.859 bash.exe
20.01.2018  10:24            71.187 cyggcc_s-seh-1.dll
20.02.2015  19:07         1.033.235 cygiconv-2.dll
23.10.2016  08:34            42.515 cygintl-8.dll
05.12.2017  10:25           324.560 cygncursesw-10.dll
13.02.2017  21:45           224.275 cygreadline7.dll
20.01.2018  10:26         1.367.059 cygstdc++-6.dll
02.02.2018  16:18         3.195.569 cygwin1.dll
27.01.2017  21:13           739.859 sh.exe
But I don't know, if it's legal to redistribute these files in our github repository...
Some manual path settings are necessary also, but this could be done automatically in the Start_compiling.bat.
Compiling of the recent master branch works with this.

Code: Select all

C:\>sdcc -v
SDCC : mcs51/z80/z180/r2k/r3ka/gbz80/tlcs90/ds390
 3.7.0 #10231 (CYGWIN)
published under GNU General Public License (GPL)
regards
stancecoke
Last edited by stancecoke on Apr 09, 2018 5:33 am, edited 1 time in total.

casainho
100 kW
100 kW
Posts: 1485
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 » Apr 09, 2018 5:32 am

stancecoke wrote:
Apr 09, 2018 5:19 am
Finally, I've managed do figure out which files of cygwin are necessary to run the windows release of 3.7.0.

Some manual path settings are necessary also, this could be done automatically in the Start_compiling.bat, I think.
Compiling of the recent master branch works with this.
So, If I can understand correctly, with SDCC 3.7.0, on Windows and Linux, the master branch compiles correctly, no more that 2 issues!! And also with added improving on firmware code size.

Good work Stancecoke. Would be great if you can write the instructions.
SDCC is GPL license. Our project uses the same kind of license and is on the same philosophy, I am pretty sure is ok for us to share the executable. Also our project is a good example/reference of using such tools.
Developer of the Flexible OpenSource firmware for EBike motor controllers:
- Kunteng/BMSBattery VLR FOC motor controller: https://opensourceebikefirmware.bitbucket.io/
- TongSheng TSDZ2 mid drive motor controller: https://opensourceebikefirmware.bitbuck ... ment_tsdz2

User avatar
stancecoke
10 kW
10 kW
Posts: 562
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 » Apr 09, 2018 5:40 am

The only instruction is to set the right path to the sdcc.exe file in the start_compiling.bat, or to extract it to the right place, that's set in the default start_compiling.bat. (After we have added the necessary files to our repository, I would add them to the \firmware\tools folder)
casainho wrote:
Apr 09, 2018 5:32 am
no more that 2 issues!!
The issue with the #defines is still the same.

regards
stancecoke

casainho
100 kW
100 kW
Posts: 1485
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 » Apr 09, 2018 9:38 am

I would like to implement the wheel speed controller like explained by David Wilson here:
Image

Right now I am "bitbang" current/torque instead of doing a PI controller and I hope it is ok. At least it is very fast as David mention that it should be.

The speed controller (which can be run much slower, right now running at 10Hz) output should be the input for the current/torque controller (using ebike_app_battery_set_current_max()) but currently I am using instead as input for PWM duty_cycle: motor_set_pwm_duty_cycle_target (wheel_speed_pi_controller_state.ui8_controller_output_value);

Why all this work? because I like to also have speed controller working (very well). I hope that implementing speed controller like this way, the PI controller coefficients will be quicker and easy to adjust by the final user.

I think is kind of magic when I feel the machine answering fast and precise to my desires. I mean, when using the torque sensor and I feel that I have refined as also fast control of the machine/bicycle.
Developer of the Flexible OpenSource firmware for EBike motor controllers:
- Kunteng/BMSBattery VLR FOC motor controller: https://opensourceebikefirmware.bitbucket.io/
- TongSheng TSDZ2 mid drive motor controller: https://opensourceebikefirmware.bitbuck ... ment_tsdz2

User avatar
stancecoke
10 kW
10 kW
Posts: 562
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 » Apr 09, 2018 11:01 am

Hmm, I don't now, why we need a speed control, the only thing we need is a smooth reduction of motor power at the speed limit.
Often people report, that it's like riding against a wall when reaching the speed limit...
A proven way to reduce the power smoothly, is ramping down the power within the speedlimit + e.g. 2km/h, like in the FC or in my fork....

regards
Stancecoke

p.s. I've just updated the master branch with the cygwin files and an adapted Start_Compiling.bat
I had to comment out the content of the uart_init function, I hope that causes no trouble with linux....

casainho
100 kW
100 kW
Posts: 1485
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 » Apr 09, 2018 12:49 pm

stancecoke wrote:
Apr 09, 2018 11:01 am
Hmm, I don't now, why we need a speed control, the only thing we need is a smooth reduction of motor power at the speed limit.
Often people report, that it's like riding against a wall when reaching the speed limit...
With a direct drive motor, yes, with the power reduction there will be a wall that is the wind + motor regen.
With a geared motor, yes, with the power reduction there will be a wall that is the wind only and unlike direct drive motor, the motor stops and will disengage from the wheel.

And on current firmware, speed control is optional.
stancecoke wrote:
Apr 09, 2018 11:01 am
p.s. I've just updated the master branch with the cygwin files and an adapted Start_Compiling.bat
I had to comment out the content of the uart_init function, I hope that causes no trouble with linux....
I updated the uart.h file and it builds ok with SDCC 3.7.0.
Developer of the Flexible OpenSource firmware for EBike motor controllers:
- Kunteng/BMSBattery VLR FOC motor controller: https://opensourceebikefirmware.bitbucket.io/
- TongSheng TSDZ2 mid drive motor controller: https://opensourceebikefirmware.bitbuck ... ment_tsdz2

User avatar
stancecoke
10 kW
10 kW
Posts: 562
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 » Apr 09, 2018 1:09 pm

The modified uart.h works with windows, too :-)

The felt "wall" is just the missing "tailwind" if you cut the power apruptly at the speed limit...

regards
stancecoke

casainho
100 kW
100 kW
Posts: 1485
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 » Apr 09, 2018 2:12 pm

stancecoke wrote:
Apr 09, 2018 1:09 pm
The felt "wall" is just the missing "tailwind" if you cut the power apruptly at the speed limit...
To control the speed, we would increase (positive) motor torque when speed is lower or decrease (put negative torque for braking) motor torque when speed is higher.
On our ebike application, maybe we should not apply negative torque/brake! On a downhill for instance, after passing the speed limit value, we do not brake the motor. On a geared motor, motor will desingage and will not make resistance/brake. On a direct drive motor, the duty-cycle will increase in a way to keep regen/brake current == zero and so tje motor should also not make resistance/brake.
The only thing braking the rider will be wind or inclination.

I need to try this ideas, but I can only if the rain stops :-)
Developer of the Flexible OpenSource firmware for EBike motor controllers:
- Kunteng/BMSBattery VLR FOC motor controller: https://opensourceebikefirmware.bitbucket.io/
- TongSheng TSDZ2 mid drive motor controller: https://opensourceebikefirmware.bitbuck ... ment_tsdz2


casainho
100 kW
100 kW
Posts: 1485
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 » Apr 10, 2018 2:21 pm

stancecoke wrote:
Apr 10, 2018 1:26 pm
I've finally managed to update the windows instructions at bitbucket :-)

https://opensourceebikefirmware.bitbuck ... ndex3.html
That's great. And I updated the ones on initial site, using your text.

I don't know howto solve that issue of the #defines.
Developer of the Flexible OpenSource firmware for EBike motor controllers:
- Kunteng/BMSBattery VLR FOC motor controller: https://opensourceebikefirmware.bitbucket.io/
- TongSheng TSDZ2 mid drive motor controller: https://opensourceebikefirmware.bitbuck ... ment_tsdz2

User avatar
stancecoke
10 kW
10 kW
Posts: 562
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 » Apr 11, 2018 4:21 am

casainho wrote:
Apr 10, 2018 2:21 pm
I don't know howto solve that issue of the #defines.
I suggest to use a

Code: Select all

#define LINUX

statement in the config.h for Linux users. I've just updated the Java-Tool at github. I've implemented your latest changes in the config.h as far as I understood them...
The option "Human Power" doesn't work in the code at the moment, there's a variable used, that's not defined...

CHROME-B.PNG
CHROME-B.PNG (55.36 KiB) Viewed 263 times

I have not updated the description of the Java-Tool in the help sites yet.

regards
stancecoke
Last edited by stancecoke on Apr 11, 2018 4:50 am, edited 3 times in total.

casainho
100 kW
100 kW
Posts: 1485
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 » Apr 11, 2018 4:23 am

stancecoke wrote:
Apr 11, 2018 4:21 am
casainho wrote:
Apr 10, 2018 2:21 pm
I don't know howto solve that issue of the #defines.
I suppose to use a

Code: Select all

#define LINUX
statement in the config.h for Linux users.
I would like to research more, at this issue is not supposed.
Maybe I will ask for help on SDCC mailing list.
Developer of the Flexible OpenSource firmware for EBike motor controllers:
- Kunteng/BMSBattery VLR FOC motor controller: https://opensourceebikefirmware.bitbucket.io/
- TongSheng TSDZ2 mid drive motor controller: https://opensourceebikefirmware.bitbuck ... ment_tsdz2

User avatar
stancecoke
10 kW
10 kW
Posts: 562
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 » Apr 11, 2018 4:53 am

It's a fast workaround. The recent code doesn't work in Throttle/PAS mode for windows users.

Regards
stancecoke

casainho
100 kW
100 kW
Posts: 1485
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 » Apr 11, 2018 5:59 am

Please play with the following change, and try different values for #define EBIKE_THROTTLE_TYPE 0, like 0, 1, 2 or 3.
Maybe try to use instead #if (EBIKE_THROTTLE_TYPE == 1) and #if (EBIKE_THROTTLE_TYPE == 2) instead of EBIKE_THROTTLE_TYPE_THROTTLE_PAS and EBIKE_THROTTLE_TYPE_TORQUE_SENSOR.

It MUST work!!...

Code: Select all

#undef EBIKE_THROTTLE_TYPE
#define EBIKE_THROTTLE_TYPE 0
  
#if (EBIKE_THROTTLE_TYPE == EBIKE_THROTTLE_TYPE_THROTTLE_PAS)
  // map throttle value from 0 up to 255 to global variable: ui8_throttle_value
  // setup ui8_is_throttle_released flag
  throttle_read ();
#elif (EBIKE_THROTTLE_TYPE == EBIKE_THROTTLE_TYPE_TORQUE_SENSOR)
  torque_sensor_throttle_read ();
#else
#error
#endif
Developer of the Flexible OpenSource firmware for EBike motor controllers:
- Kunteng/BMSBattery VLR FOC motor controller: https://opensourceebikefirmware.bitbucket.io/
- TongSheng TSDZ2 mid drive motor controller: https://opensourceebikefirmware.bitbuck ... ment_tsdz2

User avatar
stancecoke
10 kW
10 kW
Posts: 562
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 » Apr 11, 2018 6:45 am

Ah, now I found the reason why it doesn't work :-)

If you enable regen, the settings of PAS/THROTTLE and TORQUESENSOR in the config.h are overwritten in the main.h.

So you can set Throttle/PAS only, if regen is not activated. So you can't combine Throttle/PAS with regen at the moment.

regards
stancecoke

casainho
100 kW
100 kW
Posts: 1485
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 » Apr 11, 2018 10:12 am

stancecoke wrote:
Apr 11, 2018 6:45 am
Ah, now I found the reason why it doesn't work :-)

If you enable regen, the settings of PAS/THROTTLE and TORQUESENSOR in the config.h are overwritten in the main.h.

So you can set Throttle/PAS only, if regen is not activated. So you can't combine Throttle/PAS with regen at the moment.
Ok!! Good to know that is working as expected. So right now there is no issue!!

You mean enable regen like coast brakes. Yes, as I told before, I implemented that feature for me, to use with torque sensor.
By the way, I just received more torque sensors to repair the broken one. Also some LCD3 and so I can look at power used while riding, unlike on LCD5 that I has on my ebikes.
Developer of the Flexible OpenSource firmware for EBike motor controllers:
- Kunteng/BMSBattery VLR FOC motor controller: https://opensourceebikefirmware.bitbucket.io/
- TongSheng TSDZ2 mid drive motor controller: https://opensourceebikefirmware.bitbuck ... ment_tsdz2

casainho
100 kW
100 kW
Posts: 1485
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 » Apr 11, 2018 10:21 am

On the following test, with #define ADC_BATTERY_CURRENT_MAX 35 on config.h, the measured current with wheel blocked, as seen on the video, I got measured on the multimeter about 12.5 amps:


I found that at least on S06S, each ADC 8 bits step equals to 0.35 amps (35*0.35 = 12.25 amps).
The LCD5, each current step equals to 0.25 amps, so I multiply the current ADC 8 bits step value * 1.5 and the LCD shows to me a very near wattage value.
Developer of the Flexible OpenSource firmware for EBike motor controllers:
- Kunteng/BMSBattery VLR FOC motor controller: https://opensourceebikefirmware.bitbucket.io/
- TongSheng TSDZ2 mid drive motor controller: https://opensourceebikefirmware.bitbuck ... ment_tsdz2

casainho
100 kW
100 kW
Posts: 1485
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 » Apr 11, 2018 10:51 am

stancecoke wrote:
Feb 28, 2018 10:04 am
casainho wrote:
Feb 28, 2018 8:50 am

Are you aware that you will have to use torque sensor and modding it with a PAS to get that feature you like??
You don't have to add an additional PAS, you just have to solder the yellow wire of the torque-sensor to one of the PAS-Halls directly...

Torque Sensor Hall mod.jpg
Done!! tested and works as expected.

Image
Developer of the Flexible OpenSource firmware for EBike motor controllers:
- Kunteng/BMSBattery VLR FOC motor controller: https://opensourceebikefirmware.bitbucket.io/
- TongSheng TSDZ2 mid drive motor controller: https://opensourceebikefirmware.bitbuck ... ment_tsdz2

User avatar
stancecoke
10 kW
10 kW
Posts: 562
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 » Apr 11, 2018 12:42 pm

casainho wrote:
Apr 11, 2018 10:51 am
Done!! tested and works as expected.
Great! So you will adapt the code for not using X4 for the second PAS signal? Then I don't have to do that :-)

regards
stancecoke

casainho
100 kW
100 kW
Posts: 1485
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 » Apr 11, 2018 1:45 pm

stancecoke wrote:
Apr 11, 2018 12:42 pm
casainho wrote:
Apr 11, 2018 10:51 am
Done!! tested and works as expected.
Great! So you will adapt the code for not using X4 for the second PAS signal? Then I don't have to do that :-)
This mod is much more easy and clean - thanks.
Yes, I hope the adaptation of the code will be fast, maybe I can do if over the weekend.
Developer of the Flexible OpenSource firmware for EBike motor controllers:
- Kunteng/BMSBattery VLR FOC motor controller: https://opensourceebikefirmware.bitbucket.io/
- TongSheng TSDZ2 mid drive motor controller: https://opensourceebikefirmware.bitbuck ... ment_tsdz2

casainho
100 kW
100 kW
Posts: 1485
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 » Apr 12, 2018 7:58 am

casainho wrote:
Apr 11, 2018 1:45 pm
stancecoke wrote:
Apr 11, 2018 12:42 pm
casainho wrote:
Apr 11, 2018 10:51 am
Done!! tested and works as expected.
Great! So you will adapt the code for not using X4 for the second PAS signal? Then I don't have to do that :-)
This mod is much more easy and clean - thanks.
Yes, I hope the adaptation of the code will be fast, maybe I can do if over the weekend.
This mod doesn't work because the output signal from the sensor is always the same: ui16_pas_on_time_counter > ui16_pas_off_time_counter for both directions, so, there is not way to detect rotation direction. This is probably why they have added hardware/cost.
Any ideas??
Developer of the Flexible OpenSource firmware for EBike motor controllers:
- Kunteng/BMSBattery VLR FOC motor controller: https://opensourceebikefirmware.bitbucket.io/
- TongSheng TSDZ2 mid drive motor controller: https://opensourceebikefirmware.bitbuck ... ment_tsdz2

Post Reply