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

stancecoke said:
Thanks you for your hints, but I don't want to switch to Linux. I want to keep the possibility to have an easy to use tool that a normal PC user can handle with just a few self explaining clicks. Otherwise this project will end with 3 or 4 freaky users like us....

https://www.netmarketshare.com/operating-system-market-share.aspx?qprid=10&qpcustomd=0
But see that we are trying to do something that no one does: let the final user build a custom firmware. I don't remember a product/company that does this, only some configurations of the run time variables. Development environment is complex.

One idea: Linux virtual box image with all installed and the Java software app installed for user click: select firmware options; build and flash. Flash would use stm8flash in background.

For instance, I got a contact from a Portuguese group that may be interested in using this project, they build and sell electric karts: http://www.ecokartportugal.com/
They say that a firmware with every parameter open and possible customization is important for them. They also said they have technical guys on the team - I would say this kind of guys would be able to follow some instructions to build and flash the firmware.


If you decide to go with Linux for development (at least on this phase due to the issues you are finding), go with Ubuntu 17.04 that is the one I am using and I will be bale to help you.
 
casainho said:
One idea: Linux virtual box image with all installed and the Java software app installed for user click: select firmware options; build and flash.
Please consider, that 99,8% of E-Bike riders will use Windows and 99,5% of E-Bike riders will use their Windows PC just for surfing the internet, checking E-mails and do some office applications like word or excel. (My guess). They are used to have a one-click-installer. I think even the soldering of the wire for flashing is a hurdle that will be taken only by very few people.
So again, from my point of view, it would be better to switch to the Lishui controllers, where the connector for flashing is available already and the STM32 toolchain is much more common....
(And you have built the firmware for a STM32 system already :wink:)

casainho said:
For instance, I got a contact from a Portuguese group that may be interested in using this project, they build and sell electric karts: http://www.ecokartportugal.com/
I think it's not the idea of open source projects to enable commercial companies to earn money...

Anyway, as long as the FOC isn't working, it makes no sense to have discussions about operating systems :shock:
Do you see the same behavior with your motor, that the shown correction angle isn't changing with speed/load?

Regards
stancecoke
 
casainho said:
we are trying to do something that no one does: let the final user build a custom firmware.

Can you please clarify whether the goal is to allow any person (including final users) to perform the build cycles to arrive at a working firmware, or whether you require the person to do so.

The spirit of free software basically is limited to "all parts required to build the software are freely available" (where "free" can be equated with zero cost and sort of low entry barriers).

If you want to require that every final user builds firmware, you will add quite a bit on top of the requirement of actually having access to an ST-Link V2 programmer, taking the pain to register with STMicroelectronics to download, and so on.

Anyway, I had a first quick peek in the middle of the night at one of the more recent branches. Some feedback:

I had difficulties seeing the relevant files, in the relevant places. I'd propose some rearranging of files (e.g. dedicated "docs", "src" directories, some dedicated directory dedicated to user customization etc), some .gitignore management, some

The build environment is challenged in a number of ways:
1.) quite a bit of Eclipse is leaking through; moving this away (or out) would clarify matters
2.) a copy of some make.exe (cygwin or mingw) is commited; this works, but is a bit awkward in light of GPL and updates
3.) the make files used for building on Linux and Windows diverge mostly because the Windows environment lacks tooling support, most likely in the form of cygwin plus https://stm8-binutils-gdb.sourceforge.io/
4.) it might be preferable to consistently use openocd (instead of going STM tools sometimes)
5.) the Windows build (with my sdcc) bitterly complains about some unmapped things, but still produces output; this does not instill confidence ;)
6.) Linux build environment strips "useless" (ok, not, but then ...) sizable ELF sections to get the binary down in size; Windows does not (for lack of tooling - see above, cygwin etc)

Here is what I see as reasonable options to proceed:

1.) The owner(s) of the project declare(s) that this is designed to be Free Software, not "Final users must compile their own firmware". That is just a mission statement. ;)

2.) Maximize alignment of the build environment across all supported build platforms; supported platforms could be Linux, Windows Subsystem for Linux (essentially Linux user land on Windows 10, https://msdn.microsoft.com/en-us/commandline/wsl/release_notes), Windows 10 (native), macOS

3.) Define an end user(!) firmware customization strategy - what are meaningful values for an end user to configure? Battery protection - no? Wheel diameter / circumference - yes! I guess that from an 80/20 perspective, just a handful of custom builds would cover the vast majority of scenarios out in the wild - e.g. 26/28" wheels, 36/48V battery, 25 km/h limit/no limit. That's eight combination only for now. Establish continuous integration (CI) using travis-ci.org for all of that, offer the firmware binary for download immediately.

4.) Offer a ready-made, truly minimal virtual machine (based, e.g., on Alpine Linux) for download, to act as a deployable build environment (continuously composed and updated by CI, again). That would make it a 50 MB download (give or take) plus 100+ MB for installing VirtualBox (with admin privileges) as the only prerequisite.
 
stancecoke said:
I think even the soldering of the wire for flashing is a hurdle that will be taken only by very few people.

... and it starts with unscrewing the lid of the controller box.

Don't forget that getting hold of flasher hardware is another barrier. As is finding the right driver. And getting this into Windows 10 (which is picky about signatures) etc.

To be frank, many people could benefit from having OSS custom firmware built on an OSS stack, but very very few people will ever be able to get firmware into the controller, custom or not.
 
@daffy99: You can buy a STLink V2 clone for just very few dollars. OK, you have to register at ST to download the free ST Visual Programmer, but then you get an installer thats doing everthing with just one click (including the drivers for Win10). Then you have to install the SDCC, it comes with an one-click installer, too.
The rest will be done by the java tool (unlock the memory, setting user relevant parmeters and flashing), that can be download from github and just has to be unpacked. OK, the parameters are not described yet in the java tool, but that's just work that has to be done....
I think these three steps can be done even by an inexperienced windows user...., perhaps 4 steps if Java Runtime isn't installed already.

As an example: Many users pimp their BBS01 Mid-Drives with buying a USB-UART Converter (or buy a ready assembled cable), the linked thread has 1700 posts and 300.000 calls :shock: so far. I think these users don't see any difference, if they are flashing firmware with a USB-cable or just setting parameters via UART with a USB-cable. (I think they just don't know, and just don't want to know what's happening in detail, it just has to work...)

@casainho: I just pushed a commit to the CheckADC branch, can you please test, if you get reasonable values for phaseBcurrent in 6 step mode and always something about 127 in interpolation mode, like I do?

Edit: I just found, that there are Windows binaries of the stm8 binutils available already. They are just a little hidden at sourceforge. :D Now I can check the code with exactly the same compiler-options than in Linux!

Thanks
stancecoke
 
Hello, I have 3x 6fet 2x 12fet and one 18fet all sine wave kunteng +lcd5, lcd3 and I would like to help you with the firmware, I can do "real life" testing on my bikes with different controllers for you, But I cant do "any" programing. I read a lot from the development thread and others about this and I see a lot of potencial in "small" changes in lcd and controller firmware. But it seems you are reprograming it completly, Is it hard to just change the things which needs it? Or create a pc app which reprograms the original fw? What is your goal actually? I kinda dont understand why you start from zero.

Things which I need is
1. throttle lineary controlling batt. amps
2. Showing motor temperature with kty84.
3.Faster reaction to full throttle at speed.
4. More options of C4 parameter for legal reasons

Those are top few things which firmware needs by my opinion (I can pay for it) but there is more for sure.

Do you know that there is 24 mosfet 72v 70A version? By my simple math, with CSD19536KCS mosfets (+traces and wires for sure) It can easily do 180A from battery thats a serious power for 70$ controller and 20$ mosfet upgrade. Also 6fet modified for 72v with these mosfets can do 4kW. Very impressive.

With your firmware, even an adaptto user (like me) will be happy with these controllers. Thats a whole new world.

I Imagine the best result will be ability to program "everything" by lcd3 or lcd6 (like exact phase amperage value, low cutoff value, regen strenght value, ...) Is that kind of what you want to do or is it too hard?

Last question for now, Can hardware even do analog variable brake? Or it will need an aditional circuit? I mean PWM input to the brake signal wire will be possible right?

Thank you for all your hard work
 
Maybe you will find this interesting http://www.ebay.com/itm/232088804925

Best for the price.
They can add reverse switch wires and maybe more for free.
It has phase B current measuring and there are around 3.3mOhm 100A 68v mosfets, Dont remember the type.

With wires and traces +shunt moded it can safely do 90A, running cheap hallomotor 48v 1500v it does 72km/h easily (good to change phase wires in motor to 4mm2)

That's stealth bomber power for few bucks, with modded firmware even better.
 
stancecoke said:
casainho said:
So again, from my point of view, it would be better to switch to the Lishui controllers, where the connector for flashing is available already and the STM32 toolchain is much more common....
(And you have built the firmware for a STM32 system already :wink:)
That is great "feature" of Lishui for sure but what I don't like is that they only have 250W controller. The 500W or more may be different hardware. Kunteng controllers have much more potential due to higher voltages and higher currents. From the technical side I would prefer Lishui.

stancecoke said:
casainho said:
For instance, I got a contact from a Portuguese group that may be interested in using this project, they build and sell electric karts: http://www.ecokartportugal.com/
I think it's not the idea of open source projects to enable commercial companies to earn money...

Anyway, as long as the FOC isn't working, it makes no sense to have discussions about operating systems :shock:
Do you see the same behavior with your motor, that the shown correction angle isn't changing with speed/load?
[/quote]
I think may be hard to think in earn money and being a totally OpenSource company. But it is not the aim to not earn money and block that possibility. Anyway, there are well known OpenSource projects with huge success - look at Arduino for instance.
 
daffy99 said:
casainho said:
we are trying to do something that no one does: let the final user build a custom firmware.

Can you please clarify whether the goal is to allow any person (including final users) to perform the build cycles to arrive at a working firmware, or whether you require the person to do so.

The spirit of free software basically is limited to "all parts required to build the software are freely available" (where "free" can be equated with zero cost and sort of low entry barriers).

If you want to require that every final user builds firmware, you will add quite a bit on top of the requirement of actually having access to an ST-Link V2 programmer, taking the pain to register with STMicroelectronics to download, and so on.

Anyway, I had a first quick peek in the middle of the night at one of the more recent branches. Some feedback:

I had difficulties seeing the relevant files, in the relevant places. I'd propose some rearranging of files (e.g. dedicated "docs", "src" directories, some dedicated directory dedicated to user customization etc), some .gitignore management, some

The build environment is challenged in a number of ways:
1.) quite a bit of Eclipse is leaking through; moving this away (or out) would clarify matters
2.) a copy of some make.exe (cygwin or mingw) is commited; this works, but is a bit awkward in light of GPL and updates
3.) the make files used for building on Linux and Windows diverge mostly because the Windows environment lacks tooling support, most likely in the form of cygwin plus https://stm8-binutils-gdb.sourceforge.io/
4.) it might be preferable to consistently use openocd (instead of going STM tools sometimes)
5.) the Windows build (with my sdcc) bitterly complains about some unmapped things, but still produces output; this does not instill confidence ;)
6.) Linux build environment strips "useless" (ok, not, but then ...) sizable ELF sections to get the binary down in size; Windows does not (for lack of tooling - see above, cygwin etc)

Here is what I see as reasonable options to proceed:

1.) The owner(s) of the project declare(s) that this is designed to be Free Software, not "Final users must compile their own firmware". That is just a mission statement. ;)

2.) Maximize alignment of the build environment across all supported build platforms; supported platforms could be Linux, Windows Subsystem for Linux (essentially Linux user land on Windows 10, https://msdn.microsoft.com/en-us/commandline/wsl/release_notes), Windows 10 (native), macOS

3.) Define an end user(!) firmware customization strategy - what are meaningful values for an end user to configure? Battery protection - no? Wheel diameter / circumference - yes! I guess that from an 80/20 perspective, just a handful of custom builds would cover the vast majority of scenarios out in the wild - e.g. 26/28" wheels, 36/48V battery, 25 km/h limit/no limit. That's eight combination only for now. Establish continuous integration (CI) using travis-ci.org for all of that, offer the firmware binary for download immediately.

4.) Offer a ready-made, truly minimal virtual machine (based, e.g., on Alpine Linux) for download, to act as a deployable build environment (continuously composed and updated by CI, again). That would make it a 50 MB download (give or take) plus 100+ MB for installing VirtualBox (with admin privileges) as the only prerequisite.
Talking for me. First I have my own goals like I want to ride my ebikes (including the ones of my family) using custom firmware. I also want to learn firmware and have it on my portfolio.
For the project, I can't implement every idea I have nor the ideas of the others. I must say I don't know much about the technologies you mention like continuous integration. But because I don't time nor I don't have such experience, as not I have such expectations, I don't want to block others from trying to do. But at same time I would like to have a working project, I would prefer something smaller than some big thing that don't have enough quality or attractiveness for users and/or developers.

You gave a lot of what seems good feedback but that would take a great amount of work/time. I don't have such time nor I am motivated to do it on next weeks -- maybe I will learn about this in future.

3. That more about what I think now but don't know nothing about CI.
4. Would be great but I can't do it.
 
Thank you for all the information.

honya96 said:
But it seems you are reprograming it completly, Is it hard to just change the things which needs it?
It is impossible with original firmware. Let's say you have the 18 fet version and you want to use with the pedal torque sensor -- you simple can't use as the original firmware don't implement that feature (you would need to buy the controller with support for the torque sensor, BMSBattery have on selling but it is only the S09, they can't offer all the possible variations because that means all the problems of having stock hardware). With OUR OpenSource firmware, we already implemented that feature :)

That is great to see the needs from another experienced user. One question for you: would you be ok to follow 30 different instructions to be able to customize a firmware for you and flash it, including buying a hardware programmer and soldering a 5 pins header on the controller? Or that would be to much for you?

Sorry, talking for my self, I currently not available to work for others. Thank you to offer that possibility, I think it should be important for some developers.
I Imagine the best result will be ability to program "everything" by lcd3 or lcd6 (like exact phase amperage value, low cutoff value, regen strenght value, ...) Is that kind of what you want to do or is it too hard?

honya96 said:
Last question for now, Can hardware even do analog variable brake? Or it will need an aditional circuit? I mean PWM input to the brake signal wire will be possible right?
Maybe it can do directly if there are available free pins on the board and I think they are. I must say I am also interested in regen braking and exploring the ideas you mention.
Also I don't know if that information could travel by UART. You did mention the LCD. The original ones have the same STM8 microcontroller that we could program but the LCD is not customizable nor have free pins to be expanded.
I wounder if implementing a custom LCD, that could be like an expansion to the controller (sending and receiving data about other sensors, like analog variable brakes, bluetooth, etc), can be important. Maybe even the principal project would be that one and the motor controller be seen as just a generic motor controller.
 
stancecoke said:
As an example: Many users pimp their BBS01 Mid-Drives with buying a USB-UART Converter (or buy a ready assembled cable), the linked thread has 1700 posts and 300.000 calls :shock: so far. I think these users don't see any difference, if they are flashing firmware with a USB-cable or just setting parameters via UART with a USB-cable. (I think they just don't know, and just don't want to know what's happening in detail, it just has to work...)
But be careful with your expectations. While I like your motivation, I think that example is a good one for us to see the big difference -- that users are just configuring a stable firmware with a limited known tested possibilities and using the same hardware (motor + controller). I think will be hard for us to offer that quality -- see all the issues you are having!! It is very dangerous, you just burned your controller!!

stancecoke said:
@casainho: I just pushed a commit to the CheckADC branch, can you please test, if you get reasonable values for phaseBcurrent in 6 step mode and always something about 127 in interpolation mode, like I do?

Edit: I just found, that there are Windows binaries of the stm8 binutils available already. They are just a little hidden at sourceforge. :D Now I can check the code with exactly the same compiler-options than in Linux!
Sorry but I can't test on the next days. I started preparing everything to test the real ebike and I can't stop it now, I had to change some wires and I can't easily go back. I just have 1 working controller.
 
honya96 said:
But it seems you are reprograming it completly, Is it hard to just change the things which needs it? Or create a pc app which reprograms the original fw?
If you are a windows user you can read the tutorial:
https://opensourceebikefirmware.bitbucket.io/EmbeddedFiles/74-Tutorial%20for%20seting%20up%20the%20toolchain%20in%20windows%20environment.pdf

It is quite old, and we've learned a lot since I wrote that. Some links may be dead, but it still gives an introduction.

If you don't want to do programming yourself, but just set relevant parameters and flash our firmware to your controller, you can choose an even faster start and follow the steps in post #655.
But this only works with the "Support for Kingmeter J-LCD" branch yet. And be careful, as all of this is still under development and not tested in all thinkable situations....

regards
stancecoke
 
casainho said:
I wounder if implementing a custom LCD, that could be like an expansion to the controller (sending and receiving data about other sensors, like analog variable brakes, bluetooth, etc), can be important. Maybe even the principal project would be that one and the motor controller be seen as just a generic motor controller.

The file https://github.com/OpenSource-EBike-firmware/BMSBattery_S_controllers_firmware/blob/SVM_7/display.c has a comment at the top which refers to "Functions for the Nokia graphical screen mainly by m--k", which this implementation is able to drive.

That Nokia graphical screen (i.e. LCD display) is what is depicted in the German pedelecforum.de wiki at https://www.pedelecforum.de/wiki/doku.php?id=elektrotechnik:forumscontroller . The direct link to the hardware is https://www.sparkfun.com/products/10168

Note that the "Forumscontroller" mentioned is a custom (Arduino) hardware controller with custom software which is designed to act as the replacement brain (pre-controller) for any existing pedelec controller.
 
casainho said:
Maybe it can do directly if there are available free pins on the board and I think they are. I must say I am also interested in regen braking and exploring the ideas you mention.

There are free pins for many functions, but regen can work with hall sensor input to brake signal wire as it is. it just switches on at certain voltage, So it works like throttle input, just needs to be programed I think.

What is the problem with using original display? When there is the same chip then it can also be programed and thats all we need right? I can even solder programing connector straight to chip, no problem.
I am just affraid of those "30 simple steps" now I am not using pc at all but i have one with windows and I had installed linux before so it will not be a problem too.

I think I will need a lot of time reading through all documentation you guys made until I will be able to use it.
 
If you need more for testing then cheapest 6fets and displays are at http://www.pswpower.com (when buying single unit its better on their Aliexspress.
 
honya96 said:
What is the problem with using original display? When there is the same chip then it can also be programed and thats all we need right? I can even solder programing connector straight to chip, no problem.
I am just affraid of those "30 simple steps" now I am not using pc at all but i have one with windows and I had installed linux before so it will not be a problem too.

I think I will need a lot of time reading through all documentation you guys made until I will be able to use it.
Regen works already on OUR current firmware but is experimental only.

The LCD3 for instance, is the most complete LCD from Kunteng and shows only the power up to 1999W, because I can see the fixed symbols on the LCD. If the LCD as graphical, we could program anything. There is STM32F103 + LCD touchscreen on Ebay, with free pins available:
[youtube]Tg3s4WaVeSI[/youtube]

Firmware is not stable yet, I don't recommend no one to use it instead developers.
 
First EBike ride with OUR OpenSource firmware for BMSBattery S06S / Kunteng motor controllers
Happy that my son was the first one to see and try!! :)

All went ok but found some issues:
- one time the BMS from the battery pack did cutoff the power, when I was blocking the motor and pushing throttle to max
- sometimes the firmware seems to block: the motor stops goes to freewheel and the LCD stops on the latest running speed, the controller don't react anymore to the throttle -- this seems what would happen on current battery over/under voltage protection

Tomorrow I want to make a bigger riding like about 10kms.

[youtube]dWuEvUlixaA[/youtube]
 
casainho said:
First EBike ride with OUR OpenSource firmware for BMSBattery S06S / Kunteng motor controllers
Happy that my son was the first one to see and try!! :)

Congratulations, that is quite some milestone!
 
3 days ago, the famous XenonJohn posted a video where it shows how he will build an EUC using an Arduino + brushless motor controller. We can see the software it uses to configure the kelly controller he uses, to control the 3KW motor. This is first time he is using a brushless motor, 6 years ago he tried with a hub DC motor, probably because of lacking of motor controllers that could do fast switching rotation direction.
I wish hackers like XenonJohn would in future prefer to use OUR OpenSource firmware.

3 days ago:
[youtube]F1BiBumX79Q[/youtube]

6 years ago:
[youtube]2DDZrQe5rp4[/youtube]
 
I made a few more tests with my EBike and found the braking was not working. It is corrected now. For some reason cruise_control is not working but I couldn't correct it yet.

I put this code on master, I had to delete and replace the files. Created a docs folder and put there the files that are somehow documentation.
Stancecoke, maybe you should created a specific repo to the java tool, so all this will be better organized, like more modular. Could be smoething like (I think you have permissions, you need to do it on github online):
https://github.com/OpenSource-EBike-firmware/OSEC_Parameter_Configurator

I am thinking what should be next step. I need to make a real ride to understand what should be the priorities.
 
Can we agree on an name for the firmware??

I think a easy to spell and that is easy to remember, and maybe something explicit.
 
Stancecoke, I will put your code back for the LCD and PAS torque sensor.
 
Back
Top