Shop OBEX P1 Docs P2 Docs Learn Events
stepper motor control? — Parallax Forums

stepper motor control?

Bill HenningBill Henning Posts: 6,445
edited 2009-12-14 20:26 in Propeller 1
I just went through the motor control section of obex (http://obex.parallax.com/objects/category/7/?page=1) and found four pages of great stuff... but none of them appear to be for controlling stepper motors!

Does anyone know of any stepper motor software in Obex?

If not, I guess I will have to write one.

Thanks!

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.mikronauts.com Please use mikronauts _at_ gmail _dot_ com to contact me off-forum, my PM is almost totally full
Morpheusdual Prop SBC w/ 512KB kit $119.95, Mem+2MB memory IO board kit $89.95, both kits $189.95
Propteus and Proteus for Propeller prototyping 6.250MHz custom Crystals run Propellers at 100MHz
Las - Large model assembler for the Propeller Largos - a feature full nano operating system for the Propeller
«1

Comments

  • KyeKye Posts: 2,200
    edited 2009-12-10 02:46
    Wait, I'll write one... I can get to that on Saturday.

    I've been trying to exapnd my collection of motor objects.

    ... Would you like position in steps and steps/second control?

    I'll also make it support two motors at once·like the rest of my dual drivers. (Is 4 windings good? 1 pin for each?) X2 for dual stepper motors.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,

    Post Edited (Kye) : 12/10/2009 2:52:43 AM GMT
  • hover1hover1 Posts: 1,929
    edited 2009-12-10 03:08
    Bill,

    Johnny Mac wrote one in a Nut and Volts article. I can't put my hand on it right now, but it was called "Stepping Out With Spin"

    Jim
    Bill Henning said...
    I just went through the motor control section of obex (http://obex.parallax.com/objects/category/7/?page=1) and found four pages of great stuff... but none of them appear to be for controlling stepper motors!

    Does anyone know of any stepper motor software in Obex?

    If not, I guess I will have to write one.

    Thanks!

  • w8anw8an Posts: 176
    edited 2009-12-10 03:25
    Here's some info to get you started..
    http://forums.parallax.com/showthread.php?p=839549
  • Bill HenningBill Henning Posts: 6,445
    edited 2009-12-10 03:32
    Kye:

    Thank you! That would be perfect. I need to control two steppers (X & Y direction), and while all I really need is N steps forward/reverse, N steps FWD/REV in T seconds would be very nice too!

    hover1:

    Thanks, will look for it...

    w8an:

    Thank you for the link!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.mikronauts.com Please use mikronauts _at_ gmail _dot_ com to contact me off-forum, my PM is almost totally full
    Morpheusdual Prop SBC w/ 512KB kit $119.95, Mem+2MB memory IO board kit $89.95, both kits $189.95
    Propteus and Proteus for Propeller prototyping 6.250MHz custom Crystals run Propellers at 100MHz
    Las - Large model assembler for the Propeller Largos - a feature full nano operating system for the Propeller
  • Bob Lawrence (VE1RLL)Bob Lawrence (VE1RLL) Posts: 1,720
    edited 2009-12-10 03:39
    hover1 said...
    Bill,

    Johnny Mac wrote one in a Nut and Volts article. I can't put my hand on it right now, but it was called "Stepping Out With Spin"

    Jim


    Try here:
    www.parallax.com/Portals/0/Downloads/docs/cols/nv/vol7/col/NV136.pdf
  • Ken GraceyKen Gracey Posts: 7,401
    edited 2009-12-10 03:57
    Hey Kye, Bill,

    A useful stepper object would be able to do half-steps and micro-stepping for CNC applications. I've got this old ShopBot-thingie in the garage (my short video is at and it's not worth it's power consumption in full-step mode (0.015" steps) because it's a direct-drive gear/pinion setup. So, FlashCut CNC (and Gecko drives) offer some drivers that support microstepping. This increases my accuracy by using 1/10th steps (and 0.003" resolution). This particular machine was found locally on CraigsList for a song and a dance, but it does well with my robot bases.

    Braking and ramping are other characteristics I'd like to see in a completely function stepper post on OBEX.

    Sure appreciate your efforts.

    Sincerely,

    Ken Gracey
    Parallax Inc.
  • Bill HenningBill Henning Posts: 6,445
    edited 2009-12-10 04:32
    Thanks Bob!

    Hey Ken... for the time being, I'd rather use someone else's stepper object, that way I'd have more time for PropellerBasic smile.gif

    I agree about half-steps and micro-stepping... I have started acquiring parts to make a small CNC with an 18"x18" work area, for milling out robot parts, Morpheus case face plates, I/O panels etc.

    If I got it to do 3mil resolution, maybe even milling some of my own prototype PCB's, shortening my new board development cycle... so I may end up doing micro-stepping later.

    Best Regards,

    Bill

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.mikronauts.com Please use mikronauts _at_ gmail _dot_ com to contact me off-forum, my PM is almost totally full
    Morpheusdual Prop SBC w/ 512KB kit $119.95, Mem+2MB memory IO board kit $89.95, both kits $189.95
    Propteus and Proteus for Propeller prototyping 6.250MHz custom Crystals run Propellers at 100MHz
    Las - Large model assembler for the Propeller Largos - a feature full nano operating system for the Propeller
  • photomankcphotomankc Posts: 943
    edited 2009-12-10 04:35
    If you guys beat me to it (likely) I'd love to see what comes of it.· I'm looking to drive three of these:

    http://www.allegromicro.com/en/Products/Part_Numbers/97060/

    It takes care of chopping and microstepping based on digital input and can drive up to three amps.· My application will be a three axis CNC controller/driver that would be capable of acting as a stand-alone power drive with poor-man's digital readout or as a slave to a PC running CNC software.· I'd really love to be able to add an SD card and run the G-Code straight from that but that would be way down the road.· As soon as I get the ability to make my own PCBs I plan to start on this.
  • hover1hover1 Posts: 1,929
    edited 2009-12-10 04:44
    Thanks Bob,

    I normally can put my finger on that stuff pretty quick, but I am in the middle of packing to do a 4 day install in Wausau, WI. Forcast next 4 days: average 0 degrees F. Hey, where's the global warming?
    Bob Lawrence (VE1RLL) said...
    hover1 said...
    Bill,

    Johnny Mac wrote one in a Nut and Volts article. I can't put my hand on it right now, but it was called "Stepping Out With Spin"

    Jim


    Try here:
    www.parallax.com/Portals/0/Downloads/docs/cols/nv/vol7/col/NV136.pdf
  • KyeKye Posts: 2,200
    edited 2009-12-10 04:46
    With all the stuff you guys are asking for and all the various stepper motors out there... well I'll have to retract the implication that I'll get a nice driver out soon.

    I'll be going home for about a month during the holidays and I will not have acess to any stepper motors/powersupplies/etc. I don't believe I can finish the driver in a day so don't hold your breadth for me.

    The good news however is that I plan to finish the full FAT32/FAT16 file system driver I was working on over the holidays. I'm finishing up finals week at school right now so my time is not my own.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • Ken GraceyKen Gracey Posts: 7,401
    edited 2009-12-10 05:08
    Nah, Kye. You could start simple and add functionality as time is available. We need ya! It looks like for any given object, usually one of them reigns as King on OBEX after a while. Such popular objects are ultimately very functional and often simple at the same time.

    @Bill, If I were your manager, I'd also tell you to stick to the BASIC compiler.

    Ken Gracey
  • photomankcphotomankc Posts: 943
    edited 2009-12-10 05:25
    I agree. A very basic driver that took step commands and could do half and and full step would be nice. Johnny Mac's code looked pretty easy to build off of.
  • KyeKye Posts: 2,200
    edited 2009-12-10 05:36
    @Ken - Thanks,

    So, I guess I can make multiple versions of the same driver for each different type of stepper motor. I think high level position and speed control will be enough for now at the lowest level.

    Ramping and such may be put at a higher level.

    ... After a bit of research I looked into microstepping and its pretty much just a form of half stepping were you vary the current of each of the two coils your half stepping with to get a very fine accuracy.

    This can be done using pwm. Now, I'm not sure if there is any point of varying the current based on sine waveforms or just ramping the current of one coil up while ramping the current of the other coil down in operation. Both methods seem plausible to me.

    To make it a dual driver using one cog I'll have to write it in asm which I'd rather not do. But to do microstepping you'll need two channels of pwm per motor. Would be easier in spin.

    Maybe I'll make a single motor per cog driver first.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • KyeKye Posts: 2,200
    edited 2009-12-10 05:44
    I'm thinking a unipolar and bipolar version. I'll do unipolar first with half stepping.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • Bill HenningBill Henning Posts: 6,445
    edited 2009-12-10 06:12
    Except for spending some time on a couple of consulting gigs that have to get out the door ASAP I am spending my dev time on PropellerBasic [noparse]:)[/noparse]
    Ken Gracey (Parallax) said...

    @Bill, If I were your manager, I'd also tell you to stick to the BASIC compiler.

    Ken Gracey
    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.mikronauts.com Please use mikronauts _at_ gmail _dot_ com to contact me off-forum, my PM is almost totally full
    Morpheusdual Prop SBC w/ 512KB kit $119.95, Mem+2MB memory IO board kit $89.95, both kits $189.95
    Propteus and Proteus for Propeller prototyping 6.250MHz custom Crystals run Propellers at 100MHz
    Las - Large model assembler for the Propeller Largos - a feature full nano operating system for the Propeller
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2009-12-10 06:19
    Just tossing in an idea...

    How about current management? Typically with steppers, or any motor for that matter, you lose torque as the motor speeds up. If you regulate the current so that it remains constant, you can maintain constant torque, and thus higher current at higher speeds. To do this you need a boost regulator of some kind to increase the voltage the stepper sees at higher speeds verses the lower voltage it would see at lower speeds. I realize that this sort of thing is usually done at higher level applications and requires a fair amount of external hardware support for the DC-Dc conversion and the Stepper motor voltage regulation. But if an object were written equipped to manage the current based on speed and/or a feedback loop from the motor, it would be a nice little object addition.

    I have done this with standard DC motors with very good results, the same technique could be applied to steppers.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • StefanL38StefanL38 Posts: 2,292
    edited 2009-12-10 07:27
    I'm not familiar with the details of steppermotor-chopper circuits.
    But as there is done choppering at all to limit the current
    I would think this is just a matter of changing the on/off-ratio of the pwm signal that choppers the current.

    Second thought. If the current is limitted through choppering by measuring the (averaged) current this should
    include ALL effects. So it should include the effect of the increasing - hm don't know the word -
    "the voltage generated through the moving of the magnetfield "through" the coils which lowers down the supplied voltage
    as the generated voltage has opposite polarity."

    So this should allow to go always to the current limit the steppermotor can stand without OVER-heating.
    In the company I worked 3 years ago they used a lot high torque steppermotors 85V 3A. They drove them
    with a current, that they warmed up pretty much (55°C)

    best regards

    Stefan
  • mikedivmikediv Posts: 825
    edited 2009-12-10 17:00
    There were some posts months ago some of the guys were trying to help me and a few others get somethimg working on the prop to be honest I ended up just buying a cheap stepper board and controling it with the prop . I would love to see a driver for using the prop chip by itself
    I bet it would be a very big hit with everyone
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2009-12-10 17:33
    You could say that there are three elements to stepper motors in typical CNC type scenarios:

    1. The driver, creates the waveforms the motor requires from simple step and direction pulses
    2. The motion control part. Creates pulse streams to provide the required motion profile, typically trapezoidal velocity profiles.
    3. G-code interpreter or overall program issues motion commands.

    1. If you buy a commercial stepper motor driver (or build one based on relevant chips) then that will cover you for 1. Or you could create a stepper driver object to do that with appropriate hardware, hopefully it would support micro-stepping and do the current limiting side of things etc. I would rather buy something to do this as the pros do the power electronics better than me.

    2. Then you have the motion profile side of things and that should be a separate object as well with distance travelled (in steps), acceleration and maximum velocity as inputs. Two axis interpolation at least is required ideally.

    3. This could be a separate object (g-code interpreter) but in many applications this would be your main program.

    So basically don't try and do an object that does it all, divide and conquer.

    Graham
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2009-12-10 17:49
    Graham Stabler,

    Yes, I agree, divide and conquer in small steps (no pun)


    As far as power management is concerned, my days in motion control for prosthetic robotics is coming out...


    StefanL38,

    "I'm not familiar with the details of steppermotor-chopper circuits.
    But as there is done choppering at all to limit the current
    I would think this is just a matter of changing the on/off-ratio of the pwm signal that choppers the current."


    This works if your supply voltage/current is rated at least 4 times the requirement for the Stepper, but often, and I think this is a misconception with stepper motors, the supply voltage/current is rated at the same requirement of the Stepper. This causes the stepper to operate ok but it's not as efficient as it could be with the power supply and you start to have problems at higher speeds.


    Think of it this way...

    In full step mode, each coil to the stepper only "sees" 1/4th of the total available power.
    0001 , 0010 , 0100 , 1000

    Alternative full step mode, each coil to the stepper only "sees" 1/2th of the total available power.
    0011 , 0110 , 1100 , 1001


    In half step mode, each coil to the stepper only "sees" 3/8th of the total available power.
    0001 , 0011 , 0010 , 0110 , 0100 , 1100 , 1000 , 1001

    ...even if you alter the speed of the sequence, you still have the same power ratio. So two things you could do.

    1) Start out with a supply 4 times the stepper requirement.
    2) Add a DC-DC converter that effectively multiplies your voltage by a factor of 4 and that can maintain the required current drive of the stepper.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 12/10/2009 6:20:59 PM GMT
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2009-12-10 18:54
    Beau,

    Mariss from Geckodrive suggests you can pretty much go all the way up to 20X the stepper's rated voltage assuming current limiting is in place to allow high speed operation, 20X is pretty high, I typically have used something more like 6 times. That would generally be done with just a single power supply, no level changing for different speeds, not as efficient but it does work.

    Graham
  • KyeKye Posts: 2,200
    edited 2009-12-10 19:01
    I think I can get an object easily done in spin that will use two channels of pwm to half step and microstep.

    I'll put the number of microsteps you want in the constants section of the code and the driver will just use a sin/cos lookup rountine to decrease the duty cycle of one coil while increasing the duty cycle of the other smoothly.

    The microsteps number will control how many sin/cos steps it does then between each step. Shouldn't require much more than a few lines of code. However, I'm only going to test my driver on the oscilliscope since I don't have time to make the necessary driver stuff. I'll post my code on saturday, then everyone can test.

    Thanks,

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • Bill HenningBill Henning Posts: 6,445
    edited 2009-12-10 23:02
    Here is a simple full-step driver I cooked up based on the information in the
    http://forums.parallax.com/forums/default.aspx?f=25&p=1&m=384380
    thread and my data sheets.

    It's not fancy, it's not super fast, but it works well enough for my current app.

    Note: it does not do half or micro steps! I tried to do half steps, but my test motor did not like it - I was probably doing something wrong.

    ' delay is in 100us increments
    ' steps is number of steps to take - on an 18' stepper, 20 steps is one rotation
    ' dir is 1 or -1, for direction
    ' E=enable, AB=inputs for winding1, CD=inputs for winding2, bipolar stepper motor
    '                     DCE BAE
    '                     DC  BA
    ' adapted from StefanL38's post
    
    Pub FullStepMotor(delay,steps,dir)|Phase,count
      ' array should be made global and initialized, or stuffed into a rotating long
      Phase[noparse][[/noparse] 0 ] := %100_000_0
      Phase[noparse][[/noparse] 1 ] := %010_000_0
      Phase[noparse][[/noparse] 2 ] := %000_100_0
      Phase[noparse][[/noparse] 3 ] := %000_010_0
    
      DirA := %110_110_0
      count := 0
      repeat steps
        outa := Phase[noparse][[/noparse](count+=dir)&3]
        waitcnt(cnt + delay*8_000)
      outa := 0
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.mikronauts.com Please use mikronauts _at_ gmail _dot_ com to contact me off-forum, my PM is almost totally full
    Morpheusdual Prop SBC w/ 512KB kit $119.95, Mem+2MB memory IO board kit $89.95, both kits $189.95
    Propteus and Proteus for Propeller prototyping 6.250MHz custom Crystals run Propellers at 100MHz
    Las - Large model assembler for the Propeller Largos - a feature full nano operating system for the Propeller
  • KenBashKenBash Posts: 68
    edited 2009-12-10 23:51
    Hey everyone... I'm running a 5 axis machine with the propeller right now. You feed it a go command and it drives all 5 axis from where it is, to where you want to be. I'm only doing step and direction but it's not a big deal to do a phase lookup using the direction flag for 4 transistor phase control. ( however, 5 motors would tie up a full 20 pins, with limit inputs, that's 25 pins, it starts to crowd the I/O but might be OK as a dedicated controller with a second prop feeding it the positioning data.


    adding pulse width modulation to the outputs might let you do micro-stepping as well, but I haven't had the need to try to code it. I don't have ramping, but I do have speed control.

    I'd have to clean up my code a bit to post it, but if you think it would make a worthwhile object I'll put it out here.

    I have 4 axis code for the SX-48 that does have ramp control as well. ( full or half phase stepping ) You send it the XYZ coordinates in a 19.2K data packet and it drives to the correct position: Ramp up-ramp down or ramp up, run, ramp down.

    It was an amazing accomplishment for me at the time. I tried to interest Parallax in it as a product, but they weren't interested.

    The Propeller has enough horsepower that I'm getting reasonable 5 axis performance in SPIN. I haven't gotten good enough at pasm to feel comfortable re-writing it in assembly, but it should be pretty straight-forward if someone wants to take the ball and run with it.

    K.B.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    " Anything worth doing... is worth overdoing. "

    ··············································· ( R.A.H. )
    ····································
  • BergamotBergamot Posts: 185
    edited 2009-12-11 21:49
    photomankc said...
    If you guys beat me to it (likely) I'd love to see what comes of it. I'm looking to drive three of these:

    http://www.allegromicro.com/en/Products/Part_Numbers/97060/

    It takes care of chopping and microstepping based on digital input and can drive up to three amps. My application will be a three axis CNC controller/driver that would be capable of acting as a stand-alone power drive with poor-man's digital readout or as a slave to a PC running CNC software. I'd really love to be able to add an SD card and run the G-Code straight from that but that would be way down the road. As soon as I get the ability to make my own PCBs I plan to start on this.
    I've actually started work on a simple SD card G-Code interpreter in Spin, is this something that people would be interested in? I don't intend to support all of the exotic commands that rarely show up in CAM output, but basic line drawing shouldn't be too hard
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2009-12-12 01:35
    Ken,

    Sounds good Ken, does it do interpolated moves too? If so between how many axes, sounds really neat.

    I also have an stepper object that produces step and direction pulses but it only runs one axis at a time (or multiple axes but not synchronised), it is written in assembly and does trapizoidal motion profiles. It uses the exact same motion control technique as the G-rex by geckodrive, the counters are used in NCO mode and updated at regular intervals, the intergral of the frequencies is proportional to distance etc. It is possible to do coordinated moves I just have not got "a round toit" yet. That is why it has not been released as yet. Might be another Christmas project.

    Cheers,

    Graham
  • KyeKye Posts: 2,200
    edited 2009-12-12 01:46
    Maybe you should post then Graham. I'm more interested in working on FAT code.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • KyeKye Posts: 2,200
    edited 2009-12-12 16:06
    Okay, Well since bill has something to use I'll put off developement on this until next year. I have a bit of other stuff to do today.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • Bill HenningBill Henning Posts: 6,445
    edited 2009-12-12 17:03
    Thanks Kye!

    I am looking forward to your stepper control object.
    Kye said...
    Okay, Well since bill has something to use I'll put off developement on this until next year. I have a bit of other stuff to do today.
    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.mikronauts.com Please use mikronauts _at_ gmail _dot_ com to contact me off-forum, my PM is almost totally full
    Morpheusdual Prop SBC w/ 512KB kit $119.95, Mem+2MB memory IO board kit $89.95, both kits $189.95
    Propteus and Proteus for Propeller prototyping 6.250MHz custom Crystals run Propellers at 100MHz
    Las - Large model assembler for the Propeller Largos - a feature full nano operating system for the Propeller
  • KyeKye Posts: 2,200
    edited 2009-12-12 18:32
    Thanks for giving me a bit of time. I'll give it all the quality of my other current motor driver objects.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
Sign In or Register to comment.