Thoughts on interfacing with EMC2

The original plan for my CNC machine was to use an Arduino to take care of the timing-sensitive task of delivering pulses to the stepper drivers.  A few things have happened to that plan. 

First off I discovered that the power rating of the EasyDriver 4.2 boards is probably going to be a bit too low. The EasyDriver can deliver 750mA to each phase of the motor.  This was probably enough for the smaller motors I got from Sparkfun, but the motors that are mounted on my CNC rig draw significantly more current than that so I needed somewhat beefier boards.  I can't remember where I got the beefier boards, but they are in the mail by now and can deliver 2A per phase.

Second, I have been skimming the docs for EMC2 and there does not appear to be any easy route to getting the software talking to an Arduino that just takes gcode as input.  The easiest way forward seems to use the parallel port to deliver pulses generated by EMC2 to the stepper drivers.  The good thing about this is that it means I can benefit from the rich functionality in EMC2.  The bad thing about this is that using the parallel port seems to be fraught with its own set of challenges.   From the fact that it makes the system very timing sensitive to stories about ratty parallel port interfaces that produce jitter or just fire off spurious pulses when idle.

I think I read something last night about someone using an Arduino to create a lower level protocol and much simpler software aboard the Arduino -- which interfaces with EMC2.  I would feel more comfortable with having the Arduino interfacing to the stepper drivers.  The parallel ports sound dodgy.  I am hoping to find more information on this.

Also, I need to build a PSU and figure out how I want to control the spindle.  For now I will probably have manual speed control, but eventually I would like to be able to control spindle speed from software.


  1. I know we've been reading some of the same stuff, so it was probably this Polulu board that you ordered.

    I've been testing the Easydrivers, and they seem to work ok at the default 1/8 microstepping with 9 volts or less, but they fail to run the motors at faster speeds, and overheat with 12 volt power sources. I almost tried to assemble mine with the nicer, higher-impedance NEMA 17 steppers that I bought, but the shafts are a bit short and I was afraid they wouldn't reach. Let me know how the Polulu drivers work out, I'll probably be ordering the same ones.

  2. @whosawhatsis: ah yes, those are the boards. Only I think I ordered the slightly more elaborate ones so I can leech 3.3 or 5 volts from them if i need to.

    How did you test them? Just an Arduino and a loop with a fixed pulse rate or did you hook them up to EMC2?

  3. I used an Arduino. Actually, I just used the blink sketch and hooked it up to pin 13, then varied the blink rate. I just had an idea, and I tried it with a longer delay. This allowed me to use full steps. It appears that fastest this motor/driver combination can go is one *full step* every 3 milliseconds. What I have read suggests that they should be able to go faster than that, so hopefully a better driver will allow it to go fast enough to be useful as a repstrap.

  4. Another thought, it may be able to go faster if I use proper acceleration. I'll have to test that tomorrow.

  5. @whosawhatsis: I basically did the same experiment and came to the same conclusion.

    I did get an idea how to possibly test it easily: by hooking up the step pin on the driver to the headphone output of my mixer and generate the pulse trains on my synthesizer :-)

    use a square wave oscillator, adjust the pulse-width down (driver triggers on the rising edge of the pulse) and then use a envelope generator to modulate the frequency so I can ramp it up, hold it at some frequency and then let it ramp down again. That, or I could just dial in an adequate amount of legato and do the ramp-up by rapidly playing increasingly higher notes :)

    Anyway, I read the EMC2 user guide yesterday, and although I need to read it a couple of times more, it seems that if you hook up the drivers to the parallel port and fire up EMC2 there is a procedure for figuring out the needed parameters for acceleration and speed of your steppers.

  6. I did my acceleration test, no improvement in the maximum speed. In 1/8 microstep mode, it always starts missing steps if I pulse it with a delay of less than about 300 microseconds, and it runs fine if I jump from zero to that speed instantly. I hope that with higher voltage and a driver that can handle the increased current, they can go faster than that. Definitely let me know how the Polulu board work out.

    I'm pretty sure that my final setup will not involve using emc2, as all of the computers I have around are Macs, and they don't come with legacy hardware like parallel ports.

  7. Did a little more testing, maximum speed is definitely a function of the input voltage. I got it down to 200us/pulse stepping up from 6.5 volts to 9, but the chip got pretty warm. I get no movement at any speed at 12 volts.

  8. @whosawhatsis: how quickly did you ramp it up?

  9. It was a nice slow ramp-up, subtracting one microsecond from the delay every ten pulses.

  10. Quick update, I got the polulu drivers and did some more testing. Maximum speed is 36us/pulse in 1/16 microstepping mode with acceleration and running at 12 volts. This is about 2.5 times the speed with the other drivers, and translates to about 520 rpm or 1 cm/s of linear motion (calculations do not include processing time).

  11. @whosawhatsis: thanks for the update! I haven't gotten my drivers from polulu yet, but I would expect them to arrive within a week.

    I've been a bit busy lately, so there hasn't been a lot of progress.

    I spent an afternoon trying to get an old windows PC going, but the DVD drive was fried so I couldn't get it to boot. Once that has been taken care of the plan is to install Linux on it so I can use EMC2 (the distro on the LinuxCNC website).

    I also got the spindle that Zen Toolworks sells. I probably need a motor controller for it so I can control spindle speed and direction from the CNC software.

    Did the stepper drivers get very hot? I have been thinking about possibly sticking RAM heatsinks on them and put them in an enclosure with a fan.

  12. I didn't notice them getting more than a little warm, but they never ran for very long because my program didn't have any direction control, so I had to pull the power every time a stage got near the end of its axis. I thought of this too, though, and ordered some heatsinks meant for TO-220 packages and some thermal compound to stick them to the chips if I need the cooling, but they might be too big. The qfn chips are pretty small, only about 5mm square. I also got some microswitches to use as end stops, but I haven't decided how to mount them.

  13. @whosawhatsis: I got some microswitches as well and I am pondering how I should mount them. In particular I am unsure how I should mount the switches for the table: do I mount them so they catch on the edges or do I allow the table to travel over the edge a bit?

    there's a flickr-group that I made for Zen Toolworks you could have a look at. There are some images and videos from a guy who has mounted limit switches:


  14. Yeah, I had a look at that. My switches are pretty small, and I'm thinking of mounting the ones for the y axis to the bottom of the stage, against the supports so that they activate when they reach the frame of the machine. They'll be virtually invisible this way, and should activate just before the screws sticking out of the each piece make contact with the other piece. I can probably do something similar with the x axis, but z will be harder because of the shape of my switches.

    To mount them, I'll either need a glue that will bond well to the frame material or some screws that will fit through the 2mm holes in my switches.