Halved current during field weakening

Post Reply
User avatar
bexander
Posts: 834
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Halved current during field weakening

Post by bexander »

My setup using a Prius Gen 3 inverter with a Toyota/Lexus MGR gives poor performance when entering field weakening.
tom3141 have the same issue with the MGR but with a Prius Gen 2 inverter.

As I'm not satisfied with this I have done more testing and decided to measure the power output to verify what I "feel" during acceleration.
First of all, using latest SW, 5.06 and attached are my latest parameters:
Prius_MGR_FW5_06FOC_2021_06_05.json
(1.32 KiB) Downloaded 144 times
Adjusted "throtcur" to 1 (2) to get a smoother result when flooring the accelerator pedal as using 2 seem to give me slight wheelspin...
udc, speed on left and idc on right
udc, speed on left and idc on right
To double check this result I logged battery current and voltage from BMS, showing very similar results.
Current is a bit unstable around 30A as the BMS current sensor changes measuring range at 30A and I have some calibration work to do here...
voltage and speed on left and battety current on right
voltage and speed on left and battety current on right
Also, for fun, calculated the battery power output from above.
power on left and speed on right
power on left and speed on right
This picture show what I expect in terms of motor power when entering FW, slowly decaying power as speed increases.
BorgWarner-HVH250-electric-motor-power-curve.png
To my understanding, the above result can not be explained by motor behavior but rather the inverter limiting the current to about half when entering FW.
As I have only seen reports of this behaviour from the MGR I'm thinking that it could be something with the missmatch between motor pole pairs (4) and resolver pole pairs (2) which is unusual so I started looking around in the software to see if I could find anything obvious.
With limited understanding of the inner workings of the SW I find this line of code suspicious, found in "pwmgeneration-foc.cpp"

Code: Select all

fwController.SetMinMaxY(-50 * Param::Get(Param::throtcur), 0); //allow 50% of max current for extra field weakening
Could this line be limiting the current output in FW? But if this is the case, everyone using FOC SW should have the same issue.

If someone with another motor could do a similar test using the 5.06 SW and just doing a plot from web interface to conclude if only the MGR have this behavior it would be very helpful.

EDIT: Added better graphs for BMS data
User avatar
johu
Site Admin
Posts: 5682
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 153 times
Been thanked: 960 times
Contact:

Re: Halved current during field weakening

Post by johu »

Yes the additional FW current is indeed limited to half throtcur. This decision was arbitrary and could be made a parameter. It also means by increasing throtcur you also increase possible FW current. If you can compile yourself you can try to change it from 50 to 100 or so.

That said the steep drop in idc might rather indicate the inverter running out of voltage again, so changing this might not have an effect.
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
MattsAwesomeStuff
Posts: 871
Joined: Fri Apr 26, 2019 5:40 pm
Has thanked: 278 times
Been thanked: 165 times

Re: Halved current during field weakening

Post by MattsAwesomeStuff »

johu wrote: Sat Jun 05, 2021 9:45 amYes the additional FW current is indeed limited to half throtcur. This decision was arbitrary and could be made a parameter.
So, dumb question since I just barely have a concept of how this works...

Why instead of a sudden halving of current, wouldn't it be designed to... I dunno, like, gradually transition into field weakening, following some kind of "fastest way to reach a higher speed" optimization?

Or is that a nonsensical question because of what field weakening is?
User avatar
johu
Site Admin
Posts: 5682
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 153 times
Been thanked: 960 times
Contact:

Re: Halved current during field weakening

Post by johu »

The step surprises me as well, I would expect something more gradual. The available voltage is divided up between d and q component. If the d component takes up the majority (d component = field weakening) then theres not much left for q component (which produces the torque)
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
User avatar
bexander
Posts: 834
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: Halved current during field weakening

Post by bexander »

Here is a plot with "throtcur" set to 2
udc, speed on left and idc on right
udc, speed on left and idc on right
I get basically the same currents as with "throtcur" set to 1 both with and without field weakening. But there must be some difference becuase I can clearly feel a harder acceleration with "throtcur" set to 2. So I'm a bit confused to what "throtcur" really does?

I don't understand what you mean by
johu wrote: Sat Jun 05, 2021 9:45 am That said the steep drop in idc might rather indicate the inverter running out of voltage again, so changing this might not have an effect.
My understanding is that the controller should output the requested torque by driving a certain current through the motor and this up until the difference between supply (battery) voltage and back emf no longer allows the desired current to flow. This is when you start weakening the field to decrease the back emf and hence still be able to supply some current to the motor, continuing the acceleration but with reduced torque. However this is done by changing the angle between id and iq and should not have any need for reducing the motor current amplitudes.
This is done by adding id and should not need to reduce battery current amplitude.

I do not know how to compile the code but might be a good idea to learn to do this...
In the meantime, I would appreciate if someone else could make a similar udc, idc and speed plot from there setup.

EDIT: Corrections made.
User avatar
bexander
Posts: 834
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: Halved current during field weakening

Post by bexander »

Trying to figure out how to compile the SW and started by looking in the readme.md but it does not make sens after I have installed the arm-none-eabi toolchain.
Where can I find more detailed information regarding,
"The only external depedency is libopencm3 which I forked. You can download and build this dependency by typing

make get-deps

Now you can compile stm32-sine by typing

make

or

CONTROL=FOC make"?
In what directory do I run this and do I need to make settings to the toolchain first?
User avatar
johu
Site Admin
Posts: 5682
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 153 times
Been thanked: 960 times
Contact:

Re: Halved current during field weakening

Post by johu »

You run these commands in the directory you cloned, e.g. /home/user/stm32-sine
There is no such thing as toolchain settings, just arm-none-eabi-gcc (g++, ld and so on) must be in PATH
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
User avatar
bexander
Posts: 834
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: Halved current during field weakening

Post by bexander »

I got it working.
Thank you, johu!

You might add to the readme that after you run "sudo apt-get install git gcc-arm-none-eabi" you need to use git to clone the repository, i.e.
git clone https://github.com/jsphuebner/stm32-sine.git and then run the rest of the commands in the cloned directory.
Not obvious to me but relized it after what you wrote above.

Now, will try to test my newly compiled 100% FW current SW when possible and report back.

Another question regarding how to compile, how do I change the version of the SW, i.e. what is displayed in the web interface under "version"?
User avatar
bexander
Posts: 834
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: Halved current during field weakening

Post by bexander »

Did a quick test and unfortunately no change.
udc, speed on left axis and idc on right axis
udc, speed on left axis and idc on right axis
Either I screw the change/compile up or this is not the cause which is likely since changeing "throtcur" had no effect on FW current.
Will keep looking into it.
User avatar
bexander
Posts: 834
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: Halved current during field weakening

Post by bexander »

Had a very good discussion with a colleague today.
He implied that the field weakening probably is to weak, i.e. to little Id compared to motor speed. This results in the motor bottoms out on speed and fails to produce more torque.

There are or was two parameters for FW tuning, fwkp and dmargin. Dmargin is no longer available.
johu explains them a bit more here: viewtopic.php?p=22577#p22577 and also some tests done by tom3141 regarding these.
I'm thinking that maybe he didn't change them enough and perhaps the limit to half "throtcur" also plays a part here, i.e. limiting available current.

I will test to change fwkp with throtcur limit removed and see if I get any change at all.
User avatar
celeron55
Posts: 774
Joined: Thu Jul 04, 2019 3:04 pm
Location: Finland
Has thanked: 27 times
Been thanked: 110 times
Contact:

Re: Halved current during field weakening

Post by celeron55 »

When I look at those graphs the question comes to mind: What would happen if there was no field weakening at all? I think it might be useful to disable it completely and collect a graph for comparison. I don't even know what to expect, and for me that would already be enough reason to have it. Of course the other extreme will be equally valuable.
User avatar
ZooKeeper
Posts: 507
Joined: Mon Mar 30, 2020 10:23 pm
Location: USA

Re: Halved current during field weakening

Post by ZooKeeper »

celeron55 wrote: Thu Jun 10, 2021 7:14 pm When I look at those graphs the question comes to mind: What would happen if there was no field weakening at all? I think it might be useful to disable it completely and collect a graph for comparison. I don't even know what to expect, and for me that would already be enough reason to have it. Of course the other extreme will be equally valuable.
Albeit with a minuscule relative understand of it all, I wondered the same!
Huebner VCU controlling a Gen2 Prius Inverter powering an MGR
"Talent is equally distributed but opportunity is not." - Leila Janah
User avatar
bexander
Posts: 834
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: Halved current during field weakening

Post by bexander »

ZooKeeper wrote: Thu Jun 10, 2021 8:19 pm
celeron55 wrote: Thu Jun 10, 2021 7:14 pm When I look at those graphs the question comes to mind: What would happen if there was no field weakening at all? I think it might be useful to disable it completely and collect a graph for comparison. I don't even know what to expect, and for me that would already be enough reason to have it. Of course the other extreme will be equally valuable.
Albeit with a minuscule relative understand of it all, I wondered the same!
With no field weakening you would get not torque and hence no acceleration once you reach the base speed. In my plots above it looks like my base speed with my current battery is 2400rpm, so FW is definitely needed if you want to go faster than 36km/h in my car.
User avatar
bexander
Posts: 834
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: Halved current during field weakening

Post by bexander »

First some plots when varying fwkp.
id, iq on left axis, idc on right, fwkp -100
id, iq on left axis, idc on right, fwkp -100
id, iq on left axis, idc on right, fwkp -200
id, iq on left axis, idc on right, fwkp -200
id, iq on left axis, idc on right, fwkp -300
id, iq on left axis, idc on right, fwkp -300
id, iq on left axis, idc on right, fwkp -50
id, iq on left axis, idc on right, fwkp -50
id, iq on left axis, idc on right, fwkp -500
id, iq on left axis, idc on right, fwkp -500
Id goes closer to zero when I expect it to go more negative when entering FW?
Changeing fwkp seem to have no effect on this behavior or the magnitud of Id under FW.
When setting fwkp to -50 I get unstable regen during FW.
Even at -100 it is a bit unstable during regen in FW. -300 work best of the tested values when looking at regen in FW. There are still some unwanted regen going on in FW but less.

Now tow plots with added Ud and Uq.
id, iq, idc on left axis, ud, uq on right, fwkp -300
id, iq, idc on left axis, ud, uq on right, fwkp -300
id, iq, idc on left axis, ud, uq on right, fwkp -300
id, iq, idc on left axis, ud, uq on right, fwkp -300
On the last plot there is a strong unwanted regen period at time stamp 1780-1820.

Back to the main issue and there are definitely some unexpected behavior regarding Id and Ud.
I expect Id to keep going more negative when entering FW but instead it makes a step closer to zero and as a result, to weak FW and hence reduced torque. Iq seem to do what I expect.
Ud seem to somehow max out. Are there a limit to Ud and Uq? I guess, I need to further look into the FOC SW. I'm thinking, Ud and Uq are calculated values.
There are also noticable more noise on Id when in FW as compared to before FW.

Also strange with the odd behavior of Id when in regen, time stamp 1780-1820 in last plot. Unwanated regen might have the same cause as with the reduced current/power when in FW, or not?
At this moment I have raised more questions then I have answered, but will keep looking into this.

EDIT: Added conclusions, or more questions if you will...
User avatar
johu
Site Admin
Posts: 5682
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 153 times
Been thanked: 960 times
Contact:

Re: Halved current during field weakening

Post by johu »

Strange, it seems to run out of voltage to create sufficient id... The syncadv parameter is gone, can you try varying the "10" in pwmgeneration-foc.cpp:263?
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
User avatar
bexander
Posts: 834
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: Halved current during field weakening

Post by bexander »

johu wrote: Sat Jun 12, 2021 5:42 am Strange, it seems to run out of voltage to create sufficient id... The syncadv parameter is gone, can you try varying the "10" in pwmgeneration-foc.cpp:263?
I can try setting it to 20 and 5.
One question when compiling SW. How do I change the "version" displayed in the web interface. I found "#define VER 5.06.R" in param_prj.h but does not seem to be included when I compile the SW. Do I need any flags when doing "make" to force it to include param_prj.h?
User avatar
bexander
Posts: 834
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: Halved current during field weakening

Post by bexander »

Managed to test with "syncadv" chaged to 20.
id, iq, idc on left axis ud, uq on right axis, fwkp -100
id, iq, idc on left axis ud, uq on right axis, fwkp -100
id, iq, idc on left axis ud, uq on right axis, fwkp -300
id, iq, idc on left axis ud, uq on right axis, fwkp -300
id, iq, idc on left axis ud, uq on right axis, fwkp -500
id, iq, idc on left axis ud, uq on right axis, fwkp -500
id, iq on left axis idc on right axis, fwkp -500
id, iq on left axis idc on right axis, fwkp -500
Changing fwkp seem to have no effect but increasing the syncadv definitely gave an increase of current during acceleration. Did also seem to increase low speed stuttering and unwanted regen, but still positive effect on acceleration...
Idc peak goes to 45A (40A before) and during FW to 30A (20A before).

Was going to test "syncadv" set to 5 as well but managed to not copy that build over to the laptop and now there are to much traffic. I think 20 seem to give some good result. I can test with 5 tomorrow if still useful?
User avatar
bexander
Posts: 834
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: Halved current during field weakening

Post by bexander »

Just to be clear, this is what I changed:
From "int syncadv = (frq - FP_FROMINT(20)) * 10;"
To "int syncadv = (frq - FP_FROMINT(20)) * 20;"

Just speculating, but could this have anything to do with the fact that the MGR is an odd motor by using 4 motor pole pairs and 2 resolver pole pairs?
User avatar
celeron55
Posts: 774
Joined: Thu Jul 04, 2019 3:04 pm
Location: Finland
Has thanked: 27 times
Been thanked: 110 times
Contact:

Re: Halved current during field weakening

Post by celeron55 »

With that change it's clearly accepting more current in FW. Almost 50% more? Can you go even further?
User avatar
bexander
Posts: 834
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: Halved current during field weakening

Post by bexander »

celeron55 wrote: Sat Jun 12, 2021 11:32 am With that change it's clearly accepting more current in FW. Almost 50% more? Can you go even further?
One could proably go even further but changing this also increases low speed stuttering and also results in increased unwanted regeneration when in FW so not the solution but a indication that this is a good place to keep diggin into.
User avatar
bexander
Posts: 834
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: Halved current during field weakening

Post by bexander »

When looking at the code below from the pwmgeneration-foc.cpp I relized that the low speed stuttering (more info here: viewtopic.php?f=7&t=1546) I'm experiencing at 2-3km/h is probably also created by this.
When increasing syncadv I got more low speed stuttering and when doing the math I get the following:

syncadv can't be negative so for a frq from 0-20, syncadv is 0.
With a polePairRatio of 2 the rotorFrequency of 10Hz results in frq=20 and hence start of syncadv.
10Hz rotorFrequency equals 10*60/4 = 150rpm and in my car that is equal two 150/65,8 = 2,3km/h.

With a polePairRatio of 2 the rotorFrequency of 10Hz results in frq=20 and hence start of syncadv.
10Hz rotorFrequency equals 10*60/2 = 300 and in my car that is equal two 300/65,8 = 4,6km/h.
rotorFrequency is not actual rotor frequency but rather resolver frequency, so may not be related but I got an increase in this stuttering with increased syncadv.

So my theory at the moment is that these two faults may have the same cause.
Might be a good idea to perhaps measure this or do something to get a better picture of what is going on.
I think less syncadv at low speed and more at high speed would be beneficial but maybe not only speed driving this but also torque demand as it also seem to effect regen or unwanted negative torque in FW.

Code: Select all

void PwmGeneration::CalcNextAngleSync(int dir)
{
   if (Encoder::SeenNorthSignal())
   {
      uint16_t syncOfs = Param::GetInt(Param::syncofs);
      uint16_t rotorAngle = Encoder::GetRotorAngle();
      int syncadv = (frq - FP_FROMINT(20)) * 10;
      syncadv = MAX(0, syncadv);

      //Compensate rotor movement that happened between sampling and processing
      syncOfs += FP_TOINT(dir * syncadv);

      angle = polePairRatio * rotorAngle + syncOfs;
      frq = polePairRatio * Encoder::GetRotorFrequency();
   }
   else
   {
      frq = fslip;
      angle += dir * FRQ_TO_ANGLE(fslip);
   }
}
EDIT: my math is incorrect
User avatar
johu
Site Admin
Posts: 5682
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 153 times
Been thanked: 960 times
Contact:

Re: Halved current during field weakening

Post by johu »

Yes your code change was correct. And yes syncadv will introduce some speed dependent variation of id/iq distribution. It might well be that syncadv is correct (it is NOT motor dependent but depends on the time between sampling angle and actually calculating the next dutycycles). So then the id/iq distribution created by MTPA could not be appropriate for the motor.
I'm currently not sure what to vary. The relevant constant in foc.cpp are fluxLinkage and lqminusld. Also the dependent constants lqminusldSquaredBs10 and fluxLinkage2 (squared) must be recalculated accordingly.
lqminusldSquaredBs10 = lqminusld² * 1024

EDIT: thinking about it again, the pole pair ratio could matter to syncadv. Twists my brain a bit ;)
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
User avatar
bexander
Posts: 834
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: Halved current during field weakening

Post by bexander »

Trying to fully understand the syncadv first and moving from there.

Please, where does the 20 come from or in other words why is frq below 20 ignored in terms of syncadv?
int syncadv = (frq - FP_FROMINT(20)) * 10;"

Also, found here viewtopic.php?p=3964#p3964, "So at 8.8kHz the value is about 80µs in the past.". Is this true no matter what pwm frequency I use? I'm thinking that the 8.8kHz is the internal loop frequency or is it the pwm frequency?

To my understanding the syncadv should compensate for the 80us time it takes to sample, calculate and output value so the value output is in sync with the motors actual position.
User avatar
johu
Site Admin
Posts: 5682
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 153 times
Been thanked: 960 times
Contact:

Re: Halved current during field weakening

Post by johu »

bexander wrote: Sun Jun 13, 2021 5:48 am To my understanding the syncadv should compensate for the 80us time it takes to sample, calculate and output value so the value output is in sync with the motors actual position.
Yes exactly. Loop frequency is fixed at 8.8 kHz nowerdays, independent of PWM frequency.

The "20" was a try to eliminate low speed stuttering, so syncadv below 20 Hz. From there it rises linearly as I didn't want any step in there.
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
User avatar
celeron55
Posts: 774
Joined: Thu Jul 04, 2019 3:04 pm
Location: Finland
Has thanked: 27 times
Been thanked: 110 times
Contact:

Re: Halved current during field weakening

Post by celeron55 »

So, when you increase syncadv to a value higher than it actually should be, it will (rather uncontrollably, but nevertheless) move the field earlier in time, effectively causing more Id and less Iq, i.e. more field weakening. Is this correct?

So what needs to be figured out is how the fluxLinkage and lqminusld constants (with the dependent constants) should be altered if one wants more Id and less Iq.

EDIT:

Code: Select all

static const s32fp lqminusldSquaredBs10 = FP_FROMFLT(0.01722); //additional 10-bit left shift because otherwise it can't be represented
static const s32fp lqminusld = FP_FROMFLT(0.0058);
Why isn't lqminusldSquaredBs10 = lqminusld^2? It seems to be the value of lqminusld^2 / 2, i.e. half the correct value. My calculator is telling me lqminusldSquaredBs10 should be 0.03445, not 0.01722. 10-bit left shift equals multiplying by 1024, right?

Making that change will cause slightly less Id and slightly more Iq, so it obviously isn't a solution to this problem though.

For the actual MGR performance problem at hand, I would maybe try to increase the lqminusld value and see what happens.
Post Reply