Generating Stepped Motion

by Ivan Hamilton 7/28/2012 6:13:00 PM

The standard parallel port "pulsing" setup in Mach3 uses a set "kernel speed" (25-100kHz) and this is the rate at which it decides to output a step pulse (or not). It is therefore also the maximum pulsing rate. The implementation details are specific to Mach3, but how would you determine an "even" pulsing pattern?

Let's rephrase our problem: How do you evenly take Y steps over X periods (or, determine which points in a 2 dimensional raster should be plotted in order to form a close approximation of a straight line between two given points). Bresenham's line algorithm is a way to achieve this.

At the start, we're already 1/2 way to crossing into the next Y position. For each increment in X, we move Y/X closer. Once we cross into the next Y position, we're another 1 away from the next crossing.

This could be expressed as:

var accumulator = 0.5;
loop (X times)
	accumulator = accumulator + Y/X;
	if (accumulator >= 1)
		accumulator = accumulator - 1;

We can eliminate the fractional 1/X & 0.5 and use only integer math by multiplying everything by 2X.

var accumulator = X;
loop (X times)
	accumulator = accumulator + 2Y;
	if (accumulator >= 2X)
		accumulator = accumulator - 2X;

We can also reduce calculation load by precalculating and storing 2Y & 2X.

This algorithm gives nice even pulse patterns. An example of 0 to a maximum of 10 pulses is shown below:

 0  ..........
 1  ....X.....
 2  ..X....X..
 3  .X..X...X.
 4  .X.X..X.X.
 5  X.X.X.X.X.
 6  X.X.XX.X.X
 7  X.XXX.XX.X

The integer maths also makes this suitable for microcontrollers.

Below is an example of 3 & 7 (yellow top & blue bottom) pulses per 10 periods being generated by an AVR micro.

When we produce a continuous stream of these pulses, the pattern repeats (prior & next pattern shaded below)


So, how much processing power is consumed by this? I'm using a 256 cycle ring-buffer to precalulate 4 output channels, and inserting a 10ms delay when the buffer fills. To help measure calculation duration, I toggled a line (yellow) high during buffer re-fill. One of the output channels is display below (it's 25kHz signal is not decernable at this resolution).

Of a 16.80ms cycle, 10.40ms is "available" for other tasks. Pattern generation currently consumes ~40% of "available" CPU time. I say "available", since the CPU is constantly interrupted for short periods to update the output.

Currently rated 1.5 by 641 people

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


CNC | Electronics

A High(er) Power H-Bridge for Servo control - Prototype layout

by Ivan Hamilton 9/3/2011 9:43:00 PM

Ok So I laid out a board. This is layout for the prototype board. I'm going to make a single-sided PCB on the mill, so bottom side tracks only and jumper minimisation was the goal.

I certainly haven't perfected PCB isolation routing, so a single track between 0.1" DIP pads was the smallest width I allowed. I'll admit the component placement was largely manual (into relevant sections), but the routing was 95% auto-router. A couple of adjustments were made after the first prototype - this is pretty close to the layout.

Basic H-Bridge Layout in Eagle

I printed the layout and stuck it on the board before routing & drilling, it is a handy guide when inserting components. I certainly wouldn't advise a paper-overlay (absorbing moisture, catching fire, etc) but it's fine for a simple prototype.

Bottom of completed board

It's pretty ugly. I had numerous problems with the isolation routing (breaking tips, very wide). I've been using a Dremel 300 Series. The standard collet setup was just awful (massive run-out), I'd heard about using the Dremel 3-jaw chuck since this was more accurate. I put one in, and measured its run-out... yes, it is much better than the collet arrangement, so that's what I used on this board. After finishing the board (and breaking 2 tips), I rather accidentally was watching the tip of the spindle side-on and discovered that, when spinning, the bit was prone to break into periods of vibrating wildy (visually estimated at ~1mm). This explained the broken bits and wide cuts. Whilst invaluable as a hand tool, a Dremel is simply not a precision machine tool.

A Proxxon Professional drill/grinder IB/E has been ordered. With hardened steel collets and a manufacturer stated run-out of 0.03mm (1 thou), these seem to be preferred by the PCB routing hobbyists.

Top of completed board

So, besides a forgotten pullup resistor, decoupling capacitor and 2 x 1K resistors in series to make 2K, it's pretty close to the original design.

For an initial prototype - it'll do. When the design is a little more stable & tested, some cheap Chinese factory PCBs (ITead Studio or Seeed Studio) may be in order.

Currently rated 1.6 by 50 people

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


CNC | Electronics

A High(er) Power H-Bridge for Servo control - Design

by Ivan Hamilton 8/29/2011 7:26:00 PM

Alright... most of the thinking has been done. Here's what we'll need:

  • Input Opto-isolators
  • MOSFET Drivers
  • Current sensing
  • Adjustable "current" reference
  • "Current" comparator
  • Over-current latch
  • Logic/Gate/Motor supply voltages
  • Miscellaneous support circuitry

Our overall goal is to translate two 3.3V inputs (A & B) into two high voltage, high current outputs (M+ & M-).

Input Opto-isolation

Role: Protect the source of the inputs & convert 3.3V signal to 5V.

Input: 3.3V @ 12mA, Output: 5V

Although it shows the HCPL2530, I'm actually using a HCPL2531. The HCPL2531 has lower propagation times (roughly half) and a higher Current Transfer Ratio (50% more).

R1 & R2 are current limiting resistors to deliver the correct current the the emitter within the opto-isolator. The HCPL2531's emitters have a typical forward voltage of 1.45V, and we'll be looking to take a signal from a chip producing 3.3V @ 8mA (far below HCPL2531's maximum current of 25mA).

A current limiting resistor to suit is R=(VS - VF)/I=(3.3V - 1.45V)/8mA=231.25Ω, a close E6 series resistor is 220Ω, giving 8.4mA.  

The outputs of the HCPL2531 are an "Open Collector" arrangement. When the input is "on", the internal transistor will conduct to ground. By connecting this output "collector" to a current supply (a current limiting resistor to a voltage supply) a signal is produced.

Unfortunately, the signal is inverted. When the input is low, the transistor is off and the output goes high. When the input goes high, the transistor conducts and pull the output low. Further processing will to required to (un)invert the signal.

R3 & R4 are pull up resistors to place current on the output pins that the internal transistor will overcome. The HCPL2531's Current Transfer Ratio (output collector current to the forward LED input current) is 30%. So, with 8.4mA to the LED, only 2.52mA will be sunk to ground during the "on" condition. With a 5V supply, R=V/I=5V/2.52mA=1984Ω. A close E6 series resistor is 2.2KΩ, giving 2.3mA.

Input Conversion

Role: Take the output signals of the opto-isolator, and prepare signals suitable for other parts of the system.

As mentioned previously, our A & B inputs were inverted by the opto-isolators. We need to (un)invert them back to original high/low states as inputs to the H-Bridge driver chips. We also need combined A OR B signals to be fed to the reset mechanism of the current control section. So, two NOT (inverter) gates and an OR gate. This could be achieved with one 4069 hex inverter, and one 4071 quad 2-input OR gate chip. But there is another way. We have NOT A & NOT B signals, and want A OR B. De Morgan's laws state that P OR Q = (NOT P)NAND(NOT Q). Therefore we can use a NAND gate to produce A OR B from NOT A & NOT B. NAND gates can also function as inverters, by appying the signal to both inputs (or one input, and the other fixed high). By using the same gate type for both operations, a single 4011 Quad 2-Input NAND gate chip can be used for all logic conversion. A pin-compatible 4093 Schmitt Triggered Quad 2-Input NAND could also be used, with it's inputs being less suceptible to noise (our opto's output shouldn't be too noisy).


Role: Take A, B & /SD (enable) signals and produce V+ or V- at M+ & M- pads, and current sense signal (CSENSE).

This is the heavy lifting part of the circuit. 5V logic signals come in, and high voltage, high current signals go out.

The heart of the system are two IR21844 Half-Bridge Drivers (one for each side). They provide: output source/sink current capability 1.4A/1.8A, under voltage protection (gates won't drive with less than ~8V), adjustable dead-time (turn off one MOSFET vs turn on the other), floating high-side (up to 600V).

Let's look at a single side (A's, which is at the top of the diagram).

C1 & C3 are bypass capacitors to keep the voltage supply stable.

R6 is the adjustable dead-time resistor, and 39K provides ~1µS.

R5 & R7 are current limiting resistors for the IR21844. Giving that we have 12V to drive the gates, 22Ω will give 545mA - quite conversative given the IR21884 is rated to source 1.4A.

C2 & D2 provide the "bootstrap" mechanism. This is used to provide a gate voltage above the motor supply. It relies upon the lower gate Q1 conducting (the standard low state), then current flows from the gate supply (12V) thru D2 and charges C2 to 12V. When the output goes high, Q1 shuts off and the charge in C2 is connected to HO, driving (thru R5) Q3 on. The charge in C2 must be enough to supply gate voltage for the duration off the high state, since it's only recharged during the low state.

Sizing of this capacitor needs to account for: turn on required gate charge, gate-source leakage current, floating section quiescent current, floating section leakage current, bootstrap diode leakage current, desat diode bias when on, charge required by the internal level shifters, bootstrap capacitor leakage current & high side on time. International Rectifier's Design Tip DR04-4 proviodes details and examples of bootstrap sizing. In my calculations, I found it was dominated by the gate charge (70nC for the IRF540), and that 3 times the gate charge (3 x 70nC = 0.210uF) was a good guide.

D2 must switch fast enough to allow C2 to charge during the low period (~1uS), and high enough reverse breakdown to fend off the high motor supply voltages. My selected 1N4004 @ 400V may be too slow and high-speed UF4004s may be required instead.

Finally, current thru the motor must flow via U$1 & U$2 current sensing resistors. It's important that these are low value (to reduce power and voltage drop), accurate, non-inductive (giving the high-speed PWM) and capable of disapating the required power. Open air current sense resistors are suitable for this purpose. If we want to sense 30A as 0.3V, we need 10mΩ resistance @ 9W. This is achieved with 2 x 20mΩ %1 5W resistors in parallel (or a single one for <15A).

The /SD (enable) signal is supplied from the current limiting system and shutsdown the outputs.

Adjustable Current Reference

Role: Provide a user adjustable reference voltage

We need a user adjustable reference to compare the voltage from the current sense resistors against to determine an "over-current" situation.

I'm looking for a 25A limit, so adjustment across the 0-0.25V range. A voltage divider from a 39K resistor & 2K pot give a 5V/(39KΩ+2KΩ)*2KΩ=0.24V range (changing this resistor to 33KΩ would give 0-0.29V for a 29A limit).

C8 provides some filtering to avoid ambient & adjustment noise.


Current Compare & Cutout 

Role: When the sensed current rises above the reference level, disable the MOSFET drivers until A or B goes high again.

A 4013 D-type flip-flop provides the /SD (enable) line for the H-Bridge driver chips, which must be high for the drivers to operate. When A OR B goes high, the flip-flop samples it's data value (always high, since we tied D to 5V) and placed it on the output Q, thereby switching the drivers on. This happens at the start of every A OR B pulse.

The H-Bridge driver goes to ground via current sense resistors providing a voltage @ CSENSE. To keep out noise, we pass this thru a low pass filter made by R13 & C7 with a cut-off frequency of 1/(2πRC)=1/(2π 100Ω x 0.001uF)=1.5MHz.

D3 protects the comparator from the filtered CSENSE signal going negative. It is a BAT85 schottky diode providing a lower forward voltage and fast switching.

The filtered current sense voltage is compared with the user reference voltage by a LM393 comparator. When the voltage (sensed current) exceeds the user preference, the comparator will go "high". Like the opto-isolators, this is also an "open collector" device - when the comparator's output is "high", the output pin will conduct to ground (overwhelming the R14 pullup resistor) and go "low". This low signal on the flip-flop's Reset input will switch Q off, disabling the H-Bridge driver chips until the current drops below the threshold and the next A OR B pulse starts. 



And that's it for the first revision. You can get a PDF of the full schematic here: 110829_MediumPowerPwmHBridge.v0.1.pdf (19.19 kb)

A few things to remember:

  • I have no idea what I'm doing. I'm neither trained nor experienced in electronics design. I'm making this up as I go.
  • So far, this is just a theoretical design. In the "real-world", there are no theoretical components, only "real-world" ones that often need more care.
  • This has not been "designed for production", so there's probably numerous optimisations that could be make.

Next? The physical layout.

Currently rated 1.6 by 59 people

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


CNC | Electronics

A High(er) Power H-Bridge for Servo control - Ideas

by Ivan Hamilton 8/25/2011 8:15:00 PM


Off the shelf servo controllers are quite expensive, that's why I decided to hack together my own. But if you want to apply some muscle - lower voltages (12V) just won't cut it.

To get high power (>1hp/735W) from 12V you'll need to draw high current ~61 Amps. Put simply, that's a 0.2Ω load. This presents some challenges:

  • A 61Amp 12V power supply. They're rare.
  • A power supply, connectors, wiring, controller & motor with a total resistance of <0.2Ω.
  • A 1hp 12V motor. Those that exist are rare, expensive and heavy.

These are some of the reasons why higher power commercial servo motors start at 24V and progress to 36, 48, 60, 70, 90 & 180V.

My plan calls upon a modular H-bridge unit to take care of turning logic level signals into high power motor drive.

The design of choice is a MOSFET H-bridge. MOSFETs are simple enough, by inducing a voltage between the Gate and the Source, current can flow between Drain and Source. There's two types of MOSFETs: N & P channel, which are basically mirror images of each other (in terms of positive and negative voltages).

Simple N & P Channel MOSFET H-bridge


To turn a MOSFET on, apply more than the threshold voltage "VGS(th)" to the gate. But MOSFETs aren't perfect devices, they have limits, including a limit on the gate voltage. For quick switch-on/off the gate voltage should be towards the maximum allowable without going outside MOSFET limits. A stroll thru International Rectifier's MOSFET list shows 71% of their devices have a maximum gate voltage "VGS(MAX)" of 20V, 20% are 16V or less, and the remaining 9% are 30V. This means, once you go beyond a 30V supply, you can't simply use the supply voltage on the MOSFET gates.

For a motor supply of VMOTOR and gate drive of VGS (minus for p-channel, plus for n-channel), you'll need to switch:

  • High side MOSFET gate between VSUPPLY and VSUPPLY±VGS
  • Low side MOSFET gate between GND and ±VGS

That's two extra supply voltages, ±VGS & VSUPPLY±VGS (which could be the same for VSUPPLY< 2 x VGS(MAX)). Oh yeah, an extra thing - P channel MOSFETs simply aren't as "good" as N channel MOSFETS. (Since P-Channel majority carrier holes have lower mobility than N-Channel electron carriers, the on-resistance of P-Channel devices is two or three times higher than that of an N-Channel of the same area). International Rectifier's lowest RDS(ON) for a p-channel device is 4.7mΩ, whereas n-channel is 0.7mΩ. Current? 74A vs 429A.

You can't turn on both the high & low side MOSFETs, that's a short circuit and will destroy devices. That's straight foward enough... but they don't turn on & off instantly, so you need a delay between switching off one, and switching on the other.

Don't supply a gate voltage below the threshold voltage "VGS(th)", that'll partly turn on the device, and it will turn the power it's throttling into heat. We want it on or off, not in the middle.

Extra supply voltages (above the main supply for N-channel), level shifting circuitry, drop-out protection, dead-time... it's starting to get complicated.

Enter the MOSFET drivers

The complexity of this isn't lost upon semiconducter manufacturers and numerous components are available to assist. But unfortunately, they didn't get together to come up with a standard name for this device.

It's roughly called a "(Half|Full)-Bridge [N-Channel] ([Power] MOSFET|Gate|High and Low Side) (Driver|Controller)", and has part numbers like IR2104, IR2184, A3941, L6393, HIP4081A, TC4427 & LT1162.

One of the great things about them, is they often include the ability to help generate a voltage above the motor supply voltage allowing use of N channel devices all around (typically at the expense of 100% drive - ongoing switching is needed to generate that higher voltage).

What to choose? I browsed to the International Rectifier Product Line & Parametric Search for General Purpose ICs → High Voltage Gate Driver ICs. Criteria?

  • Switch our FETs on and off quickly - high current >1A
  • Amatuer friendly package - PDIP
  • Higher voltages >50V

That focuses us on three packages:

  • IR2181 - Separate high & low drivers, ignored because it doesn't block cross conduction.
  • IR2183 - 400ns deadtime, 180ns ton, 220ns toff
  • IR2184 - 400ns deadtime, 680ns ton, 270ns toff

The difference between these (IR2183 & IR2184) seems to just be the turn on delay. I think this could be handy for overcoming the gate capacitances of larger MOSFETs which could take longer to turn off (got to avoid that shoot-thru!).

I've seen many designs filled with resistors & diodes parralleled along the gate drive line. This appears to be to avoid shoot-thru by allowing the MOSFET to turn off quickly (via the diode) but on slowly (via the resistor). Both the IR2183 & IR2184 also have a variant (IR21834 & IR21844) where the deadtime is programmable via an external resistor (up to 5000ns vs 400ns). To me, that sounds like a much better alternative (especially since it appears I can source the more featured IRS21844PBF at half the price the lesser IRS2184PBF would cost).

Add a quartet of IRF540N (44mOhm 100v 33A) or IRFP260N (55mOhm 200v 46A), and we're getting close to a solution.

Limiting Current

Delivering 30A with the possibility of stalling the motor means that we should have current limitting. A standard current limiting method for inductive loads is to measure current and switch off when the limit is exceeded, and back on when it falls below. The inductive load smooths the current change so this is a reasonable method (it won't race too fast). Unfortunately when dealing with boot-strapped high-side drivers each "on" transition consumes charge in the bootstrap capacitor. If we switch off & back on 10 times in a cycle before the capacitor is refilled, we'll drain it to a point where it won't supply enough voltage to switch the MOSFET on "hard" enough (risking the MOSFET).

What we'll need to do is recognise exceeding the current limit and switch drive off until the next rising edge input. This might stop us delivering maximum levels of continous power - but this is current limiting for safety, not current control for performance.

Detecting over current

Probably the easiest way is to use a current shunt and measure the voltage drop against a reference. Let's check what we can achieve with a pair of 0.02Ω 5W current sense resistors in parrallel.

  • P = 10W = I²R = I² 0.01Ω = 31.6A
  • V = IR = 31.6A x 0.01Ω = 0.316V

Maybe use a LM393 to compare against an adjustable reference voltage, and indicate when it's exceeded.

Staying off

By using a D flip-flop (CMOS 4013) we can switch the output off on over-current (reset), and have it reset by the next rising edge for a leg (clk).

Isolating inputs

It's a good idea to electrically isolate incoming signals to this high current, high voltage board.

Let's look at an example: 50kHz PWM, 1% duty cycle: 20μS cycle with a 200nS pulse. But your standard off the self 4N25-28 has typical 2μS rise and fall times. That's just not fast enough to accurately pass the inbound waveform.

Higher up are the 6N136/HCPL-2531 1mBit/S & 6N137/HCPL-2631 10mBit/S dual optoisolators ($2/$4). With 500nS & 50nS total propagation delay they're the speed of equipment we'll need.

It's worth noting, the 6N136 is 20V, whilst the 6N137 is a 5V device. I think, treated right, we can probably get the required performance from a 6N136, and run all components from a 5V/12V supply (the IR21844 has a maximum 10V logic input voltage, and we want more that 10V to drive the gate voltage).

Design Time

All that's left is to design and build it. How hard could it be?

Currently rated 2.9 by 15 people

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


CNC | Electronics

PWM & High Speed Optocouplers

by Ivan Hamilton 8/25/2011 7:53:00 PM

One of the signals needed in my servo controller is a PWM signal to control the motor driver. From the Papilio FPGA board I plan to use, comes a 3.3V signal and there's two things that it will need.

  1. Isolate it from the "nasty" high voltage/current sections
  2. Translate it from 3.3V to 5V+

I had an 8 channel PC817 based Futurlec Opto-Isolator Mini Board ($5) lying around (it uses 560Ω series input & 1kΩ output pull ups), and wondered how it would perform. I rigged it up and was initially pleased.

PC817 based opto @ 1Khz

The bottom trace is the 3.3V input, and the top trace is the 5V output  (both 2V/div).

Then I moved the frequency from 1Khz up to 25Khz... 

PC817 based opto @ 25Khz 

At 20Khz the output is barely exceeding 3V and certainly couldn't be called a square wave. At 20% duty cycle, it's basically off, and at 80% - completely on. If we produce a 25kHz signal, and want ~1% accuracy on the duty cycle, we'll need an opto capable of switching in around 1% x 25Khz Cycle = 1% x 40μS = 0.4μS. The PC817 has a quoted 4µS rise & fall time.

It was time to find a higher performance opto, and "common" DIP optos include the 6N13n family (manufactured by Fairchild, Vishay, Avago, etc):

  • 6N138 & 6N139 - 0.1Mbs  10/35μS (High-Low/Low-High) switching
  • 6N135 & 6N136 - 1.0Mbs 1.5 & 0.8μS switching
  • 6N137 - 10Mbs - 0.1μS switching

It looks like the 6N136 should perform as required. A dual channel version, the HCPL2531 is available as well (and so I ordered a couple).

The HCPL2531 has a stated Input Forward Voltage of 1.45V and maximum average mitter current of 25mA. Passing 3.3V thru 220Ω will give IF=(3.3-1.45)/220=8.4mA. Maxium Average Output Current is a paltry 8mA (vs slower 6N138/9's 60mA), so the output side required a 2.2KΩ pull up to 5V (2.2mA). HCPL2531's propagation delay charts show the best "standard" results for IF=16mA & RL=1.9KΩ (close enough to my 8.4Ma/2.2KΩ setup).

HCPL2531 based opto @ 25Khz

The HCPL2531 was much better, and much more suitable to the PWM signals. Top is 3.3V input and the bottom is 5V output (the upper & lower traces are swapped from previous photos before).

The PC817 would still be suitable for slower signals (errors,home switches, etc), and will probably get used for exactly that.

Currently rated 3.3 by 12 people

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


CNC | Electronics

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



Relay Driver - Finished

by Ivan Hamilton 5/5/2009 12:45:00 PM

As briefly mentioned before, I need a way to take the CNC4PC C10 breakout board's output signal (5V@24μA) and switch higher currents and voltages. After the 4 pairs of step & direction signals, the C10 board still has another 4 outputs (spindle, coolant, etc). CNC4PC do sell the C15 (a nice opto-isolated dual relay board). I should just buy two of these (they're quite reasonably priced), but this is about the journey, not the destination.  

In pursuing modularisation I think that opto-isolation belongs on separate modules, so my quad relay board won't have it. All that's required is a few transistors to step up the current, some relays capable of 240V@10A, LEDs for diagnostics and supporting passives (current limiting resistors and fly-back diodes).

With the new X axis coupling, the board drilled and milled without losing position. The only issue was the double-sided tape holding the board down gave up during the final board shape routing (hence the lack of squareness). The isolation ran at 60mm/min and took about 30 minutes to run (I really need to find a way to get 30,000rpm instead of 1200rpm).

To make it easier to place the components, I printed the overlay on paper and stuck it on top of the PCB (using a needle to pierce the lead holes). The Ø1.2mm pads on the diodes & resistors were a challenge to solder (it was very easy to bridge across the milled 0.2mm isolation channels). In the future, for manually soldered boards, I should make both the pads and the channels larger (the board design didn't need such small pads -  Ø1.5mm should be fine).

If you're interested in the tool-chain: Altium Designer for Schematic & PCB layout, CopperCAM for Gerber to GCode, Mach3 for Milling.

PCB design

Milled & Soldered PCB

The top overlay and components


Currently rated 3.2 by 20 people

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


CNC | Electronics

Z Axis Demo - X Axis Coupling

by Ivan Hamilton 5/4/2009 2:20:00 PM

I got a little carried away with one of the couplers I'd made for the X axis, and it broke. I managed to jury rig it, but a few jobs I've tried recently have lost X registration. I initially thought it was a backlash issue, or lost steps due to electronic interferance, but the simplest answer is often correct. The broken coupler was most probably slipping...

I needed to make a Z axis coupler, so I thought I'd do a new X at the same time. Here's a quick look at it in action, and also a demo of the new panel.


Currently rated 1.9 by 61 people

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



Mill Panel - Rewiring

by Ivan Hamilton 4/30/2009 10:48:00 PM

In my quest to add E-Stop control to the PC & Servos, and PC spindle switching I had already created a new mill panel front and relay holding PCB. All that remains it to rewire the panel.

The only wiring that will be kept is the 240V motor supply & switching (to respective relays), all other wiring will be removed and replaced. I've already removed the control wiring (most of it relating to the dubious "tapping" feature) and need to plan the final wiring (hopefully I can reuse some of the spade terminated wires).


 It's fairly straight forward (I'm not showing the 12V supply, or 240V neutral line). You can see the 5 spots that the PCB will need to link into the 240V wiring (well 6, 1 more for neutral). This will give me a very good idea of the wiring links required, and should allow for a well planned and neat job.

After some concentrated effort, here is the result:

Rewired Panel

You can see the the new relay circuit board hanging from the bottom (it will be mounted within the box). I must have had too much time as I even colour coded the wires (and heat shrink!). I had several pieces of the original harness left over, but what remains is much more functional. The next step is a relay driver board to take the signal from the CNC4PC C10 breakout board (5V at 24μA) and deliver 12V to a 320Ω relay coil (38μA). A little transistor is in order here. I think I might mill up a PCB...

Currently rated 3.0 by 15 people

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


CNC | Electronics

Mill Panel PCB - PCB Milling

by Ivan Hamilton 4/28/2009 11:47:00 AM

My new mill panel needs both rewiring and new components to allow the PC to switch the spindle on & off. This includes 3 new relays (1 x 240V for "on" latching, and 2 x 12V relays for FWD+REV). Whilst I could just wire them up, it would result in an unstructured mess. I really wanted a nice PCB to mount them.

I had previously fallen in love with the idea of milling PCBs. With etching PCBs, after all the messy chemicals and issues with brokens tracks, etc... you still had to (manually) drill them anyway. I wanted to CNC drill the boards, and being able to isolation route them as well would make PCB creation a single "tool" process.

For about $20 AUD on eBay I bought 5 x 60˚ V-Shaped Carbide Engraving Bits. At a depth of 0.25mm these 60˚ V bits create a Ø0.29mm path at the surface. All you need is some software to create the milling G-code from the PCB's Gerber definition.

I tried a demo of CopperCAM (others have mentioned CircuitCAM, and also exporting as DXF to vector tools for manual manipulation).

After exporting the Gerber & drill files from my PCB software, I imported them into CopperCAM. CopperCAM produces the final G-code, with tool-change commands for swapping thru different engraving, milling and drilling bits. This G-code was then run in Mach3 (blank PCB was held down with double sided tape).

Milled PCB

Unfortunately my mill is designed for heavy work and 1250 RPM is the spindle's top speed. So I used a very slow feed speed of 60mm/min (~0.05mm/rev). I may be able to go faster (maybe 120mm/min) but not much more. I do plan to find a way to mount a high speed rotary tool to my mill to allow for such needs. The slots are a bit sloppy, but I did those under manual control with the V bit as I don't have a small enough endmill - yet.

I'll solder it up today, and look to mount it in the mill's control box. Once again... I'm very happy with the result of my latest mill experiment.

Currently rated 3.0 by 17 people

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


CNC | Electronics

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