Author Topic: Problems with STM32 PMSM FOC SDK  (Read 117817 times)

0 Members and 1 Guest are viewing this topic.

Offline tatus1969

  • Super Contributor
  • ***
  • Posts: 1273
  • Country: de
  • Resistance is futile - We Are The Watt.
    • keenlab
Re: Problems with STM32 PMSM FOC SDK
« Reply #200 on: March 02, 2017, 04:09:24 pm »
Under load, the current Iq is just line ... does not form any sine wave ...
sorry, mistaken. The value "Ia" and "Ib" should show sinusodial waveforms, the Iq just shows their amplitude.

Another interesting thing is when I see the Measured Electric Angle on the oscilloscope, I see strange waveforms. I stop observing a triangle waveform.
Now that looks like a clue. The magnetic encoder having problems with magnets?  :o That picture shows the motor running smoothly at higher rpm, right?
We Are The Watt - Resistance Is Futile!
 

Offline Dave_PTTopic starter

  • Frequent Contributor
  • **
  • Posts: 315
  • Country: pt
    • DavidMartinsEngineering
Re: Problems with STM32 PMSM FOC SDK
« Reply #201 on: March 02, 2017, 04:17:38 pm »
Under load, the current Iq is just line ... does not form any sine wave ...
sorry, mistaken. The value "Ia" and "Ib" should show sinusodial waveforms, the Iq just shows their amplitude.
In that case Ia shows a sinusoid.
The following picture shows Ia with the engine in charge at 1000RPM.


Another interesting thing is when I see the Measured Electric Angle on the oscilloscope, I see strange waveforms. I stop observing a triangle waveform.
Now that looks like a clue. The magnetic encoder having problems with magnets?  :o That picture shows the motor running smoothly at higher rpm, right?
No.
This image is in the rotations that I have problems, in this case at 100RPM...
 

Offline Dave_PTTopic starter

  • Frequent Contributor
  • **
  • Posts: 315
  • Country: pt
    • DavidMartinsEngineering
Re: Problems with STM32 PMSM FOC SDK
« Reply #202 on: March 02, 2017, 05:07:44 pm »
I feel that something here is not right  ???.

I'm going to take it all apart and test it only with the motor, with nothing attached to shaft (no wheel, no gear box).
 

Offline tatus1969

  • Super Contributor
  • ***
  • Posts: 1273
  • Country: de
  • Resistance is futile - We Are The Watt.
    • keenlab
Re: Problems with STM32 PMSM FOC SDK
« Reply #203 on: March 02, 2017, 05:16:28 pm »

okay, as this is showing the low-rpm "oscillation" situation, you can be sure that it is correlated to the electrical motor angle - simply because the shape of distortion from a sawtooth is similar in each cycle.

But I still don't really trust the encoder yet. At higher rpm under load, do you get a nice sawtooth? That would rule out possible problems there.

Current waveform Ia is good. If you look close at it, then you can see that it is not perfectly sinusodial. There are small flat sections around zero crossing. I have seen much worse, like this for example (googled) :

PWM also looks good, so I would say (unless the encoder has some problems) both electronics and firmware are in good shape.

I am slowly coming to the point that the BLDC's torque ripple together with the wheel's inertia leads to a situation that cannot be solved by a PI controller at low rpm. Put simple: the wheel inertia limits the Kp / Ki gains that you can allow to maintain stability. (You can try tuning the speed controller without the wheel, you should be able to use much higher gains!) The lower gains limit the controller's ability to compensate for the torque ripple.

If that turns out correct, I don't see simple options...
- use motor with higher pole count (mitigate problem by shifting it to even lower rpm)
- use motor with PMSM construction (eliminate torque ripple)
- use higher rpm motor and higher gear reduction ratio (this reduces the inertia that the motor "sees")
- I think that the speed controller has a feedforward option, that can help to improve stability, but don't expect too much from that
We Are The Watt - Resistance Is Futile!
 

Offline Dave_PTTopic starter

  • Frequent Contributor
  • **
  • Posts: 315
  • Country: pt
    • DavidMartinsEngineering
Re: Problems with STM32 PMSM FOC SDK
« Reply #204 on: March 02, 2017, 06:16:55 pm »
But I still don't really trust the encoder yet. At higher rpm under load, do you get a nice sawtooth? That would rule out possible problems there.
Above 400/500RPM, with or without load on the motor shaft, the waveform is a perfect sawtooth.


I am slowly coming to the point that the BLDC's torque ripple together with the wheel's inertia leads to a situation that cannot be solved by a PI controller at low rpm. Put simple: the wheel inertia limits the Kp / Ki gains that you can allow to maintain stability. (You can try tuning the speed controller without the wheel, you should be able to use much higher gains!) The lower gains limit the controller's ability to compensate for the torque ripple.

If that turns out correct, I don't see simple options...
- use motor with higher pole count (mitigate problem by shifting it to even lower rpm)
- use motor with PMSM construction (eliminate torque ripple)
- use higher rpm motor and higher gear reduction ratio (this reduces the inertia that the motor "sees")
- I think that the speed controller has a feedforward option, that can help to improve stability, but don't expect too much from that

Now I have only the motor and the oscillation persists below 400RPM.

It is very obvious that below ~400RPM the waveform changes like the behavior of the motor and the control as well.
Pay attention to the oscilloscope in the video. I'm measuring the electric angle via DAC.
Notice that at some moment the waveform changes completely  :o :o.
This change is the mystery...

2000RPM to 100RPM in 25sec.
VIDEO: https://meocloud.pt/link/b35a236c-0675-4494-9829-23860792966d/VID_20170302_180652.3gp/
 

Offline tatus1969

  • Super Contributor
  • ***
  • Posts: 1273
  • Country: de
  • Resistance is futile - We Are The Watt.
    • keenlab
Re: Problems with STM32 PMSM FOC SDK
« Reply #205 on: March 02, 2017, 08:15:12 pm »
Now I have only the motor and the oscillation persists below 400RPM.

It is very obvious that below ~400RPM the waveform changes like the behavior of the motor and the control as well.
Pay attention to the oscilloscope in the video. I'm measuring the electric angle via DAC.
Notice that at some moment the waveform changes completely  :o :o.
This change is the mystery...

2000RPM to 100RPM in 25sec.
VIDEO: https://meocloud.pt/link/b35a236c-0675-4494-9829-23860792966d/VID_20170302_180652.3gp/
The waveform is changing because the motor speed becomes unstable. From what I can see, there is no problem with the encoder. I think we can rule that out.

I suggest to tune the speed controller Kp/Ki again without gearbox (you should be able to set significantly higher values). If that results in a stable system down to zero rpm (which I would almost bet by now), then that would strengthen the theory in my last post: the control problem is not solvable by a PI controller, and you'd need to change components (maybe feedforward does help).

p.s. I still have in a previous post, regarding the current controller: what is happening at the falling slope in your current step response screenshot? What command do you give there?

p.p.s. another idea: did you test that the speed controller handles transitions from high to low rpm correctly? The motor should not "roll out", you should see the same quick reaction as you see when accelerating.
We Are The Watt - Resistance Is Futile!
 

Offline Dave_PTTopic starter

  • Frequent Contributor
  • **
  • Posts: 315
  • Country: pt
    • DavidMartinsEngineering
Re: Problems with STM32 PMSM FOC SDK
« Reply #206 on: March 03, 2017, 09:45:01 am »
I suggest to tune the speed controller Kp/Ki again without gearbox (you should be able to set significantly higher values). If that results in a stable system down to zero rpm (which I would almost bet by now), then that would strengthen the theory in my last post: the control problem is not solvable by a PI controller, and you'd need to change components (maybe feedforward does help).
I'm going to try to use Feed Forward, but the control uses a PID. The derivative gain can be modified via register.


p.s. I still have in a previous post, regarding the current controller: what is happening at the falling slope in your current step response screenshot? What command do you give there?
I introduced a Iq ref of 1.5A and clicked start motor.
The signal measured on the oscilloscope represents Iq in step response.
The motor jumped to full speed.

p.p.s. another idea: did you test that the speed controller handles transitions from high to low rpm correctly? The motor should not "roll out", you should see the same quick reaction as you see when accelerating.
Yes I tested it.
It works perfectly.
0RPM to 1000RPM to -1000RPM to 0RPM, no problem.
 

Offline Dave_PTTopic starter

  • Frequent Contributor
  • **
  • Posts: 315
  • Country: pt
    • DavidMartinsEngineering
Re: Problems with STM32 PMSM FOC SDK
« Reply #207 on: March 03, 2017, 09:54:39 am »
I suggest to tune the speed controller Kp/Ki again without gearbox (you should be able to set significantly higher values). If that results in a stable system down to zero rpm (which I would almost bet by now), then that would strengthen the theory in my last post: the control problem is not solvable by a PI controller, and you'd need to change components (maybe feedforward does help).
I'm going to try to use Feed Forward, but the control uses a PID. The derivative gain can be modified via register.


Derivative gain takes no effect....
 

Offline Dave_PTTopic starter

  • Frequent Contributor
  • **
  • Posts: 315
  • Country: pt
    • DavidMartinsEngineering
Re: Problems with STM32 PMSM FOC SDK
« Reply #208 on: March 03, 2017, 10:10:55 am »
Using Feed Forward, I had no difference in motor behavior.

By tuning the gains without the gearbox, the values of the gains can be higher.

But below the ~ 400RPM, the problem remains the same ... the jump between electric rotation is very remarkable.
 

Offline Dave_PTTopic starter

  • Frequent Contributor
  • **
  • Posts: 315
  • Country: pt
    • DavidMartinsEngineering
Re: Problems with STM32 PMSM FOC SDK
« Reply #209 on: March 03, 2017, 12:05:29 pm »
NOTE:
I've been reading the manufacturer's information and this motor has a nominal speed of 3100RPM.
So far I've always tested around the 2000RPM, because it was the maximum rotation I want in my application.
But there is a problem. When I try to accelerate the motor to maximum (which should reach 4000RPM according to the manufacturer), the motor does not exceed 2900RPM. It's a big question ... because the limitation I had so far was 4000RPM (in motor configuration) and I do not understand why the rotation is being limited...

I had already noticed this, but I thought it was some mistake. For my application has no difference ... but with all these problems I remembered again this situation that can give some clue of what can happen at low revs.

[EDIT]
Motor Power has also always zero ... strange  ???.

« Last Edit: March 03, 2017, 12:29:43 pm by Dave_PT »
 

Offline tatus1969

  • Super Contributor
  • ***
  • Posts: 1273
  • Country: de
  • Resistance is futile - We Are The Watt.
    • keenlab
Re: Problems with STM32 PMSM FOC SDK
« Reply #210 on: March 03, 2017, 12:18:34 pm »
I'm going to try to use Feed Forward, but the control uses a PID. The derivative gain can be modified via register.
I am using an older version of the library (4.0), and I looked again. That version definitely uses only PI. Maybe that's some future extension residue.

I introduced a Iq ref of 1.5A and clicked start motor.
The signal measured on the oscilloscope represents Iq in step response.
The motor jumped to full speed.
Okay, understood. The slow falling ramp is then caused by the motor reaching steady state rpm, and as expected. That "oscillation" which follows is normal, and is due to imperfections of motor construction (phase windings, magnetization, etc).
We Are The Watt - Resistance Is Futile!
 
The following users thanked this post: Dave_PT

Offline tatus1969

  • Super Contributor
  • ***
  • Posts: 1273
  • Country: de
  • Resistance is futile - We Are The Watt.
    • keenlab
Re: Problems with STM32 PMSM FOC SDK
« Reply #211 on: March 03, 2017, 12:27:12 pm »
Using Feed Forward, I had no difference in motor behavior.

By tuning the gains without the gearbox, the values of the gains can be higher.

But below the ~ 400RPM, the problem remains the same ... the jump between electric rotation is very remarkable.
Is it possible that the motor is damaged somehow? Can you make a measurement that would also help identifying the motor characteristics futher? Take three 1k resistors and connect one of them to each phase. Join the other ends of the three. Then use three channels of your scope and measure all three phase voltages simultaneously while turning the motor by hand. The ground clips of all channels go to the common connection of the three resistors.

I really cannot find anything suspicious in your setup, it all leads me to think that the motor is not suitable.
We Are The Watt - Resistance Is Futile!
 

Offline Dave_PTTopic starter

  • Frequent Contributor
  • **
  • Posts: 315
  • Country: pt
    • DavidMartinsEngineering
Re: Problems with STM32 PMSM FOC SDK
« Reply #212 on: March 03, 2017, 12:43:00 pm »
Is it possible that the motor is damaged somehow?

I have 2 identical motors and 2 similar electronics.
I have now tested the other setup, with the same firmware. Everything runs in a similar way. Maximum rotation of 2900RPM, vibration at low rotations, etc ...
« Last Edit: March 03, 2017, 03:15:55 pm by Dave_PT »
 

Offline Dave_PTTopic starter

  • Frequent Contributor
  • **
  • Posts: 315
  • Country: pt
    • DavidMartinsEngineering
Re: Problems with STM32 PMSM FOC SDK
« Reply #213 on: March 03, 2017, 02:50:03 pm »
Take three 1k resistors and connect one of them to each phase. Join the other ends of the three. Then use three channels of your scope and measure all three phase voltages simultaneously while turning the motor by hand. The ground clips of all channels go to the common connection of the three resistors.

From what I can see, it seems fine ...




 

Offline tatus1969

  • Super Contributor
  • ***
  • Posts: 1273
  • Country: de
  • Resistance is futile - We Are The Watt.
    • keenlab
Re: Problems with STM32 PMSM FOC SDK
« Reply #214 on: March 03, 2017, 05:54:17 pm »
Now we know that both phase voltages and phase currents look almost sinusodial, I would expect little torque ripple and the motor should be able to run smooth with FOC also at low rpm.

I made a quick test to see if we are expecting something from the FOC library. This is a video of my diy electric kart running STM32 FOC. The motor is a servo motor (PMSM), 3 pole pairs, Rs=0.13, Ls=250uH, BemfConstant = 4.2 Vrms/krpm. That should not be too far away from yours, except that it is much stronger, and that it is a motor that is constructed to have sinusodial behavior. The planetary reduction gear is 1:10. I run a sawtooth velocity ramp down to zero. There is heavy inertial load at the output shaft, the kart rear axle weighs several kilograms, you see that when the motor spins up at the end.

https://www.kicksurfer.de/index.php/2017/03/03/kart-motor-velocity-control/

It is running very smoothly down to almost zero. When you look closely then you can notice some irregularity when it almost stops spinning.
We Are The Watt - Resistance Is Futile!
 

Offline tatus1969

  • Super Contributor
  • ***
  • Posts: 1273
  • Country: de
  • Resistance is futile - We Are The Watt.
    • keenlab
Re: Problems with STM32 PMSM FOC SDK
« Reply #215 on: March 03, 2017, 06:25:14 pm »

That picture allows us to calculate the motor kV. Frequency is ~ 43Hz. Amplitude of one phase in relation to star point is ~ 5V. This means that the Amplitude phase-to-phase is ~ 5V * sqrt(3) = 8.7V.

The classical kV value of a BLDC cannot be easily calculated from that, because it assumes that you are running the motor with a six-step-commutating controller.

In the past I have done some experiments with one of my FOC controllers (max PWM duty cycle is set to 95%) to find out how to derive a "compatible" kV from the above measurement. My formula is

kV = frequency * 60 / pole_pairs / amplitude_phase_to_phase * 0.95
kV = 141 rpm/V

For a bus voltage of 24V, you can calculate the no-load speed:

rpm_no_load = kV * bus_volt
rpm_no_load = 3380 rpm

I have no idea why the manufacturer advertises the motor for 4000 rpm @ 24V, it is certainly not able to achieve this.
We Are The Watt - Resistance Is Futile!
 
The following users thanked this post: Dave_PT

Offline Dave_PTTopic starter

  • Frequent Contributor
  • **
  • Posts: 315
  • Country: pt
    • DavidMartinsEngineering
Re: Problems with STM32 PMSM FOC SDK
« Reply #216 on: March 03, 2017, 06:25:46 pm »
Yes you're right ... the motor runs smoothly almost to 0RPM.
I want to be able to do this ... but with this motor I'm not very lucky ...

Rs=0.13, Ls=250uH, BemfConstant = 4.2 Vrms/krpm.
How did you get those values?
Did you use an EVB with the "Motor Profiler"?

My EVB (P-NUCLEO-IHM001) only supports a maximum of 2.8Apk...
The values obtained may be slightly wrong. Will this make a lot of difference in the final application?

 

Offline Dave_PTTopic starter

  • Frequent Contributor
  • **
  • Posts: 315
  • Country: pt
    • DavidMartinsEngineering
Re: Problems with STM32 PMSM FOC SDK
« Reply #217 on: March 03, 2017, 06:39:01 pm »
That picture allows us to calculate the motor kV. Frequency is ~ 43Hz. Amplitude of one phase in relation to star point is ~ 5V. This means that the Amplitude phase-to-phase is ~ 5V * sqrt(3) = 8.7V.

The classical kV value of a BLDC cannot be easily calculated from that, because it assumes that you are running the motor with a six-step-commutating controller.

In the past I have done some experiments with one of my FOC controllers (max PWM duty cycle is set to 95%) to find out how to derive a "compatible" kV from the above measurement. My formula is

kV = frequency * 60 / pole_pairs / amplitude_phase_to_phase * 0.95
kV = 141 rpm/V

For a bus voltage of 24V, you can calculate the no-load speed:

rpm_no_load = kV * bus_volt
rpm_no_load = 3380 rpm

I have no idea why the manufacturer advertises the motor for 4000 rpm @ 24V, it is certainly not able to achieve this.
This morning I contacted the manufacturer to ask for some explanation/data/infos. I'm still waiting for an answer ...
The manufacturer should have more technical details than those on the site.

I'm learning a lot from you. Thank you!  :-+ :-+
This is my first contact with brushless motors and if it were not for you, I would be completely lost!

Theoretically the maximum rotation will be ~3300RPM and I am measuring a maximum rotation of ~ 2900RPM.
I'm getting -12%. Not a big difference in fact, which can be affected by motor efficiency...
 

Offline tatus1969

  • Super Contributor
  • ***
  • Posts: 1273
  • Country: de
  • Resistance is futile - We Are The Watt.
    • keenlab
Re: Problems with STM32 PMSM FOC SDK
« Reply #218 on: March 03, 2017, 06:58:11 pm »
Yes you're right ... the motor runs smoothly almost to 0RPM.
I want to be able to do this ... but with this motor I'm not very lucky ...

Rs=0.13, Ls=250uH, BemfConstant = 4.2 Vrms/krpm.
How did you get those values?
Did you use an EVB with the "Motor Profiler"?

My EVB (P-NUCLEO-IHM001) only supports a maximum of 2.8Apk...
The values obtained may be slightly wrong. Will this make a lot of difference in the final application?

The motor profiler is quite new, haven't used it yet.

Rs and Ls were measured with an LCR meter. That BemfConstant was calculated from the phase voltage measurement. I had some support from ST to understand the relationships correctly. I checked the forum there, but the posts do not seem to be there anymore.

From what I remember:
Rs, Ls: measure between two phases, divide by 2.
BemfConstant = amplitude_phase_to_phase / sqrt(2) / (frequency*60/1000)
BemfConstant = 2.4 (in your case)

Anyhow, the motor parameters are used by STMCWB to calculate parameters for sensorless operation, and they also derive the current controller Kp/Ki from that. The BemfConstant will probably also go into the velocity controller Kp/Ki and the feedforward parameters, I'm not sure about that.

As you tune all PI's manually and use sensored feedback, I am pretty sure that these three parameters do not matter at all. What needs to be correct is pole pairs, max rated speed, nominal current. For nominal DC voltage I'm not sure either.
We Are The Watt - Resistance Is Futile!
 
The following users thanked this post: Dave_PT

Offline tatus1969

  • Super Contributor
  • ***
  • Posts: 1273
  • Country: de
  • Resistance is futile - We Are The Watt.
    • keenlab
Re: Problems with STM32 PMSM FOC SDK
« Reply #219 on: March 03, 2017, 07:33:41 pm »
I'm learning a lot from you. Thank you!  :-+ :-+
This is my first contact with brushless motors and if it were not for you, I would be completely lost!

Theoretically the maximum rotation will be ~3300RPM and I am measuring a maximum rotation of ~ 2900RPM.
I'm getting -12%. Not a big difference in fact, which can be affected by motor efficiency...
No problem, youre welcome :)

My ~3300 is only a very rough estimate from looking at the screenshot, you could make more precise measurements. And yes, you would only reach that speed if the motor had no bearing losses. Does it use sealed bearings?
We Are The Watt - Resistance Is Futile!
 

Offline tatus1969

  • Super Contributor
  • ***
  • Posts: 1273
  • Country: de
  • Resistance is futile - We Are The Watt.
    • keenlab
Re: Problems with STM32 PMSM FOC SDK
« Reply #220 on: March 03, 2017, 07:35:27 pm »
just found something interesting. The motor manufacturer website advertises them with "speed, 400 - 4000 rpm" right on the front page...
We Are The Watt - Resistance Is Futile!
 

Offline Dave_PTTopic starter

  • Frequent Contributor
  • **
  • Posts: 315
  • Country: pt
    • DavidMartinsEngineering
Re: Problems with STM32 PMSM FOC SDK
« Reply #221 on: March 03, 2017, 08:22:48 pm »
just found something interesting. The motor manufacturer website advertises them with "speed, 400 - 4000 rpm" right on the front page...
I had already noticed that, but I thought that this minimum rotation was limited by sensorless.
Below the 400RPM the feedback current is very small.

However they also indicate "4000RPM" and apparently this is also not true...  :-//
 

Offline Dave_PTTopic starter

  • Frequent Contributor
  • **
  • Posts: 315
  • Country: pt
    • DavidMartinsEngineering
Re: Problems with STM32 PMSM FOC SDK
« Reply #222 on: March 03, 2017, 08:26:33 pm »
My ~3300 is only a very rough estimate from looking at the screenshot, you could make more precise measurements. And yes, you would only reach that speed if the motor had no bearing losses. Does it use sealed bearings?
The gear box yes, it has sealed bearings.
The motor I can not confirm, but I think they are of the same type.
 

Offline tatus1969

  • Super Contributor
  • ***
  • Posts: 1273
  • Country: de
  • Resistance is futile - We Are The Watt.
    • keenlab
Re: Problems with STM32 PMSM FOC SDK
« Reply #223 on: March 03, 2017, 08:43:02 pm »
just found this video. They describe a method to reduce cogging. That would be possible in your application but would also involve digging deep into the firmware.


We Are The Watt - Resistance Is Futile!
 
The following users thanked this post: Dave_PT

Offline Dave_PTTopic starter

  • Frequent Contributor
  • **
  • Posts: 315
  • Country: pt
    • DavidMartinsEngineering
Re: Problems with STM32 PMSM FOC SDK
« Reply #224 on: March 06, 2017, 09:34:29 am »
I've been busy in the weekend ... sorry for the delay.

Excellent video! I understood what they are doing.
But if all the control firmware was designed by me, it would be easier to implement that.
In this case the SDK is very advanced and its algorithm forms a "web" that would be very difficult to modify.
I would have to find another solution (a simple one) ... otherwise I have a lot to "dig" into the firmware!
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf