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

Using 10A regeneration now for ~1000km with the Custom FW, so far nothing exploded ;)

On a full battery Custom FW prevents overvoltage. Regarding stock FW: wrong thread :)

Imho regeneration is overrated though, you get maybe 10% more range, but you could also just use a geared motor which is about 10% more efficient (at least for my driving profile).
 
casainho said:
Try to disable FOC and increase motor speed and current and then take the screen shoots and show to us.

FOC was disable and the waveform was still asymmetrical.i tested other brands of controllers,there were all the same. maybe it is normal.
what is the angle interpolation used for?

#define DO_INTERPOLATION 1
#if DO_INTERPOLATION == 1
........
is the angle used to adjust the rotor position to keep ID=0?
 

Attachments

  • disable foc.jpg
    disable foc.jpg
    51.7 KB · Views: 2,473
haiyi911 said:
casainho said:
Try to disable FOC and increase motor speed and current and then take the screen shoots and show to us.

FOC was disable and the waveform was still asymmetrical.i tested other brands of controllers,there were all the same. maybe it is normal.
what is the angle interpolation used for?

#define DO_INTERPOLATION 1
#if DO_INTERPOLATION == 1
........
is the angle used to adjust the rotor position to keep ID=0?
Go and read the notes I took when I developed and tested the FOC implementation: https://opensourceebikefirmware.bitbucket.io/development/Datasheets_and_application_notes--Endless-sphere.com_forum_messages--2017.10.23_-_FOC_and_no_FOC_comparison.html

image.png
 
Has someone try this torque sensor?
http://www.forehorse.com/Product?id=FEP1

Seems an interesting product, since can be used for both hub motors and bafang mid drive
 
Thank you for that information, looks really interesting.

I think the receiver has an analogue voltage output, so it should work with our firmware out of the box. But I can't identify the pinout from the pdf.

The costs are OK, but I don't know if you can buy a single piece as a private person via "made-in-china.com"

regards
stancecoke

Pinout Forehorse Pedal Torquesensor.PNG
 
My understanding (using Google translate) is that the pedal transmit via ant, and the receiver converts the info to an analog 5v signal, which can be used in place of a throttle
 
Hi all,

I'm trying to change the controller on an electric scooter (MPman TR100). The motor is a 30 rotor poles /27 stator poles, direct drive, with hall sensors.
(I added the 10k pullups on the hall sensors since the signals didn't go to 5V, I don't know if the controller has them).

MVIMG_20190611_175043.jpg

I bought this controller from http://www.pswpower.com/ven.php?cargo.2016-3f-33c0, since it seemed like it should be able to do sine wave. I flashed the custom firmware (branch master from stancecoke) >> jump to edit
with these config modifications :

#define EBIKE_THROTTLE_TYPE EBIKE_THROTTLE_TYPE_THROTTLE_PAS
#define BATTERY_LI_ION_CELLS_NUMBER 10
#define DEFAULT_VALUE_WHEEL_SIZE 0x12 // for 6''
#define DEBUG_UART
(I'm only running without LCD for now, and trying to make sense of the debug output)

Just matching wire colors between the motor and the controller, for the power and hall sensors, didn't work well initially and I found this combination that worked better for the power wires (keeping hall sensor colors matched):
blue | yellow
yellow | green
green | blue
Even though the motor ran kind of OK at high high throttle, it drew a lot of current, and jumped around at low throttle.

Reading through the forum, I figured I'd try changing MOTOR_ROTOR_OFFSET_ANGLE, and values around 220 seem to help a lot, the motor can now run at slow speeds.
Still I feel like it's pulling a little too much current (36V ~7A full throttle), and I'd like to understand better how to set this angle value, especially since the config-example.h states that it should be close to zero.

Any ideas where to start ? and other config parameters to play with ?



>> edit 13/06/2019 : Apologies, I hadn't pulled the latest stancecoke branch for some reason. Flashed it and after changing a few parameters, my first impressions are that it runs better out of the box, I'll dive in and see what kind of tuning can be done.
 
Hello everyone,

I would like to use this firmware with a higher voltage and current limit.

The advertised limits of the controller linked below would be good for me but I can not find a confirmation that it is compatible with this firmware.

https://www.aliexpress.com/item/32809186963.html?spm=2114.search0104.3.46.738379cbzTPtTS

Is there a way to tell before ordering? If not, could someone post a current link to the highest powered compatible controller? The 24 MOSFET KT/BMS Battery version is mentionned but I am struggling to find a current source for them.

Thanks
 
Hi, i'm new to this, but have it working with the app and the motor spinning!

I've got the hall order (starting from 12 oclock on the donut, running clockwise) in the right order for my YTW-06.

I've set the gear ratio as the effective pole pairs, which is 17.5 * 8 = 140. But the speed is slow. I increase the gear ratio and it's faster, but still not reaching the correct rpm for the voltage. What other setting might i need to change to get the target rpm?

I only see a very slight sine wave in the graph when spinning the wheel backwards, i can't determine the angle from this easily. I've adjust until it runs smooth at a level of 20. Should i see a big obvious and perfect sinewave?

When i turn the motor backwards, it feels like regen kicks in, is this normal? I appear to have regen functions off, but maybe i missed a setting. I'm using X4 for temp sensor and have it set to digital regen. I can't see a setting for regen on/off.

Also, the Java documentation describes a 'cell number' option, but i can't find this?

Is there a way to change the app to display mph?

I've also tried to use my Sempu torque sensor with the setup. I've got the PAS and throttle connected to it and switched on Torque Sensor, but it just spins up immediately. Any tips anywhere on getting the right settings for this?

I've got the temp sensor linked up to X4 and set to digital Regen, but can't see where i can get a readout on the software, any suggestions on the best way to display that calculated temperature and in Celsius?

Thanks for all the efforts.
 
Gear ratio is really only needed for determining the correct speed, motor will not turn differently if you change it, only the set speed limits work different then.

I only see a very slight sine wave
That's ok, amplitude is proportional to current, no automatic upscaling is done.

I can't see a setting for regen on/off
Can be adjusted in 5 steps just as power assist in the app.

Also, the Java documentation describes a 'cell number' option, but i can't find this?
Cause nobody bothers to update the documentation. Voltage related logic has been replaced by overvoltage/undervoltage settings.

Is there a way to change the app to display mph?
Not going to happen. Don't want to invest time for SI refuseniks :wink: But you could think a moment about what I wrote about Gear ratio.

any suggestions on the best way to display that calculated temperature
App Settings -> Motor temp?
 
Thank you! :) duly noted

Xnyle said:
Gear ratio is really only needed for determining the correct speed, motor will not turn differently if you change it, only the set speed limits work different then.

Strange as this totally alters the behavior of my motor, works great at 126, if i change it to 140, starts to stutter, practically stops at 70 and starts working again at 40.

Not going to happen. Don't want to invest time for SI refuseniks :wink: But you could think a moment about what I wrote about Gear ratio.

:wink:

App Settings -> Motor temp?

I'm not able to determine how to adjust these settings correctly.

If it's useful, i would be happy to spend some time updating the documentation. Just let me know the best workflow. I'm a tech journalist and made instructional videos professionally. Happy to update.

I'm using the Sempu torque sensor and i have it working, but is it possible to use a throttle in addition to this? I have wired in additional connector so both can be plugged in at once, but the throttle no longer works when the setting is switched to Torque Sensor unless i'm pedalling, which i presume is intentional so the torque sensor isn't triggered when not rotating, but since the Sempu is measuring the twist of the crank, perhaps i can have it working regardless of the rotation of the crank.

I also noticed that the motor wouldn't stop if i stopped pedaling, but If i pedal backwards a turn it stopped, i'm guessing that's not intentional as it stopped when i changed the PAS poles from 12 to 24.

Is there any documentation on what the main App display is reading, such as the multiple blue meters and the three red meters?

Thanks,
David.
 
140, starts to stutter, practically stops at 70 and starts working again at 40

Strange indeed. Take a look at the code where the gear ratio is used. Maybe you find some explanation/bug. I'm unable to explain it right now.

I'm not able to determine how to adjust these settings correctly

Debug the X4Value in the left panel, normally it goes more or less linearly down when temp goes up. Then you have to calculte 0 point and gradient and that's what you have to enter.

What you want to do with the torquesensor would require a bit of work on the software. If you have the skills, you can do that yourself, but I don't see any benefit in implementing that for the main branch. You then can't use X4 for temperature though (or you find another free and usable gpio on your board)

Is there any documentation on what the main App display is reading

Someone asked the same question(s) in the German forum, he also started with some annotated screenshots, but I'm not sure if he's still working on it. Maybe you could contact him?
https://www.pedelecforum.de/forum/index.php?threads/custom-rom-f%C3%BCr-kunteng-s06s-kt36-controller.50061/post-1204135

If you have experience documenting things, I guess you know better how to write stuff in a way so that it's not a reference / cheat sheet for those who already understood but a really newbie friendly guide.

You could start by creating a few alternate / new pages here
https://github.com/stancecoke/BMSBattery_S_controllers_firmware/wiki
and rework what's already there.

If you have questions, feel free to ask.
After you fully understood a chapter the ultimate goal is to rewrite it in a way so that nobody will ever ask again :)
 
davideserin said:
I'm using the Sempu torque sensor and i have it working, but is it possible to use a throttle in addition to this?

I'm currently using a Sempu T4 torquesensor and also have a throttle connected. My method was to connect both throttle and torquesensor signal lines in parallel to the controller i/p via a couple of blocking diodes, I used shottky diodes here to reduce the signal voltage drop. You'll then have to alter the Throttle min/max settings to suit.

This works well enough for me, there's a little lag in the throttle response due to the averaging function applied by the torquesensor code but not too noticeable in use.
 
@davideserin or whoever edited the Wiki:

Power Based Control: ?
Switches from current regulation control to power regulation (the lower voltage the more current you get for the same assist %)

Switch to 360 degree interpol: ?
Normally the controller interpolates PWM between hall sensor signals, that is 60° interpolation
This option swithes to 360° at 60 ERPS (iirc). The faster the motor is spinning the more likely 60° interpolation is going to interpolate "rough" / incorrect especially if you have high gear ratio / high speed motor. Then there are only 7 or 8 steps left within 60° and you might get noticeable rounding errors.

Idle Disables Offroad: ?
If offroad has been enabled, this disables it after one minute of inactivity /standstill.

Motor anti-jitter (@60 degree interpol): ?
Relates to what I wrote above, if there are big rounding errors the interpolation might calculate the motor is at for instance 125° and then comes the next hall signal change that says 120° normally the controller would now go back on his wavetable which you can feel as "stutter" or whatever the right word is :) With this option it just stays where it is until interpolation catches up again.

Disable 60 degree Interpolation: ?
Similar to Switch to 360 but interpolation goes to 360° right after startup.

DC Static Zero: ?
Fixes the duty cycle statically so you create a lot of current through the controllers sensor when turning the wheel by hand. You can then read you motor angle from the diagram. If you accidentally ride with this option enabled you'll probably fry some components.
 
Awesome work!!
Hey, is there any way the BluOSec app can be switched to a landscape layout rather than portrait?
Thanks for everything
 
Yes, you invest ~40+ hours to implement that ;)

Without worsening the code quality.
Without breaking anything.
...
 
720b0bf52ed189c3f5a7e18ff5590ef1.jpg


Here’s my first project with this firmware, my wife’s stealth school run bike with tandem hitch on for our daughter. Got it working with a Sempu on the YTW-06. Working great with the Bluetooth app, now just fine-tuning the settings!

Thanks for all the questions answered and development efforts. I will try to find time to support the project too :)


Sent from my iPhone using Tapatalk
 
Ok following up with my previous post https://endless-sphere.com/forums/viewtopic.php?f=30&t=87870&start=3550#p1473693 (tldr electric scooter, direct drive motor, 6" wheel, with a KT36/48 sine controller)

With the latest code (stancecoke master), as I already mentioned it runs out of the box, without changing the wire configuration nor playing with the motor angle.
I went for a few rides yesterday, and it's nice to see it running.

However, there are a few hiccups sometimes at startup, and it doesn't reach my max speed setpoint (25kph). I got a GPS (phone logging) max speed of ~17kph and average 12-13kph. Battery sag doesn't seem to be the limiting factor from what I see on my LCD5, perhaps the motor is just not powerful enough ?

I played a bit with diagnostic mode. On my bench (no load), when I increase throttle to max :
- erps ~ 120 which corresponds to ~ 14kph (120erps / 15 pole pairs * 0.48m circumference = 3.84m/s). 120erps is true, as confirmed with a slow-mo video on my phone
- control state is 17 (PAS too slow + throttle override) : no overspeed
- battery current (~2A <-> 339 = 319cal_b + 20) stays well below current target (= max_current ~10A)
- duty cycle caps at 255

I looks like foc doesn't find the sweet spot without load because if I disable it and play with MOTOR_ROTOR_DELTA_PHASE_ANGLE_RIGHT a bit, by lowering it to 225 instead of 246 for example, I can get higher erps (170) at lower loads (330 : ~1A) at full throttle.
I don't know if it's still true when loaded. Edit : confirmed when loaded too, I reached a higher top speed on a test ride with a fixed motor angle (foc corrections disabled)

Finally, the code doesn't behave the same with or without DIAGNOSTICS enabled : when enabled, the motor never truly stops when throttle is released, whereas it does when disabled.

Hope it helps,
Thanks for the hard work !
 
I wrote some notes about using reducing the ADC and PWM resolution to 8 bits on this firmware. I think I never did explain before so here it is:

buba said:
I might as well mention another improvement that both I and my father wanted to have for a very long time. And you, thineight, have also mentioned this in your feedback.

This is the resolution of motor power for every ADC current step limited by the resolution of the ADC:
My first question: is this a real issue or desire for optimization? -- I ask this because I never felt anything that I think this can the source of an issue.

I wrote my notes about the decision I took at start of the project to use 8 bits instead of 16 bits variables when possible. I am sure that having higher resolution can be better but there are disadvantages as well and we just need to understand what matters most.

Here my notes: https://github.com/OpenSource-EBike-firmware/TSDZ2_wiki/wiki/Development:-Why-reducing-the-ADC-and-PWM-resolution-to-8-bits

---

Development: Why reducing the ADC and PWM resolution to 8 bits
This notes were written on 2019.06.17 by Casainho.

When I started this firmware, I had already developed a lot of it on the KT motor controllers OpenSource firmware. The TSDZ2 motor controller uses the same 8 bits 16MHz microcontroller STM8S105xx and so I just reused the most part of the code. The mainly big difference is the way the "low resolution FOC" algorithm is implemented because KT motor controllers has a specific part of the hardware to do it and on TSDZ2 it was to be done on a different way.

The STM8S105xx PWM channels that are in use have 16 bits resolution but I decided to use only 8 bits. The ADC channels have the resolution of 10 bits but I decided to use only 8 bits. The main advantages of using 8 bits are:

1. Faster processing speed
This microcontroller is very limited in terms of processing speed and to handle FOC we need to do it fast as possible. Also, we would like to increase the PWM frequency to make possible the motor to rotate faster with higher voltage and for that, we need more processing speed.

If not using the 8 bits resolution, the variables would be of 16 bits and the processing time would increase to a factor like x5 -- this would mean that probably FOC could not be implemented or would be worst resulting in the motor having less torque and the battery range would be lower.

2. Low pass filter of analog signals
This motor has wires with high peak currents and PWM high frequency, meaning the electric signals should be noisy.

On the analog signals measured by the ADC, the first 2 bits of the 10 bits are being discarded and this results in a fast way that filters the noisy analog signals.

3. Reducing programming memory usage
This microcontroller has very low memory size and so we need to save it if we want to implement advanced features like FOC.

The operations with 16 bits would increase to a factor like x4 the programming memory usage comparing to the 8 bits.
 
Looking a bit more at the foc algorithm, serial debugging showed that for my hardware (I have an acs712 current sensor), the phase current offset is closer to 128 than 127. With the initial value, the correction quickly built up and made the control less efficient.
Have you guys ever had to tweak that value ?

I added it as a define, as well as a hysteresis parameter that I reduced to 0, which seems to get the angle correction closer to optimal (for my hardware).

Code:
#define PHASE_CURRENT_OFFSET 128
#define PHASE_CURRENT_HYSTERESIS 0

Code:
if (ui16_ADC_iq_current >> 2 > PHASE_CURRENT_OFFSET+PHASE_CURRENT_HYSTERESIS && ui8_position_correction_value < 143) {
	ui8_position_correction_value++;
} else if (ui16_ADC_iq_current >> 2 < PHASE_CURRENT_OFFSET-PHASE_CURRENT_HYSTERESIS && ui8_position_correction_value > 111) {
	ui8_position_correction_value--;
}
 
Why do you get a buildup? If hysteresis is >1 as it was b4 you would get a constant offset of 1 once correction kicks in?
 
Back
Top