Testing FOC for synchronous motor
- johu
- Site Admin
- Posts: 6713
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 368 times
- Been thanked: 1542 times
- Contact:
Re: Testing FOC for synchronous motor
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.
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
Re: Testing FOC for synchronous motor
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.
-
- Posts: 99
- Joined: Sat Dec 22, 2018 9:39 pm
- Location: Vancouver, Canada
- Been thanked: 11 times
Re: Testing FOC for synchronous motor
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.
- johu
- Site Admin
- Posts: 6713
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 368 times
- Been thanked: 1542 times
- Contact:
Re: Testing FOC for synchronous motor
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%
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
- johu
- Site Admin
- Posts: 6713
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 368 times
- Been thanked: 1542 times
- Contact:
Re: Testing FOC for synchronous motor
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.
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
- johu
- Site Admin
- Posts: 6713
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 368 times
- Been thanked: 1542 times
- Contact:
Re: Testing FOC for synchronous motor
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
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 208 times
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
Re: Testing FOC for synchronous motor
Welcome backjohu 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?

- johu
- Site Admin
- Posts: 6713
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 368 times
- Been thanked: 1542 times
- Contact:
Re: Testing FOC for synchronous motor
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
-
- Posts: 52
- Joined: Fri Feb 15, 2019 10:22 am
- Location: United Kingdom
Re: Testing FOC for synchronous motor
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.
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.
- johu
- Site Admin
- Posts: 6713
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 368 times
- Been thanked: 1542 times
- Contact:
Re: Testing FOC for synchronous motor
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!)
So today I did a successful test drive

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
- johu
- Site Admin
- Posts: 6713
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 368 times
- Been thanked: 1542 times
- Contact:
Re: Testing FOC for synchronous motor
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.
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 253 times
-
- stm32_sine.zip
- (61.65 KiB) Downloaded 247 times
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
-
- Posts: 3562
- 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
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....
Re: Testing FOC for synchronous motor
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.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.
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.
-
- Posts: 3562
- 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
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.
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.
-
- Posts: 99
- Joined: Sat Dec 22, 2018 9:39 pm
- Location: Vancouver, Canada
- Been thanked: 11 times
Re: Testing FOC for synchronous motor
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.
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.
- johu
- Site Admin
- Posts: 6713
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 368 times
- Been thanked: 1542 times
- Contact:
Re: Testing FOC for synchronous motor
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.
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
-
- Posts: 52
- Joined: Fri Feb 15, 2019 10:22 am
- Location: United Kingdom
Re: Testing FOC for synchronous motor
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 .
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 .
- johu
- Site Admin
- Posts: 6713
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 368 times
- Been thanked: 1542 times
- Contact:
Re: Testing FOC for synchronous motor
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

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
Re: Testing FOC for synchronous motor
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:
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:
-
- 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
Meanwell dc supplies are often used in electrical substations so they have a reasonable reliability.
- johu
- Site Admin
- Posts: 6713
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 368 times
- Been thanked: 1542 times
- Contact:
Re: Testing FOC for synchronous motor
Ok, thats very interesting. So motoring in forward works out to regen in backward and vice versa. id always negative, understood.
Any idea why regen became more pronounced with rising speed? Some phase lag perhaps?

Any idea why regen became more pronounced with rising speed? Some phase lag perhaps?
Thats a good sign. I have a limited experience of 3 devices that have been running for quite a while and never failed. As opposed to noname Chinese ones you get on ebay. They failed after 3 months because the main inductor lost its coating

Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
Re: Testing FOC for synchronous motor
If the regen increased, you should see the Iq change accordingly...
On regen, the leg voltages are phase delayed compared to motoring. So, if you have lagging leg voltages as RPMs rise, then that will reducing motoring effort (when motoring is desired), and increase regen effort (when regen is desired).
-
- Posts: 3562
- 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
So like i told in the beginning when i tested Leaf motor with old code, you have to provide a bit of positive excitation (throttle) to maintain 0 torque. If you release throttle you get humongous torque at low RPM. Er... it sounds strange, but magnet vector is allways pulling back on the rotor.Rogue_Ant wrote: ↑Fri Jul 12, 2019 10:16 amIf the regen increased, you should see the Iq change accordingly...
On regen, the leg voltages are phase delayed compared to motoring. So, if you have lagging leg voltages as RPMs rise, then that will reducing motoring effort (when motoring is desired), and increase regen effort (when regen is desired).
Does this make IPM any less efficient vs ACIM in case of road glide?
We need to implement 0 torque mode though in order to be able to shift normally.
- johu
- Site Admin
- Posts: 6713
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 368 times
- Been thanked: 1542 times
- Contact:
Re: Testing FOC for synchronous motor
Now I'm starting to wonder if there is some kind of asymmetry built into the leaf motor. In one direction I can spin up to almost any speed (off the scale of the 8krpm rev counter). Now if I only change the sign of the desired iq it does spin in the other direction as expected but it doesn't spin as fast and has a tendency to trip out. It could be the motor spins in the other direction when in the Leaf.
So, anyone ever experienced a preferred spinning direction with the Leaf motor?
So, anyone ever experienced a preferred spinning direction with the Leaf motor?
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
-
- Posts: 3562
- 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
Yes i had the same experience with Pauls controler, but at 100Vdc. Can you try changing the resolver wires and phases and then spin it in another direction with positive Iq? Maybe it is asymetrical only when progressing not reversing. I remember someone said IPM motors effect is similar to ACIM slip in one direction.johu wrote: ↑Fri Jul 12, 2019 4:14 pm Now I'm starting to wonder if there is some kind of asymmetry built into the leaf motor. In one direction I can spin up to almost any speed (off the scale of the 8krpm rev counter). Now if I only change the sign of the desired iq it does spin in the other direction as expected but it doesn't spin as fast and has a tendency to trip out. It could be the motor spins in the other direction when in the Leaf.
So, anyone ever experienced a preferred spinning direction with the Leaf motor?