Page 31 of 40

Re: IPM Motor Simulation and FOC Software

Posted: Fri Nov 11, 2022 11:15 pm
by celeron55
It's quite humbling to have Johannes mention you in a motor control thread. I have no idea how I actually helped at all, but this thread has resulted in what I wanted to have!

It's a mind blowing achievement really. OI essentially went from "maybe usable for FOC, in some cases" to "here. what's your next move, OEMs?"

Now I have to find the time to finish other projects and then put this into use...

Re: IPM Motor Simulation and FOC Software

Posted: Sat Nov 12, 2022 2:32 pm
by johu
oh mmh I feel like a guru now :D

I hope you get to test it on that MGR Previa

Re: IPM Motor Simulation and FOC Software

Posted: Sun Nov 13, 2022 4:09 pm
by Bigpie
johu wrote: Thu Nov 10, 2022 1:57 pm EDIT: flux linkage calculation:
uq=25000, udc=360, fstat=300
uac = uq/37813*udc/sqrt(2)=169V
V/Hz = 83/70=0.56 V/Hz = 90 mWeber

So for this, I went to the top of a hill and started logging. Only had my esp8266 on me.
Screenshot 2022-11-13 at 4.04.39 pm.png
I plugged the uac formula in to excel and have a value about 50V? Does that seem sensible?
I'm not sure where the 83 and 70 came from on the next line and how this equals 0.56?

Re: IPM Motor Simulation and FOC Software

Posted: Sun Nov 13, 2022 4:17 pm
by johu
Oh, copy&paste error, these were still from the Prius. Must be 169V and 300Hz

So 50V, 234 Hz would be 0.21 V/Hz or 34 mWeber - surprisingly small!

Re: IPM Motor Simulation and FOC Software

Posted: Sun Nov 13, 2022 6:20 pm
by Pete9008
Not sure why a sqrt(2) has started appearing in the equations?

Re: IPM Motor Simulation and FOC Software

Posted: Sun Nov 13, 2022 8:50 pm
by johu
Because AC RMS voltage = peak voltage / sqrt(2). And peak voltage is DC bus voltage.

Re: IPM Motor Simulation and FOC Software

Posted: Sun Nov 13, 2022 9:22 pm
by Pete9008
Yes, but aren't Ud and Uq more related to peak voltage? See https://www.mathworks.com/solutions/po ... ms.html .

If using uq/37813 think it should then be pack voltage/2.

Re: IPM Motor Simulation and FOC Software

Posted: Mon Nov 14, 2022 9:02 pm
by johu
Yes, and the ratio between peak and RMS voltage is 1/sqrt(2) (for purely sinusoidal voltages)

An SVPWM inverter is the inverse of a 3-phase bridge rectifier: it rectifies 400V RMS AC to 560V DC. Chain it to an inverter, it will make 400V AC again. Industrial VFDs wouldn't work very well otherwise.

EDIT: line-to-line I should add
line-to-neutral is 1/sqrt(3) less but we're not really interested in line-to-neutral in motor control.

Re: IPM Motor Simulation and FOC Software

Posted: Mon Nov 14, 2022 9:34 pm
by Pete9008
Yes, I get all that but still don't think there should be a sqrt in the flux linkage calculation.

Uq is an instantaneous voltage not an rms voltage.

Edit - not trying to be awkward or pedantic here but this conversion is also done in the simulator to get from the dc bus voltage to phase voltages so it has an impact on its accuracy too, so would like to get it right!

Re: IPM Motor Simulation and FOC Software

Posted: Mon Nov 14, 2022 11:09 pm
by johu
Pete9008 wrote: Mon Nov 14, 2022 9:34 pm Uq is an instantaneous voltage not an rms voltage.
Yes exactly and V/Hz is RMS voltage, thats why we need to convert from instantaneous (=peak) to RMS. uq=2/sqrt(3)*32768 means we are generating a three phase sine system which peaks at pack voltage.

Say a motor generates 100V (RMS!) at 100 Hz then it is 1 V/Hz or 159 mWeber. The inverter also needs to generate 100V RMS for 0 current flow. 100V RMS means 141V peak. Say we have a 400V battery then uq must be 141/400*2/sqrt(3)*32768 = 13337 digits.

Re: IPM Motor Simulation and FOC Software

Posted: Mon Nov 14, 2022 11:22 pm
by Pete9008
Why is V/Hz in rms (in this context for these equations), do you have a reference for this?

And why is it now sqrt(3) rather than sqrt(2)?

Re: IPM Motor Simulation and FOC Software

Posted: Tue Nov 15, 2022 1:46 pm
by Pete9008
To try and clarify my understanding, and try to work out where the misunderstanding is, I'm going to post my way of calculating the flux linkage from motor plots. If anyone disagree with it please let me know as most of these calculations are also done in the simulator and so any errors will also affect it and so need sorting.

The relevant equations are:
image.png
image.png (8.37 KiB) Viewed 1853 times
When coasting (zero torque) Iq and Id must be zero, looking at the equations for Vd and Vq this means that all the terms are zero except for last one in the Vq equations so this equation simplifies to Vq = wλ (where w = 2xπxfreq(elec) and λ = flux linkage), Rearranging gives:

Code: Select all

λ = Vq / (2 x π x freq(elec))
To convert Vq from the units in the firmware to actual volts we need to scale it by the full scale PWM value and the DC bus voltage. Because we need to allow for positive an negative voltages we also need to divide the pack value by 2, so:

Code: Select all

Vq(volts) = (Vq(firmware units) / 32768) * (DCVolt / 2)


Note - this ignores space vector modulation (uses 32768 rather than 37813), if we included it we would also have to increase the DC bus voltage by ~15% to compensate.

So the complete formulae is:

Code: Select all

λ = ((Vq(firmware units) / 32768) * (DCVolt / 2) ) / (2 x π x freq(elec))
So to work this out for the numbers measured:

Johannes - Prius Gen2 MG2

λ =((25000/32768) * (360/2)) / (2 x π x 300) = 72mWeber

Bigpie - Outlander front generator

λ =((7850/32768) * (349/2)) / (2 x π x 240) = 27mWeber

Note - all the above assumes that syncadv and syncofs are correctly set. The best way to check this is to make sure that Vd is zero while coasting, if it isn't then either the syncofs or syncadv values are likely to need adjusting.

EDIT - These numbers look a bit low but can't see anything wrong with the calculations - any ideas?

EDIT2 - Used the wrong numbers above - should be:
Johannes - Prius Gen2 MG2
λ =((12000/32768) * (370/2)) / (2 x π x 70) = 154mWeber

Johannes - Leaf
λ =((25000/32768) * (360/2)) / (2 x π x 300) = 72mWeber

Bigpie - Outlander front generator
λ =((7850/32768) * (349/2)) / (2 x π x 240) = 27mWeber

Re: IPM Motor Simulation and FOC Software

Posted: Tue Nov 15, 2022 4:34 pm
by johu
Right, no sqrt(2) in there indeed. So whether or not you include the SVPWM gain doesn't matter as it cancels out: ((25000/32768) * (360/2)) or ((25000/37813) * (1.15*360/2)).

Above numbers were for the Leaf motor: viewtopic.php?p=48358&hilit=mweber#p48358

Prius has these:
λ =((12000/32768) * (370/2)) / (2 x π x 70) = 154mWeber

Still not sure if this corresponds to turning the motor with the drill and then measuring the voltage. So basically I'd (or someone'd) have to disconnect the battery, roll down the hill and observe udc and fstat.

Re: IPM Motor Simulation and FOC Software

Posted: Tue Nov 15, 2022 4:49 pm
by mjc506
It does all depend on what Vq (etc) actually is, doesn't it.. I must admit, I'm totally lost :-)

Kv is normally defined as a ratio of peak (battery) voltage and rpm but it's more of a 'laymans' unit rather than proper SI. Peak/battery voltage makes sense to me, but it seems these things are quite often defined using that theoretical single phase motor then 'converted' to 3-phase with square roots etc.

Is pack voltage/2 correct for a H-bridge? the (magic single phase) motor sees full pack voltage in both directions?

EDIT: Does pole count come into play too?

Re: IPM Motor Simulation and FOC Software

Posted: Tue Nov 15, 2022 4:55 pm
by Pete9008
Seem to remember someone posting a flux linkage equation (it might have even been you?) with sqrt(3) in it which I think might be the one to use when spinning the motor and measuring the voltage - but can't find it now.

I think the voltage over/2 is right for a 3-phase bridge but could quite easily be wrong. I find the diagrams here useful for visualising it https://www.mathworks.com/solutions/pow ... forms.html Think it would be full voltage for a single phase H bridge as you can then get the full voltage in both directions.

It's when you start working through the park/clarke transforms to see how they affect things it gets really confusing :oops:

Re: IPM Motor Simulation and FOC Software

Posted: Tue Nov 15, 2022 4:57 pm
by Pete9008
johu wrote: Tue Nov 15, 2022 4:34 pm Prius has these:
λ =((12000/32768) * (370/2)) / (2 x π x 70) = 154mWeber
Oops, did I use the wrong numbers for the Gen2 calculation above? 154mWb does sound more reasonable.

Edit - sorry, leaf, edited above to correct :oops:

Re: IPM Motor Simulation and FOC Software

Posted: Wed Nov 16, 2022 7:50 am
by johu
While resaerching the V/Hz definition I came across overmodulation. That is increasing the amplitude so that the sine wave is clipped and approaches a square wave. This yields higher amplitude at the cost of increased EMI, apparently.

But it seems it can wrangle a bit more power from the Prius motor:
image.png
All I changed is modMax in foc.cpp to 45000

Same settings without overmodulation:
image.png

Re: IPM Motor Simulation and FOC Software

Posted: Wed Nov 16, 2022 8:42 am
by Pete9008
Nice find, could be worth a try!

Apart from the EMI there could be other effects. It must make the effective gain go a little non linear towards the top end (and if you go too far it could drop to 0!) I'd also expect quite a bit of pwm freq ripple to start appearing in the control loops. As long as neither of those cause the loops a problem it should work ok. Can't see the increase in EMI being huge but the motor will start seeing much more third/fifth harmonic, not sure what the effect of that would be, more vibration or losses?

Re: IPM Motor Simulation and FOC Software

Posted: Wed Nov 16, 2022 9:30 am
by SciroccoEV
From my 1998 copy of the "Motor Control Electronics Handbook".
modulation1.jpg
modulation2.jpg

Re: IPM Motor Simulation and FOC Software

Posted: Wed Nov 16, 2022 10:43 am
by Pete9008
That looks like a usefull refernce book, is it worth buying?

Been on the lookout for a good reference, particularly one that gives the full derivation of all the equations, but they all seem a bit expensive if they don't turn out to be that good.

Interesting idea about moving to 6point modulation at higher frequencies. It would give max power and reduced switching losses.

Re: IPM Motor Simulation and FOC Software

Posted: Wed Nov 16, 2022 10:57 am
by Bigpie
Pete9008 wrote: Tue Nov 15, 2022 1:46 pm Bigpie - Outlander front generator
λ =((7850/32768) * (349/2)) / (2 x π x 240) = 27mWeber
Does 27mWeber seem reasonable?


Not calculated icrit just used -75 for now
Screenshot 2022-11-16 at 10.55.01 am.png
Screenshot 2022-11-16 at 10.54.48 am.png
Screenshot 2022-11-16 at 10.54.39 am.png
Screenshot 2022-11-16 at 10.56.56 am.png
The simulation looks OK to my limited understanding :D

Re: IPM Motor Simulation and FOC Software

Posted: Wed Nov 16, 2022 11:13 am
by Pete9008
Agree, 27mWb does seem a little low but it's what the maths says. Were iq, id and vq all zero when you took the measurement? Without spinning up a motor on the bench and measuring the voltages it's difficult to come up with a better estimate.

Graphs look good :) Only comments are stick with loop freq set to 8800. That is the frequency the control loop runs at, its also the pwm update frequency (double update at 4400Hz). The current rise times do look a little slower than expected though (although nice and stable when they hit the setpoint), might be the loop freq but if it doesn't improve when you change to 8800 try upping the loop gains slightly.

With those values for Ld and flux linkage icrit should be nearer -270A (although not familiar enough with Johannes code to comment how to set things up for that - still need to give it a try and then do the final simulator update)

Edit - I also tend to reduce the car weight most of the time - it makes the simulations run quicker! And increase it back to a realistic number just for final runs.

Edit2 - what power is the simulator showing for your setup?

Edit3! - and keep the extra cycle delay ticked. It's needed to include the delay before the new pwm values are loaded in the real hardware.

Re: IPM Motor Simulation and FOC Software

Posted: Wed Nov 16, 2022 12:38 pm
by Pete9008
Bigpie wrote: Wed Nov 16, 2022 10:57 am Does 27mWeber seem reasonable?
Regarding this I forgot to say that I still plan to run some of your logged data through the simulators motor model, basically use the logged pwm values to drive the model and then compare the measured currents with the simulated currents. If the two match the measured parameters, and the model, are right if they don't then try and adjust the values till they do to see what the difference is. Trouble is its not a simple job and I can't quite face it at the moment.

To work best it really needs logged data from flat roads (no hills), and ideally with very little, ideally no, braking (regen is fine but actual car brakes would mess it all up). Would any of your logs, or sections of your logs, work for this?

Re: IPM Motor Simulation and FOC Software

Posted: Wed Nov 16, 2022 1:02 pm
by Bigpie
I'll go make specific logs for this purpose, I'm not sure what the values for iq, id and vq were 0, was just coasting down hill, 0 throttle or regen, low rpm, but was only logging with the old esp8266.

Simulator shows a max of 45kw, which is lower than I've seen using my shunt.
Screenshot 2022-11-16 at 12.54.54 pm.png
Increasing the FWmargin to 5500 gets the power up to 68.8kw on the simulation, not tested that in the car though.

Re: IPM Motor Simulation and FOC Software

Posted: Wed Nov 16, 2022 1:10 pm
by Pete9008
That's interesting, you haven't even hit the constant/max power region of the plot yet. Would be worth letting the simulation run a bit longer (or reducing car weight - doesn't affect the power, just how quickly it gets there).

Dont need to be coasting down a hill, coasting on the flat should work fine too.

Interesting on the fwmargin, should go the other way! Making it bigger reduces the max amplitude on the pwm which should reduce power :?

Edit - what speed do you run the motor up to in the car?

Edit2 - for the flux linkage measurement it is better to coast at a higher speed as the larger numbers improve accuracy, say half base speed?