Stepper and servo motor control, with a PIC. Where to start?

Discussion in 'Off Topic' started by Jeff7, Oct 6, 2010.

  1. Jeff7

    Jeff7 Lifer

    Joined:
    Jan 4, 2001
    Messages:
    41,601
    Likes Received:
    7
    A project at work has me a bit interested in some of this stuff. The simple version of the project is:
    Move a backstop using forward and backward buttons, but when it's in the stop position, the motor needs to hold its position.

    More complex version:
    Enter a value into a controller, and have the motor move to that position, using some manner of linear encoder, likely an optical one, something like this.

    I'd like to use a PIC chip, either PIC18 or PIC32, to control this whole mess, and use Microchip's MPLAB compiler.


    What's a good, and not terribly-expensive, way to get started on learning the basics of motor control in this manner?
    I would have limited access to a circuit board router in order to make something like a breakout board to give some convenient pinouts for the PIC32 (TQFP package), for some breadboarding.
     
  2. Drako

    Drako Lifer

    Joined:
    Jun 9, 2007
    Messages:
    10,456
    Likes Received:
    70
  3. Drako

    Drako Lifer

    Joined:
    Jun 9, 2007
    Messages:
    10,456
    Likes Received:
    70
  4. Lithium381

    Lithium381 Lifer

    Joined:
    May 12, 2001
    Messages:
    12,465
    Likes Received:
    2
    A PIC18 would probably be a better platform for you, as it's available in DIP package and has plenty of horsepower for what youre trying to do. There may be similar projects online that can help give you an idea. The link DRAKO gave is pretty sweet, i had never seen that document before, but it gives a good overview. there are lots of hobby sites dedicated to robot-making, that could provide you with a lot of insight. i only very recently got into the hobby. if there is anything i can do to help, PM me.
     
  5. Jeff7

    Jeff7 Lifer

    Joined:
    Jan 4, 2001
    Messages:
    41,601
    Likes Received:
    7
    Well...I'd also like to use this as a chance to get acclimated to the PIC32, which only comes in a surface mount package. I've already got access to a breakout board that has standard 0.100" pinheaders on it, and I could simply get a circuitboard routed out that would provide some manner of pinout interface, or whatever I'd need.
    Though, well, I don't know how different it is working with the PIC32 vs one of their 18F line.
    And I've got myself a nice breadboard already. Cheaper, too. :p

    I've already worked with the 12F675, 16F72, 18F2520, and 18F4520. (The latter two are nearly the same - the 4520 just has more I/O pins, and I believe more memory as well.)
    However, I've done all the programming using CCS' PIC-C compiler. It has some nice things that make programming easier, but this also can make it tough to access the really low-level functions of the PIC, without diving into assembly language. So I'd like to get acquainted with Microchip's MPLAB compiler. It's free, and, well, it's Microchip's own compiler, so what better thing to use than that on their microcontrollers? :)


    And I shall certainly read the motor control app note PDF. Thank you for that.
     
  6. Drako

    Drako Lifer

    Joined:
    Jun 9, 2007
    Messages:
    10,456
    Likes Received:
    70
    Sounds to me like you should get these:

    http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=DM320003-2-ND

    http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=876-1000-ND
     
  7. Modelworks

    Modelworks Lifer

    Joined:
    Feb 22, 2007
    Messages:
    16,243
    Likes Received:
    2
    Stepper motors are really easy. You just power each coil in order and the motor will rotate that many degrees or step.
    You can use the pic chips you already have. You just need something that can drive the motor power since pics limit at around 20ma.
    I use the ULN2004A chips. You can get them off ebay cheap.
    Then you just pull a pin high for each wire on the motor you want to turn on. Let the motor turn then pull the pin back low. Move to the next pin in the sequence and continue.
    So to do a full rotation you would have to do
    pin 1 - H L
    pin 2 - H L
    pin 3 - H L
    pin 4 - H L

    And repeat for every revolution.
     
  8. PottedMeat

    PottedMeat Lifer

    Joined:
    Apr 17, 2002
    Messages:
    11,946
    Likes Received:
    239
    those are handy. just remember they're limited to ~500mA per driver, anything else and you'll need an output MOSFET/BJT at the rated current and a separate diode clamp.