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

So, I just broke my bottom bracket torque sensor, while I was doing a lot of force at a hill -- now I remember this already happened to me once some years ago.



But before it broke, I was able to ride and test the battery current controller, torque sensor filtering and battery regen current that is setup by pedaling backwards - the code is on this branch "improving_for_direct_drive_motor".
Much more happy with the results with my direct drive motor Q11, as now it almost doesn't vibrate:
 
Oh, I hope you weren't injured when the crank broke off....

I found a bug now: In the main.h you define

Code:
// *************************************************************************** //
// Throotle and PAS

#define EBIKE_THROTTLE_TYPE_THROTTLE_PAS		1
#define EBIKE_THROTTLE_TYPE_TORQUE_SENSOR		2
// *************************************************************************** //

with this, the #if statements in the ebike_app.c don't work properly....
I commented out these entries in the main.h, now the right #if statements are active in eclipse (not greyed in the code).

I chose #define EBIKE_THROTTLE_TYPE EBIKE_THROTTLE_TYPE_THROTTLE_PAS now and with throttle and

-with #define EBIKE_THROTTLE_TYPE_THROTTLE_PAS_PWM_DUTY_CYCLE the motor runs only very slowly now,
-with #define EBIKE_THROTTLE_TYPE_THROTTLE_PAS_CURRENT_SPEED, the motor runs well, as expected...

So next step is to improve the PAS code, as obiously this part still doesn't work...

regards
stancecoke
 
stancecoke said:
So next step is to improve the PAS code, as obiously this part still doesn't work...
No, all is ok but is dangerous that situation. Thanks.
Thanks for the bug, I will look at it later.

So, which part of PAS code doesn't work? direction detection?
For direction detection, maybe we can do as you advice before, look at the ratio of ui16_pas1_on_time_counter over ui16_pas1_off_time_counter, make a division on read_pas_cadence_and_direction() that runs every 100ms. PWM interrupt just needs to deal with ui16_pas1_on_time_counter and ui16_pas1_off_time_counter.
 
casainho said:
So, I just broke my bottom bracket torque sensor, while I was doing a lot of force at a hill -- now I remember this already happened to me once some years ago.

....I'd be interested to know which type of torque sensor (type/supplier) this was.. :shock:
 
geofft said:
casainho said:
So, I just broke my bottom bracket torque sensor, while I was doing a lot of force at a hill -- now I remember this already happened to me once some years ago.

....I'd be interested to know which type of torque sensor (type/supplier) this was.. :shock:
BMSBattery B.B. torque sensor.
 
casainho said:
geofft said:
casainho said:
So, I just broke my bottom bracket torque sensor, while I was doing a lot of force at a hill -- now I remember this already happened to me once some years ago.

....I'd be interested to know which type of torque sensor (type/supplier) this was.. :shock:
BMSBattery B.B. torque sensor.

Thanks. I'm still thinking about trying a torque sensor, will probably give the BMS one a miss on this evidence.

Thought I might try one of these (T2 version):-
https://www.aliexpress.com/item/torque-sensor-transducer-standard-buttom-bracket-parts-for-electric-scooter-e-bike-motor-assisted-bicycle/32793693999.html
...anybody have any thoughts/comments/experiences with these?
 
I just bought 2 units of BMSBattery torque sensors :)
They work well but now I know I can't put my 100kg + some more acceleration on them.
 
geofft said:
Thought I might try one of these (T2 version):-
https://www.aliexpress.com/item/torque-sensor-transducer-standard-buttom-bracket-parts-for-electric-scooter-e-bike-motor-assisted-bicycle/32793693999.html
...anybody have any thoughts/comments/experiences with these?

Yes, I've tested the first and the second generation of these Sempu sensors myself, and there's experience with the third generation in the german forum also.
I can recommend this product, but it needs higher supply voltage, you can't use the 5V from the throttle connector. The third generation works with battery volatage directly.

casainho said:
So, which part of PAS code doesn't work? direction detection?
I think so, as the difference between pedaling forward and pedaling reverse is not big with my modded torquesensor, as already shown some pages before, see the orange graph...

file.php


regards
stancecoke
 
stancecoke said:
I think so, as the difference between pedaling forward and pedaling reverse is not big with my modded torquesensor, as already shown some pages before, see the orange graph...
Can you please provide a patch against master, would be easier for me to review the code.

I suggest you to use ton/toff from PWM interrupt, on ebike_app.c and make the division and other slow operations if needed, there.
 
casainho said:
I suggest you to use ton/toff from PWM interrupt, on ebike_app.c and make the division and other slow operations if needed, there.

I will try to use your code structure as far as possible, but we have to do floatingpoint operations and we can't do it at the ebike_app.c as it runs only every 100ms, that's too slow for PAS Sensors with a high number of magnets...
I will put the code for direction detection in the main.c and run it only on a rising edge detected in the motor.c (the same way I do it in the HighSpeedMotor branch). I know, you don't like "interrupt-like" actions (for whatever reason :)), but that's the strait forward way.

regards
stancecoke
 
FOC for regen
I tried a few things like inverting the, instead of increasing, decreasing and vice-versa the adjust angle value. The actual solution is to not change the adjust angle value while regen and unlike when accelerating, I feel vibrations on my direct motor drive which makes me feel is not working as it should.

What I remember to see on oscilloscope was the phase B signal to get invert 180º, like the positive part of sinewave got negative and vice-versa...

If someone has ideas on how to solve this......
 
stancecoke said:
casainho said:
I suggest you to use ton/toff from PWM interrupt, on ebike_app.c and make the division and other slow operations if needed, there.
I will try to use your code structure as far as possible, but we have to do floatingpoint operations and we can't do it at the ebike_app.c as it runs only every 100ms, that's too slow for PAS Sensors with a high number of magnets...
I will put the code for direction detection in the main.c and run it only on a rising edge detected in the motor.c (the same way I do it in the HighSpeedMotor branch). I know, you don't like "interrupt-like" actions (for whatever reason :)), but that's the strait forward way.
Look, the output value of PAS is currently only used on ebike_app_controller() and if you process it faster, will be useless.
Even current code can be improved, I think. I would say that on PWM interrupt code, we just need to keep update the ui16_pas1_on_time_counter and ui16_pas1_off_time_counter and after on ebike_app.c file, read_pas_cadence_and_direction(), we can look at that on/off values and calculate PAS_cadence and PAS_direction as we don't need them calculated with higher frequency.
For what I could understood from the Arduino code you did show before, to calculate PAS_cadence and PAS_direction, we just need as input the values of on/off (can be expressed in PWM cycle ticks).
What do you think of this idea?
 
casainho said:
I would say that on PWM interrupt code, we just need to keep update the ui16_pas1_on_time_counter and ui16_pas1_off_time_counter

We will still need the rising edge detection and the reset of the counters in the interrupt code and have to store ui16_pas1_counter (already stored to ui16_pas1_pwm_cycles_ticks) and ui16_pas1_on_time_counter to global variables to process them in the ebike_app.c, With this, you are right, we don't need to do the dircetion detection in the main.c. We don't need ui16_pas1_off_time_counter.

Where is the PAS timeout detection for the motor stop in PAS mode located in the master branch?! Is it this part? So you just set the throttle value to zero?! Why do you set the counters to zero at this point?!

Code:
// limit min PAS cadence
  if (ui16_pas1_counter > ((uint16_t) PAS_ABSOLUTE_MIN_CADENCE_PWM_CYCLE_TICKS))
  {
    ui16_pas1_pwm_cycles_ticks = (uint16_t) PAS_ABSOLUTE_MIN_CADENCE_PWM_CYCLE_TICKS;
    ui16_pas1_counter = 0;
    ui16_pas1_on_time_counter = 0;
    ui16_pas1_off_time_counter = 0;
    ui8_pas1_direction = 1;
    ui8_torque_sensor_throttle_processed_value = 0;
  }

regards
stancecoke
 
stancecoke said:
Where is the PAS timeout detection for the motor stop in PAS mode located in the master branch?!
Here, motor.c:

Code:
  // limit min PAS cadence
  if (ui16_pas1_counter > ((uint16_t) PAS_ABSOLUTE_MIN_CADENCE_PWM_CYCLE_TICKS))
  {
    ui16_pas1_pwm_cycles_ticks = (uint16_t) PAS_ABSOLUTE_MIN_CADENCE_PWM_CYCLE_TICKS;
    ui16_pas1_counter = 0;
    ui16_pas1_on_time_counter = 0;
    ui16_pas1_off_time_counter = 0;
    ui8_pas1_direction = 1;
#if (EBIKE_THROTTLE_TYPE == EBIKE_THROTTLE_TYPE_TORQUE_SENSOR)
    ui8_torque_sensor_throttle_processed_value = 0;
#endif
  }

And in ebike_app.c:
Code:
  // cadence in RPM =  60 / (ui16_pas_timer2_ticks * PAS_NUMBER_MAGNETS * 0.000064)
  if (ui16_pas1_pwm_cycles_ticks >= ((uint16_t) PAS_ABSOLUTE_MIN_CADENCE_PWM_CYCLE_TICKS)) { ui8_pas1_cadence_rpm = 0; }

Please note that PAS value is multiplied by LCD assist level...!! Since you are not using the LCD, see if your assist level is higher than 0:
Code:
  f_temp = (float) (((float) ui8_temp) * f_get_assist_level ());

Please update your master branch as I just update it with my most recent code.
 
stancecoke said:
Where is the PAS timeout detection for the motor stop in PAS mode located in the master branch?! Is it this part? So you just set the throttle value to zero?! Why do you set the counters to zero at this point?!
Code:
// limit min PAS cadence
  if (ui16_pas1_counter > ((uint16_t) PAS_ABSOLUTE_MIN_CADENCE_PWM_CYCLE_TICKS))
  {
    ui16_pas1_pwm_cycles_ticks = (uint16_t) PAS_ABSOLUTE_MIN_CADENCE_PWM_CYCLE_TICKS;
    ui16_pas1_counter = 0;
    ui16_pas1_on_time_counter = 0;
    ui16_pas1_off_time_counter = 0;
    ui8_pas1_direction = 1;
    ui8_torque_sensor_throttle_processed_value = 0;
  }
My idea is to reset everything at that point. If you want to use the on/off counters outside, please use a temporary/internal to that code and external one that you can use on ebike_app.c, just like I did for the external speed sensor:
Code:
ui16_wheel_speed_sensor_pwm_cycles_ticks = ui16_wheel_speed_sensor_counter;

  if (ui16_wheel_speed_sensor_counter > ((uint16_t) WHEEL_SPEED_SENSOR_MIN_PWM_CYCLE_TICKS))
  {
    ui16_wheel_speed_sensor_pwm_cycles_ticks = (uint16_t) WHEEL_SPEED_SENSOR_MIN_PWM_CYCLE_TICKS;
I think is a good idea to use internal ones that will be incremented every signal change and the other ones that keep the value of every 1 rotation. Wheel rotation/speed seem similar than PAS, on PAS we also need direction...
 
I just saw, that you are using PAS2 = Pad X4 for regen?! Why that, as you get the pedal direction from PAS1 already?!

regards
stancecoke
 
stancecoke said:
I just saw, that you are using PAS2 = Pad X4 for regen?! Why that, as you get the pedal direction from PAS1 already?!
My implementation was for this, and works well. I just use torque sensor on my ebikes: https://opensourceebikefirmware.bitbucket.io/development/Various--2017.12.01_-_Regen_ebrake_like_coast_brakes.html
 
stancecoke said:
geofft said:
Thought I might try one of these (T2 version):-
https://www.aliexpress.com/item/torque-sensor-transducer-standard-buttom-bracket-parts-for-electric-scooter-e-bike-motor-assisted-bicycle/32793693999.html
...anybody have any thoughts/comments/experiences with these?

Yes, I've tested the first and the second generation of these Sempu sensors myself, and there's experience with the third generation in the german forum also.
I can recommend this product, but it needs higher supply voltage, you can't use the 5V from the throttle connector. The third generation works with battery volatage directly.

Sorry to drag you guys away from the current discussion, but just a quick question about the Sempu torque sensors. I notice the later generation of these are 'middle wire', where the connector exits from the centre of the sensor body. I'm a bit confused as to how this exits the bottom bracket - do you have to drill a hole in the bottom bracket tube to bring this out - or am I missing something here..?
 
geofft said:
do you have to drill a hole in the bottom bracket tube to bring this out - or am I missing something here..?

Yes, you have to drill a hole with a diameter of 12mm, see the Installation Manual.

casainho said:
My implementation was for this, and works well. I just use torque sensor on my ebikes:
Hmm, this is very special, I think we should implement the "coast brake regen" in a way any user with an normal PAS can use it...

regards
stancecoke
 
stancecoke said:
Hmm, this is very special, I think we should implement the "coast brake regen" in a way any user with an normal PAS can use it...
If someone does the code (in the form of a patch against master branch) and testing, for me ok. I personally don't use PAS so I will not do it.

I want to focus on FOC working well for regen also. Also, coasting the motor that isn't possible right now.
 
stancecoke said:
geofft said:
do you have to drill a hole in the bottom bracket tube to bring this out - or am I missing something here..?

Yes, you have to drill a hole with a diameter of 12mm, see the Installation Manual.

Thanks Stancecoke, that's useful info. I've no objection to drilling the frame, just wondered how the cabling was routed. I'm about to order one of these, so expect some more dumb questions in a few weeks time. I'd like to retain a throttle with the torquesensor, not sure how that's gonna work out though....
 
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 will try to compile on Linux to see. Also you can try most recent version of SDCC that I think is version 3.7.
 
the latest precompiled windows version is 3.6.0 from 2016
https://sourceforge.net/projects/sdcc/files/

regards
stancecoke
 
stancecoke said:
the latest precompiled windows version is 3.6.0 from 2016
https://sourceforge.net/projects/sdcc/files/
From version 2018-03-04 sdcc and openocd for stm8 does no longer have to be patched. Sdcc has built in support for gdb (dwarf2 debug format) and openocd support debugging of stm8 micros.
https://stm8-binutils-gdb.sourceforge.io
 
Back
Top