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.
The output signals of two orthogonally placed linear Hall sensors are:
where is the signal amplitude, the rotor electrical angle, and and the DC offsets of the two channels. Ideally, the angle is obtained by removing the offsets and taking the arctangent:
In practice, however, the following error sources exist:
These errors ultimately appear as a periodic deviation between the estimated angle and the actual rotor position, which must be compensated by calibration.
A complete linear Hall calibration consists of the following steps:
The motor is driven during calibration in id current closed loop with iq = 0: a fixed direct-axis current is commanded (e.g. 10% to 20% of rated current) with quadrature-axis current , 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:
where the index 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.
The purpose of ADC offset calibration is to obtain the DC offsets and of the two Hall channels.
Principle: as the motor rotates, the mean value of 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:
Engineering implementation: the motor enters id closed-loop mode with and commanded and the commanded angle incremented every cycle (e.g. by 32 LSB per PWM period). Shifting right by 6 bits gives a coarse index:
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.
The angle output by the Hall sensors is an absolute electrical angle , 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 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 ; otherwise . 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:
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.
The core idea of error table sampling is: with the rotor angle 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 current. The angle 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 is divided uniformly into intervals (in engineering practice 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:
That is, the compensation table stores "the correction to be applied to the Hall reading when that reading lies in interval ". 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 is subtracted to obtain a component containing only the nonlinear error:
where is the angle computed by arctangent from the raw Hall ADC values after offset calibration, and is the id closed-loop commanded angle. After subtracting , 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:
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:
After the motor has turned one full revolution at constant speed, all 256 intervals have been updated. Since 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:
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:
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 rather than compensated separately in each interval:
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:
The total offset must be merged with the initial deviation to form a single DC correction term:
The runtime angle correction is:
where .
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":
This scheme has two inherent defects:
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 (i.e. the lower bits), the interpolated compensation value is:
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.
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.