IPM Motor Simulation and FOC Software

Pete9008
Posts: 1801
Joined: Sun Apr 03, 2022 1:57 pm
Has thanked: 102 times
Been thanked: 350 times

Re: IPM Motor Simulation and FOC Software

Post by Pete9008 »

Weird! wonder why the wifi affects the first sample more?
User avatar
johu
Site Admin
Posts: 6709
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 368 times
Been thanked: 1536 times
Contact:

Re: IPM Motor Simulation and FOC Software

Post by johu »

pushed the ADC2 variant: https://github.com/jsphuebner/stm32-sine/tree/use-adc2

might not be very useful for simulation, harder to mock.

EDIT: right now I don't use any fancy hardware triggering but I call adc_start_conversion_injected(ADC2); right at the start of the ISR, then I update the resolver angle which should take long enough for the conversion to complete, then I read the conversion result.
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
Pete9008
Posts: 1801
Joined: Sun Apr 03, 2022 1:57 pm
Has thanked: 102 times
Been thanked: 350 times

Re: IPM Motor Simulation and FOC Software

Post by Pete9008 »

Can't see it making any difference for simulation, none of the low level code is run. Might bring real life and simulation closer together though :)

For testing the code a software trigger is easier and should work OK. Prefer hardware triggering in the long run though, much less jitter on the sample point.
Pete9008
Posts: 1801
Joined: Sun Apr 03, 2022 1:57 pm
Has thanked: 102 times
Been thanked: 350 times

Re: IPM Motor Simulation and FOC Software

Post by Pete9008 »

mjc506 wrote: Fri Oct 28, 2022 8:27 pm Told you I was being thick :) Thanks :)
Don't believe that for a second!

Latest simulator is on github https://github.com/Pete9008/IPMMotorSim - Enjoy :)

Main changes are:
  • More charts including operating point plot.
  • Better model.
  • Better reset of initial conditions and a few bug fixes.
  • Remembers the position of all windows and edit fields and restores when restarted (wish I'd added this ages ago!).
  • Values from param file override the above.
  • Two param_prj.h files included, rename whichever motor type you want to simulate.
  • To be used with the code in https://github.com/Pete9008/stm32-sine (won't build with anything else unless you mess around with the param file).
User avatar
johu
Site Admin
Posts: 6709
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 368 times
Been thanked: 1536 times
Contact:

Re: IPM Motor Simulation and FOC Software

Post by johu »

more Audi test driving, now with ADC2 software. No difference. Since I "fixed" this bug where the angle was updated after forward transform it no longer behaves :( But I want it to run with the correct angle.

It's not down to FW, it does the same jumps and suddenly locking in at maximum ud with field weakening turned off. Also tried various values for syncadv with no observable change.

Towards the end I let it coast downhill until I reached about 50 kph then touched the brake which brings in a little regen. And boom it goes silly.
unwanted regen2.png
And here I was kindof trying to maintain speed but instead ud saturated full positive and I got massive regen.
unwanted regen.png
Whats wrong with this motor? I thought high inductance was easier to control

EDIT: can too little proportional gain make the controller unstable? It's just set to 10 right now.
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
Pete9008
Posts: 1801
Joined: Sun Apr 03, 2022 1:57 pm
Has thanked: 102 times
Been thanked: 350 times

Re: IPM Motor Simulation and FOC Software

Post by Pete9008 »

Other way round, high inductance are a nightmare to control!

Fairly sure my understanding of motors is right now and one thing I'm sure of is that if the critical current is similar or less than Mtpa current the old control scheme isn't going to work over the full operating envelope. Whenever you cross the critical current the sense of the control loop reverses and it will go full scale. You can see it happening at the right hand side of the plots. With the phase reversal there is no gain setting that will keep it stable :(

TBH you need to try my code (I'm reasonably confident it will help a lot with the FW stability although if it doesn't I'm out of ideas)

Edit - see what you mean, high inductance makes it easier to keep the ud and uq controllers stable but makes the fw controller a nightmare. With low L motors it is the other way round!

Edit2 - looking at the plots again it might be something else going on. With a high L motor at high speed iq and id start to interact a LOT more, iq produces large amounts of ud and id produces large amounts of uq. This means that a rapid change in one controller can induce a big error in the other which can produce a big change in the output and so on. Essentially the two controllers are no longer independent. Wondering whether the dq compensation you mentioned is a way of limiting this?
User avatar
johu
Site Admin
Posts: 6709
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 368 times
Been thanked: 1536 times
Contact:

Re: IPM Motor Simulation and FOC Software

Post by johu »

Yes, just pulled your changes. I can build the firmware but I'm getting some undefined symbols when building the simulator:

Code: Select all

IPMMotorSim/stm32-sine/src/pwmgeneration-foc.cpp:166: undefined reference to `Terminal::BinLoggingEnabled()'
I'm on the experimental branch on both libopeninv and libopencm3
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
Pete9008
Posts: 1801
Joined: Sun Apr 03, 2022 1:57 pm
Has thanked: 102 times
Been thanked: 350 times

Re: IPM Motor Simulation and FOC Software

Post by Pete9008 »

Which symbols?

Just added an edit above while you were posting, might be something else going on too?

Edit - oops, thought I'd removed that, should be ok to just comment out the line causing it

Edit2 - no, that should be ok, will boot up the PC and have a look!
User avatar
Bigpie
Posts: 1769
Joined: Wed Apr 10, 2019 8:11 pm
Location: South Yorkshire, UK
Has thanked: 82 times
Been thanked: 422 times

Re: IPM Motor Simulation and FOC Software

Post by Bigpie »

So with my cheap LCR, the leaf motor I have in the garage, the minimum inductance is 0.18mH and largest is 0.71mH other values between those 2 at various angles of rotation.
BMW E91 2006
ZombieVerter
GS450h
Outlander Charger DC/DC
Renault Kangoo 36kWh battery
FOCCCI CCS
Pete9008
Posts: 1801
Joined: Sun Apr 03, 2022 1:57 pm
Has thanked: 102 times
Been thanked: 350 times

Re: IPM Motor Simulation and FOC Software

Post by Pete9008 »

Bigpie wrote: Sat Oct 29, 2022 5:31 pm So with my cheap LCR, the leaf motor I have in the garage, the minimum inductance is 0.18mH and largest is 0.71mH other values between those 2 at various angles of rotation.
Now that's interesting, not far off my Outlander motor at all:)
Pete9008
Posts: 1801
Joined: Sun Apr 03, 2022 1:57 pm
Has thanked: 102 times
Been thanked: 350 times

Re: IPM Motor Simulation and FOC Software

Post by Pete9008 »

Looks like I might have pushed the wrong build, just doing a diff now.
Pete9008
Posts: 1801
Joined: Sun Apr 03, 2022 1:57 pm
Has thanked: 102 times
Been thanked: 350 times

Re: IPM Motor Simulation and FOC Software

Post by Pete9008 »

johu wrote: Sat Oct 29, 2022 5:28 pm Yes, just pulled your changes. I can build the firmware but I'm getting some undefined symbols when building the simulator:

Code: Select all

IPMMotorSim/stm32-sine/src/pwmgeneration-foc.cpp:166: undefined reference to `Terminal::BinLoggingEnabled()'
I'm on the experimental branch on both libopeninv and libopencm3
Hopefully sorted, I'd managed to miss adding a couple of new test stub files. Now updated on github.
Pete9008
Posts: 1801
Joined: Sun Apr 03, 2022 1:57 pm
Has thanked: 102 times
Been thanked: 350 times

Re: IPM Motor Simulation and FOC Software

Post by Pete9008 »

Bigpie wrote: Sat Oct 29, 2022 5:31 pm So with my cheap LCR, the leaf motor I have in the garage, the minimum inductance is 0.18mH and largest is 0.71mH other values between those 2 at various angles of rotation.
Sorry, just read this properly, thought it was measurements for your Outlander front. Those values would make sense for the Leaf :)
Pete9008
Posts: 1801
Joined: Sun Apr 03, 2022 1:57 pm
Has thanked: 102 times
Been thanked: 350 times

Re: IPM Motor Simulation and FOC Software

Post by Pete9008 »

Pete9008 wrote: Sat Oct 29, 2022 5:09 pm Edit2 - looking at the plots again it might be something else going on. With a high L motor at high speed iq and id start to interact a LOT more, iq produces large amounts of ud and id produces large amounts of uq. This means that a rapid change in one controller can induce a big error in the other which can produce a big change in the output and so on. Essentially the two controllers are no longer independent. Wondering whether the dq compensation you mentioned is a way of limiting this?
Think it is this. Looking at the simulation again it appears this could be causing the oscillation on both the uq and ud control loops. I'd been wondering why I couldn't tune it out but the interaction between id/iq and uq/ud would explain it.

Going to have a go at a compensation scheme. Don't like the idea for firmware as it relies on knowing motor parameters and would be fairly computationally intensive bit trying it is the best way to see if the uq/ud interaction is actually the cause.
User avatar
Ev8
Posts: 818
Joined: Sat Jan 30, 2021 11:05 am
Has thanked: 43 times
Been thanked: 163 times

Re: IPM Motor Simulation and FOC Software

Post by Ev8 »

Ok I dug out some spare motor parts, only tested with stationary rotor in one position but these are Lexus rx400h transaxle

Mg2
Attachments
961F8080-EB26-42F7-A36C-A1BE9F59B534.jpeg
AAA16196-62D6-4697-92C5-9EBA01618BFB.jpeg
FA2AD36C-17B5-4219-9FDF-29FF56836AD5.jpeg
User avatar
Ev8
Posts: 818
Joined: Sat Jan 30, 2021 11:05 am
Has thanked: 43 times
Been thanked: 163 times

Re: IPM Motor Simulation and FOC Software

Post by Ev8 »

Mg1
Attachments
13CE724F-B91B-4427-94CA-026DE9A0F3FF.jpeg
2B1F91C9-7986-458A-9994-68CD335187D8.jpeg
388A9D6A-431C-42F7-9536-24C3882E6B71.jpeg
Pete9008
Posts: 1801
Joined: Sun Apr 03, 2022 1:57 pm
Has thanked: 102 times
Been thanked: 350 times

Re: IPM Motor Simulation and FOC Software

Post by Pete9008 »

Ev8 wrote: Sat Oct 29, 2022 7:05 pm Ok I dug out some spare motor parts, only tested with stationary rotor in one position but these are Lexus rx400h transaxle
Thanks for taking those but any chance you could redo them :( To measure Lq and Ld you need one lead on one phase and the other two phases shorted together to the other meter lead.

I'm sure there is a way to convert your measurements to Lq and Ld, I just don't know what it is :(

Sorry, should have mentioned that before.

Edit - I'll have a google first to see if I can find how to convert them. Anyone know if these motors are star or delta wound?
User avatar
Ev8
Posts: 818
Joined: Sat Jan 30, 2021 11:05 am
Has thanked: 43 times
Been thanked: 163 times

Re: IPM Motor Simulation and FOC Software

Post by Ev8 »

Yes no problem I thought I may have got that wrong, will redo when I’m back on Monday
User avatar
Romale
Posts: 526
Joined: Fri May 20, 2022 4:16 pm
Location: Romania
Has thanked: 307 times
Been thanked: 77 times

Re: IPM Motor Simulation and FOC Software

Post by Romale »

Pete9008 wrote: Sat Oct 29, 2022 7:18 pm Anyone know if these motors are star or delta wound?
the motor leaf is 100% two parallel stars, their midpoints are not connected.
the rear engine of the alphard or estima is the same.
motor prius mg2 gen2 one star. the Lexus motor in the photo above is one star.
evil neodymium :twisted:
User avatar
Romale
Posts: 526
Joined: Fri May 20, 2022 4:16 pm
Location: Romania
Has thanked: 307 times
Been thanked: 77 times

Re: IPM Motor Simulation and FOC Software

Post by Romale »

However, I may be wrong about the Lexus. there may also be two parallel stars like the nissan leaf
evil neodymium :twisted:
Pete9008
Posts: 1801
Joined: Sun Apr 03, 2022 1:57 pm
Has thanked: 102 times
Been thanked: 350 times

Re: IPM Motor Simulation and FOC Software

Post by Pete9008 »

Romale wrote: Sat Oct 29, 2022 8:41 pm the motor leaf is 100% two parallel stars, their midpoints are not connected.
the rear engine of the alphard or estima is the same.
motor prius mg2 gen2 one star. the Lexus motor in the photo above is one star.
Thank you! Doesn't actually matter for the calculation whether it is one star or two so that's exactly the information required. :)

Will have a go at calculating Ld and Lq using a star configuration and Ev8's data.

Edit - Is it possible to tell the configuration from the picture or did you already know the Lexus motor configuration?
Pete9008
Posts: 1801
Joined: Sun Apr 03, 2022 1:57 pm
Has thanked: 102 times
Been thanked: 350 times

Re: IPM Motor Simulation and FOC Software

Post by Pete9008 »

Ev8 wrote: Sat Oct 29, 2022 7:05 pm Ok I dug out some spare motor parts, only tested with stationary rotor in one position but these are Lexus rx400h transaxle
I think the converted numbers are:

MG2: Lq = 2mH, Ld = 1mH

MG1: Lq = 1.1mH, Ld = 0.6mH

Without spinning the rotor those could be plus or minus a bit but should be fairly close. The Lq measurement will be a bit low as the motor wouldn't have been correctly aligned for them so maybe 2.2mH and 1.2mH respectively??

Not low inductance but then nowhere near as high as some of the numbers we have been working with :)

Threw these numbers into the simulator and with 300V it gave a peak power of 100kW dropping to a steady 30kW at higher speeds for each of MG1 and MG2 (MG1 stronger at low speeds, MG2 happier spinning up to higher speeds). No idea how that compares to reality? (Edit - Hmm, those power numbers don't seem quite right, need to have another look at that)

In case the conversion equations are useful to anyone else:

Phase measurement to winding inductances La=(M1+M2-M3)/2, Lb=(M2+M3-M1)/2, Lc=(M1+M3-M2)/2
Winding inductance to Ld/Lq measurements L1 = La + ((Lb*Lc)/(Lb+Lc)), L2 = Lb + ((La*Lc)/(La+Lc)), L3 = Lc + ((La*Lb)/(La+Lb))

Assuming the motor has naturally come to rest aligned on one phase one measurement will be low and will be Ld the other two should be larger, roughly equal and a bit smaller than Lq (for example MG1 above came to 0.6mH, 1.1mH and 1.0mH).
User avatar
mjc506
Posts: 343
Joined: Wed Sep 09, 2020 9:36 pm
Location: Wales, United Kingdom
Has thanked: 30 times
Been thanked: 29 times

Re: IPM Motor Simulation and FOC Software

Post by mjc506 »

Woohoo! Virtual spinning :-)

Now to get my head around tuning this thing..
Pete9008
Posts: 1801
Joined: Sun Apr 03, 2022 1:57 pm
Has thanked: 102 times
Been thanked: 350 times

Re: IPM Motor Simulation and FOC Software

Post by Pete9008 »

:-)

If you figure it out let me know how to do it!

Did it build OK, have I managed to fix all the bugs in the git repository now?
User avatar
mjc506
Posts: 343
Joined: Wed Sep 09, 2020 9:36 pm
Location: Wales, United Kingdom
Has thanked: 30 times
Been thanked: 29 times

Re: IPM Motor Simulation and FOC Software

Post by mjc506 »

Built fine. A load of warnings (mostly 'depreciated') but that's probably a QT version thing. But it compiled and ran, and produced pretty graphs of control loops losing the will to live :) (You don't want any notes on tuning from me hahaha)
Post Reply