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

The Eclipse version I use do show me as I expect... maybe yours is looking for values also in config-example.h??
Anyway, I tested with #error to see when SDDC builds and if it "passes" on that specific piece of code.
 
I tried to run with a wheel speed controller mode only and this mode works well, although I will go back to mode speed + current mode.

Also I found that battery SOC on display was wrong (again!!) and I corrected it. It seems to works as expected now. Added 1 more level to SOC: flashing when battery is under 10%.

Code:
// Considering the follow voltage values for each li-ion battery cell
// State of charge 		| voltage
#define LI_ION_CELL_VOLTS_MAX 	4.25
#define LI_ION_CELL_VOLTS_100 	4.20
#define LI_ION_CELL_VOLTS_80 	4.02
#define LI_ION_CELL_VOLTS_60 	3.87
#define LI_ION_CELL_VOLTS_40 	3.80
#define LI_ION_CELL_VOLTS_20 	3.73
#define LI_ION_CELL_VOLTS_10 	3.69
#define LI_ION_CELL_VOLTS_0 	3.27
#define LI_ION_CELL_VOLTS_MIN 	3.10

#define BATTERY_PACK_VOLTS_100	((float) LI_ION_CELL_VOLTS_100 * (BATTERY_LI_ION_CELLS_NUMBER << 8))
#define BATTERY_PACK_VOLTS_80	((float) LI_ION_CELL_VOLTS_80  * (BATTERY_LI_ION_CELLS_NUMBER << 8))
#define BATTERY_PACK_VOLTS_60	((float) LI_ION_CELL_VOLTS_60  * (BATTERY_LI_ION_CELLS_NUMBER << 8))
#define BATTERY_PACK_VOLTS_40	((float) LI_ION_CELL_VOLTS_40  * (BATTERY_LI_ION_CELLS_NUMBER << 8))
#define BATTERY_PACK_VOLTS_20	((float) LI_ION_CELL_VOLTS_20  * (BATTERY_LI_ION_CELLS_NUMBER << 8))
#define BATTERY_PACK_VOLTS_10	((float) LI_ION_CELL_VOLTS_10  * (BATTERY_LI_ION_CELLS_NUMBER << 8))
#define BATTERY_PACK_VOLTS_0	((float) LI_ION_CELL_VOLTS_0   * (BATTERY_LI_ION_CELLS_NUMBER << 8))

Code:
  // calc battery pack state of charge (SOC)
  ui16_battery_volts = ((uint16_t) ebike_app_get_ADC_battery_voltage_filtered ()) * ((uint16_t) ADC_BATTERY_VOLTAGE_K);
  if (ui16_battery_volts > ((uint16_t) BATTERY_PACK_VOLTS_80)) { ui8_battery_soc = 16; } // 4 bars | full
  else if (ui16_battery_volts > ((uint16_t) BATTERY_PACK_VOLTS_60)) { ui8_battery_soc = 12; } // 3 bars
  else if (ui16_battery_volts > ((uint16_t) BATTERY_PACK_VOLTS_40)) { ui8_battery_soc = 8; } // 2 bars
  else if (ui16_battery_volts > ((uint16_t) BATTERY_PACK_VOLTS_20)) { ui8_battery_soc = 4; } // 1 bar
  else if (ui16_battery_volts > ((uint16_t) BATTERY_PACK_VOLTS_10)) { ui8_battery_soc = 3; } // empty
  else { ui8_battery_soc = 1; } // flashing
 
casainho said:
The Eclipse version I use do show me as I expect...

Obviously there are more differences between the toolchain in linux and the toolchain in windows. Perhaps geofft or honya96 can crosscheck my findings in a windows system, for me the errors were reproducable on two different laptops...

regards
stancecoke
 
stancecoke said:
casainho said:
The Eclipse version I use do show me as I expect...

Obviously there are more differences between the toolchain in linux and the toolchain in windows. Perhaps geofft or d can crosscheck my findings in a windows system...
Can you quick try with #error? That is a safe why to see.
 
stancecoke said:
casainho said:
The Eclipse version I use do show me as I expect...

Obviously there are more differences between the toolchain in linux and the toolchain in windows. Perhaps geofft or honya96 can crosscheck my findings in a windows system, for me the errors were reproducable on two different laptops...

....hopefully will get a chance to try this over the weekend, will let you know the result.
 
stancecoke said:
casainho said:
Can you quick try with #error? That is a safe why to see.

Where is the message shown?
During build time. If you put #error on a line that is built, you will get the error.
 
To be sure, that nothing goes wrong, I've deleted the config_example from the file system.

And I can confirm: If the lines in the main.h are not commented out, the error "Torquesensor" occurs.

Code:
#if (EBIKE_THROTTLE_TYPE == EBIKE_THROTTLE_TYPE_THROTTLE_PAS)
  ebike_throttle_type_throttle_pas ();
#error "Throttle"
#elif (EBIKE_THROTTLE_TYPE == EBIKE_THROTTLE_TYPE_TORQUE_SENSOR)
  ebike_throttle_type_torque_sensor ();
#error "Torquesensor"
#else
#error "not defined"
#endif

Code:
ebike_app.c:153:2: error: #error "Torquesensor"

regards
stancecoke
 
stancecoke said:
And I can confirm: If the lines in the main.h are not commented out, the error "Torquesensor" occurs.

Code:
#if (EBIKE_THROTTLE_TYPE == EBIKE_THROTTLE_TYPE_THROTTLE_PAS)
  ebike_throttle_type_throttle_pas ();
#error "Throttle"
#elif (EBIKE_THROTTLE_TYPE == EBIKE_THROTTLE_TYPE_TORQUE_SENSOR)
  ebike_throttle_type_torque_sensor ();
#error "Torquesensor"
#else
#error "not defined"
#endif

Code:
ebike_app.c:153:2: error: #error "Torquesensor"
So it seems to be working as supposed as on config.h file you should have other define:
Code:
#define EBIKE_THROTTLE_TYPE EBIKE_THROTTLE_TYPE_TORQUE_SENSOR
 
casainho said:
So it seems to be working as supposed as on config.h file you should have other define:
Code:
#define EBIKE_THROTTLE_TYPE EBIKE_THROTTLE_TYPE_TORQUE_SENSOR

no, as I wrote before, in the config.h EBIKE_THROTTLE_TYPE EBIKE_THROTTLE_TYPE_THROTTLE_PAS is defined.
Please, install windows on one of your computers and try it yourself, if you don't believe me :wink:

regards
stancecoke
Code:
/*
 * config.h
 *
 *  Automatically created by Flexible OpenSource firmware - Configuration tool
 *  Author: stancecoke
 *  Author: casainho
 */

#ifndef CONFIG_H_
#define CONFIG_H_

//#define EBIKE_THROTTLE_TYPE EBIKE_THROTTLE_TYPE_TORQUE_SENSOR
#define EBIKE_THROTTLE_TYPE EBIKE_THROTTLE_TYPE_THROTTLE_PAS
#define EBIKE_THROTTLE_TYPE_THROTTLE_PAS_CURRENT_SPEED
#define EBIKE_THROTTLE_TYPE_THROTTLE_PAS_ASSIST_LEVEL_PAS_ONLY
#define PAS_NUMBER_MAGNETS 12
#define PAS_MAX_CADENCE_RPM 80
#define PAS_DIRECTION PAS_DIRECTION_RIGHT
#define ASSIST_LEVEL_0 0.0
#define ASSIST_LEVEL_1 0.2
#define ASSIST_LEVEL_2 0.4
#define ASSIST_LEVEL_3 0.6
#define ASSIST_LEVEL_4 0.8
#define ASSIST_LEVEL_5 1.0
#define BATTERY_LI_ION_CELLS_NUMBER 13
#define ADC_BATTERY_CURRENT_MAX 35
#define ADC_BATTERY_REGEN_CURRENT_MAX 35
#define MOTOR_ROTOR_OFFSET_ANGLE 210 // 210 adjusted as a good value for Q11 direct drive motor
#define FOC_READ_ID_CURRENT_ANGLE_ADJUST 115
#define FOC_READ_ID_CURRENT_ANGLE_ADJUST_INVERT 242
#define MOTOR_ROTOR_ERPS_START_INTERPOLATION_60_DEGREES 10
#define ADC_MOTOR_CURRENT_MAX 120
#define ADC_MOTOR_REGEN_CURRENT_MAX 66
#define PWM_DUTY_CYCLE_RAMP_UP_INVERSE_STEP 10
#define PWM_DUTY_CYCLE_RAMP_DOWN_INVERSE_STEP 10

#define EBIKE_REGEN_EBRAKE_LIKE_COAST_BRAKES

#endif /* CONFIG_H_ */
 
Hmmm, that is really strange. Mayne you can #undefine and use #error and then define again and use error. Maybe there is a way to print the value of that macro/define....
I don't know how I can help, because it works for me and the defines seems to be correct. You be great if someone with experience could revoew this defines...
 
stancecoke said:
And I can confirm: If the lines in the main.h are not commented out, the error "Torquesensor" occurs.
Wait! So if we do not use that 2 lines, everything works as expected, right??

Because the macro value is defined on main.h and also on config.h, which I guess should not happen!! Should be definwd only once I think... If so, you got it and I took a long time to understand :)
 
stancecoke said:
casainho said:
Please update your master branch as I just update it with my most recent code.

The recent master branch throws an error while compiling with windows. :(

Code:
ebike_app.asm:366: Error: <a> machine specific addressing or addressing mode error
ebike_app.asm:403: Error: <a> machine specific addressing or addressing mode error

Can you fix that? Otherwise I have to start from an earlier commit...

regards
stancecoke

I've just given this a quick try (with either Torque_Sensor or Throttle_Pas selected in Config.h), looks like I'm getting the same errors as Stancecoke (above).... :?

Edit: Crossed posts with casainho, looks like he might now be sorting this?
 
geofft said:
Edit: Crossed posts with casainho, looks like he might now be sorting this?

Thank you for the fast testing! We have two different topics. The one with the #defines (solved now) and the one with the errors while compiling (not solved yet)....

regards
stancecoke
 
stancecoke said:
the one with the errors while compiling (not solved yet)....
Something tells me this one will be hard.

I am thinking that may be a good idea to have only one firmware for both motor controllers: Kunteng KT and Tongsheng TSDZ2. Because that way we can reuse most of the tools, since the build tools up to software configuration tool, and maybe most important, keep the users together and that way I hope both firmwares will be strong. Also I think this 2 systems are kind of a complement and not duplicate, they together will cover wider range of ebike types/needs. I think they share the same philosophy: work well, really cheap, easy to buy in many online shops including spare parts for customization or repair.
 
There are a lot of potential, as shops sells programmed controllers to have one of the 3 possible battery voltages (36V, 48V and 52V) and different currents / powers (like 250W, 350W, 500W and 750W versions). Will be much better when we can buy one version and configure for our specific battery pack voltage and max current for our specific needs and no need to buy other controllers.

On 25 April, the project of firmware for Kunteng will make 1 year and maybe I should start to TSDZ2 motors on the same day this year :)

TSDZ2 motor is appealing also because is more simple to install for no tech users (no need touch on bicycle wheels) and even no need to use/install brake wires, throttle or gear shift sensor. Only needs wheel speed sensor + LCD installation.

eyebyesickle said:
casainho said:
eyebyesickle said:
casainho said:
Nice to know that this controllers can hold 18A, this means 48V version can hold 864W (900W considering a full charged battery) with and not can the 720W (advertised 750W, considering battery will hold a bit higher voltage when charged) of 48V * 15A controller. I think 15A controller is just a configured parameter on the firmware and not the controller max current limit, that should be at least that 18A!!
Take note, alot of resellers claim 18a, but almost no one actually knows or sets it at that. FutureBike Italy is on top of his stuff, so he probably does have the 18a, but I know EVERY other company I contact doesn't even really know. If you scroll way back in this thread, you will see where I opened some '18a' motors, and they had a 15a controller inside. Furthermore, the 15a controllers usually are only set to 13a!, so take note...

18a is the highest I recommend though, FYI....
Thank you for your help. And about the voltages, do you think they can also be configured? like the 52V motor controller be configured to work at 48V and 36V?
Yes, from what I can tell, all 6 pin controllers are the same, and all 8 pin controllers are the same, you can just program them as needed. The 36v and 48v motors are different however, with slightly different winds.
 
stancecoke said:
geofft said:
Edit: Crossed posts with casainho, looks like he might now be sorting this?

Thank you for the fast testing! We have two different topics. The one with the #defines (solved now) and the one with the errors while compiling (not solved yet)....
If I comment the 2 lines at main.h:
Code:
//#define EBIKE_THROTTLE_TYPE_THROTTLE_PAS		1
//#define EBIKE_THROTTLE_TYPE_TORQUE_SENSOR		2

I get EBIKE_THROTTLE_TYPE_THROTTLE_PAS selected even if on config.h I have #define EBIKE_THROTTLE_TYPE EBIKE_THROTTLE_TYPE_TORQUE_SENSOR. I can also comment that line on config.h and the selection will also be the EBIKE_THROTTLE_TYPE_THROTTLE_PAS. So, seems the way was before is the correct way -- can you please confirm Stancecoke, that changing on config.h will have the expected result (with the commented lines on main.h)??
 
with windows it's vice versa: if the two lines in the main.h are not commented out, always torquesensormode is active....

regards
stancecoke
 
I installed SDCC 3.7.0 and the built firmware has 18kbytes of flash memory instead of 25kbytes as when was built with SDCC 3.6.0. An improvement of about 40%, and yes, the firmware works well.

TSDZ2 motor controller has only 16 kbytes flash memory, so I think using SDCC 3.7.0 is a must for that project.
 
Between sun and rain, today I did a good ride of 1h30 betweem home and near beachs.
The firmware was built with SDCC 3.7.0.

The only thing I would like to explore a different approach is the current and speed controllers, however current ones work well.

 
casainho said:
Between sun and rain, today I did a good ride of 1h30 betweem home and near beachs.
The firmware was built with SDCC 3.7.0.

Will you be making this latest version be available on github sometime? I just wondered if it may have any effect on the (windows users) compiling issue?
 
geofft said:
casainho said:
Between sun and rain, today I did a good ride of 1h30 betweem home and near beachs.
The firmware was built with SDCC 3.7.0.

Will you be making this latest version be available on github sometime? I just wondered if it may have any effect on the (windows users) compiling issue?
The version I am using is on master branch of github. I just updated the compiler version to 3.7.0 and I found that the compiled firmware was about 40% smaller but still works the same.
The issue is thay the SDCC developers didn't put online a Windows version for 3.7.0 unlike on version 3.6.0. On Linux, I had to compile/build the version 3.7.0 but it is a regular way of doing it, we are used already to compile some of the software, mainly when we want the latest versions.

Please search on Google, maybe some one already compiled SDCC 3.7.0 and is sharing the executables.
 
casainho said:
geofft said:
Will you be making this latest version be available on github sometime? I just wondered if it may have any effect on the (windows users) compiling issue?
The version I am using is on master branch of github. I just updated the compiler version to 3.7.0 and I found that the compiled firmware was about 40% smaller but still works the same.
The issue is thay the SDCC developers didn't put online a Windows version for 3.7.0 unlike on version 3.6.0. On Linux, I had to compile/build the version 3.7.0 but it is a regular way of doing it, we are used already to compile some of the software, mainly when we want the latest versions.

Please search on Google, maybe some one already compiled SDCC 3.7.0 and is sharing the executables.

Ah - ok, my lack of developer knowledge showing here, I was forgetting that the firmware has to be built into executable (in windows or linux) in the final stage.. :roll:
 
i might have the solution for windows users, i found and document describing how to build the SDCC binary using visual C++ (http://sdcc.sourceforge.net/doc/sdccman.pdf)

i am pretty sure i have almost all required software installed on my PC so will give this a try tonight.
 
I bought the TSDZ2, shipping from EU,from http://www.pswpower.com/
My plan is to first take some good pictures; try to measure PWM frequency looking at motor phases; understand how torque sensor and how we can read it; understand how we can connect wires or such on the board knowing that it is potted.
 
Back
Top