Shop OBEX P1 Docs P2 Docs Learn Events
Stepper motor control with the Propeller — Parallax Forums

Stepper motor control with the Propeller

WolfbrotherWolfbrother Posts: 129
edited 2010-01-01 05:52 in Propeller 1
Hi,

I got the stepper motor from my previous post·to work with the basic stamp. I got a K179 Stepper Driver hooked up to my Basic Stamp BOE and can spin the motor in both directions. I used the Stamp command PULSOUT to create a 40uS pulse and inserted a single pause (1mS) to create a pulse train. With 2000 iterations of this, it spins the motor 10 times (200 steps per revolution) just fine. I went back to the stamp because I am very much not a programmer and sort of can get where I am going with the Stamp. I need to have several things going on at the same time so I have to use the propeller. I can't find some of the equivalent commands to the stamp like PWM and PULSOUT. Is the only thing to do is·generate these types of commands using OUTA and WAITCNT? Does anyone have a simple example for a complete propeller novice like me? The OBEX examples are kind of robust and I'm just not seeing the forest for the trees. I have attached my Stamp code to show my logic.

Thanks,

Dave

Comments

  • hover1hover1 Posts: 1,929
    edited 2009-12-31 19:03
    Try JonnyMac's Column #136 on this page:

    ·http://www.parallax.com/Resources/NutsVoltsColumns/NutsVoltsVolume7/tabid/450/Default.aspx

    "Stepping out with Spin"

    He translates BS2 stepper code to Spin.·
  • hover1hover1 Posts: 1,929
    edited 2009-12-31 19:10
    Also Martin's great object "BS2 Functions"

    ·http://obex.parallax.com/objects/30/

    will enable you you to use PULSOUT commands in SPIN.

    Or Bean's current thread on PropBasic. Haven't tried to see if PULSOUT has been implemented yet.

    ·http://forums.parallax.com/showthread.php?p=867134

    Jim
  • photomankcphotomankc Posts: 943
    edited 2009-12-31 19:50
    Should be fairly simple in spin... using your pin numbers:

    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
     
    PUB Main
     
      repeat
       DoTest
     
    PUB DoTest | _1us, pauseTime
      _1us := CLKFREQ / 1_000_000  
      pauseTime := _1Us * 1000 
       
      dira[noparse][[/noparse]8] ~~ 
      dira[noparse][[/noparse]0] ~~
       
      outa[noparse][[/noparse]8] ~~
      outa[noparse][[/noparse]0] ~
       
      repeat 2000
        outa[noparse][[/noparse]0] ~~
        outa[noparse][[/noparse]0] ~
        
        waitcnt(pauseTime + cnt)
       
      waitcnt(clkfreq * 3 + cnt)
       
      outa[noparse][[/noparse]8] ~
       
      repeat 2000
        outa[noparse][[/noparse]0] ~~
        outa[noparse][[/noparse]0] ~
        
        waitcnt(pauseTime + cnt)
     
      waitcnt(clkfreq * 3 + cnt)
    
    
    

    Kinda quick 'n dirty but it should work the same.· The only thing I'm not sure of is if the driver you use would need more than the about 8us positive pulse that will generate with 80MHz spin.· That's what I am using to make my outbound pulses and my scope says it's just a little more than 8us in width.·· I have not found a way to reliably waitcnt for less than about 65us so if you needed a longer pulse then a couple dummy assignment operations in between the ~~ and ~ of the pulse toggle code might slow it down enough.· If there is a way to get waitcnt to execute a shorter wait than 63 to 65us I'd be interested to see it.·

    This compiles but I can't test it at the moment.

    Post Edited (photomankc) : 12/31/2009 8:00:31 PM GMT
  • w8anw8an Posts: 176
    edited 2010-01-01 05:52
    Some information here as well...
    http://forums.parallax.com/showthread.php?p=839549
Sign In or Register to comment.