Will a PIC work to translate stepper control signals for a mini CNC lathe?

Discussion in 'Embedded Systems and Microcontrollers' started by AdamM, Dec 11, 2010.

  1. AdamM

    Thread Starter Active Member

    Mar 7, 2009
    30
    0
    I'm helping do a CNC conversion for a Taig mini lathe, and I'm hoping to get some advice about `translating` the control signals. We have bipolar stepper motors and Allegro driver chips salvaged from an older Epson printer, and I need to convert the signals coming out of the computer into a format that the chips can use.

    The signal from the computer is of the 'step dir' sort. Two pins in the parallel port are used to control each motor. One pin is either high or low, indicating the direction of the step, and the other pin gets pulsed low to signal a step (pulse width can be adjusted in the software between 5 and 15 uS).

    The UDN2917EB driver chips (http://www.datasheetarchive.com/pdf-datasheets/Datasheets-304/64194.html) each take two phase signals (as well as many others for current control and such, but the phase pins are the relevant ones for this project). The two phase signals each control the phase or polarity of one of the two sets of coils inside the motor. If the motor is stepping continuously in one direction, the signal repeats every 4 steps.

    To illustrate, here's the output from the computer, showing 8 steps in one direction:

    Step pulses _|_|_|_|_|_|_|_|
    Dir pin ______________


    And the chip needs this signal:

    Phase pin 1 HHLLHHLL
    Phase pin 2 HLLHHLLH

    Or, in other words:

    p1 p2
    1 1
    0 1
    0 0
    1 0
    1 1
    0 1
    0 0
    1 0


    To go the other direction the sequence just reverses: if we're at 1, 1 we go to 1, 0 etc.


    We first attempted to do this using PIC 12F683 uCs with PICAXE firmware. The motors stepped nicely on the test bench, with the step pulse sent by hand, but when plugged into the computer they became erratic. I've since discovered how slow the PICAXE system is (a PICAXE basic command can take about 1000 times as long to execute as an assembly command) and I think the program was simply missing the pulses from the computer. I've looked at the computer output on a scope, and it looks like it's doing what it is supposed to.


    I have a couple of questions for the forum:

    1) Can anyone think of a simple enough way to do this using standard logic components, without a micro controller?

    2) Do you think a PIC 12F683 programmed in assembly would be fast enough?

    I know there are a variety of pre-fab stepper driver and translator products available, but we'd rather build one if possible.

    Thanks for your help, and let me know if any more info is needed.
    Adam
     
  2. John P

    AAC Fanatic!

    Oct 14, 2008
    1,634
    224
    I expect the PIC processor would do the job, but your question #1 was the right one--this can be done with just two logic chips, a 74HC191 and a 74HC86 (and maybe other ways too). If it's that easy, why fool around with programing something?
     
    AdamM likes this.
  3. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    Agreed, if you can just enable an inverter on the lines when your "reverse" signal is HIGH, that should be all you need.
     
  4. dikshitmm

    New Member

    Dec 17, 2010
    6
    0
    Two or more simple logic chips could do, but considering how cheap some new and powerful microcontrollers are available, I would go for a microcontroller - single device and programmable. What a combination of gates and flip-flops from multiple chips would do, can be easily codified into a simple program on a sufficiently fast microcontroller.

    A 12F683 is probably ok - hand-optimized assembly could do the trick rather than a high level library. For a 15uS pulse width you only have around 30 instructions worth of time to detect the two transitions (assuming the host expects motors to change move on the trailing edge (rising or falling) of the pulse) and then advance through the lookup table and apply the phase signals.

    Hope this helps.

    Girish
     
  5. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    I'd suggest logic ICs for this, it is somewhat straightforward.

    A microcontroller could be used, but it would be slower than discrete logic could respond, simply from I/O and processing latency. A C program compiled for a PIC running at 20Mhz could easy solve the problem.

    The larger concern is repair. If that PIC gets damaged due to many conditions around a CNC, it isn't a drop in replacement, whereas a Logic IC is.

    Keep in mind that I am a staunch supporter and promoter of microcontrollers, especially PIC. There are still some things that discrete logic ICs can simply do better, such as inverters or logic voltage changes.

    I mostly suggest a microcontroller on projects with PWM, LCD Display, Analog to Digital conversion, or when inputs require complex logic decisions for outputs. There are other special cases, but the OP's need doesn't touch on any of them.
     
  6. Rbeckett

    Member

    Sep 3, 2010
    205
    32
    Something to consider in this application might be the Gecko line of drives. They operate with a ton of open source code as well as Mach 3 and other well known CNC conversions. If you are doing a CNC conversion and wish to include DRO as well then the Gecko's are a great solution to stepping and accuracy concerns. There is a very active user group on Yahoo that includes the designer of the device who can assist you in getting the best possible resolution and set up. Worth a look es[ecially if you are still buying components.
    Bob
     
  7. shortbus

    AAC Fanatic!

    Sep 30, 2009
    4,009
    1,530
    I agree with Rbeckett, using unsupported drivers to try and save a little money is going to be a ongoing problem that will never end. The Mach 3 and other CAM programs all are based on the same basic premise, of giving a digital 1 or 0 for both the speed and direction of a motor control.

    Once you try using another style driver you will end up having to make up your own programs to control the other need functions of that driver.
    and your own version of a CAD/CAM to support just this machine.

    You might want to join http://www.cnczone.com/ They have a very knowledgeable member base there on CNC.
     
  8. AdamM

    Thread Starter Active Member

    Mar 7, 2009
    30
    0
    My apologies to everyone who replied for my very delayed return to the thread. Christmas brouha has kept me away from technical projects until now.

    Thanks to John P for the suggestion of using the 74HC191 and 74HC86. That is exactly the sort of solution I was hoping for. I'm assuming the 2nd output bit of the counter goes directly to one of the driver chip's phase inputs, and the 1st and 2nd bits are used as the input to the XOR gate, whose output becomes the driver chip's second phase input. Is that what you had in mind?

    I've looked into the Gecko drivers, but they are a bit pricey for this project. Working with salvaged bits can be more hassle than it's worth, I'd agree:) But I also learn more this way, and the requirements of this project are fairly modest. For a larger system (we're looking at doing a router/mill next) we'll definitely use different drivers.

    Good to know that a 12F683 with the appropriate software could probably do the job.

    CNCzone is a good suggestion as well.

    Thanks to everyone for your help,
    Adam
     
Loading...