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

Electric Motors and Controllers
-dg   1 kW

1 kW
Posts: 454
Joined: Jun 01 2012 4:38am
Location: Oakland, CA USA

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

Post by -dg » Jul 22 2018 12:17am

I finally got my controllers and downloaded and built the tool chain and the project sources (from github) so I can start contributing.
I'm working on Linux, specifically Ubuntu 18.04. My immediate goal is to get all the related projects to build and to document and possibly script the process. If I get this done, I'd like casainho and stancecoke to add or update the documentation to their repos so the next person has an easier time.

I tried to build both the casainho projects and the stancecoke project.

I ran into a couple problems:

The casainho project BMSBattery_S_controllers_firmware is the only one that builds easily. The others: Kunteng_LCD3_firmware and TongSheng_TSDZ2_motor_controller_firmware fail to build because the StdPeriphlib/src directory is missing. It is included in the BMSBattery_S_controllers_firmware project. Once I added it I was able to build all the projects.

May I suggest that you update your projects with the StdPeriphlib that it needs.

The stancecoke/BMSBattery_S_controllers_firmware breaks sdcc. Specifically compiling main.c seg faults in the assembler sdasstm8. I used gdb to track this down and have sent a core file and main.asm as part of a bug report to sdcc. The bug is: #2772 sdasstm8 seg faults on null pointer deref. I'm sort of stuck here for now.

Reading source code I see that all these projects use printf(). printf is almost 2Kb. I'd be happy to submit a patch to avoid printf, or to supply printf_lite() which would have just %d and %s. How should I submit patches?
If simplicity worked, the world would be overrun with insects.

User avatar
stancecoke   10 kW

10 kW
Posts: 896
Joined: Aug 02 2017 2:56pm

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

Post by stancecoke » Jul 22 2018 3:55am

First, thank you for joning this project!
-dg wrote:
Jul 22 2018 12:17am
The stancecoke/BMSBattery_S_controllers_firmware breaks sdcc.
Have you adapted the Makefile_linux? As nobody used my fork with linux so far, I never updated it. Now I've done it, perhaps you can try again.
-dg wrote:
Jul 22 2018 12:17am
Reading source code I see that all these projects use printf(). printf is almost 2Kb. I'd be happy to submit a patch to avoid printf, or to supply printf_lite() which would have just %d and %s. How should I submit patches?
The print command is only used for debugging and not necessary in normal ride. The communication to the display is done by putchar, this should be much smaller. But of course, you are welcome if you want to improve the code. You have to make the changes in your own fork and then send a pull request. (I've never worked with this also :wink: )

regards
stancecoke

-dg   1 kW

1 kW
Posts: 454
Joined: Jun 01 2012 4:38am
Location: Oakland, CA USA

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

Post by -dg » Jul 22 2018 7:50am

stancecoke wrote:
Jul 22 2018 3:55am
First, thank you for joning this project!
-dg wrote:
Jul 22 2018 12:17am
The stancecoke/BMSBattery_S_controllers_firmware breaks sdcc.
Have you adapted the Makefile_linux? As nobody used my fork with linux so far, I never updated it. Now I've done it, perhaps you can try again.
I did not change Makefile_linux. Even if it is not correct, the compiler should just complain, not crash. So I filed a bug with the sdcc project. I will pull the repo again and try again though.

I'll see about getting the linux set up and builds to work first. I know some people like Windows, but a big attraction of this project is that it is open source. This is more likely to appeal to Linux people than windows people, so I think it is important to getting more developers to have the linux set up be as smooth as possible.
If simplicity worked, the world would be overrun with insects.

-dg   1 kW

1 kW
Posts: 454
Joined: Jun 01 2012 4:38am
Location: Oakland, CA USA

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

Post by -dg » Jul 22 2018 8:19am

One idea that has come up several times in this thread is to have the configuration adjustable without reflashing. I am thinking we could use the serial interface that connects the LCD to set parameters in both the controller and in the LCD by connecting a serial line. I'm also thinking of building something like a headless Cycle Analyst that could handle things like cruise control or different types of throttle.

To make this useful we would need a protocol to communicate settings that would be more general than the current protocol between the LCD display and the controller. Looking around, I found Modbus https://www.lammertbies.nl/comm/info/modbus.html which is used to send state info and settings between different industrial controllers. It is very simple and would not require much code. The idea is that we could use any serial device like a bluetooth dongle or a USB serial and change settings, or read data back from eiher the controller and the LCD. Since it is addressable we could also use Modbus to handle the LCD to controller communication so if we wanted to provide new displays on the LCD it would be easy to do so in a structured way instead of just taking another byte onto the existing protocol.

Since Modbus has been around since 1979, there are lots of interoperable implementations for Linux and Windows in a variety of languages and for various micro controllers. There are at least a dozen AVR or Arduino packages on github and even a couple for STM8 that could be adapted.

Specifically I am interested in making a multi button throttle for drop bars that would support multiple hand positions and cruise control and power settings without requiring a display. This might be based on one of the $1 STM8S breakout boards connected via the LCD serial to the controller. It would read speed and cadence etc from the controller and the buttons state and then send throttle either via the throttle wire, or even better via Modbus over the serial line. Ideally this device could live on the bars with the brake lever sensors and the throttle buttons and only have the 4 wire serial+power interface to the controller so that it would be fly-by-wire and there would not be such a mess of cable all over the bike.

Is this of any interest? Do I need to explain it better?
If simplicity worked, the world would be overrun with insects.

User avatar
stancecoke   10 kW

10 kW
Posts: 896
Joined: Aug 02 2017 2:56pm

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

Post by stancecoke » Jul 22 2018 10:20am

-dg wrote:
Jul 22 2018 8:19am
Is this of any interest? Do I need to explain it better?
I had this discussion with casainho in early days of this project already. My aim is to make the firmware usable for unexperienced PC users. 99% will have a windows operating system. 99% will not care if they connect a ST-Link or a USB to UART converter to the controller (they will not know the difference between both devices at all...). Only if there is an android app to do the settings, it would have an advantage to set the parameters via UART. But the user would have to buy two devices, the ST-Link and a bluetooth module...

Feel free to do what ever you want. :wink:

regards
stancecoke

User avatar
stancecoke   10 kW

10 kW
Posts: 896
Joined: Aug 02 2017 2:56pm

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

Post by stancecoke » Jul 22 2018 11:20am

I've now added the throttle override in torque-simulation mode now. I can't test it at the moment, as my normal PAS-Sensor is defective :(
Throttle without pedaling in offroad mode is not implemented yet.

regards
stancecoke

geofft   1 kW

1 kW
Posts: 318
Joined: Nov 09 2012 9:41am
Location: Berkshire UK

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

Post by geofft » Jul 22 2018 1:53pm

stancecoke wrote:
Jul 22 2018 11:20am
I've now added the throttle override in torque-simulation mode now. I can't test it at the moment, as my normal PAS-Sensor is defective :(
Seems to work just fine, many thanks for your time and effort on this.
Throttle without pedaling in offroad mode is not implemented yet.
We look forward to this full feature version appearing sometime soon.... :wink:
BBS02 V2 48v 750w, 12s lipo.
Q128H (36v 201rpm), KT36/48SVPR 20amp, LCD3, 48v 12s lipo.

User avatar
stancecoke   10 kW

10 kW
Posts: 896
Joined: Aug 02 2017 2:56pm

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

Post by stancecoke » Jul 22 2018 2:25pm

geofft wrote:
Jul 22 2018 1:53pm
We look forward to this full feature version appearing sometime soon.... :wink:
Throttle is activated always in offroad mode now! There's no feedback in the display, that you've activated the offroad mode actually.

regards
stancecoke
Last edited by stancecoke on Jul 23 2018 2:45am, edited 1 time in total.

geofft   1 kW

1 kW
Posts: 318
Joined: Nov 09 2012 9:41am
Location: Berkshire UK

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

Post by geofft » Jul 22 2018 3:32pm

stancecoke wrote:
Jul 22 2018 2:25pm
geofft wrote:
Jul 22 2018 1:53pm
We look forward to this full feature version appearing sometime soon.... :wink:
Throttle is activated always in offroad mode now! There's no feedback in the display, that you've activated the offroad mode actually.

regards
stanecoke
That was quick... :shock:
Will give it a try tomorrow.
BBS02 V2 48v 750w, 12s lipo.
Q128H (36v 201rpm), KT36/48SVPR 20amp, LCD3, 48v 12s lipo.

casainho   100 MW

100 MW
Posts: 2648
Joined: Feb 14 2011 2:43pm

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

Post by casainho » Jul 22 2018 7:40pm

-dg wrote:
Jul 22 2018 12:17am
I finally got my controllers and downloaded and built the tool chain and the project sources (from github) so I can start contributing.
I'm working on Linux, specifically Ubuntu 18.04. My immediate goal is to get all the related projects to build and to document and possibly script the process. If I get this done, I'd like casainho and stancecoke to add or update the documentation to their repos so the next person has an easier time.
I would like to give you write access - please tell me your github account.

I tried to build both the casainho projects and the stancecoke project.
-dg wrote:
Jul 22 2018 12:17am
The others: Kunteng_LCD3_firmware and TongSheng_TSDZ2_motor_controller_firmware fail to build because the StdPeriphlib/src directory is missing. It is included in the BMSBattery_S_controllers_firmware project. Once I added it I was able to build all the projects.
Good to know. I will correct that later.

So, TSDZ2 and LCD3 are really different projects from BMSBattery_S_controllers_firmware. Which hardware/motor controller do you have and plan to develop for??
-dg wrote:
Jul 22 2018 12:17am
Reading source code I see that all these projects use printf(). printf is almost 2Kb. I'd be happy to submit a patch to avoid printf, or to supply printf_lite() which would have just %d and %s. How should I submit patches?
Fork and than submit a pull request.
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, you can consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

casainho   100 MW

100 MW
Posts: 2648
Joined: Feb 14 2011 2:43pm

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

Post by casainho » Jul 22 2018 7:52pm

-dg wrote:
Jul 22 2018 8:19am
One idea that has come up several times in this thread is to have the configuration adjustable without reflashing. I am thinking we could use the serial interface that connects the LCD to set parameters in both the controller and in the LCD by connecting a serial line. I'm also thinking of building something like a headless Cycle Analyst that could handle things like cruise control or different types of throttle.

To make this useful we would need a protocol to communicate settings that would be more general than the current protocol between the LCD display and the controller. Looking around, I found Modbus https://www.lammertbies.nl/comm/info/modbus.html which is used to send state info and settings between different industrial controllers. It is very simple and would not require much code. The idea is that we could use any serial device like a bluetooth dongle or a USB serial and change settings, or read data back from eiher the controller and the LCD. Since it is addressable we could also use Modbus to handle the LCD to controller communication so if we wanted to provide new displays on the LCD it would be easy to do so in a structured way instead of just taking another byte onto the existing protocol.

Since Modbus has been around since 1979, there are lots of interoperable implementations for Linux and Windows in a variety of languages and for various micro controllers. There are at least a dozen AVR or Arduino packages on github and even a couple for STM8 that could be adapted.
Well, I am developing LCD3 and TSDZ2 firmware and I am at a point that I feel the need of a more elaborated protocol between them, mostly like some specific communication to send data when we are on configuration menu and other data when we are at main menu/screen.

Here the list of features of our OpenSource LCD3 firmware: https://github.com/OpenSource-EBike-fir ... d-features
-dg wrote:
Jul 22 2018 8:19am
Specifically I am interested in making a multi button throttle for drop bars that would support multiple hand positions and cruise control and power settings without requiring a display. This might be based on one of the $1 STM8S breakout boards connected via the LCD serial to the controller. It would read speed and cadence etc from the controller and the buttons state and then send throttle either via the throttle wire, or even better via Modbus over the serial line. Ideally this device could live on the bars with the brake lever sensors and the throttle buttons and only have the 4 wire serial+power interface to the controller so that it would be fly-by-wire and there would not be such a mess of cable all over the bike.

Is this of any interest? Do I need to explain it better?
Currently, I am interested in using LCD3 and TSDZ2 motor and motor controller - not much using a very custom hardware.
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, you can consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

-dg   1 kW

1 kW
Posts: 454
Joined: Jun 01 2012 4:38am
Location: Oakland, CA USA

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

Post by -dg » Jul 23 2018 12:14am

casainho wrote:
Jul 22 2018 7:40pm
So, TSDZ2 and LCD3 are really different projects from BMSBattery_S_controllers_firmware. Which hardware/motor controller do you have and plan to develop for??
I have Q100H, Q128H and Bafang SWXH, but I'm not opposed to trying other things.

I will say that it seems to me better to have submodules of the same project than different projects as surely there is lot of common code and setup. For example, the board initialization, reading the ADC, the UART handling, the PAS/throttle/torque sensor input, brake levers, under voltage monitoring, etc and probably a lot more are similar or identical between the original KT controller project and the TSDZ2. LCD3 applies to both. I'm thinking an organization more like SDCC where most of the compiler is the same but stm8 and 8051 have specific sub modules.

I say this because I think the current multiple projects approach risks fragmenting what is already a very small user base. The number of people who:

- want an electric bike
- want to make their own bike
- want to have open source firmware
- know enough/are brave enough to open the controller and solder onto it.

That's not that many users. Then for contributors they have also to be able to program and debug. Very few people are left. But, I am hopeful that there might be still be enough to make this a real project if we can collect them all in one place. If we divide them up along the lines of hubmotor/central motor/display/no display/extra hardware/no extra hardware/windows/linux then it seems we will have 3 or 5 or 7 one person projects that die off soon instead of one multi person project that can survive and make a better more complete controller and display system.
If simplicity worked, the world would be overrun with insects.

Mavabo   10 µW

10 µW
Posts: 5
Joined: Jun 24 2018 10:57am
Location: The Netherlands

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

Post by Mavabo » Jul 23 2018 2:18am

Hello to you all..

[Finally the holidays are over :wink: and got my system running like a Cadillac! Must been a combination of wires I didn't come up with :oops:
Exept for one thing: If I stop pedaling the motor won't stop until I use my digital electric brake. Even so when I'm standig still and push my bike foreward without pedaling, it softly switches the motor on...until I brake again. Tried some changes in the configurator but nothing seemes to work....
What do I have to change in the code to overcome this?
Attached my config.h...

Greetz..

S06SConfig.h230718.txt
(1.05 KiB) Downloaded 11 times

User avatar
stancecoke   10 kW

10 kW
Posts: 896
Joined: Aug 02 2017 2:56pm

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

Post by stancecoke » Jul 23 2018 2:44am

Mavabo wrote:
Jul 23 2018 2:18am
If I stop pedaling the motor won't stop until I use my digital electric brake. Even so when I'm standig still and push my bike foreward without pedaling, it softly switches the motor on...
Nice to see that you've managed to install all things needed! 8)
Please try the older commit:
https://github.com/stancecoke/BMSBatter ... a40e4b.zip

I have to check it in THROTTLE_AND_PAS mode in the recent code.
geofft wrote:
Jul 22 2018 3:32pm
That was quick... :shock:
Will give it a try tomorrow.
I've added the feedback for activated offroad mode by showing high velocity for 3 seconds now. would be fine if you could check it. :-)

-dg wrote:
Jul 23 2018 12:14am
I say this because I think the current multiple projects approach risks fragmenting what is already a very small user base.
I agree totally, I'm looking forward to see your solutions! :D

regards
stancecoke

casainho   100 MW

100 MW
Posts: 2648
Joined: Feb 14 2011 2:43pm

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

Post by casainho » Jul 23 2018 3:57am

-dg wrote:
Jul 23 2018 12:14am
casainho wrote:
Jul 22 2018 7:40pm
So, TSDZ2 and LCD3 are really different projects from BMSBattery_S_controllers_firmware. Which hardware/motor controller do you have and plan to develop for??
I have Q100H, Q128H and Bafang SWXH, but I'm not opposed to trying other things.

I will say that it seems to me better to have submodules of the same project than different projects as surely there is lot of common code and setup. For example, the board initialization, reading the ADC, the UART handling, the PAS/throttle/torque sensor input, brake levers, under voltage monitoring, etc and probably a lot more are similar or identical between the original KT controller project and the TSDZ2. LCD3 applies to both. I'm thinking an organization more like SDCC where most of the compiler is the same but stm8 and 8051 have specific sub modules.

I say this because I think the current multiple projects approach risks fragmenting what is already a very small user base. The number of people who:

- want an electric bike
- want to make their own bike
- want to have open source firmware
- know enough/are brave enough to open the controller and solder onto it.

That's not that many users. Then for contributors they have also to be able to program and debug. Very few people are left. But, I am hopeful that there might be still be enough to make this a real project if we can collect them all in one place. If we divide them up along the lines of hubmotor/central motor/display/no display/extra hardware/no extra hardware/windows/linux then it seems we will have 3 or 5 or 7 one person projects that die off soon instead of one multi person project that can survive and make a better more complete controller and display system.
I really like that idea of try using the submodules but I lack knowledge and experience to do that.
Also, I think the project like that will be big and harder to understand for developers, probably also hard to debug and a change for one project may break the other project -- that will be difficult because we are testing with real hardware and takes a lot of time for testing/validate new changes and every deveper will not have all the hardware to test.

For now, I think at least sharing knowledge between projects is already a big win. And even are different developers that will explore different paths and that can be good, if they share the results/knowledge.

There is one good thing: the flash memory is only 16kbytes so each project can't be big - more than enough for 1 only experienced developer to maintain. I feel the hard part is to have hardware and test on the hardware.

I wish you could help on the LCD / controller communication interface. TSDZ2 firmware is almost done, I would say it is at 80% and LCD3 firmware is very complete by now but lacks a good interface specific for sending configuration data. All the LCD menus are now implemented and well structured in the code so it is easy to expand.
Both TSDZ2 and LCD3 firmware take currently about 18kbytes flash memory while the limit is 32kbytes, so there is opportunity to improve much more, mainly on LCD side.
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, you can consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

User avatar
stancecoke   10 kW

10 kW
Posts: 896
Joined: Aug 02 2017 2:56pm

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

Post by stancecoke » Jul 23 2018 7:13am

There is an installer for SDCC 3.7.1 for 64 bit Windows available. It's in a snapshot folder, so not a proven release ?!
https://sourceforge.net/projects/sdcc/f ... w32-setup/

Compiling our project works, it even throws this warning no longer.

Code: Select all

Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp4. Please contact sdcc authors with source code to reproduce.
I'm not sure if I should refer to this installer in the tutorial, as it's much easier to install and doesn't need the cygwin files...

regards
stancecoke

geofft   1 kW

1 kW
Posts: 318
Joined: Nov 09 2012 9:41am
Location: Berkshire UK

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

Post by geofft » Jul 23 2018 9:07am

stancecoke wrote:
Jul 23 2018 2:44am
geofft wrote:
Jul 22 2018 3:32pm
That was quick... :shock:
Will give it a try tomorrow.
I've added the feedback for activated offroad mode by showing high velocity for 3 seconds now. would be fine if you could check it. :-)
Just tried this but can't get offmode mode (cheat) to switch, no display indication or throttle enable.

I'm using the default 1sec timing, I could trigger this every time when it was added to casainho's branch (after you commented out the print commands...?), so I guess something's not quite right here..
BBS02 V2 48v 750w, 12s lipo.
Q128H (36v 201rpm), KT36/48SVPR 20amp, LCD3, 48v 12s lipo.

User avatar
stancecoke   10 kW

10 kW
Posts: 896
Joined: Aug 02 2017 2:56pm

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

Post by stancecoke » Jul 23 2018 10:44am

You are right, there was a bug in the latest commit. now it works without display, Please check the display feedback again!

Thanks
stancecoke

User avatar
stancecoke   10 kW

10 kW
Posts: 896
Joined: Aug 02 2017 2:56pm

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

Post by stancecoke » Jul 23 2018 10:45am

Mavabo wrote:
Jul 23 2018 2:18am
Exept for one thing: If I stop pedaling the motor won't stop until I use my digital electric brake.
I tried it with the most recent code in THROTTLE_and_PAS mode, it worked for me. I guess it's a problem of the auto-zero process for battery current at start up. Maybe your controller needs more time to get a constant ADC reading. Perhaps we should try a longer delay.

regards
stancecoke
Last edited by stancecoke on Jul 23 2018 11:30am, edited 3 times in total.


geofft   1 kW

1 kW
Posts: 318
Joined: Nov 09 2012 9:41am
Location: Berkshire UK

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

Post by geofft » Jul 23 2018 11:35am

stancecoke wrote:
Jul 23 2018 10:44am
You are right, there was a bug in the latest commit. now it works without display, Please check the display feedback again!

Thanks
stancecoke
Strange, still can't get this to trigger, no display indication or throttle.
I'm in no rush for this fix, please take your time... :)
BBS02 V2 48v 750w, 12s lipo.
Q128H (36v 201rpm), KT36/48SVPR 20amp, LCD3, 48v 12s lipo.

User avatar
stancecoke   10 kW

10 kW
Posts: 896
Joined: Aug 02 2017 2:56pm

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

Post by stancecoke » Jul 23 2018 11:46am

Can you please try again. The morse-phases are shorter than expected, I'm sure you will manage to activate the offroad mode! The throttle needs some tries before the motor starts the first time sometimes, I guess that's because of the phase current limitation...

regards
stancecoke

geofft   1 kW

1 kW
Posts: 318
Joined: Nov 09 2012 9:41am
Location: Berkshire UK

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

Post by geofft » Jul 23 2018 12:45pm

stancecoke wrote:
Jul 23 2018 11:46am
Can you please try again. The morse-phases are shorter than expected, I'm sure you will manage to activate the offroad mode! The throttle needs some tries before the motor starts the first time sometimes, I guess that's because of the phase current limitation...

regards
stancecoke
Ok, but I did try many attempts with different timings (slow-medium-fast) without a single success.
Will try again tomorrow and get back to you.. :wink:
BBS02 V2 48v 750w, 12s lipo.
Q128H (36v 201rpm), KT36/48SVPR 20amp, LCD3, 48v 12s lipo.

User avatar
stancecoke   10 kW

10 kW
Posts: 896
Joined: Aug 02 2017 2:56pm

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

Post by stancecoke » Jul 23 2018 1:01pm

Thank you for your patience! :)
Here a video from the output in diagnostics mode. First time I failed, the second try is successful. In the fourth column is the "cheat state", in the fifth the time counter. So the sequence is pull - release - pull - release.
During state "4" (3seconds, the counter runs to 150) the display should show a high velocity. In state "5" the offroad mode is active.



I've updated the repo at github again, with a different timing for the auto zero process of battery current. I found no difference to the old solution, but perhaps it helps Mavabo with his problem.
Motor start is still not reliable from standstill with throttle, I have to improve the phase current limitation algorithm...

regards
stancecoke
Last edited by stancecoke on Jul 24 2018 3:23am, edited 4 times in total.

-dg   1 kW

1 kW
Posts: 454
Joined: Jun 01 2012 4:38am
Location: Oakland, CA USA

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

Post by -dg » Jul 24 2018 12:38am

casainho wrote:
Jul 23 2018 3:57am
I wish you could help on the LCD / controller communication interface. TSDZ2 firmware is almost done, I would say it is at 80% and LCD3 firmware is very complete by now but lacks a good interface specific for sending configuration data. All the LCD menus are now implemented and well structured in the code so it is easy to expand.
Both TSDZ2 and LCD3 firmware take currently about 18kbytes flash memory while the limit is 32kbytes, so there is opportunity to improve much more, mainly on LCD side.
The concept here is to collect and move all the configuration and run time variables into a big structure and let it be managed entirely by Modbus. So all those magic constants like angle correction and limits and magnet numbers from config.h, and all the read outs from the ADC and the brake switches and PAS sensor and all the messages to the LCD would all be handled via Modbus.

Modbus is a master slave system, the master asks for values, the slave replies, The master commands new settings, the slave sets them. There can be one master, but many slaves. Inside a slave there are what they quaintly call "coils" and "registers". A coil is one bit corresponding to a switch or relay. A register is 16 bits, Some are inputs, ie data the slave collects from sensors fore example battery voltage, some are settings, ie commands or configuration value, for example low battery limit.

In operation when the controller comes up it is a Modbus slave. It initializes all the state with defaults and as it runs it updates the live values, ie adc readings. If there is another device, like an LCD display, or a PC serial, or a custom control unit (like I want for drop bars) then that is the Modbus master. It can read any information it wants via Modbus query. It can also set configuration via Modbus set commands.

As a Modbus master, the LCD or PC program would just loop using Modbus queries to ask for whatever information it wants and displaying it. Commands, eg LCD button presses, or settings updates from the PC are just Modbus set commands to the controller.

By putting all the configuration and all the data into theMmodbus accessible data area we can see any detail we like about the operation of the controller and make changes to any setting on the fly. For example, when bringing up a new motor there seem to be a few settings that have to be discovered by trial and error. With config under Modbus control, this could be done from a connected laptop or something while the motor is running and the resulting currents, rpm, and voltages, phase angles read back in real time. No need to edit files, recompile, or re-flash. We could even have a binary distribution and let people configure it to a new setup without having to build the firmware at all. Someone could even sell pre-flashed controllers should there be any interest in such a thing.

Since Modbus is very simple it would not take much code space. The configuration, (writable) Modbus registers could go in the EEPROM and the run time (read only) register would be in RAM. As I understand it, we are mostly short of flash, not RAM or EEPROM.

The other component is the Modbus Map. This is basically a text file or dictionary defining all the Modbus registers. The C language definition of how to access these in the controller, ie the replacement for config.h could be generated from the map file.

Here is a sample Modbus slave implementation for small systems. We could adapt this, or one of several similar projects: https://github.com/FxDev/PetitModbus. Take a look at the code just to get an idea of the size.

Here is a generic Modbus gui for Windows and Linux, pretty basic, but shows the idea: https://sourceforge.net/projects/qmodmaster/. I'm sure there are nicer ones available, but this should serve to test against.

And here is a giant PDF with the Modbus map documentation of a line of industrial standby power generation systems: https://www.ccontrols.com/support/dp/modbus2300.pdf Basically every configurable or observable about this equipment is in the Modbus map and so is by default remotely controllable and viewable. Just skip the first few pages to get an idea of the kinds of items it handles. Our system is much simpler but the same sort of meta-data driven approach will give us a well defined and extendable interface between the controller and displays other devices.

If we do this, I plan to make a fully fly by wire bike, all control going over two wires as Modbus messages from a MCU on the bars to the controller near the cranks. PAS/Torque and rear wheel speed would go to the controller. Throttle, display, brake levers, handlebar buttons would go to the handlebar MCU, just data tx+rx would connect the two. No wire rats nests, no wet shorted throttle connectors just one thin four conductor cable.
If simplicity worked, the world would be overrun with insects.

Post Reply