Losing steps in Mach3: Kernel Speed, Pulse Width and "Sherline 1/2 Pulse mode"

by Ivan Hamilton 7/7/2010 8:50:00 AM


The standard signalling for hobby CNC axes is know as STEP/DIR. Two lines, one indicating direction (High/Low=Fwd/Rev), and the second is pulsed (Low to High to Low) to indicate a single step. A problem with this scheme is the possibility of this STEP pulse going by unnoticed.

While hardware based schemes for capturing this pulse may have no trouble dealing with fairly short pulses (1µS or less), in a solution where the signal is "captured" by software (even one initially triggered by a hardware interrupt) may not respond quickly enough to catch these fleeting pulses.

I've seen numerous discussions about getting reliable pulsing from Mach3 to the external device (stepper or servo driver). There's usually claims of accuaracy or reliability from certain setting changes... usually without providing any basis for such claims.

Kernel Speed

Manual: "The Mach3 driver can run at frequencies from 25,000 Hz (pulses per second) up to 100,000 Hz, depending on the speed of your processor and other loads placed on it when running Mach3. The frequency you need depends on the maximum pulse rate you need to drive any axis at its top speed."

That sounds fair enough. The kernel can produce at most 1 pulse per cycle - the maximum pulse rate is the kernel rate.

Pulse Width

Manual: "Pulse width is another consideration. Most drives will work well with a 1 microsecond minimum pulse width. If you have problems with the test moves (e.g. motor seems too noisy), first check that your step pulses are not inverted (by Low active being set incorrectly for Step on the Ports and Pins>Motor Outputs tab), then you might try increasing the pulse width to, say, 5 microseconds. The Step and Direction interface is very simple but, because it can still 'sort of work' when configured badly, it can be difficult to fault-find without being very systematic and/or looking at the pulses with an oscilloscope."

On my copy of Mach3, I can alter the step pulse width (Config->Motor Tuning->"Step Pulse 1-5 us") between 1 and 15 (values greater than 15, are reverted back to 15). This is three times greater than the UI or manual might lead you to believe. How do these changes present in the real world?

Watched on an ol' silly-o-scope, my machine produced step pulse widths matching this setting, but with a minimum width of 3µS (entering 1, 2 or 3, all produced a 3µS pulse).

"Sherline 1/2 Pulse mode"

1/2 a pulse? If you can't even catch the short duration pulse currently produced, why would you want a shorter pulse?

The name is misleading because what it performs is actually half of the pulse change on each kernel cycle (ignoring the pulse width setting). The pulse rises at the start of one kernel cycle and falls on the next, so that the pulse duration is a full kernel cycle duration. With a kernel set to 25kHz, that's a full 40µS of pulse width - much greater than the UI would let you set.

Timing of various pulsing sizes & methods

What's the catch? The downside is that a full pulse cycle (rise & fall) will now take 2 full kernel cycles - effectively halving your maximum pulse output rate. That said... you could always up the kernel speed if your hardware has the grunt to support it. Even at 65kHz, the pulse width will still be slightly longer (15.4µS) than the maximum configurable width with standard pulsing (15µS).

Kernel Speed (kHz)

















Pulse Width µS

As per config

Sherline 1/2 Pulse mode









Pulse Width µS








Kernel speed & pulse widths

"Enhanced Pulsing"

What's this do? Well... it doesn't affect the pulse duration. So it's not about "recognising" steps.

Manual: "Enhanced Pulsing, if checked, will ensure the greatest accuracy of timing pulses (and hence smoothness of stepper drives) at the expense of additional central processor time. You should generally select this option."

Accurate timing pulses? Accuracy of what? Pulse duration, cycle length, spacing?

It turns out, that Mach3 calculates movement in sets of 5 kernel cycles - "In the next 5 cycles, I need 2 steps", "In the next 5 cycles, I need 4 steps", etc, etc. "Enhanced Pulsing" distributes these steps more evenly within the sets of 5 (e.g. wait-STEP-wait-STEP-wait instead of STEP-STEP-wait-wait-wait). It takes more processing, but a "smoother" stream of steps it the result.

Art wrote: "Shifter is a bit special, it tells the engine how to space the maximum of five steps the move represents to keep them as well anti-aliased as possible in time. Smoothness is the result. This 'Shifter' variable is what you are turning off or on when you select 'Enhanced Pulsing' in the App configurations."

So, "Enhanced Pulsing" helps with smoothness, and this may be more important for stepper based systems (where each step results in a physical actions), than servo based systems (where a step just updates the desired position).

For my controller (and probably everyone else's) it probably makes sense to push the pulse width as close as possible to half the cycle duration. For 25 or 35kHz, that's the maximum 15µS available in standard (non-Sherline) mode, and 11, 8, 8, 7 & 5µS for 45, 60, 65, 75 & 100kHz respectively.

This makes sense to me... but of course, there could be some reason internal Mach3 that would make this a "bad thing".

Currently rated 3.8 by 44 people

  • Currently 3.772727/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5



Powered by BlogEngine.NET
Original theme by Mads Kristensen

About the author

Name of author Ivan Hamilton
"My inner nerd can beat up your inner nerd."

E-mail me Send mail



<<  October 2021  >>

View posts in large calendar

Recent comments





    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2021

    Sign in