Specialist Supplier of Crystals & Frequency Control Componentssales@mecxtal.com.cn0755-26500570
MERLIN home / Rednote / Passive Crystals and Oscillator Circuits

The motor runs smoothly. Why does the encoder speed spike or turn negative?

A motor sounds and moves normally, but the reported speed periodically spikes or shows reverse. Two replacement oscillators leave the symptom unchanged. Separate the calculation into counts per revolution and the elapsed time between reads. The sensor and decoder determine the first. System timing determines the second. Between them is a finite counter register. If a reading crosses the end of that register’s range, ordinary subtraction can return an implausible result.

Incremental encoders often provide two signals offset from each other. The controller detects direction from edge order and counts the appropriate transitions. Catalogs may describe lines, pulses or positions with different conventions. In ×4 decoding, each signal cycle offers four transitions across both channels. A 1,000-pulse specification can mean 1,000 cycles per revolution on one channel, giving the controller 4,000 counts per revolution. If another supplier offers 1,000 counts, ask whether that is decoded counts or channel cycles. An oscillator change does not alter these definitions.

Account for wrap before subtracting register readings

Worked example with assumed values. An encoder gives 1,000 cycles per turn and the controller uses ×4 decoding. At 600 rpm, the motor turns 10 times per second, so the count rate is about 40,000 per second. A read every 10 ms should differ by 400. A 16-bit counter starting at 65,400 wraps at the top and returns 264 on the next read. Direct subtraction gives −65,136. The true forward increment is 65,536 − 65,400 + 264 = 400. Document units and register width.

When the shaft can reverse, a common rule selects the most plausible signed increment within the count range. For that rule to be unambiguous, actual displacement between reads must have magnitude less than half the counter’s full range. If maximum speed and worst-case task latency could cross that boundary, choose a wider register, track overflow as designed or guarantee more frequent reads. A bench pass at 600 rpm cannot qualify maximum speed and worst-case scheduling. Missed reads under load can make a previously adequate interval ambiguous.

A separate error comes from time. Suppose a scheduled 10 ms separation occasionally becomes 12 ms. Using the original denominator gives a higher speed even if the motor did not change. Keep actual timestamps with count increments to distinguish a longer window, a count error and real variation. If an industrial controller changes timing reference, check timer input frequency and prescaler, then measure intervals with an independent reference. Frequency accuracy sets the time scale. Counter wrap and scheduling need their own handling.

Run three repeatable tests before acceptance

First turn the encoder one revolution using a bench mark and compare the increment with the configured decoding and product specification. Next hold speed steady and capture raw counts on both sides of a wrap to verify the software result. Finally, under approved safe conditions, run slowly forward and reverse, including the read process under high load. Save speed, direction flag, elapsed read time and mechanical movement together. Real reversal should appear across successive count changes. One negative reading around a register boundary points to wrap handling.

ST’s STM32 timer note describes encoder interfaces and available counting modes. It also describes input filtering to reject interference. If counts are lost at top speed, check filter settings, actual pulse widths and timer documentation. Aggressive filtering can reject valid edges. Optical and magnetic encoders also depend on mounting, wiring, supply and conditioning. Compare slow operation and a known stable fast input to separate mechanical causes from how the controller detects edges.

Ask suppliers to define resolution, two-channel interface, maximum pulse rate and measurement method. Engineering can document decoding, time accuracy, count range and the longest permitted read interval separately. Acceptance should cover slow and maximum speed, reversal and register wrap using the real operating setup. Counts per revolution and measured intervals make an unexpected reverse indication traceable to arithmetic, input or clock.

Include a low-speed case. When few edges occur inside the window, count-based speed updates change in steps. Extending the window gives finer resolution and slower response. For smooth low-speed behavior, consider estimating from edge-to-edge intervals if the design supports it. Specify required resolution and response time instead of comparing only average speed.

References

WeChat

MERLIN · TIMING COMPONENTS

Scan with WeChat to contact Sales

Add our WeCom contacts from your usual WeChat app.

On desktop, scan with your phone. On mobile, save the QR image and select it from your album in WeChat Scan.