How to set encoder offset
Motor control often relies on using the rotating dqreference frame. The rotating dqreference frame for permanent magnet synchronous machines (PMSM) is aligned with the daxis and relies on the knowledge of the angle \(\vartheta_{el}\) between daxis and \(\alpha\) axis. The angle \(\vartheta_{el}\) can be measured or estimated and is used in the transformation, e.g., using Coordinate Transformation. Additionally, machine models in dqframe assume this alignment. Several different encoder technologies exist, e.g., Incremental Encoder. The encoder reference (the zeropoint of the encoder) is not necessarily aligned with the daxis of the machine.
This alignment is shown in fig. Fig. 37 with the angle \(\vartheta_m\) between the \(\alpha\)axis and the daxis and the mechanical encoder offset \(\vartheta_{m,offset}\) between the \(\alpha\)axis of the machine and the encoder reference. Note that a machine with \(p\) pole pairs has \(p\) different daxis (each with a positive and negative pole). While the encoder measures the mechanical angle \(\vartheta_m\) of the machine , the electrical angle \(\vartheta_{el}\) is required for the dqtransformations. The electrical angle is calculated using the modulo operation:
With the encoder offset in the electrical radian \(\vartheta_{el,offset}\) assuming \(\vartheta_m\) is measured in radian and one mechanical rotation is equal to \(\vartheta_m=2\pi\). The usage of the offset \(\vartheta_{el,offset}\) is assumed in the subsequent sections. The following methods for determining the offset are commonly used for PMSM:
Constant current in the aphase
The linked flux of the \(a\)phase winding is aligned with the \(\alpha\)axis of the machine. The main idea in this offset estimation is to drive a constant current through the \(a\)phase of the machine, which generates a linked magnetic flux leading the daxis with the permanent magnet to mechanically turn and align with the \(\alpha\)axis of the machine. This can be achieved by stepping the duty cycle of the \(a\)phase from zero to an arbitrary duty cycle. The duty cycle is kept on its value and the current angle \(\vartheta_{el}\) is set as \(\vartheta_{el,offset}\). Since the method does not use a closedloop current control, a duty cycle has to be chosen that does not lead to aphase current above the rated current of the machine. However, the duty cycle has to be sufficiently large to move the rotor reliably into the \(\alpha\) axis. This method is quick but results in suboptimal alignment, requires manual tuning of the duty cycle, and is often unreliable in the laboratory. Additionally, \(L_d=L_q\) is assumed.


The figure left showcases the relationship between the current angle \(\beta\) and machine torque with the torque generated by the reluctance effect \(T_{Rel}\), the torque generated by the linked flux of the permanent magnet \(T_{PM}\) and the sum of both torque components \(T_{I}\) (the inner torque of the machine). The current angle \(\beta\) describes the angle between the qaxis and the space vector of the stator current \(\underline{i}=i_d + ji_q\) (with the imaginary unit \(j\)). Therefore, \(\beta=\arctan{\big( \frac{i_d}{i_q} \big) }\). For machines with \(L_d=L_q\) only the blue torque curve applies. Therefore, current in the \(a\)phase prompts the rotor to move into the \(\alpha\)axis aligning the peak of the torque with the daxis. If \(L_d \neq L_q\), the blue curve is superimposed with the red curve yielding the resulting torque (black line). Thus, current in the \(a\)phase does not align the \(\alpha\)axis with the daxis but with an angle that is skewed depending on the specific values of the inductances \(L_d\), \(L_q\), and flux linkage of the permanent magnet \(\psi_{PM}\). The method for determining the encoder offset \(\vartheta_{el,offset}\) must not be used on a machine with \(L_d \neq L_q\).
Quick & easy
Assumes \(L_d = L_q\)
Manual estimation of endvalue for duty cycle step (high enough to move the rotor, not too high to damage machine)
No closedloop control to prevent exceeding the rated current of the machine
Notorque by dcurrent
A possible alternative for driving current through the \(a\)phase of the machine is to ensure that no torque is generated if \(i_q=0\) and \(i_d \neq 0\) since the PMSM does not generate torque in this case [[1],p. 1092]:
This alignment method uses a closedloop current control and control the setpoints \(i_q^*=0\) and \(i_d^* \neq 0\). Using a torque sensor on the test bench (as described in [[2]]), the encoder offset can manually be adjusted until the torque sensor measures zero torque. The setpoint for the current \(i_d\) depends on the machine under test.
Simple concept
Manual tuning
Requires torque sensor
Suitable for machines with \(L_d = L_q\) and \(L_d \neq L_q\)
Not suitable for synchronous reluctance machines with \(\psi_{PM}=0\,Vs\) (since neither \(I_d\) nor \(I_q\) generates torque if the other current is zero)
The accuracy of the torque sensor determines the accuracy of the encoder alignment
Induced voltage (backEMF)
Alignment of the encoder and the daxis can be achieved if the zerocrossing of the induced voltage \(u_i=\omega_{el}\psi_{PM}\) (backEMF) and the position signal is aligned as shown in Fig. 40 [[2]]. However, this method for determining the encoder offset \(\vartheta_{el,offset}\) requires that the machine under test is driven by an external machine to a fixed rotational speed and the induced voltage, as well as the encoder signal, are measured by one oscilloscope or the controller. The machine under test is operated with open circuit, i.e., \(i_d=i_q=0\). If the induced voltage should be measured by the controller, a phase voltage measurement is required on the power electronics. Voltage measurement on the power electronics is not always available and if it is, usually a low pass filter is included which adds a phase lag to the measured voltage which has to be accounted for when aligning the encoder. Furthermore, the position alignment does not account for iron losses.
Complex setup with encoder signal on external measurement device (e.g., oscilloscope) or voltage measurement on inverter
Does not account for iron losses. This leads to misalignment since the linked flux is not solely based on the induced voltage of the permanent magnet but also generated by the iron loss current (see Fluxbased (without testbench machine)).
Fluxbased (with testbench machine)
The fluxbased encoder alignment is based on the induced voltage (backEMF) and uses the same operating condition as the backEMFbased method. The machine under test for which the encoder offset should be determined is driven by a prime mover (e.g., a test bench machine)to a constant speed (open circuit, thus \(I_d=I_q=0\)). In steady state, the voltage equations of the PMSM are given by [[4],p. 16]:
With \(I_d=0\) and \(I_q=0\) due to open circuit, the equations simplify to:
Based on these equations, encoder alignment is reached for an offset \(\vartheta_{el,offset}\) in which \(U_d=0\) and \(U_q=\omega_{el} \psi_{PM}\) is measured. However, this approach does not work due to iron losses in the machine and the alignment is skewed if this method is used.
Fig. 41 shows the equivalent circuit of the PMSM including iron losses. With the parallel iron resistance \(R_c\), the equations of the PMSM in steady state can be written as:
Simplifying the equations by using open circuit operation with \(I_d=I_q=0\) and \(\omega_{el}\neq 0\):
Following the equivalent circuit and the equations, the induced voltage \(\omega_{el}\psi_d\) leads to the iron loss current \(I_{q0}\) and the current \(I_{q0}\) generates the flux linkage \(\omega_{el} \psi_q\) [[5], p. 44]. If the dqframe is aligned with the daxis, the induced voltage in the daxis \(U_d \neq 0\) according to Fig. 41. Therefore, the encoder offset to match \(U_d=0\) and \(U_q=\omega_{el} \psi_{PM}\) does not lead to an alignment of the dqframe to the daxis in the aforementioned operating conditions. Instead, the encoder offset \(\vartheta_{el}\) has to be determined for positive and negative rotational speeds accounting for the effect of the iron losses as discussed. The dqframe is aligned with the daxis if \(U_q\) changes the sign for positive and negative rotational speed but not its magnitude and the value for \(U_d\) does not change when changing the direction.
To simplify the method, a closedloop current control with set points \(I_q^*=0\) and \(I_d^*=0\) can be used instead of open circuit. The following steps have to be performed to align the encoder and determine \(\vartheta_{el,offset}\):
Machine coupled with test bench machine
Closedloop current control with set points \(I_q^*=0\) and \(I_d^*=0\)
Measure \(U_d\) and \(U_q\) or measure controller outputs \(U_d^*\) and \(U_q^*\)
Set test bench machine to some \(\omega \neq 0\) within the operating range and alternate between positive and negative rotation
Adjust encoder offset \(\vartheta_{el,offset}\) until \(U_{d,\omega > 0}=U_{d,\omega < 0}\) and \(U_{q,\omega > 0}=  U_{q,\omega < 0}\)
This method yields good results for determining the encoder offset but requires a testbench machine.
Fig. 42 shows measurement results for the voltages (control value of the current controller) \(U_d^*\), \(U_q^*\) and the calculated flux linkage \(\psi_d=\frac{U_q^*}{\omega_{el} }\), \(\psi_q=\frac{U_d^*}{\omega_{el} }\).
Fig. 43 shows a section of the measurement to highlight the described point in which the dqframe is aligned (dashed line).
Fluxbased (without testbench machine)
The concept of the fluxbased alignment can be extended to not require a testbench with a load machine. The basic principle stays the same regarding the aim of the encoder offset, i.e., \(U_{d,\omega > 0}=U_{d,\omega < 0}\) and \(U_{q,\omega > 0}=  U_{q,\omega < 0}\). However, instead of using a load machine to keep the machine for which the encoder offset should be determined at a constant rotational speed the machine itself is controlled to a rotational speed, then the currents in d and qaxis are controlled to zero \(I_q^*=0\) and \(I_d^*=0\) and the measurement is automatically done during run out of the machine.
Fig. 44 shows the basic principle of the measurement during runout of the machine. As described in the preceding section, the control value of the current controller are used for the calculation.
Rearranged:
Fig. 45 shows the measurement result for measuring in the run out of the machine with the run out starting at \(n=2300\,min^{1}\) and \(n=2300\,min^{1}\).