## True FOC: definition and examples

Electric Motors and Controllers
mxlemming   100 W

Posts: 203
Joined: Jul 17 2020 7:56am

### Re: True FOC: definition and examples

everythingisawave wrote:
Apr 06 2021 6:44am
marka-ee wrote:
Apr 06 2021 4:21am
Yes, I guess. So is that really what the FOC is doing, just moving the hal timing a little to compensate for the current lag? Boiling it down to the simple here. Does the ultimate FOC implementation modify the shape of the sine wave being generated?
The 'field weakening' still eludes me. Maybe field weakening involves more than a timing change ( read: phase change ) and actually changes the shape of the output to the motor phase wire.
So in summary: FOC at first approximation is nothing more that optimized hal timing. That I can code and to hell with the vector theory. None of this interests me if it does not increase range or speed measurably.
The modification is done during the PWM generation, in a separate process. The decision on suitable reference currents and voltages is unaffected.

I guess you can consider it as a being able to control timing and magnitude in a very smooth way, although IMHO it's not really possible to fullly understand FOC without vector theory (yes, mental gymnastics needed ). It does increase maximum speed and range, which is why it is defacto standard for higher power machines and servomotors. Cost and development effort is higher for software, sensors etc. although that cost is coming down as an industry trend.
The FOC has no awareness of timing. It takes the angle for timing from the halls and/or observer. FOC and timing/phase are independent.

FOC operates on two orthogonal vectors, id and iq, and since they are orthogonal they do not influence each other. If your timing is wrong, the FOC loop will not know and the only effect is that the magnitude of Vd will increase and the Vq will decrease to maintain the same currents.
The Earth is flat. Flat flat flat. How would transistors work otherwise?

stancecoke   100 kW

Posts: 1403
Joined: Aug 02 2017 2:56pm

### Re: True FOC: definition and examples

everythingisawave wrote:
Apr 06 2021 6:44am
It does increase maximum speed and range
This is right in comparison to simple six step commutation, but not in comparison to the sinusoidal commutation that Kunteng does on their sinewave controllers. There is more than one way, to determine the needed advance angle...

https://www.ti.com/lit/an/slaa699/slaa6 ... e.com%252F
advance angle.JPG (134.46 KiB) Viewed 129 times
mxlemming wrote:
Apr 06 2021 8:32am
FOC and timing/phase are independent.
Yes, this is the trick that the FOC does. You get values in the rotating frame, that are not depending on time.
Nevertheless, the timing is extremly important. You have to know the rotorposition exactly, otherwise FOC can't work. It's in the name already: field oriented control....

regards
stancecoke
Last edited by stancecoke on Apr 06 2021 10:06am, edited 2 times in total.

everythingisawave   100 mW

Posts: 42
Joined: Sep 13 2016 8:01pm

### Re: True FOC: definition and examples

mxlemming wrote:
Apr 06 2021 8:32am
The FOC has no awareness of timing. It takes the angle for timing from the halls and/or observer. FOC and timing/phase are independent.

FOC operates on two orthogonal vectors, id and iq, and since they are orthogonal they do not influence each other. If your timing is wrong, the FOC loop will not know and the only effect is that the magnitude of Vd will increase and the Vq will decrease to maintain the same currents.
Technically by changing the Idq current vector angle you are changing the "timing" (taking this as a mental vehicle in this context), so while the dq part of the loop has no control over the basis vector angle, it does have control over your vector angle relative to the magnet flux.

The word "timing" is so vague though and leads to all these semantic issues, we should really deprecate its use

mxlemming   100 W

Posts: 203
Joined: Jul 17 2020 7:56am

### Re: True FOC: definition and examples

everythingisawave wrote:
Apr 06 2021 9:25am
mxlemming wrote:
Apr 06 2021 8:32am
The FOC has no awareness of timing. It takes the angle for timing from the halls and/or observer. FOC and timing/phase are independent.

FOC operates on two orthogonal vectors, id and iq, and since they are orthogonal they do not influence each other. If your timing is wrong, the FOC loop will not know and the only effect is that the magnitude of Vd will increase and the Vq will decrease to maintain the same currents.
Technically by changing the Idq current vector angle you are changing the "timing" (taking this as a mental vehicle in this context), so while the dq part of the loop has no control over the basis vector angle, it does have control over your vector angle relative to the magnet flux.

The word "timing" is so vague though and leads to all these semantic issues, we should really deprecate its use
While this is true, doing so would trash the point of FOC. The control algorithms would be odd at the least, field weakening and MTPA would become difficult to compute (you'd probably end up realigning your computation with the real rotor angle...)

I don't think it's useful to think about it in terms like this.

Timing = the correlation between the angle your controller thinks the rotor is vs the angle it really is. For 6 step timing is very important since switching at the wrong time wreaks havoc since large pwm voltage with small back emf results in big current spikes. For FOC, there is no discontinuous calculation so its much more forgiving, it just results in poor efficiency.

Actually I found FOC easier to implement than 6 step BLDC and easier to debug. To run phase advance with BLDC you pretty much have to make an angle interpolator or have discontinuous logic to advance by a full step and then delay or... Something complicated that by the time you've done it you might as well find the real angle and do 4 trig transforms like you learnt age 17 at school.
The Earth is flat. Flat flat flat. How would transistors work otherwise?

Posts: 2646
Joined: Apr 25 2014 10:26pm
Location: sausalito cali..up the hill in front of the cruising club.

### Re: True FOC: definition and examples

How likely and soon do you think till a reliable field-weakening program for the Vesc? I need 20% more speed!

Vbruun   100 W

Posts: 154
Joined: Sep 26 2019 8:42am

### Re: True FOC: definition and examples

stancecoke wrote:
Apr 06 2021 1:03am
mxlemming wrote:
Apr 05 2021 5:19pm
By contrast, stancecoke lishui foc is easy to follow but less complete
Hm, it's fully working . But of course some features like field weakening or detection of motor inductance and resistance are not implemented. I don't need this features

It has a user friendly GUI with an up to date wiki to set up your system. It should be usable even for people with no computer skills
And it works with cheap and widely available China hardware, that is used by many european Ebike OEMs like Prophete, Fischer, NCM...

regards
stancecoke

I quite like what you did here and especially the proper ebike features that you implemented (torque sensor, speed limit, assist level selection), but I dislike the hardware. It is quite expensive and not really All that powerful.
What I dream of at night is a board capable of ~25 batt amps and 50v that Will run the firmware you made

stancecoke   100 kW

Posts: 1403
Joined: Aug 02 2017 2:56pm

### Re: True FOC: definition and examples

Vbruun wrote:
Apr 06 2021 1:01pm
~25 batt amps and 50v that Will run the firmware you made
@slipy has build a 12FET version already as far as I know, I don't know, if he has tested it yet.

viewtopic.php?f=30&t=109578

regards
stancecoke

Slipy   10 mW

Posts: 25
Joined: Mar 19 2020 6:22pm

### Re: True FOC: definition and examples

Vbruun wrote:
Apr 06 2021 1:01pm

I quite like what you did here and especially the proper ebike features that you implemented (torque sensor, speed limit, assist level selection), but I dislike the hardware. It is quite expensive and not really All that powerful.
What I dream of at night is a board capable of ~25 batt amps and 50v that Will run the firmware you made
I have 18mos board, not tested yet but smaller version for hailong was builded with using same scheme. My board up to 110v (but i haven't so high voltage mosfets only up to 100v)

marka-ee   10 W

Posts: 87
Joined: Mar 24 2020 5:17pm

### Re: True FOC: definition and examples

Forgive me for simplifying the FOC to just a 'timing' change, but where the code meets the mosfets, isn't that what is exactly happening? You start producing the sine wave a wee bit earlier that before. I was wondering though, do cheap KT controllers do any kind of timing advance at all to even in the grossest way get a little more optimal results?

everythingisawave   100 mW

Posts: 42
Joined: Sep 13 2016 8:01pm

### Re: True FOC: definition and examples

marka-ee wrote:
Apr 07 2021 3:34am
Forgive me for simplifying the FOC to just a 'timing' change, but where the code meets the mosfets, isn't that what is exactly happening? You start producing the sine wave a wee bit earlier that before.
Yes, good point. This is what is happening. When explaining to students I often tell them that aligning the rotor position sensor is akin to adjusting the engine timing, it really helps mechanics and non-EE engineers to understand its importance. Whatever helps you understand:)
Last edited by everythingisawave on Apr 07 2021 10:29am, edited 1 time in total.

stancecoke   100 kW

Posts: 1403
Joined: Aug 02 2017 2:56pm

### Re: True FOC: definition and examples

marka-ee wrote:
Apr 07 2021 3:34am
do cheap KT controllers do any kind of timing advance at all
Yes, I think so. I don't know how the original Kunteng firmware manages it, in the open firmware, we look at the zero crossing of the current on one phase wire and syncronize it with a defined rotor position. The BEMF is strictly depending on the rotor position, so we can shift the voltage vector according to the picture qouted above from the TI paper.

regards
stancecoke