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

geofft wrote: ↑11 Jul 2018, 11:00
when initially powered up the bike can be pushed in reverse with no resistance from the motor (as with stock fw) but if any throttle or pas input is made then afterwards the bike always resists being moved in reverse
This is normal, as the center aligned PWM is disabled at startup and gets enabled with the first ask for power. With a freewheeled motor this does't matter, with a direct drive this is necessary for doing regen...

Thanks stancecoke, a nice clear explanation for a numpty end user. In reality this doesn't cause any problems.

I look forward to "Master branch, non-regen" appearing on github at some point in the future... :D
 
geofft said:
Had a bit of a disaster with my controller tonight....

Just pulled all the mosfets out and I'm seeing a short across the (green phase, high side) gate/source pads on the pcb, looks like the mosfet driver has shorted. Not quite sure why but I strongly suspect the 12v/5v buck converter that powers these may have something to do with this, I'm going to revert to the LM317's.

Trouble is I'm now into the difficult surface mount stuff so this controller is now consigned to the 'spares only' box. Good job these things are so cheap.... :shock:
 
geofft said:
Trouble is I'm now into the difficult surface mount stuff so this controller is now consigned to the 'spares only' box. Good job these things are so cheap.... :shock:
Yes, being cheap and widely available are some of the strategic points to choose this controllers!!
 
Can someone check what data (what bit is set) is sent from LCD3 to controller when you hold DOWN button to enter cruise mode. I dont have LCD3 to test.
Thanks in advance.
 
Demion said:
when you hold DOWN button to enter cruise mode.

The protocol is described in detail here. You found the thread yourself, but obviously you didn't read the txt-files :)
The "long press button down" is a "6" in the three least signifikant bits of byte 2.

regards
stancecoke
 
Sorry. I missed it, silly of me.
By the way I want to connect controller LCD cables to Arduino.
I am going to connect Green to RX, Yellow to TX, Black to Ground, Red to Blue, and maybe Red through resistors (voltage divider, something like 110k to 10k 1:12) to analog to read voltage.
Anyone done this before, am I doing it correct? Thanks again.
 
Demion said:
Green to RX, Yellow to TX,

The other way round. The display sends on the yellow wire, so you have to connect it to Rx of the arduino.
Then it should work. I've done that on different projects already. What do you plan with the arduino? Perhaps you should have a look at jenkies "forumscontroller" project. It's based on arduino and has several functions implemented already...

regards
stancecoke
 
stancecoke said:
there are some open source examples for driving a BLDC with FOC on a STM32, so you won't have to start from scratch. I would prefer if we could write an open firmware for the Lishui controllers, they use STM32 processors and offer sensorless sinusodial drive.

regards
stancecoke

That's actually pretty expensive for the specs, due to the popularity of BLDC power tools there's quite a few new ICs aimed at cheap motor controllers. The components for a 48v/30A/1200W power stage are only about $25 USD and it's so integrated you only need 4 ICs for the entire 3x gate drive, current sense and mosfet halfbridge and voltage supply setup. To build them you would still need to take into account the cost of a 32bit MCU, passive components and PCB+assembly costs, however it would be pretty close if not maybe slightly cheaper while being open hardware and 4x as powerful.
 
Demion said:
Sorry. I missed it, silly of me.
By the way I want to connect controller LCD cables to Arduino.
I am going to connect Green to RX, Yellow to TX, Black to Ground, Red to Blue, and maybe Red through resistors (voltage divider, something like 110k to 10k 1:12) to analog to read voltage.
Anyone done this before, am I doing it correct? Thanks again.

What about an arduino nano with functions like CA v3? With kt-lcd3 or some better display which can show 9999watts.

I think it may be interesting for way more people than this FW and add functions to ANY controller.

CA v3 being the only of its kind is extremely overpriced. Worth 20$ compared to products from China

Now I realised, Casainho has Opensource FW for lcd3,

are there free pins for throttle input, output, pas input, additional buttons, hall (speed), shunt, etc etc?

So it can work as CA v3 alone??
 
honya96 said:
Demion said:
Sorry. I missed it, silly of me.
By the way I want to connect controller LCD cables to Arduino.
I am going to connect Green to RX, Yellow to TX, Black to Ground, Red to Blue, and maybe Red through resistors (voltage divider, something like 110k to 10k 1:12) to analog to read voltage.
Anyone done this before, am I doing it correct? Thanks again.

What about an arduino nano with functions like CA v3? With kt-lcd3 or some better display which can show 9999watts.

I think it may be interesting for way more people than this FW and add functions to ANY controller.

CA v3 being the only of its kind is extremely overpriced. Worth 20$ compared to products from China

Now I realised, Casainho has Opensource FW for lcd3,

are there free pins for throttle input, output, pas input, additional buttons, hall (speed), shunt, etc etc?

So it can work as CA v3 alone??
Yes, the firmware I am being develop for KT LCD3 supports printing data to odometer field that can show 9999.9 value.

LCD3 receives data from UART from the motor controllers, like KT and TSDZ2. It has no input for pins, that ones you ask are on the motor controllers. Even KT motor controllers support the Bluetooth communication that no one explored yet with an OpenSource mobile app.
 
honya96 said:
CA v3 being the only of its kind is extremely overpriced.

If your're looking for an alternative to the CA, you should have a look at the forumscontroller, it does the same as the CA but supports a variety of different displays! It's open source.

See here also:
https://endless-sphere.com/forums/viewtopic.php?f=2&t=47124


jenkie sells the PCB for just a few Euros :wink:

regards
stancecoke
 
I just updated my fork with code for phase current limiting in throttle mode (by the formula phasecurrent=batterycurrent/dutycycle)
I've added the reading of the motor temperature via pad X4 with calibration for a TMP36 sensor. It's not used for limiting the power yet. The temperature is just plotted via UART in diagnostics mode actually.

regards
stancecoke
 
stancecoke said:
I just updated my fork with code for phase current limiting in throttle mode (by the formula phasecurrent=batterycurrent/dutycycle)
I've added the reading of the motor temperature via pad X4 with calibration for a TMP36 sensor. It's not used for limiting the power yet. The temperature is just plotted via UART in diagnostics mode actually.

regards
stancecoke

Great! Can't wait to try it.

So now linear brake at x4 doesn't work?

Do you plan to show the temp on lcd3? I can order one for you if you will implement NTC10K, KTY 83, KTY 84 sensors.

I found lcd3 which can be set up to 99km/h stock.. just saying, if it's interesting for anyone.
 
stancecoke said:
honya96 said:
CA v3 being the only of its kind is extremely overpriced.

If your're looking for an alternative to the CA, you should have a look at the forumscontroller, it does the same as the CA but supports a variety of different displays! It's open source.

See here also:
https://endless-sphere.com/forums/viewtopic.php?f=2&t=47124


jenkie sells the PCB for just a few Euros :wink:

regards
stancecoke

Thanks

It looks way too complicated for me, but I may look into it more later.

Do you know if it supports some ebike display or just "arduino" displays?

Edit: OK I see it does. Even bafang displays..
 
honya96 said:
So now linear brake at x4 doesn't work?
You can use only one of both options, there is no analog input pin left on the processor, to read in two different additional signals :(
If you choose linear regen in the settings, you can't read in the temperature...


honya96 said:
Do you plan to show the temp on lcd3? I can order one for you if you will implement NTC10K, KTY 83, KTY 84 sensors.

I don't use any display. Perhaps Casainho can implement it in his custom firmware for LCD3. Of course we have to send the temperature data from controller side. I can implement it, if Casainho tells me the needed bytes in the communicatian protocol. :D

regards
stancecoke
 
stancecoke said:
I just updated my fork with code for phase current limiting in throttle mode (by the formula phasecurrent=batterycurrent/dutycycle)
That seems an incorrect implementation because:
1. battery_current has a big delay because of the low pass filter on hardware and so that code will not be able to detect the fast phase current peaks mainly on the more powerfull motors
2. the KT controllers has the specific hardware for reading the phase current without any delay, you just need to copy my implementation. You can also understand it by reading my notes and I am available to explain
 
casainho said:
That seems an incorrect implementation because:

This implementation is not incorrect, it's based on the theory of "phase current = battery current / dutycycle", not on the measured battery current. It limits the target-value for battery- and phase current. So we will never set a current target, that's critical for the motor or the mosfets.

I know and understand your implementation. Perhaps I will copy it, if the first useres report burned mosfets with my solution... :wink:

The control loop doesn't allow high gradients in duty cycle anyway. The biggest risk is to block the wheel while braking hard at riding, so you should avoid this.

regards
stancecoke
 
Ok, so I am finally trying to build the firmware on Linux. My distro has the entire x86 toolchain, so now I'm looking at cross-compiling for stm8.

I'm looking at the docs. I'm having a hard time wrapping my head around the necessary tools, and what they're needed for.

sdcc - compiler: stm8-binutils-gdb claims that "From version 2018-03-04 sdcc and openocd for stm8 does no longer have to be patched" and "The latest version of SDCC is 3.7.0 and support debugging with dwarf2 format". So I suppose I'll be needing v3.7.0 then? Or does stm8-binutils-gdb already come with sdcc?

OpenOCD - debugger?: As with sdcc, it needs a newer version for compatibility with stm8-binutils-gdb. The latest release is 0.10.0 from Jan 2017. I guess I'll have to compile the newest sources then?

stm8-binutils-gdb - toolchain??: As far as I can tell, this is a toolchain patchset for stm8 support. But then shouldn't gdb be the debugger? What's openocd for?

stm8flash - flasher: Do I even need this? According to the docs page: "tools like OpenOCD that will let you flash and debug the firmware"
 
1N4001 said:
Ok, so I am finally trying to build the firmware on Linux.

I can't help with linux. I 've tried it, see the very first pages of this thread, but I despaired after several days :shock:

Good luck :)

regards
stancecoke
 
sdcc - compiler: stm8-binutils-gdb claims that "From version 2018-03-04 sdcc and openocd for stm8 does no longer have to be patched" and "The latest version of SDCC is 3.7.0 and support debugging with dwarf2 format". So I suppose I'll be needing v3.7.0 then? Or does stm8-binutils-gdb already come with sdcc?[/quote]
I think you should foow the instructions of stm8binutils site and then they point you to build and install sdcc 3.7.0.
I use sdcc 3.7.0.

1N4001 said:
OpenOCD - debugger?: As with sdcc, it needs a newer version for compatibility with stm8-binutils-gdb. The latest release is 0.10.0 from Jan 2017. I guess I'll have to compile the newest sources then?
I use and built the 0.10.0. You can look at build examples for STLinkv2, which is very popular.

1N4001 said:
stm8-binutils-gdb - toolchain??[/b]: As far as I can tell, this is a toolchain patchset for stm8 support. But then shouldn't gdb be the debugger? What's openocd for?


- flasher: Do I even need this? According to the docs page: "tools like OpenOCD that will let you flash and debug the firmware"
If you look online for flash and debug ARM with OpenOCD, JTAG and Eclipse, for STM8 is just the same workflow and tools.

If you are on Windows amd just want to build the firmware, then follow Stancecoke guide. On Linux you get plus developer tools like JTAG debug.
 
stancecoke said:
I know and understand your implementation. Perhaps I will copy it, if the first useres report burned mosfets with my solution... :wink:

The control loop doesn't allow high gradients in duty cycle anyway. The biggest risk is to block the wheel while braking hard at riding, so you should avoid this.
I think some users here want fast throttle response and use the version of higher power KT controllers, so is a must to have the implementation I did. But I understand if you are limited of time to implement it.

stancecoke said:
casainho said:
That seems an incorrect implementation because:
This implementation is not incorrect, it's based on the theory of "phase current = battery current / dutycycle", not on the measured battery current. It limits the target-value for battery- and phase current. So we will never set a current target, that's critical for the motor or the mosfets.
I should had use better words. Sure it is correct but will fail (probably burning the mosfets). In fact, I am using just that on TSDZ2 firmware because the hardware of TSDZ2 motor controller can't read motor phase current unlike KT but that is probably because TSDZ2 motor is not so powerful as some motors run by KT controllers and also TSDZ2 motor must be configured to accelerate slower...
 
stancecoke said:
honya96 said:
Do you plan to show the temp on lcd3? I can order one for you if you will implement NTC10K, KTY 83, KTY 84 sensors.

I don't use any display. Perhaps Casainho can implement it in his custom firmware for LCD3. Of course we have to send the temperature data from controller side. I can implement it, if Casainho tells me the needed bytes in the communicatian protocol. :D
Sorry but I can't implement support for KT controllers on LCD3, because of time limitations. But I accept pull requests/contributions from others that want to make support for KT firmware.
 
casainho said:
stancecoke said:
honya96 said:
Do you plan to show the temp on lcd3? I can order one for you if you will implement NTC10K, KTY 83, KTY 84 sensors.

I don't use any display. Perhaps Casainho can implement it in his custom firmware for LCD3. Of course we have to send the temperature data from controller side. I can implement it, if Casainho tells me the needed bytes in the communicatian protocol. :D
Sorry but I can't implement support for KT controllers on LCD3, because of time limitations. But I accept pull requests/contributions from others that want to make support for KT firmware.

Lcd3 can show the temp with stock FW, I don't want to mess with the lcd FW..

But I understand that if someone needs it, he has to implement it... :roll:
 
honya96 said:
Lcd3 can show the temp with stock FW, I don't want to mess with the lcd FW..

Ah, I did't know that. It's Byte 9. So it is very simple to implement :).


honya96 said:
Do you plan to show the temp on lcd3? I can order one for you if you will implement NTC10K, KTY 83, KTY 84 sensors.
I chose the TMP36 because it delivers an analog signal with no additional external hardware.
Perhaps we can use the pullup resistor (6,7K) on X4 for the voltage divider when using a thermistor? We will need 10bit ADC value to get satisfiying resolution?! Is a linear approximation OK? I would add two parameters to the Javatool for the calibration.

Code:
Temperatur (°C) = a * ADC + b
So everybody can set the right value for his specific sensor... And I have to use a signed integer for the variable as the temperature can get negative...

regards
stancecoke
 
stancecoke said:
So everybody can set the right value for his specific sensor... And I have to use a signed integer for the variable as the temperature can get negative...

Great!!!

I can use KTY, they are used mostly in bigger motors, but NTC10K is the "most available" I would say, everyone has multiple of them at home without even knowing.

but it's not linear and not for high temps.
 
Back
Top