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

Hi I'm trying to understand the delay in motor starting, just wondered if anyone has encountered it? thanks

...I have noticed this on a couple of occasions, in both cases I 'fiddled' with the throttle connector which seemed to fix it. Looking back though I guess it could have been fw related. In both cases it happened when the battery was at a low state of charge.

Sorry, that's probably not much help... :(
 
Screenshot (4).png

this is the config, seems to work consistently now with the raised phased voltage. Also now have PAS working but it works in both pedal directions.

Using this setup without LCD 3 and it works fine, do you know if the controller is constantly powered.

C:\Users\controller\Downloads\BMSBattery_S_controllers_firmware-Master\BMSBattery_S_controllers_firmware-Master>PATH = C:\Program Files (x86)\STMicroelectronics\st_toolset\asm;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\iCLS\;C:\Program Files\Intel\Intel(R) Management Engine Components\iCLS\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Users\controller\AppData\Local\Microsoft\WindowsApps;C:\Program Files\SDCC\bin;C:\Program Files\STMicroelectronics\st_toolset\stvp;C:\Program Files (x86)\STMicroelectronics\st_toolset\stvp;C:\SDCC\usr\local\bin;C:\Users\controller\Downloads\BMSBattery_S_controllers_firmware-Master\BMSBattery_S_controllers_firmware-Master\tools\cygwin\bin

C:\Users\controller\Downloads\BMSBattery_S_controllers_firmware-Master\BMSBattery_S_controllers_firmware-Master>del main.hex

C:\Users\controller\Downloads\BMSBattery_S_controllers_firmware-Master\BMSBattery_S_controllers_firmware-Master>sdcc --version
SDCC : mcs51/z80/z180/r2k/r3ka/gbz80/tlcs90/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8 3.7.2 #10526 (MINGW64)
published under GNU General Public License (GPL)

C:\Users\controller\Downloads\BMSBattery_S_controllers_firmware-Master\BMSBattery_S_controllers_firmware-Master>make -f Makefile_windows clean
Cleaning files...

C:\Users\controller\Downloads\BMSBattery_S_controllers_firmware-Master\BMSBattery_S_controllers_firmware-Master>cd stdperiphlib\src

C:\Users\controller\Downloads\BMSBattery_S_controllers_firmware-Master\BMSBattery_S_controllers_firmware-Master\StdPeriphLib\src>del *.asm

C:\Users\controller\Downloads\BMSBattery_S_controllers_firmware-Master\BMSBattery_S_controllers_firmware-Master\StdPeriphLib\src>del *.rel

C:\Users\controller\Downloads\BMSBattery_S_controllers_firmware-Master\BMSBattery_S_controllers_firmware-Master\StdPeriphLib\src>del *.lk
Could Not Find C:\Users\controller\Downloads\BMSBattery_S_controllers_firmware-Master\BMSBattery_S_controllers_firmware-Master\StdPeriphLib\src\*.lk

C:\Users\controller\Downloads\BMSBattery_S_controllers_firmware-Master\BMSBattery_S_controllers_firmware-Master\StdPeriphLib\src>del *.lst

C:\Users\controller\Downloads\BMSBattery_S_controllers_firmware-Master\BMSBattery_S_controllers_firmware-Master\StdPeriphLib\src>del *.rst

C:\Users\controller\Downloads\BMSBattery_S_controllers_firmware-Master\BMSBattery_S_controllers_firmware-Master\StdPeriphLib\src>del *.sym

C:\Users\controller\Downloads\BMSBattery_S_controllers_firmware-Master\BMSBattery_S_controllers_firmware-Master\StdPeriphLib\src>del *.cdb
Could Not Find C:\Users\controller\Downloads\BMSBattery_S_controllers_firmware-Master\BMSBattery_S_controllers_firmware-Master\StdPeriphLib\src\*.cdb

C:\Users\controller\Downloads\BMSBattery_S_controllers_firmware-Master\BMSBattery_S_controllers_firmware-Master\StdPeriphLib\src>del *.map
Could Not Find C:\Users\controller\Downloads\BMSBattery_S_controllers_firmware-Master\BMSBattery_S_controllers_firmware-Master\StdPeriphLib\src\*.map

C:\Users\controller\Downloads\BMSBattery_S_controllers_firmware-Master\BMSBattery_S_controllers_firmware-Master\StdPeriphLib\src>del *.elf
Could Not Find C:\Users\controller\Downloads\BMSBattery_S_controllers_firmware-Master\BMSBattery_S_controllers_firmware-Master\StdPeriphLib\src\*.elf

C:\Users\controller\Downloads\BMSBattery_S_controllers_firmware-Master\BMSBattery_S_controllers_firmware-Master\StdPeriphLib\src>del *.bin
Could Not Find C:\Users\controller\Downloads\BMSBattery_S_controllers_firmware-Master\BMSBattery_S_controllers_firmware-Master\StdPeriphLib\src\*.bin

C:\Users\controller\Downloads\BMSBattery_S_controllers_firmware-Master\BMSBattery_S_controllers_firmware-Master\StdPeriphLib\src>cd..

C:\Users\controller\Downloads\BMSBattery_S_controllers_firmware-Master\BMSBattery_S_controllers_firmware-Master\StdPeriphLib>cd..
Could Not Find C:\Users\controller\Downloads\BMSBattery_S_controllers_firmware-Master\BMSBattery_S_controllers_firmware-Master\*.elf
Done.

C:\Users\controller\Downloads\BMSBattery_S_controllers_firmware-Master\BMSBattery_S_controllers_firmware-Master>make -f Makefile_windows
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debug -oStdPeriphLib/src/stm8s_itc.c StdPeriphLib/src/stm8s_itc.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debug -oStdPeriphLib/src/stm8s_clk.c StdPeriphLib/src/stm8s_clk.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debug -oStdPeriphLib/src/stm8s_iwdg.c StdPeriphLib/src/stm8s_iwdg.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debug -oStdPeriphLib/src/stm8s_gpio.c StdPeriphLib/src/stm8s_gpio.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debug -oStdPeriphLib/src/stm8s_exti.c StdPeriphLib/src/stm8s_exti.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debug -oStdPeriphLib/src/stm8s_uart2.c StdPeriphLib/src/stm8s_uart2.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debug -oStdPeriphLib/src/stm8s_tim1.c StdPeriphLib/src/stm8s_tim1.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debug -oStdPeriphLib/src/stm8s_tim2.c StdPeriphLib/src/stm8s_tim2.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debug -oStdPeriphLib/src/stm8s_adc1.c StdPeriphLib/src/stm8s_adc1.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debug -oStdPeriphLib/src/stm8s_flash.c StdPeriphLib/src/stm8s_flash.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debug -ogpio.c gpio.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debug -outils.c utils.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debug -ocruise_control.c cruise_control.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debug -ouart.c uart.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debug -oadc.c adc.c
adc.c:76: warning 85: in function adc_init unreferenced local variable : 'ui16_counter'
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debug -obrake.c brake.c
brake.c:23: warning 110: conditional flow changed by optimizer: so said EVELYN the modified DOG
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debug -otimers.c timers.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debug -opwm.c pwm.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debug -omotor.c motor.c
motor.c:217: warning 158: overflow in implicit constant conversion
motor.c:231: warning 158: overflow in implicit constant conversion
motor.c:244: warning 158: overflow in implicit constant conversion
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debug -oPAS.c PAS.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debug -oSPEED.c SPEED.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debug -oupdate_setpoint.c update_setpoint.c
update_setpoint.c:253: warning 85: in function update_setpoint unreferenced function argument : 'PAS'
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debug -odisplay.c display.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debug -odisplay_kingmeter.c display_kingmeter.c
sdcc -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debug main.c StdPeriphLib/src/stm8s_itc.rel StdPeriphLib/src/stm8s_clk.rel StdPeriphLib/src/stm8s_iwdg.rel StdPeriphLib/src/stm8s_gpio.rel StdPeriphLib/src/stm8s_exti.rel StdPeriphLib/src/stm8s_uart2.rel StdPeriphLib/src/stm8s_tim1.rel StdPeriphLib/src/stm8s_tim2.rel StdPeriphLib/src/stm8s_adc1.rel StdPeriphLib/src/stm8s_flash.rel gpio.rel utils.rel cruise_control.rel uart.rel adc.rel brake.rel timers.rel pwm.rel motor.rel PAS.rel SPEED.rel update_setpoint.rel display.rel display_kingmeter.rel

C:\Users\controller\Downloads\BMSBattery_S_controllers_firmware-Master\BMSBattery_S_controllers_firmware-Master>ren main.ihx main.hex

C:\Users\controller\Downloads\BMSBattery_S_controllers_firmware-Master\BMSBattery_S_controllers_firmware-Master>STVP_CmdLine -BoardName=ST-LINK -ProgMode=SWIM -Port=USB -Device=STM8S105x6 -FileProg=main.hex -verbose -no_loop
STVP_CmdLine version 1.6

Verbose ON
Log activity ON
Display Progress OFF
Message box warning if protect option byte ON
Loop mode OFF
Erase device OFF
Blank check device OFF
Verify device ON

Configuration:
BoardName=ST-LINK ST-LINK_ID=0 Device=STM8S105x6 Port=USB ProgMode=SWIM

>>> Filling PROGRAM MEMORY image in computer with Blank Value
<<< Filling PROGRAM MEMORY image in computer succeeds

>>> Loading file main.hex in PROGRAM MEMORY image in computer
<<< Loading file succeeds

Hit 'Esc' key to abort during communication.

>>> Programming PROGRAM MEMORY
<<< Programming PROGRAM MEMORY succeeds

>>> Verifying PROGRAM MEMORY
<<< Verifying PROGRAM MEMORY succeeds

C:\Users\controller\Downloads\BMSBattery_S_controllers_firmware-Master\BMSBattery_S_controllers_firmware-Master>pause
Press any key to continue . . .

stancecoke said:
reset said:
Hi I'm trying to understand the delay in motor starting, just wondered if anyone has encountered it? thanks

Please tell us, which commit you have tried and what the content of your config.h is!

regards
stancecoke
 
has anyone had success with the PAS working in only one direction, any guidance gratefully received. thanks
 
reset said:
has anyone had success with the PAS working in only one direction, any guidance gratefully received. thanks

Yes! Have you experimented with 'PAS Threshold' in the configurator? On my setup any value outside the range 1.7 - 2.1 gave this sort of issue, I settled on 1.9 but yours may be different. Find a value that gives best reliable operation in one direction only then swap 'Pas direction left/right' if it's going the wrong way... :wink:
 
After today's tests, it was possible to start the engine from the handle on the steering wheel.
While getting a speed of more than 25 km.ch did not work.
and I try to make a smooth throttle adjustment

Аnd who will explain to me how to use cheat code? and does it work or not?
and another question: why when I release the throttle stick, my engine continues to spin, gradually stopping, and the controller does not respond to the brake knob.
 
Reading about this got me interested.
I am trying to hook up my motor controller, a LSW722 to my ST-Link/v2 controller via the white 4pin connector on the controller.
But so far no luck, can anyone help me with the exact pinout, just to make sure that I have not fried everything already.

Is the LSW722 a very rare controller? I have not found any information about it online.
 
geofft said:
reset said:
has anyone had success with the PAS working in only one direction, any guidance gratefully received. thanks

Yes! Have you experimented with 'PAS Threshold' in the configurator? On my setup any value outside the range 1.7 - 2.1 gave this sort of issue, I settled on 1.9 but yours may be different. Find a value that gives best reliable operation in one direction only then swap 'Pas direction left/right' if it's going the wrong way... :wink:

Hi Geoff thanks for the info will check it out again tomorrow. I had tried adjusting this setting but not above 1.8. I'll give the higher values a try out in the morning.
 
pegpe said:
I am trying to hook up my motor controller, a LSW722 to my ST-Link/v2 controller via the white 4pin connector on the controller.
Is the LSW722 a very rare controller? I have not found any information about it online.

index.php


But be aware, Lishui controllers are using STM32 processors, so our firmware will not work with them.

The Numbers in the Name "LSWxxx" are just a code for the distributor, so they say nothing about the kind of the controller.

regards
stancecoke
 
Romantas said:
After today's tests, it was possible to start the engine from the handle on the steering wheel.
While getting a speed of more than 25 km.ch did not work.
and I try to make a smooth throttle adjustment

Аnd who will explain to me how to use cheat code? and does it work or not?

Romantas, you'll find an explanation of the 'cheat' procedure in stancecoke's notes:-

https://opensourceebikefirmware.bitbucket.io/windows_instructions/index4.html

...although this may not translate too well for you, so I'll try to make it simpler:-

1) Operate brake lever
(wait 1 second)
2) Release brake lever
(wait 1 second)
3) Operate brake lever
(wait 1 second)
4) Release brake lever.

You will see the speed display momentarily change when successful. If you find this difficult, try changing 'CHEAT TOLERANCE' (in main.h file) from 40 to 80, you can reduce this again later)

and another question: why when I release the throttle stick, my engine continues to spin, gradually stopping,

...that sounds like normal behaviour, you probably won't notice this with the wheel on the ground.
 
Big request to stancecoke:
Fix to the configurator tool "OSEC Parameter Configurator.jar" to read the last recorded values from config.h
every time you run the configurator, it reads its default values.

...that sounds like normal behaviour, you probably won't notice this with the wheel on the ground.
This is definitely not normal behavior, because the engine inside the wheel does not turn off, and continues to slowly slow down, if you start to brake it with a brake, it resists and starts to consume additional power from the power source.

and the information on the KT-LCD5 display is not displayed.
battery condition is not, condition about speed is not.
And about the difficulties of translation and the language barrier do not have to worry, I can perfectly understand everything :)
 

Attachments

  • config.h
    1.1 KB · Views: 27
Romantas said:
Big request to stancecoke:
Fix to the configurator tool "OSEC Parameter Configurator.jar" to read the last recorded values from config.h
every time you run the configurator, it reads its default values.
+1 for this change, the current system is driving me mad.. :wink:
 
Sorry for the inconvenience.

The settings of the last flash process are written to a new file now. You can easily restore your latest setting after a new start of the tool by clicking on the latest ini-file, srcoll to the right in the window to see which file is the latest.

OSEC_screenshot.JPG

Perhaps we can improve the code to have the newest file in the top of the list or automatically load the newest...
The last changes in the tool were done by the user Xnyle (in the german forum), he helps since several weeks with the development!

regards
stancecoke
 
or automatically load the newest...

...that would be my preference. There is also a small issue, my display type is 'KT-LCD3', but it always reloads from the .ini as 'none'.

Also thanks to Xnyle, it's good to see you're getting some help.. :D

Edit: I see the display options are now different, I probably need to retry this.
 
Thank you for the help, with the latest version of the configurator, which downloaded from GITIHAB, the engine starts its rotation immediately after the controller is turned on, the brake knob does not respond either. The throttle grip only adds speed :) The only good news is that the speed has increased to 33 km / h
The comparison function in the motor.h file showed differences in the code
And removed the cheat procedure in main.c
 

Attachments

  • config.h
    1.2 KB · Views: 28
  • 111u.png
    111u.png
    150.6 KB · Views: 1,409
Are you sure that's not because you flashed default values? See above.

I'll change the tool so that it loads the newest file on startup.

Regarding config.h, yes a few things have changed. Maybe there are some new bugs due to that.
It's mainly code refactoring though. Nothing has changed about how the controller should work.

You'll find the "offroad" procedure somewhere else now.
 
I fully understand that this is in the development period, there may be breakages in the code.
I downloaded the old version of the code from
Code:
https://github.com/OpenSource-EBike-firmware/BMSBattery_S_controllers_firmware
now, the display shows the speed and the battery charge, for a new part of the code this does not work.
 
Romantas said:
the display shows the speed and the battery charge, for a new part of the code this does not work.

In the code in casainho's master, the info from the controller is send to display without having received a valid message from the display. The "new" code only sends data, if a valid message was received. (it "answers" to the display)
So it seems, that your display is sending something, that our firmware doesn't understand, probably it uses a different XOR in the checksum procedere....

You have to log the message from the display with an USB-UART converter and post it here, then we can check it.

regards
stancecoke
 
stancecoke said:
Romantas said:
the display shows the speed and the battery charge, for a new part of the code this does not work.

In the code in casainho's master, the info from the controller is send to display without having received a valid message from the display. The "new" code only sends data, if a valid message was received. (it "answers" to the display)
So it seems, that your display is sending something, that our firmware doesn't understand, probably it uses a different XOR in the checksum procedere....

You have to log the message from the display with an USB-UART converter and post it here, then we can check it.

regards
stancecoke

if you do not mind, show me instructions how to do it :) I will be very glad to help you.
 
Romantas said:
if you do not mind, show me instructions how to do it :) I will be very glad to help you.

That's quite easy. Follow the instructions for the USB-UART-converter in the tutorial and just connect the yellow wire of the display to Rx of the module and the black one to GND instead of connecting the controller. Switch to "hex" in the receive check boxes in hterm. Switch on the display, then you will see a block of data is sent by the display several times per second. Just post a screenshot of hterm with the received data....

regards
stancecoke

Display to USB-UART Module.PNG
 
stancecoke said:
That's quite easy. Follow the instructions for the USB-UART-converter in the tutorial and just connect the yellow wire of the display to Rx of the module and the black one to GND instead of connecting the controller. Switch to "hex" in the receive check boxes in hterm. Switch on the display, then you will see a block of data is sent by the display several times per second. Just post a screenshot of hterm with the received data....

regards
stancecoke
111.png
Here is the result of what happened when writing to hterm
The downloaded version of the sources this morning and programmed the controller, the response to the throttle is regulated well, the engine starts without jerks. So far, it is not possible to raise a speed above 25 km.
Another note on low battery voltage: when the battery is in a discharged state, the controller shuts down the engine, but this happens in "jerks" because the hysteresis function has not been added.
For example: the voltage dropped to 31.5V - the controller switched off the engine and waits for 5-10 seconds until the voltage rises to 32.5V. In this case, with a deeply discharged battery, there will be no unnecessary jerking of the engine

Thanks for the help in searching for the code for the KT-LCD5 display.
added line 281 to the display. c
Code:
	((ui8_crc ^ 3) == ui8_rx_buffer [7]) 	||
 

Attachments

  • DATA_DISPLAY.txt
    1.8 KB · Views: 63
  • config.h
    1.2 KB · Views: 59
Now we have a controller accepting 5/10 possible checksums, Where is the sense in that :)

Shouldn't this be another option in config.h, so you actually have a check mechanism again?
 
Xnyle said:
Now we have a controller accepting 5/10 possible checksums, Where is the sense in that :)

Shouldn't this be another option in config.h, so you actually have a check mechanism again?

I set the value of the checksum until I got a working display :)

I'm interested in how to make the motor spin faster?
At the moment I'll switch to a spare original microcontroller, for testing a bicycle :)

I want him to travel faster than 25 km / h, because it is not convenient to be in urban traffic at a speed below 30 km / h, bicycle paths have not been done yet :(
 
Romantas said:
I'm interested in how to make the motor spin faster?
At the moment I'll switch to a spare original microcontroller, for testing a bicycle :)

Set speedsensor to extern or set the right gear ratio!

Regards
stancecoke
 
Back
Top