Build Thread PIC/Parallel port CNC driver code

Results 1 to 8 of 8

Thread: PIC/Parallel port CNC driver code

  1. #1
    Registered
    Join Date
    Jun 2013
    Location
    Argentina
    Posts
    5
    Downloads
    0
    Uploads
    0

    Question PIC/Parallel port CNC driver code

    Hi, I am building a CNC driver with PIC 16f628a that goes connected to the parallel port. It will be a simple 3-axis CNC router.
    I made a program for the pic that verifies the state of step and dir.
    So it is something like this (THIS IS NOT THE REAL CODE, obviously):
    :loop
    if xstep = 1 then goto xmakestep
    the same with the other axis
    goto loop

    :xmakestep
    if xdir = 1 then goto xstepforward
    else goto xstepbackwards

    :xstepforward
    if whatstepx = 0 then whatstep = 1
    else if whatstepx = 1 then whatstep = 2
    else if whatstepx = 2 then whatstep = 3
    else if whatstepx = 3 then whatstep = 0
    end if
    (HERE'S WHERE THE QUESTIONS START)
    if whatstep = 1 then port1 = 1
    pause HOW MUCH TIME???
    low port1
    goto loop
    else if whatstep = 2 then port2 = 1
    BLAH BLAH THE SAME AS ABOVE

    The backward step is the same as forward but backwards

    I am using turboCNC, I did not build the CNC machine yet but I am starting with this.
    The code I don't know if it is OK, I just felt It was the right way to do it.

    THE REASON I AM USING A PIC TO CONTROL THE CNC:
    I am using a pic instead of using up/down counters and decoders, but I will need to use one decoder because there is not enough ports in this PIC.
    (Maybe then moving to other pic)

    So the final question is: How much time I will need to make an output stay high? Is the code OK?

    Regards,
    Facundo, 15, from Argentina
    Excuse me for my bad english.

    Similar Threads:


  2. #2
    Gold Member doorknob's Avatar
    Join Date
    Jan 2010
    Location
    USA
    Posts
    2141
    Downloads
    0
    Uploads
    0

    Default

    Quote Originally Posted by faacuunndoo View Post

    So the final question is: How much time I will need to make an output stay high? Is the code OK?


    If I understand correctly what you are doing, your PIC is taking the step and direction outputs from Turbo CNC via the parallel port, and either driving an H-bridge circuit which in turn drives one winding of a bipolar stepper motor (with additional code to handle the other winding), or are you driving switching transistors for a unipolar stepper motor?

    In either case, if your PIC is directly driving the stepper motor windings (via some kind of power stage), then you will need to hold the output state until the next step pulse comes along.

    But it looks like your pseudo-code is handling just one phase of the motor, so you must have additional code for the other phase. Maybe that's what you're doing with port1, port2, etc. I think that you need a "state machine" that will translate step and direction into the proper energization sequence of the motor phases, though, and I'm not sure that you have that based on your simplified code.

    It would be useful for you to specify whether you are trying to do full steps, or half steps, and whether you are driving a bipolar or unipolar motor - maybe referring to Jones on Stepper Motors for the coil energization sequence: http://homepage.cs.uiowa.edu/~jones/step/types.html



  3. #3
    Registered
    Join Date
    Jun 2013
    Location
    Argentina
    Posts
    5
    Downloads
    0
    Uploads
    0

    Default

    First of all, thanks for the reply.
    I didn't write the whole code, but don't worry about the other axis they will be controlled like the X.
    The idea is to control unipolar stepmotors, the outputs connected to UNL2003 or power transistors because I broke one using a big motor.
    There will be full steps only.
    If someone did this before, please help me!
    Thanks



  4. #4
    Member
    Join Date
    Apr 2013
    Location
    Sweden
    Posts
    1899
    Downloads
    2
    Uploads
    0

    Default

    Facundo, I think the 16F628 is too simple and slow for a CNC. I also wonder what the point is to make a driver, because this is what you are planning, isn't it? I mean, why not buy three TB6560AHQ chips and build the driver based on those. It is much simpler, involves no programming and the probability of getting it right is much higher. Using those you would need basically no other parts, just some simple resistors and a few capacitors. It is really easy, as opposed to the PIC implementation, where you would need some additional drivers, a complicated programing and a lot of time before anything works. I don't want to sound negative, but I think it is a better approach to use that chip. It is cheap and works well and also allows micro stepping.



  5. #5
    Member
    Join Date
    Apr 2013
    Location
    Sweden
    Posts
    1899
    Downloads
    2
    Uploads
    0

    Default

    Quote Originally Posted by faacuunndoo View Post
    First of all, thanks for the reply.
    I didn't write the whole code, but don't worry about the other axis they will be controlled like the X.
    He is not talking about the other axises but about the other phase. A step motor has two coils, both must be controlled individually but synchronized. I don't think your pseudo code handles the other phase (coil) and there is also the need for the hold state, which is also missing. Without the hold state the motor will not be able to hold the load and will shift position.

    Quote Originally Posted by faacuunndoo View Post
    The idea is to control unipolar stepmotors, the outputs connected to UNL2003 or power transistors because I broke one using a big motor.
    There will be full steps only.
    If someone did this before, please help me!
    Thanks
    I think it needs too much effort for this simple task. If you do it for fun that's fine, but implementing quadrature control is not so easy if you need to do it in real time. Remember that all three axises must be able to move in a synchronized manner otherwise you will never be able to mill or draw real circles. That's also one reason why a dedicated driver is better than a slow PIC solution, which demands three PICs in total. With the TB6560AHQ you don't have to worry about synchronized moves, the chip handles that very well.



  6. #6
    Registered
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    607
    Downloads
    0
    Uploads
    0

    Default

    If you run the steppers full step @ 1000rpm, you will have be outputting pulses at around 3333hz. Running the 16F628A @ 4mhz with the internal oscillator, you will have around 300 instructions per step cycle. If all you are trying to do is to drive H bridges based on step/dir, then you just have to read the inputs, read the next line in 3 tables, and outputting those lines. I believe I could do that in assembly without a problem.

    TurboCNC also has a sequential stepping setup for this application. You will need 4 outputs for each axis to do it though. You might also be interested in this page on TCNC DAK Engineering - U2 Stepper Translator

    Gecko drives need a 5µs pulse for stepping, but I don't know about any others.



  7. #7
    Registered
    Join Date
    Jun 2013
    Location
    Argentina
    Posts
    5
    Downloads
    0
    Uploads
    0

    Default

    Thanks for the replies. I will try to implement your solutions.
    I can't believe I did not see the U2, thanks The Blight



  8. #8
    Registered
    Join Date
    Feb 2008
    Location
    USA
    Posts
    217
    Downloads
    0
    Uploads
    0

    Default

    Quote Originally Posted by faacuunndoo View Post
    Hi, I am building a CNC driver with PIC 16f628a that goes connected to the parallel port. It will be a simple 3-axis CNC router.
    I made a program for the pic that verifies the state of step and dir.
    So it is something like this (THIS IS NOT THE REAL CODE, obviously):
    :loop
    if xstep = 1 then goto xmakestep
    the same with the other axis
    goto loop

    :xmakestep
    if xdir = 1 then goto xstepforward
    else goto xstepbackwards

    :xstepforward
    if whatstepx = 0 then whatstep = 1
    else if whatstepx = 1 then whatstep = 2
    else if whatstepx = 2 then whatstep = 3
    else if whatstepx = 3 then whatstep = 0
    end if
    (HERE'S WHERE THE QUESTIONS START)
    if whatstep = 1 then port1 = 1
    pause HOW MUCH TIME???
    low port1
    goto loop
    else if whatstep = 2 then port2 = 1
    BLAH BLAH THE SAME AS ABOVE

    The backward step is the same as forward but backwards

    I am using turboCNC, I did not build the CNC machine yet but I am starting with this.
    The code I don't know if it is OK, I just felt It was the right way to do it.

    THE REASON I AM USING A PIC TO CONTROL THE CNC:
    I am using a pic instead of using up/down counters and decoders, but I will need to use one decoder because there is not enough ports in this PIC.
    (Maybe then moving to other pic)

    So the final question is: How much time I will need to make an output stay high? Is the code OK?

    Regards,
    Facundo, 15, from Argentina
    Excuse me for my bad english.
    Hello Facundo,
    I know parts can be scarce in Argentina (according to some PBP forum members there) but if you intend to "roll your own" you might consider the Linistepper by Roman Black as presented by James Newton. See Here: PIC Linear Stepper Motor Controller
    Linistepper uses PIC 16F628A

    We're not in business to make parts, we're in business to make money, making parts is just how we do that.


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


About CNCzone.com

    We are the largest and most active discussion forum for manufacturing industry. The site is 100% free to join and use, so join today!

Follow us on


Our Brands

PIC/Parallel port CNC driver code

PIC/Parallel port CNC driver code