National High-Tech Enterprise IEC 61000 EMC · IEC 60730 Class B · RoHS ISO 9001 certified Jinhua, Zhejiang · around 200 staff · 25 in R&D
TECHNICAL NOTE 16 / 22

FOC Motor Control - Per-Unit and Fixed-Point Arithmetic

Sailike R&DFOC technical notes 中文原文

In embedded motor control systems, physical quantities usually take part in the computation as per-unit (PU) values or fixed-point numbers, so that the algorithms are simplified and numerical stability and computational efficiency are improved. This chapter systematically describes the basic principles of per-unit normalization and of fixed-point arithmetic, their derivations, and their engineering implementation.

a. Basic concepts of per-unit normalization

Per-unit normalization divides a physical quantity by a selected base value and turns it into a dimensionless relative value. Per-unit values remove differences in system rating and parameters, decoupling the controller design from concrete hardware parameters and making analysis and porting easier.

Selection of base values : For permanent magnet synchronous motor control, base values are usually selected for the following physical quantities:

  • Voltage base Ub : usually the DC bus voltage Udc or the peak rated output phase voltage of the inverter.
  • Current base Ib : usually the peak rated motor current or the output current limit of the controller.
  • Frequency base fb : usually the rated electrical frequency of the motor frated , with the corresponding angular frequency base ωb=2πfb .

Derivation of the derived base values :

  • Impedance base Zb=UbIb
  • Inductance base Lb=Zbωb=UbIbωb
  • Flux linkage base ψb=Ubωb
  • Time base tb=1ωb

b. Physical meaning of the time base 1/ωb

The time base tb=1/ωb is the time required to rotate through 1 radians at the rated electrical angular speed. In a per-unit system the per-unit value of the time variable t is defined as:

tpu=ttb=ωbt

This per-unit normalization relates actual time to the electrical rotation period. For example, in the motor dynamic equations the differential operator ddt becomes:

ddt=ωbddtpu

Consequently, in the per-unit differential equations the time constants, inductances, resistances and other parameters all appear in normalized form, which facilitates numerical computation and controller design.

c. Per-unit normalization of the PI controller

PI controller in the actual domain : In the continuous-time domain the transfer function of a PI controller is:

G(s)=Kp+Kis

where Kp is the proportional gain and Ki is the integral gain. After discretization (for example by the forward Euler method):

u(k)=Kpe(k)+KiTs∑i=0ke(i)

where Ts is the sampling period and u(k) is the output control variable.

Per-unit PI controller : Dividing the input error e and the output u by their base values Eb and Ub gives the per-unit values epu and upu . The sampling period is normalized at the same time:

Ts,pu=Tstb=ωbTs

Dividing both sides of the original PI equation by Ub and substituting the per-unit quantities:

upu(k)=KpUbEbepu(k)+KiTsUbEb∑i=0kepu(i)

Defining the per-unit proportional gain and integral gain:

Kp,pu=KpUbEb,Ki,pu=KiTsUbEb=KitbUbEb·Ts,pu

Note that KiTs=Ki·tb·Ts,pu . The per-unit PI controller can therefore be written as:

upu(k)=Kp,puepu(k)+Ki,pu∑i=0kepu(i)

This form is identical to the original PI form, but the gain coefficients are now dimensionless and the per-unit sampling period is implicit in Ki,pu . In practice the per-unit gains are often designed directly and the actual gains are then back-calculated from the base values, which simplifies parameter tuning and porting.

d. Per-unit normalization of the nonlinear flux observer

Consider the flux linkage equations of a permanent magnet synchronous motor in the αβ reference frame:

ψα=∫(uα–Riα)dt,ψβ=∫(uβ–Riβ)dt

The actual values are all dimensional physical quantities. Introducing per-unit normalization:

  • Per-unit voltage upu=u/Ub
  • Per-unit current ipu=i/Ib
  • Per-unit flux linkage ψpu=ψ/ψb , where ψb=Ub/ωb
  • Per-unit resistance Rpu=R/Zb , where Zb=Ub/Ib
  • Per-unit normalization of time: dt=tbdtpu , and tb=1/ωb

Dividing both sides of the actual equations by ψb :

ψαψb=1ψb∫(uα–Riα)dt

Substituting the per-unit quantities:

ψα,pu=1Ub/ωb∫(Ubuα,pu–ZbRpu·Ibiα,pu)·tbdtpu

Noting that Zb=Ub/Ib , we obtain ZbRpuIb=RpuUb . Therefore:

ψα,pu=ωbUb∫Ub(uα,pu–Rpuiα,pu)·1ωbdtpu=∫(uα,pu–Rpuiα,pu)dtpu

The per-unit flux observer equations are finally obtained as:

ψα,pu=∫(uα,pu–Rpuiα,pu)dtpu,ψβ,pu=∫(uβ,pu–Rpuiβ,pu)dtpu

This form is exactly the same as the original equations, but all variables are per-unit values and the integration runs over per-unit time. This result follows from the appropriate choice of base values, which keeps the per-unit equations compact and easy to implement in a digital controller.

e. Fixed-point principles and the Q format

Fixed-point representation expresses real numbers with integers and manages precision and range by an agreed position of the binary point (the Q format). In motor control, fixed-point arithmetic avoids the high cost and low efficiency of a floating-point unit and suits resource-constrained microcontrollers.

Q format representation : A number in Qm.n format has m integer bits and n fractional bits, m+n bits in total (usually including the sign bit). For example, the Q15 format (1 sign bit, 15 fractional bits) covers the range [−1,1−2−15] with a resolution of 2−15 . In the macro definitions provided by the user, Q0 to Q31 denote the number of fractional bits (that is, the Q format), where Q0 is a pure integer and Q15 is the commonly used Q1.15 format.

Fixed-point arithmetic rules :

  • Addition and subtraction : Numbers with the same Q format can be added or subtracted directly; different Q formats must first be aligned (shifted).
  • Multiplication : Multiplying two Qn numbers yields a Q(2n) result, which usually has to be shifted right by n bits to return to the Qn format and prevent overflow.
  • Division : Dividing two Qn numbers requires shifting the dividend left by n bits before dividing by the divisor, so that the result is in Qn format.
  • Square root and square : These can be implemented by Newton iteration or by a lookup table; the Q format of the input and the output must be handled with care.

f. Implementation of fixed-point arithmetic

1\. Conversion macros

#define F2Q(f, Qn) ((int32_t)((f) * (1 << (Qn)))) // float to fixed point #define Q2F(q, Qn) ((float)(q) / (float)(1 << (Qn))) // fixed point to float

Example: converting the floating-point value 0.5 to Q15 format

int32_t q15_val = F2Q(0.5, 15); // 0.5 * 32768 = 16384

2\. Shift macros

#define QML(q, QnLift) ((q) << (QnLift)) // left shift (higher precision) #define QMR(q, QnRight) ((q) >> (QnRight)) // right shift (lower precision)

Used for Q format adjustment or for multiplying and dividing by powers of 2 .

3\. Addition and subtraction macros

#define QAdd(q1, q2) ((q1) + (q2)) #define QDec(q1, q2) ((q1) - (q2))

Both operands must have the same Q format.

4\. Multiplication macro

#define QMul(q1, q2, Qn) (((q1) * (q2)) >> (Qn))

Qn is the Q format required for the result (usually the Q format of the operands), because multiplying two Qn numbers gives Q(2n) and shifting right by n bits restores Qn. Example: computing the product of a=0.3,b=0.4 in Q15 format

int32_t a = F2Q(0.3, 15); // 9830 int32_t b = F2Q(0.4, 15); // 13107 int32_t c = QMul(a, b, 15); // (9830*13107)>>15 ≈ 0.12 * 32768 ≈ 3932, correct

5\. Division macro

#define QDiv(q1, q2, Qn) (((q1) << (Qn)) / (q2))

The dividend is shifted left by Qn bits so that the result is in Qn format. The divisor must not be zero. Example: computing a=0.5/0.2 in Q15

int32_t a = F2Q(0.5, 15); // 16384 int32_t b = F2Q(0.2, 15); // 6554 int32_t c = QDiv(a, b, 15); // (16384<<15)/6554 ≈ 16384*2.5=40960, that is 2.5*32768=81920? Check: 16384<<15=536870912, divided by 6554 ≈ 81920, 81920/32768=2.5, correct.

6\. Square and square root Squaring can use the multiplication macro directly:

int32_t square = QMul(x, x, Qn); // result is Qn

Square roots are usually computed by Newton iteration, assuming the input is in Qn format and the output is also in Qn format. For example, a Q15 square root:

int32_t sqrt_q15(int32_t x) { if (x <= 0) return 0; int32_t root = x; for (int i = 0; i < 8; i++) { root = QAdd(root, QDiv(x, root, 15)) >> 1; // (root + x/root) / 2 } return root; }

Note that the division macro must preserve sufficient result precision and that the number of iterations must be large enough to converge.

7\. Use in actual programs In motor control all physical quantities are converted to fixed-point representation, for example in the current loop:

// assume the current error is in Q15 format and the proportional gain Kp is in Q15 int32_t err = F2Q(0.1, 15); // per-unit error 0.1 int32_t Kp = F2Q(0.5, 15); // proportional gain 0.5 int32_t output = QMul(Kp, err, 15); // output in Q15

By designing the base values so that all variables stay within [−1,1) , the Q15 format can be used without overflow.

g. Combining per-unit normalization with fixed-point arithmetic

Per-unit normalization and fixed-point representation are often combined: all physical quantities are first normalized so that their ranges concentrate between [−1,1) , and are then represented as Q15 or Q31 fixed-point numbers. This combination has the following advantages:

  • Predictable numerical range : Per-unit normalization guarantees that physical quantities do not exceed their base values under rated conditions, so per-unit magnitudes are usually ≤1 , which suits coverage of the whole range by the Q15 format.
  • Computationally efficient : Fixed-point multiplication and division replace floating-point operations with shifts and are extremely fast.
  • Controllable precision : The Q format is chosen from the actual dynamic range, balancing precision against the risk of overflow.

Conclusion

Per-unit normalization simplifies the control equations and decouples the controller design from the hardware; fixed-point representation provides an efficient computation method for embedded platforms. The combination of the two is an indispensable basic technique in motor control engineering. Understanding base value selection, the derivation of per-unit equations and the rules of fixed-point arithmetic is of great significance for developing stable and reliable sensorless control systems.

This article was compiled by AI and proofread manually.