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

Electric Motors and Controllers
User avatar
stancecoke   100 kW

100 kW
Posts: 1383
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 » Feb 20 2021 11:58am

sylvain_wm wrote:
Feb 20 2021 7:29am
Is that normal?
Yes. why should there be other changes than ui16BatteryCurrent?!
ui16_current_cal_b (ADC offset of the battery current channel) is determined once at startup and will never change later at runtime.

If ui16BatteryCurrent is lower than ui16_current_cal_b you are doing regen, if ui16BatteryCurrent is higher than ui16_current_cal_b, you are getting power from the motor.

ui16_control_state will only change, if you run in a special situation like speed limitation or overcurrent limitation.
State28.JPG
State28.JPG (36.26 KiB) Viewed 320 times
regards
stancecoke

sylvain_wm   100 mW

100 mW
Posts: 44
Joined: Feb 02 2020 6:09am

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

Post by sylvain_wm » Feb 20 2021 1:18pm

Thanks stancecoke,

I measured currents and printed out their adc values.
For ui16_BatteryCurrent I obtain the equation:
ui16_BatteryCurrent = 2.68 x I_batt + 315
For ui16_adc_read_phase_B_current I obtain the equation:
ui16_adc_read_phase_B_current = 2 x I_phase_B + 511

I'd like to limit the battery current to about 15A and the motor current to about 20A.
What are the parameters I should put in Battery Current max, Phase Current max and Battery Current cal a?
In my opinion :
Battery Current max = 355
Phase Current max = 551
And Battery Current cal a = 27 I'm not sure?

I don't want to make another mistake. So I prefer to be sure.

Question : Voltage Calibration and Battery Current cal a are only for the display?

Thank you.

User avatar
stancecoke   100 kW

100 kW
Posts: 1383
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 » Feb 21 2021 3:31am

sylvain_wm wrote:
Feb 20 2021 1:18pm
ui16_BatteryCurrent = 2.68 x I_batt + 315
Have you did this for different currents? If you get a good linearity, the 2.68 should be OK. You can set Battery Current cal a to 27.

For the phase current you have to use the same formula as for the battery current. The phase current is not measured but calculated from

Code: Select all

phase current = battery current / duty cycle
The ADC value of the phasecurrent sensor is used to do the simplified FOC, only. We look at the zero crossing to adjust the advance angle.
sylvain_wm wrote:
Feb 20 2021 1:18pm
Voltage Calibration and Battery Current cal a are only for the display?
yes.

regards
stancecoke

sylvain_wm   100 mW

100 mW
Posts: 44
Joined: Feb 02 2020 6:09am

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

Post by sylvain_wm » Feb 21 2021 4:25am

stancecoke wrote:
Feb 21 2021 3:31am
Have you did this for different currents?
Yes I did. I think I was pretty accurate.
stancecoke wrote:
Feb 21 2021 3:31am
For the phase current you have to use the same formula as for the battery current.
Ok. I thought the firmware used the current sensor because the value is read in the program. It's only used for the zero crossing.

Thank you.

Have a great day.

endlessolli   10 mW

10 mW
Posts: 22
Joined: Jul 31 2020 11:55am

Re: KT motor controllers -- erratic / non smooth Motor behavior

Post by endlessolli » Feb 21 2021 4:58am

endlessolli wrote:
Jan 23 2021 10:43am
stancecoke wrote:
Jan 23 2021 7:13am
endlessolli wrote:
Jan 22 2021 12:59pm
this opensource firmware results in erratic / non smooth Motor behavior (under load).
What is your setting for max battery current and for max phase current?
Set max phase current much higher than max battery current!

regards
stancecoke
Thanks for the reply, stancecoke!
These are my current settings:
Battery current = 70
Phase current = 100
Cal a = 50 (I have small a 6 FET controller - so I should put this to 100 accroding to the wiki. (Is that a fudge factor or is there a way to calculate the correct value?)

I also found another potential issue: I digged some more in the forums (also german pedelec forum) and realized that my 'pre-controllers' RC low pass filter for the thumb input was maybe too low. (You used 1kOhm & 5µF for some experiments, the 'Forum-controller' uses 150Ohm and 100µF; I used 10kOhm & 5µF. Still wondering why it worked w/ the std. Firmware and not so good with your open source f/w.
I will also experiment with the current settings.
But the weather forces me to take a break......
OK, weather gets better and I did further testing, so I wanted to give a brief update on this (older) topic:

It turns out that all my problems with eratic motor behavoir seem to be due to the fact that I use Bluetooth w/ the BluOsec App!

When I compile it with 'no Display', everything behaves as smooth as with the stock firmware (and better).

Note: I don't want to blackmail the BluOsec App with this - it is a great tool to efficiently finetune motorparameters for initial setup i.e. on a motor test setup. But when actually using the setup / driving, it does not work properly.
I think @stancecoke mentioned that also already in this thread, but I was so far under the impression, that it 'sometimes' (as in rarely) causes problems, whereas for me, it *contantly* caused problems during use (also, when the Smartphone is not even on / connected to the controller)

But again: Thank you for all the work to all the contributors! Great project!!

sdobbie   10 W

10 W
Posts: 69
Joined: Dec 14 2013 12:56pm
Location: Fife Scotland

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

Post by sdobbie » Feb 21 2021 6:29am

I managed to get hterm working, the blueterm app didn't show up any options for connecting. I have attached three log files, rev up.log is me revving the motor up under no load, cycle regen.log is just slowly moving the regen throttle from closed to open without the wheel spinning and motor drag.log is turning the wheel quite hard with no regen throttle connected and no throttle input.

A new issue has now arisen and this is with the regen being stuck on all the time when the regen throttle is plugged in. This prevents the main throttle from responding as expected because we changed the code so that we don't need to pull the brake to get regen to work. I have measured the regen throttle output voltage while it was attached to the controller and it is 0.973v in the closed position , 0.95 just slightly open and 3.459 fully open. This is a fault with my throttle and not so much the software so is there a way to change the x4 throttle range like you can with the main throttle?
Attachments
motor drag.log
(4.3 KiB) Downloaded 6 times
rev up.log
(4.52 KiB) Downloaded 5 times
cycle regen throt.log
(4.51 KiB) Downloaded 2 times
Solder that shunt!

User avatar
stancecoke   100 kW

100 kW
Posts: 1383
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 » Feb 21 2021 11:06am

endlessolli wrote:
Feb 21 2021 4:58am
But when actually using the setup / driving, it does not work properly.
Yes, the app is known to freeze the system sometimes. We have the bugfix in the branch "torque from X4" already. @Xnyle has used very much floating point and division operations in the master branch. In combination with the massivie UART communication of the BluOSEC app, we get an overload on the processor. The solution is to replace all the floating points and divisions by integer arithmetics and shifts. It's just half an hour of work to port the solutions of the "torque from X4" branch to the master, but nobody have done this job so far.
sdobbie wrote:
Feb 21 2021 6:29am
the blueterm app didn't show up any options for connecting
You have to long press one of the three "hardware" buttons of the cell phone to open the menu for connecting, logging etc.
sdobbie wrote:
Feb 21 2021 6:29am
I have attached three log files
Thank you, I made some graphs from the data, everything is OK, so far. The log with the regen throttle makes no sense, you have to print out the relevant variables (I listed them in the post addressed to you before :wink: ) You have to change them manually on line 193 of the main.c

In the drag graph, you can see, that the motor regenerates slightly at the first acceleration, before the PI control brings the battery current to (almost) zero again. The duty cycle is controlled, to get exactly the same voltage from the controller as from the BEMF. So we get no voltage difference and therefore no battery current. As written before, you could manipulate the ADC offset (battery current cal b) a little, to get a slightly positive torque and avoid a "braking" feeling.
drag.JPG
drag.JPG (75.7 KiB) Viewed 246 times
In the rev up graph, everything looks normal. No speed or current limits are reached, so the wheel just spins up and stops again...
rev up.JPG
rev up.JPG (84.72 KiB) Viewed 246 times
sdobbie wrote:
Feb 21 2021 6:29am
is there a way to change the x4 throttle range like you can with the main throttle?
Of course. Quick and dirty, you could hardcode your values in line 173 of the ACAsetpoint.c or you can define own variables for the X4 limits.

regards
stancecoke

sdobbie   10 W

10 W
Posts: 69
Joined: Dec 14 2013 12:56pm
Location: Fife Scotland

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

Post by sdobbie » Feb 21 2021 11:19am

Hugely appreciated, thank you :D . I'm going to play around with the settings a bit more as you suggest to sort the regen throttle range and the motor drag. It would be nice to get the wheel going faster though because as I said previously, I accidentally changed this line ui16_current_cal_b >>= 4; to >>=8 and as soon as the controller was powered up, the wheel spun around twice as fast as it would normally on full throttle without me even touching the throttle, so it would be good if we could find a way to reach that speed with normal throttle operation.
Solder that shunt!

User avatar
stancecoke   100 kW

100 kW
Posts: 1383
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 » Feb 21 2021 12:25pm

sdobbie wrote:
Feb 21 2021 11:19am
so it would be good if we could find a way to reach that speed with normal throttle operation.
Is this behaviour repeatable?! I know no reason, why the wheel should spin faster with a misstuned ADC offset of the battery current channel.
As you can see in the rev up graph, the duty cycle reaches 255 at idle run, that's the maximum. The wheel can only spin faster with a higher battery voltage or with field weakening.

regards
stancecoke

endlessolli   10 mW

10 mW
Posts: 22
Joined: Jul 31 2020 11:55am

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

Post by endlessolli » Feb 21 2021 12:37pm

stancecoke wrote:
Feb 21 2021 11:06am
endlessolli wrote:
Feb 21 2021 4:58am
But when actually using the setup / driving, it does not work properly.
Yes, the app is known to freeze the system sometimes. We have the bugfix in the branch "torque from X4" already. @Xnyle has used very much floating point and division operations in the master branch. In combination with the massivie UART communication of the BluOSEC app, we get an overload on the processor. The solution is to replace all the floating points and divisions by integer arithmetics and shifts. It's just half an hour of work to port the solutions of the "torque from X4" branch to the master, but nobody have done this job so far.

stancecoke
Thanks, @stancecoke!
Can you tell / do you know: Is the "torque from X4" branch usable? I.e. for my use case, where I only use the throttle (plus BlueOsec App)?
(No Torque sensing, no PAS, no Regen- just: throttle, rotor angle correction, 'external' Speedsensor and "360 deg interpol at 75")

P.S. I would be glad to help to port to the main branch, but I don't know enough about programming and especially what does what in the OSFM, so I don't want to mess things up.... (Probalby the situation for many others here as well)
You - being deeply familiar with the code - probably think its an easy task and: "These lazy bastards - just want to freeload and when it comes to work, nobody is there...." I definetely would spend the time to do it. But, as said, I am unfortunately pretty clueless. (However, if you want to give some guidance....)

User avatar
stancecoke   100 kW

100 kW
Posts: 1383
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 » Feb 21 2021 2:43pm

endlessolli wrote:
Feb 21 2021 12:37pm
I.e. for my use case, where I only use the throttle
in this case, you can delete lines 206 to 290 in the ACAsetpoint.c and replace all of the stuff with the simple line (no guarantee, for this simple solution, of course...)

Code: Select all

uint32_current_target = (ui16_sum_throttle*ui16_battery_current_max_value)>>8 + ui16_current_cal_b;
regards
stancecoke

endlessolli   10 mW

10 mW
Posts: 22
Joined: Jul 31 2020 11:55am

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

Post by endlessolli » Feb 21 2021 4:51pm

stancecoke wrote:
Feb 21 2021 2:43pm
endlessolli wrote:
Feb 21 2021 12:37pm
I.e. for my use case, where I only use the throttle
in this case, you can delete lines 206 to 290 in the ACAsetpoint.c and replace all of the stuff with the simple line (no guarantee, for this simple solution, of course...)

Code: Select all

uint32_current_target = (ui16_sum_throttle*ui16_battery_current_max_value)>>8 + ui16_current_cal_b;
regards
stancecoke
Great - I will try that.
One clarification question: Would I apply the above on the master branch or in the Torque from X4 branch?

sdobbie   10 W

10 W
Posts: 69
Joined: Dec 14 2013 12:56pm
Location: Fife Scotland

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

Post by sdobbie » Feb 21 2021 6:09pm

I had a ride on the bike and the resistance from the motor when trying to coast is definitely noticeable. The bike is very easy to pedal if I switch the controller off. On a more positive note, regen works really well and is good fun.

I tried again to do a diagnostic with the exact parameters you were looking for but it won't compile when I add them in. This is what I changed the printf line to

Code: Select all

printf("%u,%u, %u, %u, %u, %u\r\n", ui8_control_state, uint32_current_target, ui16_motor_speed_erps, ui16_BatteryCurrent, ui32_SPEED_km_h, ui16_current_cal_b);
And this is the error. I have attached my current config.h


C:\BMSBattery_S_controllers_firmware-Master>PATH = C:\Program Files (x86)\STMicr
oelectronics\st_toolset\asm;C:\Program Files (x86)\Common Files\Oracle\Java\java
path;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32
\WindowsPowerShell\v1.0\;C:\EDIABAS\BIN\;C:\Program Files (x86)\Universal Extrac
tor;C:\Program Files (x86)\Universal Extractor\bin;C:\Program Files\SDCC\bin;C:\
Program Files\STMicroelectronics\st_toolset\stvp;C:\Program Files (x86)\STMicroe
lectronics\st_toolset\stvp;C:\SDCC\usr\local\bin

C:\BMSBattery_S_controllers_firmware-Master>REM ;C:\BMSBattery_S_controllers_fir
mware-Master\tools\cygwin\bin

C:\BMSBattery_S_controllers_firmware-Master>cd C:\BMSBattery_S_controllers_firmw
are-Master\

C:\BMSBattery_S_controllers_firmware-Master>del main.hex
Could Not Find C:\BMSBattery_S_controllers_firmware-Master\main.hex

C:\BMSBattery_S_controllers_firmware-Master>sdcc --version
SDCC : mcs51/z80/z180/r2k/r3ka/gbz80/tlcs90/ez80_z80/ds390/pic16/pic14/TININativ
e/ds400/hc08/s08/stm8/pdk13/pdk14/pdk15 4.0.0 #11528 (MINGW64)
published under GNU General Public License (GPL)

C:\BMSBattery_S_controllers_firmware-Master>make -f Makefile_windows clean
echo "Cleaning files..."
"Cleaning files..."
cmd /C del *.asm
Could Not Find C:\BMSBattery_S_controllers_firmware-Master\*.asm
cmd /C del *.rel
Could Not Find C:\BMSBattery_S_controllers_firmware-Master\*.rel
cmd /C del *.lk
Could Not Find C:\BMSBattery_S_controllers_firmware-Master\*.lk
cmd /C del *.lst
Could Not Find C:\BMSBattery_S_controllers_firmware-Master\*.lst
cmd /C del *.rst
Could Not Find C:\BMSBattery_S_controllers_firmware-Master\*.rst
cmd /C del *.sym
Could Not Find C:\BMSBattery_S_controllers_firmware-Master\*.sym
cmd /C del *.cdb
Could Not Find C:\BMSBattery_S_controllers_firmware-Master\*.cdb
cmd /C del *.map
Could Not Find C:\BMSBattery_S_controllers_firmware-Master\*.map
cmd /C del *.adb
Could Not Find C:\BMSBattery_S_controllers_firmware-Master\*.adb
echo "Done."
"Done."

C:\BMSBattery_S_controllers_firmware-Master>make -f Makefile_windows
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debu
g -oBOdisplay.c BOdisplay.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debu
g -oACAcontrollerState.c ACAcontrollerState.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debu
g -oACAeeprom.c ACAeeprom.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debu
g -oACAsetPoint.c ACAsetPoint.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debu
g -oACAcommons.c ACAcommons.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debu
g -ogpio.c gpio.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debu
g -ocruise_control.c cruise_control.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debu
g -ouart.c uart.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debu
g -oadc.c adc.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debu
g -obrake.c brake.c
brake.c:23: warning 110: conditional flow changed by optimizer: so said EVELYN t
he modified DOG
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debu
g -otimers.c timers.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debu
g -opwm.c pwm.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debu
g -omotor.c motor.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debu
g -oPAS.c PAS.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debu
g -oSPEED.c SPEED.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debu
g -odisplay.c display.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 --std-c99 --nolospre --out-fmt-ihx --debu
g -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 StdPeriphLi
b/src/stm8s_iwdg.rel StdPeriphLib/src/stm8s_gpio.rel StdPeriphLib/src/stm8s_exti
.rel StdPeriphLib/src/stm8s_uart2.rel StdPeriphLib/src/stm8s_tim1.rel StdPeriphL
ib/src/stm8s_tim2.rel StdPeriphLib/src/stm8s_adc1.rel StdPeriphLib/src/stm8s_fla
sh.rel BOdisplay.rel ACAcontrollerState.rel ACAeeprom.rel ACAsetPoint.rel ACAcom
mons.rel gpio.rel cruise_control.rel uart.rel adc.rel brake.rel timers.rel pwm.r
el motor.rel PAS.rel SPEED.rel display.rel display_kingmeter.rel
main.c:193: error 20: Undefined identifier 'ui8_control_state'
main.c:193: error 20: Undefined identifier 'ui32_SPEED_km_h'
make: *** [main] Error 1
Attachments
config.h
(1.41 KiB) Downloaded 3 times
Solder that shunt!

sylvain_wm   100 mW

100 mW
Posts: 44
Joined: Feb 02 2020 6:09am

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

Post by sylvain_wm » Feb 22 2021 12:29am

Hi,
sdobbie wrote:
Feb 21 2021 6:09pm
it won't compile
I had the same issue : ui32_SPEED_km_h and ui8_control_state don't exist.

Have a good day.

User avatar
stancecoke   100 kW

100 kW
Posts: 1383
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 » Feb 22 2021 2:24am

endlessolli wrote:
Feb 21 2021 4:51pm
Would I apply the above on the master branch or in the Torque from X4 branch?
to the master.
sylvain_wm wrote:
Feb 22 2021 12:29am
I had the same issue : ui32_SPEED_km_h and ui8_control_state don't exist.
Ah, the variable names in the wiki seem to be outdated.
ui16_control_state (is already printed by default)

the speed in kph * 100 has to be calculated from ui16_virtual_erps_speed/ui16_speed_kph_to_erps_ratio (not sure about the 100)

so the print command can could be

Code: Select all

printf("%u,%lu, %u, %u, %u, %u\r\n", ui16_control_state, uint32_current_target, ui16_virtual_erps_speed, ui16_BatteryCurrent, ui16_virtual_erps_speed/ui16_speed_kph_to_erps_ratio, ui16_current_cal_b);
regards
stancecoke

endlessolli   10 mW

10 mW
Posts: 22
Joined: Jul 31 2020 11:55am

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

Post by endlessolli » Feb 22 2021 8:07am

stancecoke wrote:
Feb 21 2021 2:43pm
endlessolli wrote:
Feb 21 2021 12:37pm
I.e. for my use case, where I only use the throttle
in this case, you can delete lines 206 to 290 in the ACAsetpoint.c and replace all of the stuff with the simple line (no guarantee, for this simple solution, of course...)

Code: Select all

uint32_current_target = (ui16_sum_throttle*ui16_battery_current_max_value)>>8 + ui16_current_cal_b;
regards
stancecoke
@stancecoke
When I do that, I get the following compile error:

Code: Select all

C:\BMSBattery_S_controllers_firmware-Master>make -f Makefile_windows
sdcc -c -IStdPeriphLib/inc -I.  -mstm8 --std-c99 --nolospre --out-fmt-ihx --debug  -oBOdisplay.c BOdisplay.c
sdcc -c -IStdPeriphLib/inc -I.  -mstm8 --std-c99 --nolospre --out-fmt-ihx --debug  -oACAcontrollerState.c ACAcontrollerState.c
sdcc -c -IStdPeriphLib/inc -I.  -mstm8 --std-c99 --nolospre --out-fmt-ihx --debug  -oACAeeprom.c ACAeeprom.c
sdcc -c -IStdPeriphLib/inc -I.  -mstm8 --std-c99 --nolospre --out-fmt-ihx --debug  -oACAsetPoint.c ACAsetPoint.c
ACAsetPoint.c:328: error 20: Undefined identifier 'ui8_walk_assist'
ACAsetPoint.c:354: error 1: Syntax error, declaration ignored at 'ui16_control_state'
ACAsetPoint.c:354: syntax error: token -> '=' ; column 21
make: *** [ACAsetPoint.rel] Error 1
(It states something about 'ui8_walk_assist'. I don't use walk_assist, but I don't see, where I would disable that in the configurator either)

To double check, if I did this as intended by you, I'll attatch the ACAsetpoint.c file
ACAsetPoint.c
(15.7 KiB) Downloaded 4 times
If you have time, it would be great, if you coud give me a hint.

Thanks, again

User avatar
stancecoke   100 kW

100 kW
Posts: 1383
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 » Feb 22 2021 8:31am

endlessolli wrote:
Feb 22 2021 8:07am
If you have time
very simple solution: you have to comment out just one line more ( the "}") :wink:

regards
stancecoke

endlessolli   10 mW

10 mW
Posts: 22
Joined: Jul 31 2020 11:55am

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

Post by endlessolli » Feb 22 2021 10:03am

stancecoke wrote:
Feb 22 2021 8:31am
endlessolli wrote:
Feb 22 2021 8:07am
If you have time
very simple solution: you have to comment out just one line more ( the "}") :wink:

regards
stancecoke
Doh! Thank you, @stancecoke!

However, 1 error remains after your suggested correction:

Code: Select all

C:\BMSBattery_S_controllers_firmware-Master>make -f Makefile_windows
sdcc -c -IStdPeriphLib/inc -I.  -mstm8 --std-c99 --nolospre --out-fmt-ihx --debug  -oBOdisplay.c BOdisplay.c
sdcc -c -IStdPeriphLib/inc -I.  -mstm8 --std-c99 --nolospre --out-fmt-ihx --debug  -oACAcontrollerState.c ACAcontrollerState.c
sdcc -c -IStdPeriphLib/inc -I.  -mstm8 --std-c99 --nolospre --out-fmt-ihx --debug  -oACAeeprom.c ACAeeprom.c
sdcc -c -IStdPeriphLib/inc -I.  -mstm8 --std-c99 --nolospre --out-fmt-ihx --debug  -oACAsetPoint.c ACAsetPoint.c
ACAsetPoint.c:328: error 20: Undefined identifier 'ui8_walk_assist'
make: *** [ACAsetPoint.rel] Error 1
Do you have further hints?

User avatar
stancecoke   100 kW

100 kW
Posts: 1383
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 » Feb 22 2021 11:08am

endlessolli wrote:
Feb 22 2021 10:03am
Do you have further hints?
Hm, I have no problems with compiling.
ui8_walk_assist is defined in the ACAcontrollerState.h, that is included by the ACAsetPoint.c
https://github.com/stancecoke/BMSBatter ... alk_assist

In doubt, just comment out the line 328....

regards
stancecoke

endlessolli   10 mW

10 mW
Posts: 22
Joined: Jul 31 2020 11:55am

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

Post by endlessolli » Feb 22 2021 11:33am

stancecoke wrote:
Feb 22 2021 11:08am
Hm, I have no problems with compiling.
ui8_walk_assist is defined in the ACAcontrollerState.h, that is included by the ACAsetPoint.c
https://github.com/stancecoke/BMSBatter ... alk_assist

In doubt, just comment out the line 328....

regards
stancecoke
Strange, that it works for you and not in my case.
But - commenting out line 328 works -> compiles w/o error.
Thanks!
I will try it on the bike tomorrow.

Update:
I noticed that I did not work off the latest github version. (mine was from July last year and after that there were changes done to walk assist. That explains the different behavior)
Updating to the newest version resolves the compiling error and now I do not have to comment out line 328.

-> All good - will test tomorrow
Thanks again @stancecoke!

sdobbie   10 W

10 W
Posts: 69
Joined: Dec 14 2013 12:56pm
Location: Fife Scotland

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

Post by sdobbie » Feb 22 2021 4:21pm

Well I tried to program the controller again tonight to get more debug logs to you but it won't program anymore as it has probably been programmed about 300 times and the chip can't be written to now. I have another 6 fet kt controller without phase current sensing which still programs without issue. I think I am just going to have to leave it now and find a different foc controller as this is just costing too much time and money.

>>> Programming PROGRAM MEMORY
(API) ERROR : Cannot communicate with the device !
Check the SWIM cable connection and check all the needed pin connections on the
SWIM connector.

If the application code uses Swim Disable and Reset pin as Output or has disable
d SWIM Clock Divider:
Try Now to SWITCH OFF and ON the application Power Supply while NRST Reset pin i
s forced low.

<<< Programming PROGRAM MEMORY fails

C:\BMSBattery_S_controllers_firmware-Master>pause
Press any key to continue . . .
Solder that shunt!

sdobbie   10 W

10 W
Posts: 69
Joined: Dec 14 2013 12:56pm
Location: Fife Scotland

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

Post by sdobbie » Feb 22 2021 4:33pm

Sorry, please ignore that, it is now programming but only intermittently.
Solder that shunt!

sdobbie   10 W

10 W
Posts: 69
Joined: Dec 14 2013 12:56pm
Location: Fife Scotland

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

Post by sdobbie » Feb 22 2021 4:44pm

OK, here is another log file of the motor giving quite strong drag and the controller consuming about 650ma at 46.4v while doing this.

This log was made using this printf line

Code: Select all

printf("%u,%lu, %u, %u, %u, %u\r\n", ui16_control_state, uint32_current_target, ui16_virtual_erps_speed, ui16_BatteryCurrent, ui16_virtual_erps_speed/ui16_speed_kph_to_erps_ratio, ui16_current_cal_b);
We really need to have the software changed so that whenever the throttle is closed, or less than the current speed of the bike, all pwm is off unless regen is called for in which case the bottom mosfets of the h bridge are pulsed at the required duty cycle to give the desired regen.

Additionally, how can I enable field weakening?
Attachments
drag2.log
(5.98 KiB) Downloaded 3 times
Solder that shunt!

User avatar
stancecoke   100 kW

100 kW
Posts: 1383
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 » Feb 23 2021 2:43am

sdobbie wrote:
Feb 22 2021 4:44pm
the controller consuming about 650ma at 46.4v while doing this.
I guess, it is producing 650 mA, not consuming. As you said before, your wattmeter can't show negative values...

As you can see in the graph, the cal b value is lower than the current reading at standstill. So the battery current is controlled to be slightly negative (this means regen) during dragging. As I suggested several times now, just tune the offset a little. e.g ui16_current_cal_b += 1; instead of ui16_current_cal_b -= 1;

The speed log doesn't work obviously, so I calculated the speed in kph x10 from the erps by the formula
speed (kph x10) = erps/gearratio*3600*wheel circumference/1000000*10

Switching on the PWM while the wheel is turning with a direct drive is dangeorus for the FET's as you're getting high voltage and current peaks, if the duty cycle does not match exactly with the recent BEMF....

regards
stancecoke

p.s. please draw the graph yourself next time, I'm not your plotting service... :wink:
Drag with speed and target.JPG
Drag with speed and target.JPG (73.29 KiB) Viewed 95 times

endlessolli   10 mW

10 mW
Posts: 22
Joined: Jul 31 2020 11:55am

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

Post by endlessolli » Feb 23 2021 6:59am

endlessolli wrote:
Feb 22 2021 11:33am
stancecoke wrote:
Feb 22 2021 11:08am
Hm, I have no problems with compiling.
ui8_walk_assist is defined in the ACAcontrollerState.h, that is included by the ACAsetPoint.c
https://github.com/stancecoke/BMSBatter ... alk_assist

In doubt, just comment out the line 328....

regards
stancecoke
Strange, that it works for you and not in my case.
But - commenting out line 328 works -> compiles w/o error.
Thanks!
I will try it on the bike tomorrow.

Update:
I noticed that I did not work off the latest github version. (mine was from July last year and after that there were changes done to walk assist. That explains the different behavior)
Updating to the newest version resolves the compiling error and now I do not have to comment out line 328.

-> All good - will test tomorrow
Thanks again @stancecoke!
@stancecoke
So, programming worked as stated. However - with the suggested change, my motor spins at a constant speed, ignoring any (thumb-) throttle input.

But don't bother with this too much - I don't need BlueOsec App functionality that urgend.
My setup works with your std. masterbranch (w/o display) very quiet and nicely. That is all I really need .
Anything else is 'icing on the cake' / toying around.

Thanks again!

Post Reply