Thanks - no problem extracting them with 7Zip, think I'll throw Peazip away....casainho wrote: ↑Apr 17, 2018 4:33 amTo extract, use 7Zip for Windows that is OpenSource: https://www.7-zip.org/download.html
After, copy that 3 folders "lib", "local" and "share" to inside C:/SDCC, as per instructions of Stancecoke.
KT motor controllers -- Flexible OpenSource firmware for BMSBattery S/Kunteng KT motor controllers (0.25kW up to 5kW)
Re: Flexible OpenSource firmware for BMSBattery S/Kunteng KT motor controllers (0.25kW up to 5kW)
BBS02 V2 48v 750w, 12s lipo.
Q128H (36v 201rpm), KT36/48SVPR 20amp, LCD3, 48v 12s lipo.
Q128H (36v 201rpm), KT36/48SVPR 20amp, LCD3, 48v 12s lipo.
- stancecoke
- 10 kW
- Posts: 553
- Joined: Aug 02, 2017 2:56 pm
Re: Flexible OpenSource firmware for BMSBattery S/Kunteng KT motor controllers (0.25kW up to 5kW)
Winrar works for extracting the files from the archive also, as suggested in the instructions. I'll add the links to the tutorial.
regards
stancecoke
regards
stancecoke
Re: Flexible OpenSource firmware for BMSBattery S/Kunteng KT motor controllers (0.25kW up to 5kW)
Finally got this installed and working today, some early observations:-stancecoke wrote: ↑Apr 15, 2018 6:05 amI've just uploaded a new branch with improved direction detection on PAS and made Regen like coast brakes availabe in normal PAS/Throttle mode.
1) The modified PAS detection works well once PAS ratio is set. On my installation the range over which PAS operated without malfunction was 1.7 - 2.1, so the default of 1.7 was a little low. Set it at the obvious centre point of 1.9, at this figure it works reliably with no false triggering. So, for me, this is an improvement on the previous code and I found achieving the best setting for PAS ratio is not difficult.
2) Was initially confused by the brake indicator showing at times (lcd3) without the brakes being operated. Guessed this was probably to indicate regen/coast brake in operation(?) but it's a little unnecessary and distracting for gear motors, maybe this function can be switched off in config.h. when not required...?
Probably unrelated to the new pas code, it seems the wattmeter holds zero well now but has lost it's previous accuracy and is now indicating around 60% of its 'expected' value.
Didn't notice any occurrences of this problem:-
..not sure if the recent changes could have affected this, maybe I need to do a longer test ride to be sure of this.Just noticed one small 'glitch' though, often when under full power (800w on my setup, usually using throttle but I think has also happened under pas only) the LCD3 wattmeter reading will suddenly decay down to zero, although the motor is still at full drive. If at this point you release throttle/stop pedalling the motor 'hangs in' at full power for a further 2-3 secs before stopping. Not a big deal but just thought I'd mention it, it can catch you out if it happens at a bad moment.
BBS02 V2 48v 750w, 12s lipo.
Q128H (36v 201rpm), KT36/48SVPR 20amp, LCD3, 48v 12s lipo.
Q128H (36v 201rpm), KT36/48SVPR 20amp, LCD3, 48v 12s lipo.
- stancecoke
- 10 kW
- Posts: 553
- Joined: Aug 02, 2017 2:56 pm
Re: Flexible OpenSource firmware for BMSBattery S/Kunteng KT motor controllers (0.25kW up to 5kW)
@geofft: Thank you for testing and the feedback!
I think you had a similar idea, as you had the parameter
in your code at an earlier commit, but I can't find that in the recent master branch any more?!
regards
stancecoke
I've logged the phase current while riding and while regeneration with FOC disabled (correction angle always 127). The log shows, that the phase current is 120° late at regen. In my fork I normally read phase current at 180°, now I suggest to do the reading of the phase current at 60° when battery current is negative. I've implemented it in the latest commit, but I have not tried it on the road, as it's already dark outside...

I think you had a similar idea, as you had the parameter
Code: Select all
#define FOC_READ_ID_CURRENT_ANGLE_ADJUST_INVERT 242
regards
stancecoke
Re: Flexible OpenSource firmware for BMSBattery S/Kunteng KT motor controllers (0.25kW up to 5kW)
I received my TSDZ2 motor today and I also officially started the project: Flexible OpenSource firmware for TongSheng TSDZ2 mid drive motor
Please join the thread here: https://endless-sphere.com/forums/viewt ... 30&t=93818
Please join the thread here: https://endless-sphere.com/forums/viewt ... 30&t=93818
Developer of the Flexible OpenSource firmware for EBike motor controllers:
- Kunteng/BMSBattery VLR FOC motor controller: https://opensourceebikefirmware.bitbucket.io/
- TongSheng TSDZ2 mid drive motor controller: https://opensourceebikefirmware.bitbuck ... ment_tsdz2
- Kunteng/BMSBattery VLR FOC motor controller: https://opensourceebikefirmware.bitbucket.io/
- TongSheng TSDZ2 mid drive motor controller: https://opensourceebikefirmware.bitbuck ... ment_tsdz2
Re: Flexible OpenSource firmware for BMSBattery S/Kunteng KT motor controllers (0.25kW up to 5kW)
Ok, TSDZ2 is out off topic but I would like to say that the firmware development started the best way possible!!!
and thanks to all the knowledge earned on this project for Kunteng motor controllers.



casainho wrote: ↑Apr 18, 2018 7:34 amVICTORY!!
The connection for firmware programming and debug are available on the connector for the speed sensor.
Seems that the original firmware is not read protected. I was able to read the option bytes, firmware and finally connect with OpenOCD for a debug session.
Please read my full notes here: https://opensourceebikefirmware.bitbuck ... enOCD.html


Developer of the Flexible OpenSource firmware for EBike motor controllers:
- Kunteng/BMSBattery VLR FOC motor controller: https://opensourceebikefirmware.bitbucket.io/
- TongSheng TSDZ2 mid drive motor controller: https://opensourceebikefirmware.bitbuck ... ment_tsdz2
- Kunteng/BMSBattery VLR FOC motor controller: https://opensourceebikefirmware.bitbucket.io/
- TongSheng TSDZ2 mid drive motor controller: https://opensourceebikefirmware.bitbuck ... ment_tsdz2
Re: Flexible OpenSource firmware for BMSBattery S/Kunteng KT motor controllers (0.25kW up to 5kW)
Well done, that's a great start. I guess people will be much more inclined to try the 'new' firmware if they know they can restore the original fw if required.casainho wrote: ↑Apr 18, 2018 7:39 amOk, TSDZ2 is out off topic but I would like to say that the firmware development started the best way possible!!!and thanks to all the knowledge earned on this project for Kunteng motor controllers.
casainho wrote: ↑Apr 18, 2018 7:34 amVICTORY!!
The connection for firmware programming and debug are available on the connector for the speed sensor.
Seems that the original firmware is not read protected. I was able to read the option bytes, firmware and finally connect with OpenOCD for a debug session.
Have subscribed to the thread, will be watching progress with interest..
BBS02 V2 48v 750w, 12s lipo.
Q128H (36v 201rpm), KT36/48SVPR 20amp, LCD3, 48v 12s lipo.
Q128H (36v 201rpm), KT36/48SVPR 20amp, LCD3, 48v 12s lipo.
Re: Flexible OpenSource firmware for BMSBattery S/Kunteng KT motor controllers (0.25kW up to 5kW)
Hi,
I got controller 60V KT 18 MOSFETS, and motor Nine Continent RH205 kassette. I can`t to configure it to run motor smoothly, i got effect like on the video https://www.youtube.com/watch?v=exmxFgL ... tu.be&t=13 . Motor has 46 magnets, I set P1 on 46 and still works wrong. Do you think with the new firmware I will be able to make it run well?
I got controller 60V KT 18 MOSFETS, and motor Nine Continent RH205 kassette. I can`t to configure it to run motor smoothly, i got effect like on the video https://www.youtube.com/watch?v=exmxFgL ... tu.be&t=13 . Motor has 46 magnets, I set P1 on 46 and still works wrong. Do you think with the new firmware I will be able to make it run well?
- stancecoke
- 10 kW
- Posts: 553
- Joined: Aug 02, 2017 2:56 pm
Re: Flexible OpenSource firmware for BMSBattery S/Kunteng KT motor controllers (0.25kW up to 5kW)
I've tested it on the road now, but I was not successful. It seems, that the zero crossing of the phase current is not influenced by the correction angle at all...stancecoke wrote: ↑Apr 17, 2018 2:33 pmI've implemented it in the latest commit, but I have not tried it on the road,

regards
stancecoke
Re: Flexible OpenSource firmware for BMSBattery S/Kunteng KT motor controllers (0.25kW up to 5kW)
Thanks for logging and testing. Really nice to see that is really different on both situations.stancecoke wrote: ↑Apr 18, 2018 1:11 pmI've tested it on the road now, but I was not successful. It seems, that the zero crossing of the phase current is not influenced by the correction angle at all...stancecoke wrote: ↑Apr 17, 2018 2:33 pmI've implemented it in the latest commit, but I have not tried it on the road,![]()
Also see that 2 lines may not be comparable since the current phase displacemente depends on motor speed and current, and I think you can't assure they were registered on that same conditions.
One thing: I remember to play with magnets and if we think we have 2 magnets, were 1 we control his position (by controlling the pahse current), we need to put at a specific distance to have max attraction force (90 degrees per FOC).
At motoring mode, we want let's say to put current at 90 degres. At regen mode, we want to push to the other side, so, at -90 degrees. Maybe at regen mode we need to put current at -90 degrees, or the same as 270 degrees.
And also, since the current is flowing to battery, on the inverse direction, shouldn't the phase current be inverted 180 degrees also??
Developer of the Flexible OpenSource firmware for EBike motor controllers:
- Kunteng/BMSBattery VLR FOC motor controller: https://opensourceebikefirmware.bitbucket.io/
- TongSheng TSDZ2 mid drive motor controller: https://opensourceebikefirmware.bitbuck ... ment_tsdz2
- Kunteng/BMSBattery VLR FOC motor controller: https://opensourceebikefirmware.bitbucket.io/
- TongSheng TSDZ2 mid drive motor controller: https://opensourceebikefirmware.bitbuck ... ment_tsdz2
Re: Flexible OpenSource firmware for BMSBattery S/Kunteng KT motor controllers (0.25kW up to 5kW)
Try changing C2 and reset display everytime.mjentos wrote: ↑Apr 18, 2018 1:04 pmHi,
I got controller 60V KT 18 MOSFETS, and motor Nine Continent RH205 kassette. I can`t to configure it to run motor smoothly, i got effect like on the video https://www.youtube.com/watch?v=exmxFgL ... tu.be&t=13 . Motor has 46 magnets, I set P1 on 46 and still works wrong. Do you think with the new firmware I will be able to make it run well?
- stancecoke
- 10 kW
- Posts: 553
- Joined: Aug 02, 2017 2:56 pm
Re: Flexible OpenSource firmware for BMSBattery S/Kunteng KT motor controllers (0.25kW up to 5kW)
After thinking a little: The current controller pulls the dutycycle to zero, if high regen current is wanted. In this case the correction angle can't have any effect, as the PWM puts no sinewave to phase lines.
Can we achieve higher regen current, if we set a higher dutycyle and a "misstuned" correction angle?!
With dutycycle = 0 I get about 1.5A regen current at about 20km/h with my BionX...
regards
stancecoke
Can we achieve higher regen current, if we set a higher dutycyle and a "misstuned" correction angle?!
With dutycycle = 0 I get about 1.5A regen current at about 20km/h with my BionX...
regards
stancecoke
Re: Flexible OpenSource firmware for BMSBattery S/Kunteng KT motor controllers (0.25kW up to 5kW)
Interesting is that with stock fw you can regen by decreasing throttle possition and the transition between braking and accelerating is not noticeable at all.
Re: Flexible OpenSource firmware for BMSBattery S/Kunteng KT motor controllers (0.25kW up to 5kW)
I tried 0-7, no improvementhonya96 wrote: ↑Apr 18, 2018 2:35 pmTry changing C2 and reset display everytime.mjentos wrote: ↑Apr 18, 2018 1:04 pmHi,
I got controller 60V KT 18 MOSFETS, and motor Nine Continent RH205 kassette. I can`t to configure it to run motor smoothly, i got effect like on the video https://www.youtube.com/watch?v=exmxFgL ... tu.be&t=13 . Motor has 46 magnets, I set P1 on 46 and still works wrong. Do you think with the new firmware I will be able to make it run well?
Re: Flexible OpenSource firmware for BMSBattery S/Kunteng KT motor controllers (0.25kW up to 5kW)
No, the current controller tries to decrease the duty_cycle. Let's say motor is rotating at 100 erps and that gives a 12v BEMF. If duty-cycle value equals to a 12v from battery, no current flows. If you decrease duty-cycle a bit, now the voltage from battery will be lower than the BEMF voltage from motor and current will start to be regen.stancecoke wrote: ↑Apr 18, 2018 2:41 pmAfter thinking a little: The current controller pulls the dutycycle to zero, if high regen current is wanted. In this case the correction angle can't have any effect, as the PWM puts no sinewave to phase lines.
Can we achieve higher regen current, if we set a higher dutycyle and a "misstuned" correction angle?!
With dutycycle = 0 I get about 1.5A regen current at about 20km/h with my BionX...
So, on motor regen duty-cycle is not always zero but will be a value in a way that regen current is not more the value we define/control, so, there will be sinewave phase voltages while regen. Maybe the current phase will simple invert in direction and so shoild have 180 degrees...
Developer of the Flexible OpenSource firmware for EBike motor controllers:
- Kunteng/BMSBattery VLR FOC motor controller: https://opensourceebikefirmware.bitbucket.io/
- TongSheng TSDZ2 mid drive motor controller: https://opensourceebikefirmware.bitbuck ... ment_tsdz2
- Kunteng/BMSBattery VLR FOC motor controller: https://opensourceebikefirmware.bitbucket.io/
- TongSheng TSDZ2 mid drive motor controller: https://opensourceebikefirmware.bitbuck ... ment_tsdz2
Re: Flexible OpenSource firmware for BMSBattery S/Kunteng KT motor controllers (0.25kW up to 5kW)
You mean changing the angle to get regen?? Idon't think so. On FOC, for regen and invert rotation, we change Iq current from positive to negative. Let's say motor is running with a reference Iq = 10A, to start regen we should put Iq ref = -10A.stancecoke wrote: ↑Apr 18, 2018 2:41 pmCan we achieve higher regen current, if we set a higher dutycyle and a "misstuned" correction angle?!
If we imagine 2 parallel rails, with 2 magnets on each rail at a very low distance each one, one north pole and other south, they will attract them selfs and stay inline (0 degrees). Now if we move one, the other will follow and if the other has some contrary force to movement direction, like a pull finger, the max torque will be at 90 degrees an not inline 0 degrees. If we push the first magnet to right to move the second one, max torque will be at 90 degrees and after being moving, to brake, max torque will be at -90 degrees (now on the left side).
Developer of the Flexible OpenSource firmware for EBike motor controllers:
- Kunteng/BMSBattery VLR FOC motor controller: https://opensourceebikefirmware.bitbucket.io/
- TongSheng TSDZ2 mid drive motor controller: https://opensourceebikefirmware.bitbuck ... ment_tsdz2
- Kunteng/BMSBattery VLR FOC motor controller: https://opensourceebikefirmware.bitbucket.io/
- TongSheng TSDZ2 mid drive motor controller: https://opensourceebikefirmware.bitbuck ... ment_tsdz2
- stancecoke
- 10 kW
- Posts: 553
- Joined: Aug 02, 2017 2:56 pm
Re: Flexible OpenSource firmware for BMSBattery S/Kunteng KT motor controllers (0.25kW up to 5kW)
I don't know if it's a matter of the BionX. As I wrote, the max regen current I get at 20 km/h is about 1.5Amps only. If I ask for e.g. 5A regen current, the current controller drives the duty cycle to zero. If I ask for e.g. 0.5 A, of course the dutycycle will be higher than zero...
regards
stancecoke