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

casainho said:
vex_zg said:
In the meantime:
I asked the seller who sold me this bluetooth module if he can get more. He might be able to get some from the KT factory. Is anybody interested? I only asked because somebody here wrote BT modules can't be purchased separately.
I would like to buy 3 units of this module.

OK, I will post here when I have reply with availability/price
 
Support for J-LCD works partly now . Receiving Data is controlled by interrupt. See updated github branch and this video:

[youtube]lierB7DXYA4[/youtube]

Sending the speed to the display is still sticky....

Bluetooth Support:
there is a plug and play solution from Lishui:
http://app.lsdzs.com/home/

The module is available at the lishui store:
http://app.lsdzs.com/home/online-store/

It works with several protocols, included the J-LCD protocol.
The module can be easily homebrewed: :wink:

regards
stancecoke
 
stancecoke said:
Support for J-LCD works partly now . Receiving Data is controlled by interrupt. See updated github branch and this video:
You are the men!! :)

On that video, the assistance level you were selecting, what did define on the firmware? the motor current? motor speed??

stancecoke said:
You are the men 2!! :)
So you did document your build for the bluetooth module and it is even more complex than I thought.... and you got it working with Lishui original app :)

I will copy-past your forum message to the HTML/notes of this documentation!! :)

So much work and achievements! -- my girlfriend is joking saying that by now, your wife already put you out of the house :)
 
Hi guys,

I've discovered a triple error in the S06C schematic.

+ of C1 is conected to cathode of D2, + of C3 is conected to cathode of D4, + of C14 is conected to cathode of D8, and not to Vout.
Otherwise the boostrap will not work :!:

Hope it may help in case of troubleshooting.

I have 2 S06SC (for central motor, and the waveform is also not very sinusoïdal, it is equipped with ACS711.

I also noticed that the Cheeta looks like the VESC of Benjamin Vedder, did it share the same firmware :?: :!:

Have a Nice Day.

Thierry
 
casainho said:
On that video, the assistance level you were selecting, what did define on the firmware? the motor current? motor speed??

It's just used to set the duty cycle by now

Code:
 pwm_set_duty_cycle ((ui8_assistlevel_global-1)*60); //for test of display communication

casainho said:
my girlfriend is joking saying that by now, your wife already put you out of the house :)

My whole family was laughing when I read out this sentence loud. :lol: Lucky enough, my wife is very tolerant!

regards
stancecoke
 
great work Stan with the lishui bt adapter / app.

I presume the app will only work with lishui controllers, and not KT controllers?
 
ThierryGTLTS said:
Hi guys,

I've discovered a triple error in the S06C schematic.

+ of C1 is conected to cathode of D2, + of C3 is conected to cathode of D4, + of C14 is conected to cathode of D8, and not to Vout.
Otherwise the boostrap will not work :!:

Hope it may help in case of troubleshooting.

I have 2 S06SC (for central motor, and the waveform is also not very sinusoïdal, it is equipped with ACS711.

I also noticed that the Cheeta looks like the VESC of Benjamin Vedder, did it share the same firmware :?: :!:
Thanks.

I just started an issue on the schematic repo, let's see if KingQueenWong can correct the schematic: https://github.com/KingQueenWong/bmsbattery_s06s_controller_hardware/issues/1

Link for Cheeta??
 
vex_zg said:
I presume the app will only work with lishui controllers, and not KT controllers?
you are right, it has only Kingmeter and Bafang protocols implemented. (Unless you use the Open Source firmware... ;))

file.php


casainho said:
Link for Cheeta??
https://endless-sphere.com/forums/viewtopic.php?f=30&t=87870&p=1317505&hilit=cheeta#p1317505

regards
stancecoke
 

Attachments

  • Screenshot_protocol settings.png
    Screenshot_protocol settings.png
    46.9 KB · Views: 2,260
stancecoke said:
vex_zg said:
I presume the app will only work with lishui controllers, and not KT controllers?
you are right, it has only Lishui and Bafang protocols implemented. (Unless you use the Open Source firmware... ;))
I am planning to move on to software development (professionally). I am start learning JavaScript and I think my first project may be the Android app for this project (to build experience and portofolio) -- (will be using Reactive Native javascript to develop the app).
In parallel I will keep working on the firmware but more specifically on the motor control.
 
casainho said:
I am planning to move on to software development (professionally).
I wish you much success!
I've played around with app development (for home automation and geocaching) a little, but I wasn't very happy with my progress... :?

Here another video, using the bluetooth module to drive the controller

[youtube]kuYl4skwyws[/youtube]

regards
stancecoke
 
Thanks.
stancecoke said:
Here another video, using the bluetooth module to drive the controller
From 3 to 2, seems the motor makes a strong noise... seems that it switch from sinewave interpolation to no interpolation. Seems your motor do regen on that step... to help improve this I need to make a stable motor code so you can adopt it. Let's see If I can do it tomorrow:
- max current limit value setup
- max current regen limit value setup (regen happens when decelerating)
 
vex_zg said:
casainho said:
vex_zg said:
In the meantime:
I asked the seller who sold me this bluetooth module if he can get more. He might be able to get some from the KT factory. Is anybody interested? I only asked because somebody here wrote BT modules can't be purchased separately.
I would like to buy 3 units of this module.

OK, I will post here when I have reply with availability/price

Seller responded that he doesn't have any BT modules to sell now (the ones like the sample I photographed)
 
vex_zg said:
Seller responded that he doesn't have any BT modules to sell now (the ones like the sample I photographed)
Thank you. I will then build my own module following stancecocke documentation :)
 
casainho said:
ThierryGTLTS said:
Hi guys,

I've discovered a triple error in the S06C schematic.
I just started an issue on the schematic repo, let's see if KingQueenWong can correct the schematic: https://github.com/KingQueenWong/bmsbattery_s06s_controller_hardware/issues/1
KingQueenWong had corrected that issue :)
 
casainho said:
Thanks.
stancecoke said:
Here another video, using the bluetooth module to drive the controller
From 3 to 2, seems the motor makes a strong noise... seems that it switch from sinewave interpolation to no interpolation. Seems your motor do regen on that step... to help improve this I need to make a stable motor code so you can adopt it. Let's see If I can do it tomorrow:
- max current limit value setup
- max current regen limit value setup (regen happens when decelerating)
stancecoke, can you please start using the motor code from motor branch?? https://github.com/OpenSource-EBike-firmware/BMSBattery_S_controllers_firmware/tree/motor

That code works well for my but only for my Q85 motor, for the other direct drive motor it has some issues that I need to understand to fix.

Code:
/***************************************************************************************/
// Motor interface
void hall_sensor_init (void); // must be called before using the motor
void motor_init (void); // must be called before using the motor
void motor_set_mode_coast (void); // disable PWM output
void motor_set_mode_run (void); // enable PWM output
void motor_set_pwm_duty_cycle_target (uint8_t value);
void motor_set_current_max (uint8_t value); // steps of 0.5A each step
void motor_set_regen_current_max (uint8_t value); // steps of 0.5A each step
void motor_set_pwm_duty_cycle_ramp_inverse_step (uint8_t value); // each step = 64us
uint16_t motor_get_motor_speed_erps (void);
/***************************************************************************************/

New on this motor interface
- motor_init (): must be called before using motor. This mainly averages some ADC samples of motor current, to find the zero value.
- motor_set_current_max (): now you can define the torque for the assistance level, instead of duty_cycle - don't forget to first define motor_set_pwm_duty_cycle_target (255).
My intuition tells me that assistance level is like different fixed throttle values but where throttle is a "speed+torque".
- motor_set_pwm_duty_cycle_ramp_inverse_step (uint8_t value): it doesn't work as it should because seems motor current control interacts with this value. But you can use a very low value like 1 or 2.
 
Added motor OC (over current) protection, using an pin change interrupt that have the following code:

Code:
#define CURRENT_MOTOR_TOTAL_OVER__PIN  GPIO_PIN_7
#define CURRENT_MOTOR_TOTAL_OVER__PORT GPIOD

  /***************************************************************************************/
  // motor overcurrent pin as external input pin interrupt
  GPIO_Init(CURRENT_MOTOR_TOTAL_OVER__PORT,
	    CURRENT_MOTOR_TOTAL_OVER__PIN,
	    GPIO_MODE_IN_FL_IT); // with external interrupt

  //initialize the Interrupt sensitivity
  EXTI_SetExtIntSensitivity(EXTI_PORT_GPIOD,
			    EXTI_SENSITIVITY_FALL_LOW);
  /***************************************************************************************/

Code:
// motor overcurrent interrupt
void EXTI_PORTD_IRQHandler(void) __interrupt(EXTI_PORTD_IRQHANDLER)
{
    motor_set_mode_coast ();
    while (1) ; // infinite loop, user will need to reset the system
}
 
stancecoke,

I tried the firmware with my bicycle Q85 motor and turns out it doesn't have torque (I even did disable motor max current control for testing). The only way to have torque, I tested, is with 6 steps!! But I still can't start with 6 steps and transition to sinewave.... :-(
 
casainho said:
I tried the firmware with my bicycle Q85 motor and turns out it doesn't have torque

Hmm, I changed nothing concerning the motor.c / pwm.c functions. Have you tried the original code of the J-LCD branch, or have you merged something together? Is the motor running without load?
With the simple setting of assistLevel to dutycycle, the motor isn't running with the lab power supply properly, as with the change of the assistLevel a high current peak occurs, the power supply drops the voltage and the controller stops the motor due to undervoltage protection. With a battery the motor runs properly.

Regards
stancecoke
 
Display of speed and power is working now! 8)

[youtube]p0gGOhoxhzo[/youtube]


casainho said:
stancecoke, can you please start using the motor code from motor branch??

Which parts do I have to merge? Just motor.c and pwm.c?

Regards
stancecoke
 
stancecoke said:
stancecoke, can you please start using the motor code from motor branch??

Which parts do I have to merge? Just motor.c and pwm.c?
[/quote]
Great progress!! :)

Many changes... install Meld and to the folder comparition between your branch and motor branch. Meld shows you with pretty visuals the diffs and you can even merge/delete the changes.
 
stancecoke said:
casainho said:
I tried the firmware with my bicycle Q85 motor and turns out it doesn't have torque

Hmm, I changed nothing concerning the motor.c / pwm.c functions. Have you tried the original code of the J-LCD branch, or have you merged something together? Is the motor running without load?
With the simple setting of assistLevel to dutycycle, the motor isn't running with the lab power supply properly, as with the change of the assistLevel a high current peak occurs, the power supply drops the voltage and the controller stops the motor due to undervoltage protection. With a battery the motor runs properly.
The power supply I am using can give 10 amps which is a good value.
Seems that my direct drive motor is very different from Q85. Let's see if I can something working fro Q85. I am trying on the bicycle but with lab power supply and as soon I have something working ok I will move to a battery :)
 
Don't put any time in this stupid way of using the assistLevel information. I was just too lazy to verify the function of the UART Communication in a more intelligent way.

I suggest to define an array with the percentage of an absolute max current (defined in an #define statement) the assistLevels should stand for.

Code:
assistLevel_percentage[5] = {20, 40, 60, 80, 100};

then you can use that for the "torque simulation" mode.

Code:
#ifdef TORQUE_SIMULATION
   if (ui16_PAS_Counter<timeout){
     if (ui16_PAS>ramp_end){ 
     ui8_ADC_motor_current_max=(assistLevel_percentage[(ui8_assistlevel_global-1)]/100*ADC_MOTOR_CURRENT_MAX)* ramp_end/ui16_PAS;
      }
     else{
      ui8_ADC_motor_current_max=(assistLevel_percentage[(ui8_assistlevel_global-1)]/100*ADC_MOTOR_CURRENT_MAX)
      }
    else{
       ui32_setpoint=0;
       printf("you are not pedaling!");
      }

#endif

In this way you ramp up ui8_ADC_motor_current_max with the cadence. In your existing pwm_duty_cycle_controller you then can add a simple p-controller to tune duty cycle to the recent current setpoint, instead of just decreasing the dutycycle if current is too high.


regards
stancecoke
 
casainho said:
casainho said:
ThierryGTLTS said:
Hi guys,

I've discovered a triple error in the S06C schematic.
I just started an issue on the schematic repo, let's see if KingQueenWong can correct the schematic: https://github.com/KingQueenWong/bmsbattery_s06s_controller_hardware/issues/1
KingQueenWong had corrected that issue :)

OK, it's right now.

Thierry
 
Just got the Q85 motor running well -- it starts with 6 steps/block commutation and transition to sinewave very well. Turns out I had to increase the speed at which that transition happens (before was 25 and now is 150).

Now it does have torque/force to start, I tested on my bicycle. But it needs more torque - my power supply gives only 10A and this controller can give 15A... can't wait to test on real battery with the current limit of 15A.

And for some reason, now the ui8_adc_read_motor_total_current (); don't work anymore... makes no sense but let's see if I found the reason or a workaround.
 
stancecoke said:
Don't put any time in this stupid way of using the assistLevel information. I was just too lazy to verify the function of the UART Communication in a more intelligent way.
I think would be great if you could use the motor code in your branch and then we could merge your branch to master and take out a stable version of the firmware.

stancecoke said:
In this way you ramp up ui8_ADC_motor_current_max with the cadence. In your existing pwm_duty_cycle_controller you then can add a simple p-controller to tune duty cycle to the recent current setpoint, instead of just decreasing the dutycycle if current is too high.
Now I remember what you said before about slow loop current controller.

The current controller on pwm_duty_cycle_controller is low level and fast, to protect the system. For this Throttle/PAS/Torque sensor controller, I agree with you that this (PI ??) controller can run at slower speed -- this have the advantage also make possible running a more complex PI controller or something, that needs more heavy math.

Also I keep seeing the Throttle/PAS/Torque sensor as "speed+torque". Using the torque sensor, your controller would control the motor speed and the motor current max:
- read motor_get_motor_speed_erps() to get motor speed and control the motor speed by adjusting the value of motor_set_pwm_duty_cycle_target()
- adjust linearly the motor_set_current_max() from the torque sensor value

Refer to the image bellow - what do you think??

firmware_structure.png
 
Back
Top