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.
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:
Derivation of the derived base values :
The time base is the time required to rotate through radians at the rated electrical angular speed. In a per-unit system the per-unit value of the time variable is defined as:
This per-unit normalization relates actual time to the electrical rotation period. For example, in the motor dynamic equations the differential operator becomes:
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.
PI controller in the actual domain : In the continuous-time domain the transfer function of a PI controller is:
where is the proportional gain and is the integral gain. After discretization (for example by the forward Euler method):
where is the sampling period and is the output control variable.
Per-unit PI controller : Dividing the input error and the output by their base values and gives the per-unit values and . The sampling period is normalized at the same time:
Dividing both sides of the original PI equation by and substituting the per-unit quantities:
Defining the per-unit proportional gain and integral gain:
Note that . The per-unit PI controller can therefore be written as:
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 . 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.
Consider the flux linkage equations of a permanent magnet synchronous motor in the reference frame:
The actual values are all dimensional physical quantities. Introducing per-unit normalization:
Dividing both sides of the actual equations by :
Substituting the per-unit quantities:
Noting that , we obtain . Therefore:
The per-unit flux observer equations are finally obtained as:
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.
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 with a resolution of . 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 :
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 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 .
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 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 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 , the Q15 format can be used without overflow.
Per-unit normalization and fixed-point representation are often combined: all physical quantities are first normalized so that their ranges concentrate between , and are then represented as Q15 or Q31 fixed-point numbers. This combination has the following advantages:
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.