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

casainho said:
please share/promote this project on german forums

Done ;)

I would prefer an open firmware for the lishui, as i have already one and I've some experience in programming STM32 with STM32duino

But i'll try to get familiar with OpenOCD to implement a bottom bracket torque sensor (one digital singal for PAS and one analog signal for torque)

Regards
stancecoke
 
stancecoke said:
casainho said:
please share/promote this project on german forums

Done ;)

I would prefer an open firmware for the lishui, as i have already one and I've some experience in programming STM32 with STM32duino

But i'll try to get familiar with OpenOCD to implement a bottom bracket torque sensor (one digital singal for PAS and one analog signal for torque)
Thank you.

I just bought the LSW-675 controller from BMSBattery -- let's see If I get it b the end of August.

Give a look to this my project - OpenSource firmware for electric unicycles, for a board using STM32F103 and that implements simplified FOC: https://eggelectricunicycle.bitbucket.io/MicroWorks_30B4_board.html

For the LSW-675 controller, it will be much harder for me, (even If I have my firmware done, that's why was fast to start S06S firmware because STM32F103 and STM8 PWM is almost the same and in general the development tools), because:
- no hall sensors (sensorless)
-- need to develop startup sequence that I never did
-- need to implement the observer to get rotor angle: heavy math to understand but luckily Shane Colton developed as OpenSource the simplified FOC (the one that I implemented) and the observer: https://eggelectricunicycle.bitbucket.io/FOC--Shane_Colton_documentation_and_firmware.html

I would say firmware for LSW-675 may take at least 1 year for me to finish...
 
Do you have a link to a tutorial how to setup the toolchain in eclipse/windows? I read your information already and tried this, but was not sucessful yet...

Regards
stancecoke
 
My advice is for you go with Linux Ubuntu. On a virtual machine may be a very good option since is very fast to boot, experiment, backup. There are a few tools that I am using to develop that work very well on Linux and maybe do not exist on Windows, like serialplot, gitg, stm8flash. See that Linux is used for technical development and windows more for play games or surf web, IMO, I missed some basic software on windows for development.
 
On the current code, the motor works well: starts up well and runs using low current and doing low noise. But near the high speed, it starts to make some noise and current starts to increase a bit more than expected and also the power supply voltage increases a bit.

I played with the MOTOR_ROTOR_DELTA_PHASE_ANGLE to adjust the fixed angle and now I think the issue with the noise at high speed is due to the lack of
angle control/FOC. Now I want to work on this, find a way to adjust this angle and I see 2 paths:
1. find some experimental values for angle adjust that is dependent on speed and also phase current
2. look at phase current displacement and find the angle adjust needed

I already tried 2. and I am not sure I will be able to do it, as I am reading phase current and try find the minimum value point in time and I am having some fails sometimes.

As for 1., this means it will be motor dependent and I would prefer to avoid this. But may be the fast and less risky way to go. I wonder how the original firmware does.
 
stancecoke said:
I would prefer an open firmware for the lishui
Which one do you have? can you please share some pictures of it??
 
casainho, you are trying to do a great job.
To achieve success, you will need to make the controller better than the original. More periphery: display, bluetooth, sensor/sensorless mode for one controller, maybe gyro sensor, smooth regulated regen brake.

The first s06 starts in the trapezoidal mode (you say 6 step), and after acceleration goes into sinewave mode.
For smoother rotation, you need to make programming adjustment of the angles of the hall sensors . And changing the angle when changing the speed of the motor, as it is already maked in Adapto controllers.

Did you try to get the firmware from the working controller, it would be very good to be able to roll back to the original firmware?
 
tony16 said:
casainho, you are trying to do a great job.
To achieve success, you will need to make the controller better than the original. More periphery: display, bluetooth, sensor/sensorless mode for one controller, maybe gyro sensor, smooth regulated regen brake.
Thank you.
It depends "what is better". The original firmware is very good, have good features for a so cheap and limited hardware!! I don't think I can't do more, I would be happy to achieve the same BUT for me better will be to have more flexibility!! For instance, there is no generic and cheap BLDC motor controller for Arduino... people with Arduino are using DC motors because of lack of such generic motor controller -- with S06S and custom firmware, we can get that, a controller that can run a motor and be commanded be the serial port or bluetooth!! See this guy that went to reuse the Hoverboard motor controllers to be able to build a electric kart: http://drewspewsmuse.blogspot.pt/2016/06/how-i-hacked-self-balancing-scooter.html

IMG_0863.JPG


For EBike, I would like to have a button or throttle that helps only on the start by giving like 25% power and then cyclist would get the full power by pedaling -- S06S can't do this, it works with both PAS and throttle and both gives 100%.

So I think the success will be flexibility/freedom for users like me to do different devices/vehicles :)

tony16 said:
The first s06 starts in the trapezoidal mode (you say 6 step), and after acceleration goes into sinewave mode.
For smoother rotation, you need to make programming adjustment of the angles of the hall sensors . And changing the angle when changing the speed of the motor, as it is already maked in Adapto controllers.
Next task!! :)

tony16 said:
Did you try to get the firmware from the working controller, it would be very good to be able to roll back to the original firmware?
Original firmware/flash reading was protected.
 
casainho said:
Which one do you have? can you please share some pictures of it??

Here are some pictures. The big white plug is for flashing, there is some experience in the german forum.
The controller has hall-sensor inputs, so you don't have to worry about the start up.

I still was not able to setup Eclipse with SDCC under windows :? I tried Cosmic, but I think I would have to port all your code.

Hmm, perhaps I have to switch to linux :|

Regard
stancecoke
 

Attachments

  • Lishui_Label.JPG
    Lishui_Label.JPG
    84 KB · Views: 6,067
  • Lishui_Overview.JPG
    Lishui_Overview.JPG
    112.9 KB · Views: 6,068
  • Lishui_Detail.JPG
    Lishui_Detail.JPG
    84.3 KB · Views: 6,068
  • 00034.jpg
    00034.jpg
    112 KB · Views: 6,067
stancecoke said:
Here are some pictures. The big white plug is for flashing, there is some experience in the german forum.
The controller has hall-sensor inputs, so you don't have to worry about the start up.
I can't identify Lishui controllers... can you understand what model is your based on this list?? http://www.lsdzs.com/en.php/content/index/id/67.html

The controller that BMSBattery sells, I think is the cheapest from Lishui and I think is important to adopt a very cheap one and that is widely available.
 
I think my model is a LD-LS09-F

I'm quite sure,that a Firmware for the Controller from BMS-Battery will run on my model too. The "LSW-675" is widely discussed in the german forum.

I'm still struggling with the toolchain. Do you create the hex- / elf- files with a command-line like the example?

Code:
sdcc -mstm8 led.c --out-fmt-elf --all-callee-saves --debug --verbose --stack-auto --fverbose-asm  --float-reent --no-peep
Regards
stancecoke
 
stancecoke said:
I think my model is a LD-LS06-F

I'm quite sure,that a Firmware for the Controller from BMS-Battery will run on my model too. The "LSW-675" is widely discussed in the german forum.

I'm still struggling with the toolchain. Do you create the hex- / elf- files with a command-line like the example?

Code:
sdcc -mstm8 led.c --out-fmt-elf --all-callee-saves --debug --verbose --stack-auto --fverbose-asm  --float-reent --no-peep
Ok, I think we can buy that models online on a few shops. The one you have is the most expensive but for more power.

For building, I am using the Makefile -- see this part of the build:

# How to build the overall program
$(PNAME): $(MAINSRC) $(RELS)
$(CC) $(INCLUDES) $(CFLAGS) $(ELF_FLAGS) $(LIBS) $(MAINSRC) $(RELS)
$(SIZE) $(PNAME).elf
$(OBJCOPY) -O binary $(ELF_SECTIONS_TO_REMOVE) $(PNAME).elf $(PNAME).bin

First elf file is created that includes the debug information and after objcopy is used to create the bin file that is flashed on the STM8.
 
casainho said:
# How to build the overall program
$(PNAME): $(MAINSRC) $(RELS)
$(CC) $(INCLUDES) $(CFLAGS) $(ELF_FLAGS) $(LIBS) $(MAINSRC) $(RELS)
$(SIZE) $(PNAME).elf
$(OBJCOPY) -O binary $(ELF_SECTIONS_TO_REMOVE) $(PNAME).elf $(PNAME).bin

OK, that's all greek to me :?
Up to now I only worked with tools with a GUI like Bascom, Arduino, Eclipse...
Can you post the right syntax for your project, so that i just have to do copy - paste?

Regards
stancecoke
 
I hope you are motivated to learn new things :)

On Linux, go to command line on the same sources directory and do:
make clean
make

Will build the firmware.

The Make file works like this: first build the source files as rel files and finally build main.c and link with the all rel files.

STM8 seems a kind of new chip but very cheap and there are now some Arduino versions for it. Since is new, it is most command line Linux style for now.
 
casainho said:
I hope you are motivated to learn new things :)

Of course in principle, but I think would get in trouble with my wife, spending too much time in this thing. :wink:

I will have a closer look at cosmic, if I'm not successful there, I will quit this topic.

The STM8 are not really new, they are mentioned 2008 already...

Regards
stancecoke
 
stancecoke said:
casainho said:
I hope you are motivated to learn new things :)

Of course in principle, but I think would get in trouble with my wife, spending too much time in this thing. :wink:

I will have a closer look at cosmic, if I'm not successful there, I will quit this topic.
Can you please reconsider using Linux on a VM, like the free VMWare player or VirtualBox?
I can help you put the development tools for STM8 working, I have them working and I know the details. I can quick answer your questions, here.
After you having the development tools installed, you just need to issue "make" for build the code and "stm8flash" to flash the firmware. If you prefer to also be able to debug the code (something that is not available on Arduino), I suggest to do like me, using Eclipse and OpenOCD.
If we are 2 using the same tools, we will move forward faster!!

Right now, I am trying to do a fast and dirty low pass filter to filter the "ui16_PWM_cycles_counter_total_filtered" and the value where sine phase current wave invert the signal, so I can adjust dynamically the angle (kind of FOC). Your help is important.
 
If you can give me a detailed step-by-step tutorial, I would try. If we're writings posts in here for every step, it will take too much time.

Regards
stancecoke
 
stancecoke said:
If you can give me a detailed step-by-step tutorial, I would try. If we're writings posts in here for every step, it will take too much time.
Then I will. I will write on the notes file. Will have then in next 2 hours.

Can you please tell me what you need other than setup the dev tools? Should I consider that you will use Linux Ubuntu in a virtual machine?

Are you ok with git and github? Can you clone the firmware repo?

Can you add me on Gmail so we can chat, I will be able to help you in real time?? - I will send you my e-mail on a private message.
 
stancecoke said:
Thank you for your help and the tutorial.
But as far as I have seen, there is no new information how to install the toolchain, that it was already in your website.
Good! I just put some more structure and a few new images.

stancecoke said:
if there is written
$ PREFIX=/home/cas/software/stm8-binutils

it means, that i have to copy "PREFIX=/home/cas/software/stm8-binutils" to the prompt of the linux-shell an then hit enter?!
Yes (but see that you have to adapt for your case -- here "cas" is my user name on Linux and "software" the folder where I keep my software). And you can verify before and after doing:
$ echo $PREFIX

stancecoke said:
comes cygwin with the linux distribution or has it to be installed manually?
No need to install cygwin. I understand that cygwin is an environment where Linux shell commands can work, on Windows.

If you think your question is trivial, google should provide help on the first search results -- there is a lot of information for Linux.
 
OK,now I re-activated a very very old netbook (with USB-ports not running) and installed ubuntu. Downloaded the utils, while
./configure_sdcc.sh
there's an error

checking for flex... no
checking for lex... no
checking for bison... no
checking for byacc... no
checking for yacc... no
checking for python2... python2
configure: error: Cannot find required program bison.

hm...

regards stancecoke
 
stancecoke said:
OK,now I re-activated a very very old netbook (with USB-ports not running) and installed ubuntu. Downloaded the utils, while
./configure_sdcc.sh
there's an error

checking for flex... no
checking for lex... no
checking for bison... no
checking for byacc... no
checking for yacc... no
checking for python2... python2
configure: error: Cannot find required program bison.
You will need USB for the STLinkV2.

Using a virtual machine have the advantage that you copy the folder of the virtual machine quickly, like 3 minutes on a USB 3, making a backup -- because for first time on Linux, you may do something wrong and you will need to start again the installation, etc.

Ok, about bison. Means that it need to be installed -- like on Windows when you can't install something without install NET framework or something like that. You need to install bison. If you search on google "ubuntu install bison", you should find an answer. I do like this:
- install Synaptic that is a visual package manager: https://help.ubuntu.com/stable/ubuntu-help/addremove-install-synaptic.html
- on Synpatic I search for bison and install it and every "dev" version -- sometimes the dev versions includes header files that are needed by the software you are trying to build and install
- on Synaptic, find and install "build-essential" that is a package that includes most tools needed on ubuntu for build software

I think you will encounter more situations like this -- you should try find the name or keywords about the missing software and find it on Synaptic. Also you can try find on google.

I suggest you to install only, for now, this software and then try build the firmware:

▸ Tools to build the firmware
▸ stm8-binutils-gdb
 
I have some good news: I tested to find when phase current waveform passes the 0 point and I find it correctly most of the time. When I filter the values, I seem to get a good stable value and with that I should be able to do a kind of FOC!! :)
 
after installing Flex + Bison next error occured:

graf@altes-netbook:~/stm8-binutils-gdb-sources$ ./configure_sdcc.sh
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking for gawk... no
checking for mawk... mawk
checking version of the package... 3.6.0
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking for a BSD-compatible install... /usr/bin/install -c
checking for ranlib... ranlib
checking for autoconf... autoconf
checking for strip... strip
checking for as... as
checking for cp... cp
checking for ar... ar
checking for flex... flex
checking for bison... bison -y
checking for python2... python2
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking endian.h usability... yes
checking endian.h presence... yes
checking for endian.h... yes
checking sys/endian.h usability... no
checking sys/endian.h presence... no
checking for sys/endian.h... no
checking machine/endian.h usability... no
checking machine/endian.h presence... no
checking for machine/endian.h... no
checking sys/isa_defs.h usability... no
checking sys/isa_defs.h presence... no
checking for sys/isa_defs.h... no
checking stdalign.h usability... yes
checking stdalign.h presence... yes
checking for stdalign.h... yes
checking how to run the C++ preprocessor... g++ -E
checking stx/btree_set.h usability... no
checking stx/btree_set.h presence... no
checking for stx/btree_set.h... no
configure: WARNING: STX library missing, using STL instead.
checking stx/btree_map.h usability... no
checking stx/btree_map.h presence... no
checking for stx/btree_map.h... no
configure: WARNING: STX library missing, using STL instead.
checking boost/graph/adjacency_list.hpp usability... no
checking boost/graph/adjacency_list.hpp presence... no
checking for boost/graph/adjacency_list.hpp... no
configure: error: boost library not found (boost/graph/adjacency_list.hpp).

:roll:

Regards
stancecoke
 
stancecoke said:
after installing Flex + Bison next error occured:

checking for boost/graph/adjacency_list.hpp... no
configure: error: boost library not found (boost/graph/adjacency_list.hpp).
What I have installed about boost:

 
Back
Top