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   10 kW

10 kW
Posts: 896
Joined: Aug 02 2017 2:56pm

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

Post by stancecoke » Apr 15 2018 9:39am

Are you planning to use the java tool? Then I have to update it, too, as there is an additional #define necessary in the config.h for the PAS ratio.

regards
stancecoke

geofft   1 kW

1 kW
Posts: 318
Joined: Nov 09 2012 9:41am
Location: Berkshire UK

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

Post by geofft » Apr 15 2018 10:53am

stancecoke wrote:
Apr 15 2018 9:39am
Are you planning to use the java tool? Then I have to update it, too, as there is an additional #define necessary in the config.h for the PAS ratio.

regards
stancecoke
I normally do the user setup directly in config.h. Do I need add the #define in config.h to set PAS ratio at this time?
BBS02 V2 48v 750w, 12s lipo.
Q128H (36v 201rpm), KT36/48SVPR 20amp, LCD3, 48v 12s lipo.

User avatar
stancecoke   10 kW

10 kW
Posts: 896
Joined: Aug 02 2017 2:56pm

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

Post by stancecoke » Apr 15 2018 11:58am

No, the config.h in the branch works, but if you use the Java Tool, this config.h will be overwritten. If you want to use a display, you have to comment the line

Code: Select all

#define DEBUG_UART

regards
stancecoke.

casainho   100 MW

100 MW
Posts: 2662
Joined: Feb 14 2011 2:43pm

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

Post by casainho » Apr 15 2018 12:47pm

bardbe wrote:
Apr 15 2018 4:50am
Great effort of you guys from making stuff more configurable, and better performance!
Thank you for your feedback!!
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, you can consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

casainho   100 MW

100 MW
Posts: 2662
Joined: Feb 14 2011 2:43pm

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

Post by casainho » Apr 15 2018 2:03pm

stancecoke wrote:
Apr 15 2018 6:05am
I've just uploaded a new branch with improved direction detection on PAS and made Regen like coast brakes availabe in normal PAS/Throttle mode. No wire at X4 is necessary, just a normal PAS at the origin PAS connector.
@casainho: you are right, with your code for handling the PAS signal, the mod of the BMS-Sensor doesn't work. With my interrupt-based handling, it works. Quite strange, but not important, as we won't use this sensor any more, I think....
I was looking at your code and I have some notes/questions:
1. The code have Printfs, please remove and "clean" the code
2. Your improved PAS direction detection is the same I looked before. With this new code, user will need to define another parameter and is also hard to find the correct value: #define PAS_THRESHOLD 1.7 <--- do we really need this improvement? what kind of PAS you have that didn't work with current code? The BMSBattery PAS, and I guess others may be very similar, work very well for me with current code and without the need of that additional parameter.
3. Seems some code is missing, because ui8_pas_flag is tested on read_pas_cadence_and_direction() but I don't see it being changed in any other place
4. This implementation seems to overwrite my implementation using the torque sensor + extra PAS. Please make your implementation to not overwrite, maybe using another define like EBIKE_REGULAR_PAS_REGEN_EBRAKE_LIKE_COAST_BRAKES
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, you can consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

User avatar
stancecoke   10 kW

10 kW
Posts: 896
Joined: Aug 02 2017 2:56pm

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

Post by stancecoke » Apr 15 2018 2:36pm

I think the additional parameter PAS_ratio will be OK with 1.7 in most cases, I've tested it with a cheap normal PAS and the modded BMS-Torquesensor, for both it was OK. As geofft already mentioned, the very simple implementation in the recent master branch causes hickups sometimes, that's my experience, too.

The ui8_pas_flag is set at the rising edge of the PAS signal in the motor.c and is reset in the ebike_app.c after processing the PAS information.

Please try to connect your extra PAS from your modded torquesensor to the origin PAS connector. This should work for you also, without the need of using X4.

regards
stancecoke

casainho   100 MW

100 MW
Posts: 2662
Joined: Feb 14 2011 2:43pm

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

Post by casainho » Apr 16 2018 4:23am

stancecoke wrote:
Apr 15 2018 2:36pm
I think the additional parameter PAS_ratio will be OK with 1.7 in most cases, I've tested it with a cheap normal PAS and the modded BMS-Torquesensor, for both it was OK. As geofft already mentioned, the very simple implementation in the recent master branch causes hickups sometimes, that's my experience, too.
For me it is clear that direction can be detected, in a robust way, by comparing if ton is higher than toff, for a regular PAS. And that is working very well on current code, including the cadence value.
What may be failing that wasn't done yet, is the detection of the situation where there is a quick oscillation of the pedals, where ton and toff will have erroneous values and should be the reason for the hickups on the direction changing detection, direction and even cadence. I would implement a validation of min ton and toff values. And maybe after, a needed sequence of at least 1 ton + 1 toff with the correct min times.

I am afraid to regress on the robustness of PAS cadence and direction. Maybe since geofft want to try your code, we should wait for his experience results. I simple can't test on a regular PAS that is what really matters to me.

I saw that Sempu torque sensors, at least the latest version that works with 5V power supply, have specific wire/signal for indicate only the direction and other for indication of cadence. For the implementation of braking like coast brakes, will be much easier and very near of my implementation of the added PAS. In fact, will need 3 wires unlike BMSBattery torque sensor, so, will be 3 wires like my mod for braking like coast brakes.

Also Sempu torque sensor seems to be like 3x expensive, like about 125€...
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, you can consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

geofft   1 kW

1 kW
Posts: 318
Joined: Nov 09 2012 9:41am
Location: Berkshire UK

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

Post by geofft » Apr 16 2018 6:35am

To recap, the issue I had with the master branch (casainho pas) was that it had a tendency to trigger pas on slow reverse pedalling. On casainho's advice I played around with the 'ticks' count in this line (main.h):-

#define PAS_ABSOLUTE_MIN_CADENCE_PWM_CYCLE_TICKS (156250 / PAS_NUMBER_MAGNETS) // min hard limit to 6RPM PAS cadence

...and found that changing from 156250 to 100000 reduced the issue. I still get some 'kicks' from the motor with reverse pas on the test stand but it doesn't notice too much in normal use and still gives acceptable response to forward pas. This is the fix I've been using ever since.

@stancecoke

I've tried to install your modified branch with the new pas code but it fails to build and flash - I've attached the CMD DUMP, maybe you could take a look sometime?

Edit to add:- This is the Sempu torquesensor I've ordered (T2)
https://www.aliexpress.com/item/torque- ... 0.0.HCKx3b
Attachments
cmd dump master stancecoke pas.txt
(8.73 KiB) Downloaded 55 times
BBS02 V2 48v 750w, 12s lipo.
Q128H (36v 201rpm), KT36/48SVPR 20amp, LCD3, 48v 12s lipo.

User avatar
stancecoke   10 kW

10 kW
Posts: 896
Joined: Aug 02 2017 2:56pm

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

Post by stancecoke » Apr 16 2018 8:10am

geofft wrote:
Apr 16 2018 6:35am
I've tried to install your modified branch with the new pas code but it fails to build and flash
I think you have a typo in the config.h.

Please make sure, that you have the right entry for PAS/Throttle mode:

Code: Select all

#define EBIKE_THROTTLE_TYPE EBIKE_THROTTLE_TYPE_THROTTLE_PAS
I've changed the code a little to avoid the thing with the motor starting when pulling reverse, please download the latest revision!

casainho wrote:
Apr 16 2018 4:23am
I saw that Sempu torque sensors, at least the latest version that works with 5V power supply,
Where you got this information from? In the specification there's this information:
Supply voltage: 10-60V DC
casainho wrote:
Apr 16 2018 4:23am
Also Sempu torque sensor seems to be like 3x expensive, like about 125€...
You can get it a little cheaper at aliexpress, see the link from geofft. The second generation is available for 75$...

regards
stancecoke

geofft   1 kW

1 kW
Posts: 318
Joined: Nov 09 2012 9:41am
Location: Berkshire UK

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

Post by geofft » Apr 16 2018 9:54am

stancecoke wrote:
Apr 16 2018 8:10am
geofft wrote:
Apr 16 2018 6:35am
I've tried to install your modified branch with the new pas code but it fails to build and flash
I think you have a typo in the config.h.

Please make sure, that you have the right entry for PAS/Throttle mode:

Code: Select all

#define EBIKE_THROTTLE_TYPE EBIKE_THROTTLE_TYPE_THROTTLE_PAS
I've changed the code a little to avoid the thing with the motor starting when pulling reverse, please download the latest revision!
Have downloaded latest revision and checked config.h for correct #define but still won't flash. Guess I'm doing something dumb, could you take a look at my config.h and tell me where I'm going wrong.... :roll:
Attachments
config.h
(1.24 KiB) Downloaded 55 times
BBS02 V2 48v 750w, 12s lipo.
Q128H (36v 201rpm), KT36/48SVPR 20amp, LCD3, 48v 12s lipo.

User avatar
stancecoke   10 kW

10 kW
Posts: 896
Joined: Aug 02 2017 2:56pm

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

Post by stancecoke » Apr 16 2018 10:22am

I tried to compile with your config.h and it worked without errors. Can you post the output of the cmd window again?
Have you already updated to SDCC 3.7.0?

regards
stancecoke

geofft   1 kW

1 kW
Posts: 318
Joined: Nov 09 2012 9:41am
Location: Berkshire UK

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

Post by geofft » Apr 16 2018 10:42am

stancecoke wrote:
Apr 16 2018 10:22am
I tried to compile with your config.h and it worked without errors. Can you post the output of the cmd window again?
Done
Have you already updated to SDCC 3.7.0?
Err......no. So I guess this is my problem?
Attachments
cmd dump master stancecoke pas(2).txt
(10.96 KiB) Downloaded 32 times
BBS02 V2 48v 750w, 12s lipo.
Q128H (36v 201rpm), KT36/48SVPR 20amp, LCD3, 48v 12s lipo.

casainho   100 MW

100 MW
Posts: 2662
Joined: Feb 14 2011 2:43pm

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

Post by casainho » Apr 16 2018 11:03am

geofft wrote:
Apr 16 2018 10:42am
Have you already updated to SDCC 3.7.0?
Err......no. So I guess this is my problem?
I see this errors on log:

Code: Select all

ebike_app.asm:378: Error: <a> machine specific addressing or addressing mode error
ebike_app.asm:415: Error: <a> machine specific addressing or addressing mode error
and I don't know what they mean, but is nothing about specific errors on the code - going with SDCC 3.7.0 is a must.
Last edited by casainho on Apr 16 2018 11:05am, edited 1 time in total.
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, you can consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

User avatar
stancecoke   10 kW

10 kW
Posts: 896
Joined: Aug 02 2017 2:56pm

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

Post by stancecoke » Apr 16 2018 11:04am

Yes, that's the fault.

Please see the updated installation instructions:

https://opensourceebikefirmware.bitbuck ... ndex3.html

regards
stancecoke

hmm, I darkly remember that you are using a 32 bit PC?! Sadly, this isn't supported any longer :(

geofft   1 kW

1 kW
Posts: 318
Joined: Nov 09 2012 9:41am
Location: Berkshire UK

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

Post by geofft » Apr 16 2018 11:18am

hmm, I darkly remember that you are using a 32 bit PC?! Sadly, this isn't supported any longer :(
Your dark memory is telling you lies.... :twisted:

Will update SDCC and try again, probably tomorrow.

Thanks guys.
BBS02 V2 48v 750w, 12s lipo.
Q128H (36v 201rpm), KT36/48SVPR 20amp, LCD3, 48v 12s lipo.

casainho   100 MW

100 MW
Posts: 2662
Joined: Feb 14 2011 2:43pm

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

Post by casainho » Apr 16 2018 1:26pm

geofft wrote:
Apr 16 2018 6:35am
Edit to add:- This is the Sempu torquesensor I've ordered (T2)
https://www.aliexpress.com/item/torque- ... 0.0.HCKx3b
Thanks. Would be great if you can share pictures of it when you get it, including the installation on the bicycle.
That one has a good price compared to the BMSBattery, considering it will not break. Also, what I don't like much is that BMSBattery one seems to not be water resistance/prof... I hope that Sempu torque sensor is better on that characteristic.

Torque sensor is really "magic"!! Yesterday my girlfriend rode for the first time the ebike with torque sensor and this "stable" firmware. We were 3h outside riding, it was great. Happens that I tried also and ebike with Bionx direct drive motor and torque sensor, really smooth but not much better than our solution. I really need to improve for direct drive motor.
But torque sensor is a way to control the ebike without throttle, which is much more close feeling with the machine, dynamic experience, etc. Also is great for fitness, and user can define "how much fitness" want to do.
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, you can consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

geofft   1 kW

1 kW
Posts: 318
Joined: Nov 09 2012 9:41am
Location: Berkshire UK

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

Post by geofft » Apr 16 2018 3:30pm

Torque sensor is really "magic"!!
Yes, I'm looking forward to trying one, but can see another steep learning curve looming to get it all up and running... :shock:
BBS02 V2 48v 750w, 12s lipo.
Q128H (36v 201rpm), KT36/48SVPR 20amp, LCD3, 48v 12s lipo.

User avatar
stancecoke   10 kW

10 kW
Posts: 896
Joined: Aug 02 2017 2:56pm

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

Post by stancecoke » Apr 16 2018 3:47pm

casainho wrote:
Apr 16 2018 1:26pm
I really need to improve for direct drive motor.
What's the problem with the direct drive? I never got your master branch running satisfying with the torque sensor due to the PAS issue, but with the code from my fork, my BionX direct drive runs really good now, including regen by "thumb-brake" 8)

regards
stancecoke

casainho   100 MW

100 MW
Posts: 2662
Joined: Feb 14 2011 2:43pm

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

Post by casainho » Apr 16 2018 4:09pm

geofft wrote:
Apr 16 2018 3:30pm
Torque sensor is really "magic"!!
Yes, I'm looking forward to trying one, but can see another steep learning curve looming to get it all up and running... :shock:
It is actually very simple!! For my torque sensor ebikes, I am using only the throttle signal and I am ignoring PAS signal. You can go like that, from Sempu, use only torque wire and connect it to throttle wire input of the controller. Yes, I am not using human power, I must say that I am being happy like this and may try later human power (torque * cadence).
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, you can consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

casainho   100 MW

100 MW
Posts: 2662
Joined: Feb 14 2011 2:43pm

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

Post by casainho » Apr 16 2018 4:11pm

stancecoke wrote:
Apr 16 2018 3:47pm
casainho wrote:
Apr 16 2018 1:26pm
I really need to improve for direct drive motor.
What's the problem with the direct drive? I never got your master branch running satisfying with the torque sensor due to the PAS issue, but with the code from my fork, my BionX direct drive runs really good now, including regen by "thumb-brake" 8)
Well, regen vibrates the motor and I know FOC is not working while regen. All this needs work. I don't have much time... It will take time.
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, you can consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

casainho   100 MW

100 MW
Posts: 2662
Joined: Feb 14 2011 2:43pm

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

Post by casainho » Apr 16 2018 11:49pm

I think I got how TSDZ2 motor controllers run the most efficient possible, without even doing very low resolution FOC:
casainho wrote:
Apr 16 2018 11:41pm
I am being thinking on how to do the motor control firmware in a way to get the most torque per amp possible, to be the most efficient possible.

I need help from you guys!!
We need to measure the TSDZ2 motor winding resistance and inductance - maybe some of you have a precise multimeter/equipment to do that?? Once some one does it, we can consider that values as a constants for this motors, as I hope TongSheng will not change the motor characteristics over time.

More expensive controllers do FOC and typically have 32 bits microprocessor running at least 50MHz. TSDZ2 has instead a 8 bits running at 16MHz.

Kunteng motor controllers with the same low processing power as TSDZ2, implement "very low resolution FOC" because they has a phase current sensor and they can run many different motors.

I am thinking that TSDZ2 don't has such phase current sensor but instead uses a look up table with pre defined values on how phase current will change with both motor speed and phase current increasing (this depends only of motor inductance and motor resistance). That should be good because this motor controller only has to drive this specific motor, unlike generic EBike motor controllers.
Using this look up table, there will be few math calculations per PWM cycle and that way PWM frequency can be increased to be able to drive this motor at higher RPMs - unlike on Kunteng where PWM frequency is 16kHz and max motor ERPM is 520, so the SVM/Sinewave is draw with the min of 30 different points at motor max speed.
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, you can consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

casainho   100 MW

100 MW
Posts: 2662
Joined: Feb 14 2011 2:43pm

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

Post by casainho » Apr 17 2018 2:11am

I am being thinking about TSDZ2 motor firmware and I changed my ideas about using the same firmware for both motors, because:
- we need a stable firmware and after 1 year, seems we are close to it
-- keep developing this firmware for other motor would bring instability
- I think is important to have the firmware clean and simple so others can learn with it, to make even more efficient motor controllers in the future and more EVs, that's the biggest point for be because of urgent need for a better green environment
- I think I will create even a dedicated notes files, etc, because current development notes file is "heavy"
- will start a new thread, which may happen soon
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, you can consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

bendik.vignes@gmail.com   1 mW

1 mW
Posts: 19
Joined: Aug 16 2016 12:44pm

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

Post by bendik.vignes@gmail.com » Apr 17 2018 2:45am

Does anyone know if these controllers (with this software) will work fine also for non-hub motors like the GoldenMotor BLT-800?

I have a three-wheel cargo bike with two of these motors (dual motor: two front wheels). For the moment I am using the goldenmotor "cruise" controllers for these motors, but I am not happy with the controllers performance (especially PAS and regen) so I am looking for alternative controllers...

geofft   1 kW

1 kW
Posts: 318
Joined: Nov 09 2012 9:41am
Location: Berkshire UK

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

Post by geofft » Apr 17 2018 4:23am

stancecoke wrote:
Apr 16 2018 11:04am
Yes, that's the fault.

Please see the updated installation instructions:

https://opensourceebikefirmware.bitbuck ... ndex3.html

regards
stancecoke
I'm struggling to make any sense of the .tar.xz files in that SDCC 3.7.0 download link, getting nowhere trying to unpack them with peazip. I think I'll have to wait for a simpler Windows installer version to become available before I can go any further with this.
BBS02 V2 48v 750w, 12s lipo.
Q128H (36v 201rpm), KT36/48SVPR 20amp, LCD3, 48v 12s lipo.

casainho   100 MW

100 MW
Posts: 2662
Joined: Feb 14 2011 2:43pm

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

Post by casainho » Apr 17 2018 4:33am

geofft wrote:
Apr 17 2018 4:23am
I'm struggling to make any sense of the .tar.xz files in that SDCC 3.7.0 download link, getting nowhere trying to unpack them with peazip. I think I'll have to wait for a simpler Windows installer version to become available before I can go any further with this.
To 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.
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, you can consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

Post Reply