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 04 / 22

FOC Motor Control: Linear Hall Calibration

Sailike R&DFOC technical notes 中文原文

In the position-sensorless control of permanent magnet synchronous motors, the medium- and low-speed range often relies on a back-EMF observer to estimate rotor position. Under operating conditions such as zero-speed startup and flying restart, however, the back-EMF signal-to-noise ratio is insufficient and a position sensor is required as an aid. Linear Hall sensors have been widely adopted in servos, robot joints, power tools and other fields because of their low cost, small size and ability to provide absolute position information. But linear Halls suffer from mounting misalignment, non-sinusoidal magnetic field, temperature drift and other errors, and must be systematically calibrated to reach adequate angular accuracy. This article describes in detail the calibration principle and engineering implementation of 2 orthogonal linear Halls, and, drawing on version iteration experience from real projects, explains several easily confused key points in the calibration algorithm.

a. Principle of linear Hall angle measurement

The output signals of two orthogonally placed linear Hall sensors are:

Va=Asin(θ)+Voffset\_a
Vb=Acos(θ)+Voffset\_b

where A is the signal amplitude, θ the rotor electrical angle, and Voffset\_a and Voffset\_b the DC offsets of the two channels. Ideally, the angle is obtained by removing the offsets and taking the arctangent:

θ=tan−1(Va−Voffset\_aVb−Voffset\_b)

In practice, however, the following error sources exist:

  • DC offset error: the Hall element itself has a static offset, which also drifts with temperature.
  • Amplitude mismatch: the two Hall channels have unequal sensitivity, resulting in Aa≠Ab .
  • Orthogonality error: the two Halls are not strictly 90° apart when mechanically mounted.
  • Magnetic field harmonics: the field produced by the permanent magnets is not ideally sinusoidal and contains higher-order harmonic components.

These errors ultimately appear as a periodic deviation between the estimated angle and the actual rotor position, which must be compensated by calibration.

b. Calibration procedure overview

A complete linear Hall calibration consists of the following steps:

  1. ADC offset calibration — acquire ADC data from both channels while the motor rotates one full revolution in id closed loop, and compute the DC offsets.
  2. Direction detection — determine the correspondence between the Hall sensor outputs and the rotor rotation direction, and simultaneously capture the initial deviation θoffset between the commanded angle and the Hall angle.
  3. Error table sampling (forward) — during forward rotation in id closed loop, use the Hall sensor angle as the index and record the deviation of the Hall angle from the commanded angle at that position.
  4. Error table sampling (reverse) — repeat the sampling during reverse rotation in id closed loop to cancel the error introduced by torque ripple.
  5. Data fusion — average the forward and reverse sampling results, separate the DC offset from the nonlinear error, and generate the final compensation lookup table.

The motor is driven during calibration in id current closed loop with iq = 0: a fixed direct-axis current id_ref is commanded (e.g. 10% to 20% of rated current) with quadrature-axis current iq_ref=0 , and the rotor is made to follow by progressively incrementing the angle command. Since iq = 0 and the motor is unloaded, it produces no torque, and the rotor angle estimated by the observer stays locked near the true d-axis, providing an accurate reference for error sampling.

The runtime angle after calibration is computed as:

θcomp=dir·θraw+Δθlut[index]−θbias

where the index index=(dir·θraw)≫(16−log2N) is derived directly from the Hall angle without offset removal. The runtime sequence is therefore: direction correction first → table lookup to compensate the nonlinear error → removal of the DC offset as a whole term at the end. This order is the key to the improved calibration accuracy; see below for details.

c. ADC offset calibration

The purpose of ADC offset calibration is to obtain the DC offsets Voffset\_a and Voffset\_b of the two Hall channels.

Principle: as the motor rotates, the mean value of sin(θ) over a complete cycle is zero. The offset is therefore obtained simply by taking the arithmetic mean of the ADC samples of each Hall channel over a complete electrical cycle:

Voffset\_a=1N∑k=1NVa[k]
Voffset\_b=1N∑k=1NVb[k]

Engineering implementation: the motor enters id closed-loop mode with id_ref and iq_ref=0 commanded and the commanded angle θref incremented every cycle (e.g. by 32 LSB per PWM period). Shifting θref right by 6 bits gives a coarse index:

index=θref≫6

Whenever index == 0, the commanded angle has passed the electrical zero position and an ADC sample is triggered. As the commanded angle keeps increasing over a full revolution, the index rises from 0 and returns to 0, ensuring that the sample points uniformly cover the entire electrical cycle. After enough samples have accumulated (e.g. 1024 points), the arithmetic mean (equivalent to shifting the accumulated sum right by 10 bits) yields an accurate DC offset.

d. Direction detection and initial deviation capture

The angle output by the Hall sensors is an absolute electrical angle θhall , but the actual rotor rotation direction may be the same as, or opposite to, the direction in which the Hall angle increases. Before calibration, a short id closed-loop rotation is used to determine dir from the speed direction estimated by the observer.

The decision logic is: after the angle is commanded in the positive direction, if the actual speed computed by the observer is positive then dir=+1 ; otherwise dir=−1 . This coefficient is used throughout calibration and in subsequent operation.

Initial deviation capture: after the direction is confirmed and before formal sampling, the steady-state deviation between the current Hall angle and the commanded angle is recorded:

θoffset=θhall−θref

This deviation contains the initial alignment error of the Hall mounting. It is stored separately and subtracted in the subsequent error definition, so that it does not contaminate the compensation table as a DC component.

e. Error table sampling

The core idea of error table sampling is: with the rotor angle θobs estimated by the observer as the reference, record the deviation of the Hall angle from the reference at each Hall angle position, and build an angle compensation lookup table.

Why the observer angle can serve as the reference: calibration is performed in id closed loop with iq = 0 and no load. The motor produces only the d-axis flux-alignment torque and no load torque; the rotor follows the commanded angle precisely under the pull of the id current. The angle θobs estimated by the observer therefore corresponds to the true d-axis direction, and the deviation originates only from the Hall sensor itself, so it can serve as the benchmark for error calibration.

Angle interval division: the electrical angle [0,2π) is divided uniformly into N intervals (in engineering practice N=256 is often used, i.e. 8-bit resolution). The upper 8 bits of the 16-bit electrical angle form the interval index and the lower 8 bits give the sub-interval position.

What the compensation table acts on (key design point): the index of the compensation table is taken from the Hall sensor output angle, not from the commanded angle:

index=θhall≫(16−log2N)

That is, the compensation table stores "the correction to be applied to the Hall reading when that reading lies in interval i ". Since the runtime lookup also uses the Hall angle as index, the table-building and table-lookup coordinate systems are exactly the same, and each compensation interval corresponds one-to-one with a physical interval of the Hall reading, so no misalignment occurs.

Error definition: the deviation between the Hall angle and the commanded angle is computed in each sampling period, and the initial deviation θoffset is subtracted to obtain a component containing only the nonlinear error:

Δθerr=θhall−θref−θoffset

where θhall is the angle computed by arctangent from the raw Hall ADC values after offset calibration, and θref is the id closed-loop commanded angle. After subtracting θoffset , Δθerr reflects only periodic nonlinear errors such as amplitude mismatch, orthogonality error and magnetic field harmonics, and contains no initial-alignment DC component.

To prevent a single sample from being disturbed by noise, the deviation signal is smoothed by a first-order low-pass filter:

Δθfit[k]=Δθfit[k−1]+Δθerr−Δθfit[k−1]2Q

Sampling write method: during forward rotation (CW), the index is computed from the current Hall angle in every PWM period, and the filtered deviation is written directly over the formal compensation table:

ΔθCW[index]=Δθfit

After the motor has turned one full revolution at constant speed, all 256 intervals have been updated. Since Δθfit has itself passed through a first-order low-pass filter, a single-revolution overwrite already yields a smooth compensation curve and no multi-revolution averaging is needed. During reverse rotation (CCW) the deviation is written to a temporary compensation table:

ΔθCCW[index]=Δθfit

Forward/reverse averaging: during forward and reverse rotation, non-ideal factors such as residual friction torque affect the angle deviation in opposite directions. To eliminate this systematic error, the two sampling results for the same interval are averaged arithmetically:

Δθlut[i]=ΔθCW[i]+ΔθCCW[i]2

f. Offset computation and table lookup compensation

After the forward and reverse sampling, the raw deviation data in the lookup table still contains an overall DC component, namely the mean of all intervals. This DC component comes from the residual alignment error between the Hall and the commanded angle and should be removed as a fixed offset θbias rather than compensated separately in each interval:

θbias=1N∑i=0N−1Δθlut[i]

The final compensation value of each interval is the difference between the mean and the deviation, which gives the compensation table a zero-mean property:

Δθcomp[i]=θbias−Δθlut[i]

The total offset must be merged with the initial deviation θoffset to form a single DC correction term:

θbias\_total=θbias+θoffset

The runtime angle correction is:

θcorrected=dir·θraw+Δθcomp[index]−θbias\_total

where index=(dir·θraw)≫(16−log2N) .

Key difference from earlier versions (the reason for higher accuracy): earlier versions computed the runtime angle in the order "subtract offset first, then look up the table":

θcorrected=(dir·θraw−θbias)+Δθlut[(dir·θraw−θbias)≫(16−log2N)]

This scheme has two inherent defects:

  1. Table-building and table-lookup coordinate systems inconsistent: earlier versions built the table with the commanded angle as index ( θref ), but looked it up at runtime with the Hall angle ( dir·θraw ); the two coordinate systems are offset from each other, so the compensation intervals cannot correspond exactly.
  2. Offset participates in index computation: subtracting the offset first shifts the lookup index as a whole. When the offset is not an integer multiple of the interval width, the shift falls inside an interval, which amounts to correcting the current angle with the error of the adjacent interval and introduces an additional compensation error.

The new version unifies what the compensation table acts on to the Hall angle (table building and lookup are consistent), and moves the offset to the final step as a whole-term subtraction that does not participate in index computation, thereby eliminating the misalignment at its root; this is the core reason for the marked improvement in calibration accuracy.

This compensation table can cover all periodic errors such as Hall mounting deviation, non-sinusoidal magnetic field and orthogonality error.

Accuracy improvement — linear interpolation: if only the 256-point table lookup is used, the angle resolution is limited by the interval width (about 1.4° electrical). To improve accuracy further, linear interpolation can be performed between adjacent intervals. If the sub-interval position of the current angle is θfrac (i.e. the lower log2N bits), the interpolated compensation value is:

Δθ=Δθcomp[index]+Δθcomp[index+1]−Δθcomp[index]2log2N·θfrac

With linear interpolation the angle resolution is no longer limited by the interval width, and the compensation accuracy can theoretically approach 16-bit electrical angle resolution, markedly improving angle smoothness at low speed.

g. Key points of engineering implementation

  • id closed-loop parameters: id_ref should be large enough to overcome static friction and produce a stable flux linkage pull; it is typically 10% to 20% of rated current. iq_ref=0 , ensuring unloaded conditions.
  • Rotation speed: the increment step of the commanded angle determines the rotation speed. Too large a step may cause the rotor to lose synchronism; too small a step makes calibration excessively long. 16 to 32 LSB per PWM period is generally appropriate.
  • Reliability of the reference angle: since iq = 0 and no load is applied, the observer-estimated angle lies near the true d-axis and the error comes mainly from the Hall sensor itself, which guarantees an accurate calibration benchmark.
  • Compensation table coordinate system: table building and table lookup must use the same coordinate system (the Hall angle). Building the table with the commanded angle while looking it up with the Hall angle makes the compensation intervals mismatch because of the coordinate offset; this is the most common cause of poor calibration results.
  • Separation of offset and nonlinearity: at runtime the nonlinear table lookup compensation is applied first and the offset is subtracted as a whole term at the end; the offset does not participate in index computation, which avoids lookup misalignment.
  • Initial deviation capture: the initial deviation between the commanded angle and the Hall angle is captured during direction detection, subtracted in the error definition, and finally merged into the total offset, so that the compensation table retains only the pure nonlinear component.
  • Low-pass filter parameters: the cut-off frequency of the deviation low-pass filter should be below the rotation frequency; Q=3 typically gives good noise suppression. A single-revolution overwrite after filtering is already smooth, and no multi-revolution accumulation is needed.
  • Data storage: after calibration, the compensation table Δθcomp[i] , the total offset θbias\_total and the direction coefficient dir should be written to non-volatile storage (Flash) and loaded directly on the next power-up.
  • Operating mode switching: at power-up the calibration data is read from Flash first; if the flag is valid, the system enters compensation operating mode directly, otherwise it enters the calibration procedure.
  • Linear interpolation enable: if higher angle accuracy is required, linear interpolation can be enabled in the runtime code, trading a small computational overhead for a smooth angle output.

h. Conclusion

The 2 orthogonal linear Hall sensors, once systematically calibrated, can provide the motor control system with high-accuracy absolute rotor position information at zero and low speed, making up for the shortfall of the back-EMF observer in the low-speed range. The essence of the calibration is: use id closed-loop, iq = 0, unloaded driving so that the observer angle locks onto the true d-axis and serves as the reference; remove the DC component of the Hall signals by ADC offset subtraction; build the compensation table on the Hall angle and look it up at runtime in the same coordinate system so that the intervals correspond one-to-one; separate the initial alignment deviation from the nonlinear error and subtract the offset at the end as a whole DC term; average the forward and reverse samples to cancel residual friction disturbance. The most important lesson from engineering practice is: the coordinate system in which the compensation table is built must be the same as the coordinate system used for the runtime lookup, and the offset must not participate in the lookup index computation — these two points are the root cause of the poor performance of early calibration schemes. With them corrected, the angle error can be held consistently within 1° electrical, and can be reduced further with a first-order low-pass filter and linear interpolation, meeting the needs of most servo and drive applications.

This article was compiled by AI and proofread manually.