How-to
Calculate RPM from an absolute encoder position difference
Short answer
Speed from a single-turn absolute encoder is the rollover-corrected position difference over a fixed sample interval. Sampled every 100 ms in OB35 with 8192 counts per revolution, RPM = corrected difference x 600 / 8192, one count is about 0.073 RPM, and the reading is unambiguous below 300 RPM.

On this page
- How do you get RPM from an encoder that only reports position?
- Why does the position difference need modulo correction at rollover?
- Which counts per revolution should you use for a 6FX2001-5AP25?
- Where should the calculation run, and at what interval?
- What is the maximum speed this method can read?
- How fine is the reading, and should you filter it?
- Why is differencing better than timing one revolution?
- How do you program and verify the calculation step by step?
- Questions asked
An absolute encoder reports position, not speed, so the speed is the change in position over a fixed sample interval. Read the position word in the cyclic interrupt OB35, subtract the previous sample, correct the difference for the rollover to zero, and scale it: RPM = corrected difference × 60 / (counts per revolution × sample seconds). For the 8192-count encoder sampled every 100 ms this reduces to RPM = corrected difference × 600 / 8192 — one count is about 0.073 RPM — and the reading is unambiguous up to 300 RPM, updated ten times a second, well inside the 500 ms the PID needs.
How do you get RPM from an encoder that only reports position? #
Speed is the rollover-corrected change in position divided by the time between two samples, scaled to revolutions per minute: RPM = corrected difference × 60 / (counts per revolution × sample seconds), with the counts per revolution taken from the configured encoder resolution.
A single-turn absolute encoder delivers one position word per read: a cyclic count that runs from zero up to its resolution and wraps back to zero once per shaft revolution. Two readings a fixed time apart give the angle travelled in that time; dividing by the interval gives revolutions per second, and multiplying by 60 gives revolutions per minute. Nothing else is needed — no pulse counting, no timer, no waiting for a full revolution.
With N = 8192 counts per revolution and a 0.1 s sample, the formula collapses to RPM = corrected difference × 600 / 8192. Scale with the configured resolution only: an even 8000 is sometimes assumed because it divides nicely, and it quietly puts a 2.4 % error into every speed value.
Why does the position difference need modulo correction at rollover? #
Straight subtraction fails once per revolution: when the word wraps from the top of its range to zero, the raw difference comes out large and negative although the shaft moved forward, so you correct it before scaling.
Apply this rule to every sample, where the raw difference is the current position minus the previous position:
- If the difference is greater than N/2, subtract N.
- If the difference is less than −N/2, add N.
- Otherwise keep the difference as it is.
Worked example, a calculation for two sample values and not a measured result: the previous sample reads 8100, the current sample reads 20, and the shaft is turning forward. Raw difference = 20 − 8100 = −8080. Half a revolution is 4096 counts, and −8080 lies below −4096, so the correction adds N and the result is +112 counts. RPM = 112 × 600 / 8192 = 8.20 RPM. Without the correction the same two samples would report about −592 RPM, a spike in the wrong direction.
Which counts per revolution should you use for a 6FX2001-5AP25? #
Use the resolution the encoder is configured to deliver over PROFIBUS — for the 6FX2001-5AP25 here that is 8192 counts per revolution — and confirm it by watching the position word wrap once with the shaft turned slowly by hand.
The stated range "0 to 8192" is ambiguous at the top end: a modulo-N counter normally shows the values 0 through 8191, wrapping from 8191 to zero, and only a live observation settles which endpoint you actually see. Take that reading with the drive disabled and the machine locked out, because an axis that also runs cam control can move without warning. Record the last value before the wrap; that observed modulus, cross-checked against the configured PROFIBUS resolution, is the N you scale with.
The same number belongs in the technology object: where the encoder parameterization asks for the increments the encoder supplies per revolution, enter the configured resolution there too, so the controller's internal scaling and your speed formula agree. If the position word jumps anywhere other than the mechanical rollover, stop and fix the data interpretation or the coupling first — the speed calculation turns every position glitch into a speed spike, because the glitch lands entirely inside one difference.
Where should the calculation run, and at what interval? #
Run it in the cyclic interrupt OB35 of the CPU 314C-2DP, with the interval set in HW Config, and use that configured interval in seconds as the sample time in the formula.
That setting gives ten speed updates per second, comfortably inside the 500 ms the PID input allows, and the interrupt guarantees the interval is fixed. Two rules keep it honest: execute the calculation exactly once per OB35 invocation, and overwrite the stored previous position only after the difference is computed, so every call compares two adjacent samples. If the cyclic interrupt is configured to another value the method still works, but the scale factor must be built from the actual seconds, never from an assumed interval. Do not run it in the main cyclic scan: its duration varies with the program, and with a fixed scale factor that variation lands directly in the speed reading as error.
What is the maximum speed this method can read? #
The shortest-path correction is unambiguous while the shaft moves by less than half a revolution between samples, which at the 100 ms interval works out to 300 RPM in either direction.
Half a revolution is 4096 counts, and 4096 × 0.073 RPM ≈ 300 RPM. Beyond that displacement the two samples cannot tell a short move in one direction from a long move in the other, and the sign can flip on a real machine. That ceiling comes from the sampling method, not from the encoder's own speed rating. If the rotation is known to be unidirectional, a direction-specific correction that adds N to every negative difference extends the readable displacement to just under one full revolution per sample — about 600 RPM at this interval — but whole revolutions completed between two samples are still invisible, the same information loss that turning a single-turn absolute encoder into multi-turn position has to solve. If your machine can cross the limit, shorten the OB35 interval or take speed from a source that preserves the intervening motion.
How fine is the reading, and should you filter it? #
One count per sample is the smallest step the value can take: with ten samples a second that is 0.073 RPM, so the calculated speed moves in increments of that size and reads exactly zero at a steady standstill.
The steps are visible in the arithmetic: a difference of 819 counts in one sample gives just under 60 RPM, because exactly one revolution per second is 819.2 counts per sample and the integer difference must land on one side of it. Stretching the interval to 500 ms sharpens the step to 0.0146 RPM per count, but it feeds the PID only twice a second and drops the unambiguous ceiling to 60 RPM — resolution bought with response, which a synchronization loop usually cannot afford.
Keep the arithmetic in floating point: convert the corrected integer difference to a real number before multiplying by the scale, and keep the intermediate product in a type that cannot overflow. Converting the final RPM to an integer zeroes every speed below one revolution per minute and damages the sign handling. Filtering comes last: a moving average over several samples adds most of its window as lag to the PID feedback, so first look for coupling play, shaft vibration, or an unstable interval, and filter only as much as the loop tolerates.
Why is differencing better than timing one revolution? #
Timing one revolution with a marker and a timer gives one update per revolution at best, which at low speed is far slower than the 500 ms your PID allows, while differencing delivers a fresh value every 100 ms at any speed, standstill included.
The timer method sets a marker bit such as M0.0 when the position word equals zero, lets a timer run, and moves the timer value when the marker resets. That measures the period of one revolution, not the speed: at 30 RPM a revolution takes 2 s, so the PID would be fed a two-second-old value, and below a few revolutions per minute the wait grows without bound while the machine is effectively blind. It also cannot produce a signed speed, and it depends on catching one exact value, which a fast word can skip. Position differencing has none of those failure modes and needs no marker and no timer. Incremental encoders, which give pulses instead of a position word, are the other case: the counting method for them is in calculating roller RPM from encoder HSC counts.
How do you program and verify the calculation step by step? #
Wire it as one cyclic routine: seed the previous value on the first valid sample, then on every later OB35 call subtract, correct the difference, scale it, and hand the signed RPM to the PID or the synchronizing logic.
- Confirm the counts per revolution with a slow hand turn through the rollover, drive disabled, and set N to the observed, configured value.
- Check the OB35 interval in HW Config and put that figure in seconds into the scale factor.
- On the first valid position word, copy it into the previous-position store and suppress the speed output for that one sample, so startup data cannot produce a spike.
- Each call, compute the raw difference: current position minus previous position.
- Correct it: subtract N when the difference exceeds N/2, add N when it falls below −N/2.
- Convert to floating point and scale: RPM = difference × 60 / (N × sample seconds).
- Overwrite the previous-position store with the current word, after the calculation.
- Pass the signed RPM to the PID or the speed synchronization, adding only the least filtering the loop tolerates.
Then verify. At standstill with the drive disabled, successive positions hold steady and the speed reads zero apart from real one-count dither. Turn the shaft by hand in the machine's positive direction: the sign must come out positive; if it does not, the encoder counts opposite to your chosen sign, so flip the sign in the scaling or change the configured counting direction. Finally time one revolution against a stopwatch: a shaft turned once per second must read 60 RPM.
If the PID input is noisy after all this, the cause is mechanical or timing, not the formula: check coupling play, shaft vibration, and that the interrupt interval is really fixed, in that order.
Questions asked
How much delay does a moving average add to the speed value?
A moving average over five samples divides the step size by five but adds four sample intervals of lag: at ten samples a second that is 400 ms, most of a fast loop's update budget. Start with the raw value and use the shortest average the loop tolerates rather than a long one.
Does the method change for a multi-turn absolute encoder?
A multi-turn encoder counts whole revolutions internally, so you subtract the full position word and scale it exactly as described, and the half-revolution ambiguity disappears because turns completed between samples are tracked rather than lost. Rollover correction is then needed only when the multi-turn range itself wraps at its own end.
How do you use the RPM value to synchronize a second machine?
Use the calculated signed RPM directly as the remote speed setpoint for the second machine, or scale it when the shaft speeds must differ: line speed in metres per second equals RPM times the driven circumference in metres divided by 60. Because the value already arrives in engineering units, the receiving axis needs no pulse scaling, only the same sign convention.
What does a flickering one-count position word do to the reading?
Vibration or coupling play that dithers the word by one count makes the calculated speed flip between zero and the one-count step in either direction; that flicker is quantization, not real motion. Confirm it at standstill with the drive disabled, fix the mechanical cause first, and only then add a small deadband or the shortest filter the loop tolerates.