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

casainho said:
I did a quick code and it seems to work
That sounds good!

It seems that I just killed one ore more of my Mosfets, so have to make a short break with testing here.... :cry: :? :shock:

edit: mosfets seem to be OK, so I think the PWM Channels don't work properly.

Regards
stancecoke
 
Very low resolution FOC seems to be working with my motor (EUC2 motor, low eRPM, at power supply 45V) but I had to do the interpolation every hall sensor signal and now the motor startup ok and do ok the interpolation.

My code is on the SVM_3 branch.

My EUC2 motor, low eRPM, at power supply 30V.
Next image: without FOC, angle keeps constant. First part, motor at max eRPM speed of +100 and using about -500mA if IQ current. Second part, also using -500mA but I was blocking a bit the motor, so it could not get the max velocity:


Now with FOC enable and and just changing the velocity/PWM duty_cycle. We can see that FOC try to keep IQ current near zero:


Now as before, but but on second part I tried to bloc with my hand and we can see angle going decreasing to very low values while the IQ current then goes to near zero value (it takes sometime to go to zero value, needs a PI controller):
 
OK, fine that your start up is running now. I don't understand your the start up procedere in the code of motor.c completly yet, it would be great, if you add some comments to explain what happens when.

@KingQueenWong: Do you have the equipment for reflow soldering? I'm always in despair if I have to solder SMDs :shock:, even if it's just an 8pinner like the ACS712....

Regards
stancecoke
 
stancecoke said:
OK, fine that your start up is running now. I don't understand your the start up procedere in the code of motor.c completly yet, it would be great, if you add some comments to explain what happens when.

@KingQueenWong: Do you have the equipment for reflow soldering? I'm always in despair if I have to solder SMDs :shock:, even if it's just an 8pinner like the ACS712....

Regards
stancecoke
I have not a reflow soldering machine,i use a heat gun to solder it well. :D
 
KingQueenWong said:
stancecoke said:
@KingQueenWong: Do you have the equipment for reflow soldering? I'm always in despair if I have to solder SMDs :shock:, even if it's just an 8pinner like the ACS712....
I have not a reflow soldering machine,i use a heat gun to solder it well. :D
My lab equipment is all from China, bought on Ebay or other chinese online shops like www.dx.com :) -- all cheap!!

- Soldering and hot air station, 75€: Atten Hot Air Gun Soldering Rework Station At858d 220V
- Digital Oscilloscope, 280€: Rigol Digital Oscilloscope Ds1052e 50Mhz
- Lab power supply, 70€ (use this one for electric unicycle with a battery of 60V): STP6005 60V 5A Adjustable Variable Regulated DC Power Supply Lab Grade 110/220V
- Lab power supply, 50€: DC Power Supply Precision Variable 0-30V 0-5A Adjustable 3 Digital Lab
 
stancecoke said:
OK, fine that your start up is running now. I don't understand your the start up procedere in the code of motor.c completly yet, it would be great, if you add some comments to explain what happens when.
For now, I would prefer to explain here and when having a working code, I will go back and do some comments. I try to use variable names that help understand the code, because comments also need maintenance and we tend to not maintain the comments.

So motor get on MOTOR_STATE_COAST when it stops. It stops when
Code:
void motor_fast_loop (void)
{
  if (ui16_PWM_cycles_counter > PWM_CYCLES_COUNTER_MAX)

After being on MOTOR_STATE_COAST, it reads hall sensors only once:
Code:
 if ((hall_sensors != hall_sensors_last) ||
      (ui8_motor_state == MOTOR_STATE_COAST)) // let's run the code when motor is stopped/coast so it can pick right motor position for correct startup
     hall_sensors_last = hall_sensors;

    if (ui8_motor_state == MOTOR_STATE_COAST) { ui8_motor_state = MOTOR_STATE_RUNNING_6_STEPS; }

It gets the correct ui8_motor_rotor_absolute_position and apply the correct PWM duty_cycle: pwm_duty_cycle_controller ();
Now the motor should startup moving, until it get with an eRPM speed and change to MOTOR_STATE_RUNNING_SINE_NO_INTERPOLATION:
Code:
      // update motor state based on motor speed
      if (ui16_motor_speed_erps > 35)
      {
//	ui8_motor_state = MOTOR_STATE_RUNNING_SINE_INTERPOLATION;
      }
      else if (ui16_motor_speed_erps > 8)
      {
	ui8_motor_state = MOTOR_STATE_RUNNING_SINE_NO_INTERPOLATION;
      }

The variable names are wrong as I am not using 6 steps... and the MOTOR_STATE_RUNNING_SINE_INTERPOLATION end up not working... so I am just experimenting code to have my motors working and find a working FOC, after that I can go back and make a stable code for the motor.c. Then I need to add the max and over currents control and the motor code should be mainly finished.
 
casainho said:
Very low resolution FOC seems to be working with my motor (EUC2 motor, low eRPM, at power supply 45V) but I had to do the interpolation every hall sensor signal and now the motor startup ok and do ok the interpolation.

My code is on the SVM_3 branch.
Just tested this code with my Q85 motor and it is not working good. The FOC works overall the motor is asking to much current at least at high speed -- but I need to make the code to execute the interpolation
at every eRPM and not at eRPM/6 as I did on my slow eRPM motor EUC2 (I know that my Q85 have hall sensors with somehow incorrect placement)

stancecoke, I think this code will not work for you because your motor is like my Q85, kind of fast eRPM motor. I will now focus on putting the FOC code working with my Q85 motor.
 
OK, thank you for the explanation. I hope, that i'll receive my new controller until weekend. I've ordered it in Germany.
By the way, you say, that the S06S is just 22$ at BMSBattery, but if you add shipping costs, it's more or less the same price as if you order in europe. PSWPower offers the controller for even less, but it's the same: with shipping costs it is not really cheap....

SMD soldering: I've got a cheap hot air gun from China too, but I'm not really satisfied with it. It takes much to long time to heat up the SMD Part and the board. What temperature-, air-flow- and nozzle setting do you suggest eg. for soldering an 8pinner like the ACS712?

Regards
stancecoke
 
stancecoke said:
OK, thank you for the explanation. I hope, that i'll receive my new controller until weekend. I've ordered it in Germany.
By the way, you say, that the S06S is just 22$ at BMSBattery, but if you add shipping costs, it's more or less the same price as you order in europe. PSWPower offers the controller for even less, but it's the same: with shipping costs it is not really cheap....
$22 is just a reference price. And from BMSBattery, if we buy more components, the shipping cost will not be that much. I am waiting to have the firmware working and be happy with it, to buy more components for this controllers, like LCDs, more controllers, the torque sensor and direct drive motor(with this one to develop regen on the firmware).

stancecoke said:
SMD soldering: I've got a cheap hot air gun from China too, but I'm not really satisfied with it. It takes much to long time to heat up the SMD Part and the board. What temperature-, air-flow- and nozzle setting do you suggest eg. for soldering an 8pinner like the ACS712?
I don't use much and I don't have much experience. But I know that a board with big pads (maybe like the ones on the ACS712 because of higher current) will take much time to heat because that dissipate a lot of heat also... I think there are equipments that heat the board under side while the user heat on the top side with the hot air...
 
Got FOC running with my fast eRPM Q85 motor. stancecoke, can you please test with your motor?

No FOC, the see the amount of current from the power supply!!
[youtube]2utXb6SLvBk[/youtube]



With FOC but there are issues, because the is no ui8_position_correction_value value that put a good sinewave at high speed!! This is not an issue with my EUC2 sloe eRPM motor.
See the decreased amount of current!! and speed also increased.
[youtube]5qT1iKuSuPU[/youtube]

NOTE: correct speed is at about 480 eRPS -- higher values the motor was running to fast and doing that high noise and asking more current and as can be seen, the ui8_position_correction_value was at an higher value!!
 
So, I got my both motors (the EUC2 motor which is low eRPM and Q85 which is high eRPM motor) running with FOC and with interpolation 360 degrees -- both motors, then even start with SVM no interpolation --> interpolation 60º --> interpolation 360º. Before, I had for sure some bugs when I could not do interpolation 360º on my EUC2 motor.

As you will be able to see on the video, this motor runs very well!! But the Q85 does not :-(

So, the EUC2 motor runs at 125 eRPM and since each eRPM needs to draw the SVM/Sinewave with steps of 64us, for EUC2 motor the sinewave is draw using 125 points. Q85 motor runs at 480 eRPM wich is only 32 points to draw the sinewave!! I am pretty sure the issue is this!! And I also know that I am not using the full PWM resolution, as I am using only 8 bits while the max is 10 bits... maybe I can improve this. Also maybe I can make PWM frequency run a bit more higher.
I also know that the Lishui LSW-675 uses the same PWM frequency and could run the Q85 well but maybe at lower velocity... I need to test again and find the max eRPM it runs Q85!!

Video of my EUC2 motor running at 60V (yes, the S06S did hold 60V for at least 5 minutes). That motor should run at 60V, that is the voltage of electric unicycles battery packs (13S):
[youtube]Mca5V6ez9Fo[/youtube]




As for comparison, here is the MicroWorks 30B4 board running the OpenSource firmware with FOC -- I did that firmware and the board have the STM32F103 32 bits microcontroller that runs at 72MHz:
[youtube]2nDZW4-uVys[/youtube]
 
I was using PWM values with 8 bits resolution, to have fast processing since the microcontroller is 8 bits. I changed now the PWM to be the 10 bits (max possible by the STM8) and started using 16 bits variables... didn't noticed better results, like motor a bit more silent.

I measured the PWM cycle processing and got this results:
- PWM 8 bits values: 40us
- PWM 10 bits values: 72us

So the PWM cycle happens every 64us and in this case, at 72us, means that will take 2 PWM cycles change the value, like if the time resolution was halved -- this is really bad because means that a fast eRPM motor, we halved the max speed :-( -- so I think I will keep using the 8 bits PWM resolution.

Next test is to increase angle resolution. Currently it is at 8 bits / 256 for the 360º. I would like to have a resolution of 0.5º while now it is at 1.4º.
 
Njay said:
Post that piece of 16bit code if you want, I may be able to optimize it.
Here: https://github.com/OpenSource-EBike-firmware/BMSBattery_S_controllers_firmware/blob/SVM_4/pwm.c

The main changes were on pwm.c file -- you can see online the diff, here: https://github.com/OpenSource-EBike-firmware/BMSBattery_S_controllers_firmware/commit/19eaa3dbb19db09c4be5d57e368b9f0a772c14a4#diff-38a06fa4ea7ae0de48d9d604779664dc
 
casainho said:
zeocio said:
Just found out about this forum after I bought a few FOC controllers on taobao:
https://world.taobao.com/item/544557726531.htm
Going by the taobao sales volume, this is one of the most popular FOC controllers in chinese ebike market.

The bare board item (https://world.taobao.com/item/551416490678.htm) from the same taobao seller seems to use STM32F031C6T6.

Is there anything I can do to help STM32 firmware dev with this FOC controller?
Welcome!!

That one seems the same that KingQueenWong already suggested and seems it is used on the Scrooser.
For now I am betting on the one with STM8 that is cheaper and available on the most stores online for ebikes.
But seems there are much more people with knowledge with STM32...
KingQueenWong, do you have any news about this controller??

Seems it may have advantage of Lishui LSW-65 because that controllers can be found from 6 mosfets 24V 17A up to 96V 58A (5KW!!)

Maybe we will not find a motor controller with more than 32kb flash memory because seems it is not needed...
 
Hum, not using GCC... so, 1st of all I don't see any optimization flags on your makefile... so 1st thing to do is to add --opt-code-speed to the C flags.

Can you get me the .LST file of the original code (as you have it after adding optimization flags)?

Then try the files in attach to see, 1st if it still works :D and then if there was any improvement. Either way please get me the .LST file from these changes.

Do you have free RAM, like 256 bytes or more?

p.s.: The SVM table isn't symmetric, I guess it's on purpose...?
 

Attachments

  • optimizations_njay.zip
    3.5 KB · Views: 40
Trying to get rid of the if/else... When you have

[pre]uint16_t duty = ui16_svm_table[angle];
if (duty > MIDDLE_PWM_VALUE_DUTY_CYCLE_MAX)
{
duty = ((uint32_t)(duty - MIDDLE_PWM_VALUE_DUTY_CYCLE_MAX) * i16_duty_cycle_value) >> 9;
duty = MIDDLE_PWM_VALUE_DUTY_CYCLE_MAX + duty;
} else {
duty = ((uint32_t)(MIDDLE_PWM_VALUE_DUTY_CYCLE_MAX - duty) * i16_duty_cycle_value) >> 9;
...[/pre]
you're "compensating" for the fact that the svm table is unsigned, so that should be the same as

[pre]uint16_t duty = abs((int16_t)(ui16_svm_table[angle]) - MIDDLE_PWM_VALUE_DUTY_CYCLE_MAX);
duty = ((uint32_t)(duty) * i16_duty_cycle_value) >> 9;
duty += MIDDLE_PWM_VALUE_DUTY_CYCLE_MAX;[/pre]
The abs() call is relatively heavy, but you could change your svm table to give you duty directly, thus no subtracting MIDDLE_PWM_VALUE_DUTY_CYCLE_MAX nor abs() needed (and the table could be 8 bit instead of 16!). But I don't know yet what are you doing in the rest of the else part, will check later with a fresher mind...
 
casainho said:
casainho said:
zeocio said:
Just found out about this forum after I bought a few FOC controllers on taobao:
https://world.taobao.com/item/544557726531.htm
Going by the taobao sales volume, this is one of the most popular FOC controllers in chinese ebike market.

The bare board item (https://world.taobao.com/item/551416490678.htm) from the same taobao seller seems to use STM32F031C6T6.

Is there anything I can do to help STM32 firmware dev with this FOC controller?
Welcome!!

That one seems the same that KingQueenWong already suggested and seems it is used on the Scrooser.
For now I am betting on the one with STM8 that is cheaper and available on the most stores online for ebikes.
But seems there are much more people with knowledge with STM32...
KingQueenWong, do you have any news about this controller??

Seems it may have advantage of Lishui LSW-65 because that controllers can be found from 6 mosfets 24V 17A up to 96V 58A (5KW!!)

Maybe we will not find a motor controller with more than 32kb flash memory because seems it is not needed...
EUC1 controller(https://item.taobao.com/item.htm?spm=a1z09.2.0.0.2ed6e797zYFu2e&id=528731314428&_u=bm58rj4e4ba) and JinHui controller(https://world.taobao.com/item/544557726531.htm) both can do foc.
 

Attachments

  • 123.jpg
    123.jpg
    145.6 KB · Views: 1,995
  • 456.jpg
    456.jpg
    144.5 KB · Views: 1,995
@casainho: I'll get my new controller today. Wich branch should I test first?

Regards
stancecoke
 
stancecoke said:
@casainho: I'll get my new controller today. Wich branch should I test first?
SVM_4 but that specific commit for my EUC2 motor. You will need to change the motor parameters for your motor (again!)
I still don't have the motor code stable, when get it I will merge to master...
 
KingQueenWong said:
Are you kidding?? All this time and we didn't know EUC1 controller could do FOC????

I have some of that boards with me... they are great if they can do FOC and because of the 128kb flash memory. The only think missing is a way to printf, because the UART pins are used for PWM :-( -- once I were able to printf to SWIM but that was very slow... but maybe I should try again?? I wounder if it is still being produced...
 
KingQueenWong,

Can you find on taobao the MicroWorks 30B4 board or equivalent??

Any EBike motor controller with STM32F103??
 
casainho said:
KingQueenWong,

Can you find on taobao the MicroWorks 30B4 board or equivalent??

Any EBike motor controller with STM32F103??
I can not find MicroWorks 30B4 board or equivalent on taobao.
 
KingQueenWong said:
casainho said:
KingQueenWong,

Can you find on taobao the MicroWorks 30B4 board or equivalent??

Any EBike motor controller with STM32F103??
I can not find MicroWorks 30B4 board or equivalent on taobao.
Thank you. Just found, and I guess maybe was with your help: https://eggelectricunicycle.bitbucket.io/MicroWorks_30B4_board--Links_to_sellers.html

Can you please tell me what are the connectors? does it have a bluetooth/UART connector?
https://world.taobao.com/item/529511401695.htm?fromSite=main&spm=a230r.1.14.75.6XNyi3&ns=1&abbucket=6#detail
 
Back
Top