I was looking at the way we are limiting the current here (LimitCurrent method). As far as I understand, the LimitCurrent method is called at every PWM interrupt and uses the raw current values, not the RMS values. The software reads il1 and il2, calculates il3=-il1-il2, then finds IlMax = MAX(ABS(il1), ABS(il2), ABS(il3)). Then it starts limiting the current when the IlMax reaches 95% of iacmax (the code comment says 80%, maybe a mistake?). However, due to the nature of the sine wave, IlMax results in an "umbrella" shape, so are the Fslip limit and Ampnom limits.
In order to make sure, I recreated the LimitCurrent() method in Matlab and plotted some graph. Created three sinusoidal waves (50Hz) representing il1, il2 and il3, swinging from -400 to +400 amps, with 120 deg phase shift. I set iacmax to 400 and this is what I got (curlim.m file is attached):
Plot shows that the limit kicks in and out 5 times over one current period. So there is some point when running near iacmax where the torque starts rippling. I was wondering whether it would be better if we used this in the LimitCurrent():
So by multiplying the RMS values by sqrt(2) and taking them into account as well as the raw il values makes the "umbrella" shape disappear since the RMS is flat, so the torque ripple shall be gone.
...
Or, am I just overrating the importance of the ripple here?
Re: Unstable rms current reading and a possible fix
Posted: Fri Feb 22, 2019 8:33 am
by johu
I think you do have a point. It might well be the reason why current limiting didn't work for Damien. Can you think of a way to eliminate the ripple?
I haven't used RMS because it's updating too slowly, especially at low speeds
Re: Unstable rms current reading and a possible fix
Posted: Fri Feb 22, 2019 10:19 am
by nailgg
Yes, the RMS updates slowly especially at low speeds so changing the LimitCurrent algorithm to completely RMS would make it act slower. It'd react fast enough after the RMS gets calculated fast, after 20-30 Hz or so maybe. That's why I kept the original ilMax and am comparing it to sqrt(2)*rms, then get the maximum among them. With the original algorithm, when you set iacmax to 400, currents can still get to 400 amps or even exceed it because of the sine wave shape, but if you take the RMS into account it would react better at speeds where RMS is calculated fast enough, in my humble opinion.
I'm thinking of a proper method to test it on the real hardware and my motor. I'll try to test it with the original algorithm first, then compare it with the one I'm proposing.
For very low speeds (take-offs for example) where the RMS is not calculated yet, the current can still exceed iacmax, even with my proposed method. I hope we can figure it out too.
Re: Unstable rms current reading and a possible fix
results in either fslipmin or fslipspnt, no middle values despite filtering. Maybe this is the reason why limiting didn't work for Damien? Johannes, could you please verify this?
Re: Unstable rms current reading and a possible fix
Posted: Tue Mar 05, 2019 8:43 pm
by nailgg
For the records, I streamed the final slip value under current limit through CAN with 10ms period and plotted it. This is how it looks like. fslipmin=2.5 and fslipmax=3.6.
Re: Unstable rms current reading and a possible fix
Posted: Wed Mar 06, 2019 5:59 am
by johu
Hi Nail,
sorry I keep overlooking new posts. We need some "Latest posts" function. So thats an interesting find, I'll look into it.
EDIT: in fact there is a "New posts" function hidden in the burger menu top left.
Re: Unstable rms current reading and a possible fix
Posted: Wed Mar 06, 2019 6:31 am
by johu
Yes you're right, that was a mistake.
Now I found something I did years ago but must have forgotten about. Basically I applied the space vector algorithm to the 3 phase currents.
So blue is MAX(ABS(I1), ABS(I2), ABS(I3)) as current implemented
Red is ABS((MIN(I1, I2, I3) + MAX(I1, I2, I3)) / 4)
Yellow is blue - red. Still some ripple but much smoother!
Re: Unstable rms current reading and a possible fix
Posted: Wed Mar 06, 2019 6:59 am
by arber333
johu wrote: ↑Wed Mar 06, 2019 6:31 am
Yes you're right, that was a mistake.
Now I found something I did years ago but must have forgotten about. Basically I applied the space vector algorithm to the 3 phase currents.
sin.png
So blue is MAX(ABS(I1), ABS(I2), ABS(I3)) as current implemented
Red is ABS((MIN(I1, I2, I3) + MAX(I1, I2, I3)) / 4)
Yellow is blue - red. Still some ripple but much smoother!
HM.... the AC current limiter i can live with. It is quite good and if set to 400A it will stop thereoff...
It is the DC limiter that was off for me. I had to set aclimit/1.7 to get approximate limit. After some testing i just set this at aclimit/2 and use some overhead. I dont know why such a difference? is it slow sensors?
Re: Unstable rms current reading and a possible fix
Posted: Wed Mar 06, 2019 10:17 am
by nailgg
johu wrote: ↑Wed Mar 06, 2019 6:31 am
Yes you're right, that was a mistake.
Now I found something I did years ago but must have forgotten about. Basically I applied the space vector algorithm to the 3 phase currents.
So blue is MAX(ABS(I1), ABS(I2), ABS(I3)) as current implemented
Red is ABS((MIN(I1, I2, I3) + MAX(I1, I2, I3)) / 4)
Yellow is blue - red. Still some ripple but much smoother!
Nice approach! Will try it and post the results here.
Re: Over current limiting issues
Posted: Wed Mar 06, 2019 6:30 pm
by nailgg
The negative offset in the current when gate drivers are active prevents me from having a stable current waveform.
Attached is the plot of ilmax with Johannes' space vector approach, just after starting the inverter operation, with no current. It reads around 2-3 amps initially, which is acceptable, then there's a jump in the current reading around the center of the plot. That point is where I put the direction switch to forward, even before pushing the throttle. When a direction is set and motor is not spinning, duty cycles are all 50% so the gate drivers are active. We fixed the faulty RMS readings caused by this negative offset by averaging lower and higher peaks (in the other forum thread), but since we're using the raw values here, this method failed in my case.
I also tried powering the current sensors through a separate non-isolated 5V DC/DC converter, same thing happened. Current still becomes biased around 15-20 amps when PWM is active. Still trying to figure out how I can achieve a better current reading. Without a nice current reading I don't think I can limit the current well enough.
@arber333, I don't think that's caused by the slow sensors as they're probably not slow. You are probably having a similar current reading issue.
so if separate supply of current sensors doesn't help, could it be something else? Do you actually see a small voltage drop on the current sensor output? Maybe you can simulate the gate driver operation by putting a 10Ohm resistor from 5V to GND and see if it causes the same problem. Can you observe any voltage drop on 3V3 line? Because that is the ADC reference voltage.
I have to test again in Polo but I've never observed that behaviour as far as I remember. I'm using 400A Tamura sensors with V2 sensor board there.
I'm on a train so I can't test myself right now
Re: Over current limiting issues
Posted: Thu Mar 07, 2019 8:59 am
by nailgg
Actually I noticed a similar issue on one of your videos while running Leaf motor, this video (around 5:00)
You might not have noticed that current plots are not symmetrical around zero, they have a small negative offset as well
I measured the current sensor outputs but there doesn't seem to be a voltage drop there. I'm suspicious of the ADC reference voltage, unfortunately the STM32F103RBT6 doesn't have an external Vref for ADC so the issue might be there. The 5V to 3.3V scaling operation is done through an opamp, which is supplied by the same 5V with gate drivers, I will look into that too.
Re: Over current limiting issues
Posted: Thu Mar 07, 2019 9:02 am
by johu
Oh, one simplification: you don't need to convert integer constants to fixed point.
FP_MUL(fp, FP_FROMINT(4)) == 4*fp
Likewise for division
Re: Over current limiting issues
Posted: Thu Mar 07, 2019 5:37 pm
by nailgg
If the Rev. 2 sensor board you are referring to is the one with the opamp scaling, I have the same sensor board, and the current reading issue arises from the non-inverting input of the scaling opamp. At least in my case. There is a voltage divider from 5V to GND through 4.7k/3.3k resistors, and the voltage drop occurs on that node. Since the (+) input of the opamp is offsetted when PWM is active, the output sees the same difference. Well, I bypassed the opamp and scaled the sensor outputs to 3.3V through a simple voltage divider (while the current sensors were supplied by a separate 5V DC/DC converter) and connected them to the ADC inputs. No more offset in the current anymore
So attached are the most recent measurements I have done with no motor load, only the transmission and wheels. slipmin/slipmax: 2.5/3.6, boost: 2000, fmax: 55, ampmin: 5, fweak: 135
ilmax still exceeds iacmax when motor is starting and goes up to 80 amps, but it's impossible to lower it since the slip and ampnom saturate at fslipmin / 40% respectively. With no iacmax limit, I noticed that ilmax goes up to 180 amps momentarily, so the limiting works pretty well