Testing FOC for synchronous motor

Post Reply
nailgg
Posts: 119
Joined: Sat Dec 22, 2018 8:40 pm

Re: Testing FOC for synchronous motor

Post by nailgg »

johu wrote: Sun Jun 02, 2019 5:45 am I still can't get my head around how to detect that we've run out of voltage and now need to decrease id even further to enter field weakening.
Let's say when we spin the Leaf motor externally at 3000 RPM, it outputs a 200 Hz (for 4 pole pairs) 280V phase-to-phase back-emf (I don't actually know what voltage it outputs, I'm using random values). That means 280V*sqrt(2) ~= 400V DC-link is what we need for operating up to 3000 RPM until the weakening starts. So let's assume we've set udcnom to 400, and fweak to 200.

So the software knows the base RPM point where the weakening should start. But that's under the assumption of DC-link being supplied where the inverter is able to provide with motors nominal phase to phase voltage. If we're supplying the DC-link with a voltage below than the nominal voltage i.e. udcnom, the software already shifts the fweak point back or forth, so the weakening start point is shifted accordingly.

So instead of detecting we've run out of voltage, can't we simply start decreasing IdRef right after fweak, as the name already suggests? For the speeds under the weakening point, a fixed IdRef could be given. Above that point, a declining IdRef curve (with a lookup table maybe) based on motor speed, could be used. Since Leaf is an IPM, a smarter algorithm for IdRef can be implemented in the future.

After we run the field weakening logic and find the required IdRef, then run the PI control for IdRef->VdRef, we now have the Vd vector. Then we run the IqRef->VqRef PI controller, but now we should saturate the upper/lower points of Vq so that vectorial sum of new Vd/Vq vectors doesn't exceed the maximum voltage radius.

--

Below is a snippet from the Microchip's PMSM FOC example (link http://ww1.microchip.com/downloads/en/A ... _MCHV3.zip, pmsm.c:491). Above this snippet Clarke and Park are done. VdRef is defined by the need for field weakening, and VqRef is defined by the torque control knob/speed regulator. Then here it prioritizes VdRef and dynamically limits VqRef so that sqrt(VdRef^2+VqRef^2)<=1.

Code: Select all

        /* Flux weakening control - the actual speed is replaced 
        with the reference speed for stability 
        reference for d current component 
        adapt the estimator parameters in concordance with the speed */
        ctrlParm.qVdRef=FieldWeakening(_Q15abs(ctrlParm.qVelRef));

        /* PI control for D */
        piInputId.inMeasure = idq.d;
        piInputId.inReference  = ctrlParm.qVdRef;
        MC_ControllerPIUpdate_Assembly(piInputId.inReference,
                                       piInputId.inMeasure,
                                       &piInputId.piState,
                                       &piOutputId.out);
        vdq.d    = piOutputId.out;

        /* Dynamic d-q adjustment
         with d component priority 
         vq=sqrt (vs^2 - vd^2) 
        limit vq maximum to the one resulting from the calculation above */
        temp_qref_pow_q15 = (int16_t)(__builtin_mulss(piOutputId.out ,
                                                      piOutputId.out) >> 15);
        temp_qref_pow_q15 = Q15(MAX_VOLTAGE_VECTOR) - temp_qref_pow_q15;
        piInputIq.piState.outMax = Q15SQRT (temp_qref_pow_q15);

        /* PI control for Q */
        piInputIq.inMeasure  = idq.q;
        piInputIq.inReference  = ctrlParm.qVqRef;
        MC_ControllerPIUpdate_Assembly(piInputIq.inReference,
                                       piInputIq.inMeasure,
                                       &piInputIq.piState,
                                       &piOutputIq.out);
        vdq.q = piOutputIq.out;
User avatar
johu
Site Admin
Posts: 6714
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 369 times
Been thanked: 1543 times
Contact:

Re: Testing FOC for synchronous motor

Post by johu »

Now I'm wondering, does it make any sense to make id dynamic below field weakening. Like right now I'm scaling it with throttle. Should I rather set it to a fixed value?
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
nailgg
Posts: 119
Joined: Sat Dec 22, 2018 8:40 pm

Re: Testing FOC for synchronous motor

Post by nailgg »

johu wrote: Mon Jun 03, 2019 6:18 am Now I'm wondering, does it make any sense to make id dynamic below field weakening. Like right now I'm scaling it with throttle. Should I rather set it to a fixed value?
Is’s best to tell it after test but I think we’ll end up setting it to a fixed value until weakening starts.
User avatar
johu
Site Admin
Posts: 6714
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 369 times
Been thanked: 1543 times
Contact:

Re: Testing FOC for synchronous motor

Post by johu »

Tried a fixed value, wasn't convinced. The motor will hardly start spinning. Apparently it's the ratio of iq/id that matters.

I have also introduced a PI controller now.

id regulation is still kind of weird. It works quite good when there is load on the motor but if I just want to spin it up in idle, id can quickly reach -70A even though I set it to 0.

I guess I'm running out of time to figure this out before going on holiday, so firmware and parameters are attached for testing.
Attachments
stm32_sine.zip
(25.67 KiB) Downloaded 283 times
Leaf 2019-06-03.json
(1.27 KiB) Downloaded 360 times
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
nailgg
Posts: 119
Joined: Sat Dec 22, 2018 8:40 pm

Re: Testing FOC for synchronous motor

Post by nailgg »

johu wrote: Mon Jun 03, 2019 9:28 am id regulation is still kind of weird. It works quite good when there is load on the motor but if I just want to spin it up in idle, id can quickly reach -70A even though I set it to 0.
Kp and Ki parameters might need to be tuned more carefully maybe, until you reach zero id at zero id reference? I’d initially lower the Ki very close to zero to validate if it oscillates around zero with only Kp.
User avatar
johu
Site Admin
Posts: 6714
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 369 times
Been thanked: 1543 times
Contact:

Re: Testing FOC for synchronous motor

Post by johu »

Didn't work that way. Current have kp=2. Anything more will lead to trips, so I guess thats oscillation? But it doesn't keep id at zero as set.
Adding more ki eventually leads to the motor spinning even with 0 id and iq commanded. I guess thats down to the remaining offset of the sensors.
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
nailgg
Posts: 119
Joined: Sat Dec 22, 2018 8:40 pm

Re: Testing FOC for synchronous motor

Post by nailgg »

johu wrote: Mon Jun 03, 2019 1:27 pm Adding more ki eventually leads to the motor spinning even with 0 id and iq commanded. I guess thats down to the remaining offset of the sensors.
Yes, probably. Maybe you can remember I tried to achieve zero current offset here: viewtopic.php?p=416#p416

When the inverter is started software finds the current offset, but also when the gate drivers draw current from the 5V line more (negative) offset is added because of a small drop in the 5V. So I fed the current sensors through a separate 5V DC/DC with common ground to the main PCB, and scaled the outputs to 3.3V through voltage dividers. Offset is no more.
kiwifiat
Posts: 99
Joined: Sat Dec 22, 2018 9:39 pm
Location: Vancouver, Canada
Been thanked: 11 times

Re: Testing FOC for synchronous motor

Post by kiwifiat »

johu wrote: Mon Jun 03, 2019 6:18 am Now I'm wondering, does it make any sense to make id dynamic below field weakening. Like right now I'm scaling it with throttle. Should I rather set it to a fixed value?
When you say fixed value do you mean x amps or do you mean x=-y%Iq?

To achive MTPA on an IPM motor Id = -x%Iq . In the case of say a gen2 toyota prius x turns out to be -30 % of Iq. x needs to be determined experimenally and is different for IPM motors of different designs primarily because in FOC speak the inductance on the d axis is determined by the physical structure of the rotor. So from that perspective Id must be dynamic for best performance. And we should only employ FW once we have approached the maximum rpm with the available line voltage.
User avatar
johu
Site Admin
Posts: 6714
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 369 times
Been thanked: 1543 times
Contact:

Re: Testing FOC for synchronous motor

Post by johu »

Yes that clear things up, thank you!
So currently you can configure A/% for id and iq separately. So you could set it to 3 for iq (resulting in max 300A torque current) and -1 for id for x=-33%
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
User avatar
johu
Site Admin
Posts: 6714
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 369 times
Been thanked: 1543 times
Contact:

Re: Testing FOC for synchronous motor

Post by johu »

I submitted new code that limits the maximum modulation and gives priority to id.
I have only tested with my "HIL" as the Touran is out of service due to some resolver problem.
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
User avatar
johu
Site Admin
Posts: 6714
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 369 times
Been thanked: 1543 times
Contact:

Re: Testing FOC for synchronous motor

Post by johu »

So one more round of testing now that I'm back from holiday. I've reduced PWM frequency to 8.8kHz as learned in Sweden and also increased deadtime to 75.

I've fixed the integrator windup so now ki should actually have an effect. I still don't quite get the expected results. So yes I can spin but the current draw is still too high.

I also forced iqref=0 and searched the syncofs where the motor produced no torque at all. That seems somewhere around 62000. But then the measured iq is not 0 but almost equal to id. Also when I set iqref to a positive value it reads a negative value :?

It looks different when I put the car into gear and put the hand brake on. Then the commanded id and iq values are hit spot-on. Its only when the thing starts moving that things go weird. Anyone?

Forgot to pull a parameter dump, basically synofs=62000, curqkp=curdkp=30, curqki=curdki=10. throtid=-1, throtiq=3
Attachments
stm32_sine.zip
(63.02 KiB) Downloaded 209 times
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
nailgg
Posts: 119
Joined: Sat Dec 22, 2018 8:40 pm

Re: Testing FOC for synchronous motor

Post by nailgg »

johu wrote: Sun Jul 07, 2019 7:14 pm Also when I set iqref to a positive value it reads a negative value :?

It looks different when I put the car into gear and put the hand brake on. Then the commanded id and iq values are hit spot-on. Its only when the thing starts moving that things go weird. Anyone?
Welcome back :) So if it works nicely when there's no movement, maybe you need to "unswap" the resolver sin/cos?
User avatar
johu
Site Admin
Posts: 6714
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 369 times
Been thanked: 1543 times
Contact:

Re: Testing FOC for synchronous motor

Post by johu »

Thanks :) Did all sorts of swaps yesterday and so far they all resulted in either no movement or instant over current. Then the wifi kept dying on me and I quit. Will try to be more systematic today.
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
purplespark
Posts: 52
Joined: Fri Feb 15, 2019 10:22 am
Location: United Kingdom

Re: Testing FOC for synchronous motor

Post by purplespark »

Hi folks,
Please excuse me butting in , I don't know much about motors or coding , but Paul Holmes runs a routine
that establishes the motor parameters first, and after that it's good to go . I presume it's something along the lines of
the leaf resolver code stamped on the motor ?
Sorry to interrupt.
User avatar
johu
Site Admin
Posts: 6714
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 369 times
Been thanked: 1543 times
Contact:

Re: Testing FOC for synchronous motor

Post by johu »

Yes he has a procedure to find the best offset I believe. That is useful to have once the basics are sorted.

So today I did a successful test drive :) It's still not mighty powerful but improving. I could go 30 km/h up hill.

In idle things are as weird as ever. Commanding positive iq and getting negative.

I changed the resolver code to give a sample every time, not just every other. But that didn't change things either.

Updated code is on github (foc-test branch!)
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
User avatar
johu
Site Admin
Posts: 6714
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 369 times
Been thanked: 1543 times
Contact:

Re: Testing FOC for synchronous motor

Post by johu »

Finally! The first test drive with some serious power. At least more serious than anything so far.

What was the problem? The motor is spinning backwards, as indicated by "angle" running from 360 to 0°. And that means we need NEGATIVE iq reference!

Now I can spin to 4000rpm without tripping and without excessive currents and most of all without iq going negative even though being commanded positive.

I started out with maximum iq of 300A and maximum id of 200A but thats still leading to frequent over-current trips. When set to 200A I can floor throttle without tripping. So still some room for improvement but I think I'm on the right track now.

EDIT: also theres some strange whine from the inverter when flooring the throttle, maybe regulator oscillation?

Software and parameters attached, video coming.
Attachments
Leaf 2019-07-10.json
(1.25 KiB) Downloaded 254 times
stm32_sine.zip
(61.65 KiB) Downloaded 248 times
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
arber333
Posts: 3563
Joined: Mon Dec 24, 2018 1:37 pm
Location: Slovenia
Has thanked: 134 times
Been thanked: 335 times
Contact:

Re: Testing FOC for synchronous motor

Post by arber333 »

johu wrote: Wed Jul 10, 2019 6:46 pm Finally! The first test drive with some serious power. At least more serious than anything so far.

EDIT: also theres some strange whine from the inverter when flooring the throttle, maybe regulator oscillation?
Congratulations, crossing my fingers here...

Yes if you listen carefully in this video you can hear the same whine from Leaf motor that Stane has in his Mazda. We use Lebowski FOC code here. Code is proprietary, but brain schematic is free.
I think this is the rotating field overtaking the mechanical rotor and colapsing the energy when encoder reports everything is not correct. I think i will have to tinker with FOC settings further....
nailgg
Posts: 119
Joined: Sat Dec 22, 2018 8:40 pm

Re: Testing FOC for synchronous motor

Post by nailgg »

johu wrote: Wed Jul 10, 2019 6:46 pm Finally! The first test drive with some serious power. At least more serious than anything so far.

What was the problem? The motor is spinning backwards, as indicated by "angle" running from 360 to 0°. And that means we need NEGATIVE iq reference!

Now I can spin to 4000rpm without tripping and without excessive currents and most of all without iq going negative even though being commanded positive.
Congratulations! But I have to say I was surprised that you achieved it with negative iq reference. What about the id? If iq needs to be negative in your case, the id reference probably needs to be positive (according to Id = -x%Iq suggestion by @kiwifiat). Looking at your parameters, gains of both id and iq have the same sign. Maybe this is the reason for over current? I'm not sure.

Anyway, after we can verify the FOC works well for Leaf, we can integrate FOC for ACIM as well. Just need to replace the angle read by resolver with the rotor flux angle calculated by using the "current model". We only need to know the mutual inductance.
arber333
Posts: 3563
Joined: Mon Dec 24, 2018 1:37 pm
Location: Slovenia
Has thanked: 134 times
Been thanked: 335 times
Contact:

Re: Testing FOC for synchronous motor

Post by arber333 »

I am also waiting on results of FOC and hoping it could be adapted to ACIM. My Mazda ACIM motor still shows vibration when throttle is near 0%.
Also regen over 30% causes violent jerks that have to be dampened by reducing regen power or stopping the car. I think FOC will help with regen a lot.
kiwifiat
Posts: 99
Joined: Sat Dec 22, 2018 9:39 pm
Location: Vancouver, Canada
Been thanked: 11 times

Re: Testing FOC for synchronous motor

Post by kiwifiat »

Great progress, congratulations.

We know from the 202kW dyno run of Arlo1's Leaf motor driven Honda CRX over on Endless-Sphere that FOC works extremely well on IPM motors. No doubt it is just a matter of time before the open inverter is performing just as well.
User avatar
johu
Site Admin
Posts: 6714
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 369 times
Been thanked: 1543 times
Contact:

Re: Testing FOC for synchronous motor

Post by johu »

Thanks everyone.

So yes I do consider using FOC also for async motors but thats a low priority now as slip control works well. Depending on the outcome I might split into 2 firmwares, FOC and slip control. Reason being I want to limit the number of parameters.

I will try positive id today. Whichever one revs higher is the correct one.
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
purplespark
Posts: 52
Joined: Fri Feb 15, 2019 10:22 am
Location: United Kingdom

Re: Testing FOC for synchronous motor

Post by purplespark »

Well done Johannes !
Can I just ask about your DC-DC converter - Is it a meanwell ac/dc psu ? I've been looking at the meanwell range
and their dc/dc converters are quite expensive .
User avatar
johu
Site Admin
Posts: 6714
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 369 times
Been thanked: 1543 times
Contact:

Re: Testing FOC for synchronous motor

Post by johu »

Thanks :)
Yes it's AC/DC and they also specify up to 380V DC input. When the battery is full (4.1 Vpc) that's 393V, I hope that's within tolerance.
I will eventually put it somewhere where there is no spray water as it's not water proof
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
Rogue_Ant
Posts: 3
Joined: Thu Jan 03, 2019 6:27 pm

Re: Testing FOC for synchronous motor

Post by Rogue_Ant »

With normal FOC control, Iq's sign is direction of torque production.

Consider the 4-quadrant operation:
Motor direction = forward; Positive Iq = motoring torque.
Motor direction = forward; Negative Iq = regeneration torque.
Motor direction = reverse; Negative Iq = motoring torque.
Motor direction = reverse; Positive Iq = regeneration torque.

An IPM will always want negative Id:
IPM.JPG
johnspark
Posts: 264
Joined: Fri Apr 12, 2019 10:42 pm
Location: Adelaide, South Australia
Has thanked: 59 times
Been thanked: 48 times

Re: Testing FOC for synchronous motor

Post by johnspark »

Meanwell dc supplies are often used in electrical substations so they have a reasonable reliability.
Post Reply