Stepper Motor Program


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2007
    Posts
    26

    Default Stepper Motor Program

    I have got a stepper motor working nicely on a basic stamp with the following code. But am unsure of what changes should I make for the same code to work on a PIC. I understand most of what is going on but am a bit unsure about what the Phase is about and the OUTB

    Phase VAR OUTB ' phase control outputs
    idx VAR Byte ' loop counter
    stpIdx VAR Nib ' step pointer
    stpDelay VAR Byte ' delay for speed control

    Steps DATA %0011, %0110, %1100, %1001

    Setup:
    DIRB = %1111 ' make P4..P7 outputs
    stpDelay = 5 ' set step delay

    Main:
    FOR idx = 1 TO 200 ' one revolution
    GOSUB Step_Fwd ' rotate clockwise
    NEXT
    PAUSE 500 ' wait 1/2 second
    FOR idx = 1 TO 200 ' one revolution
    GOSUB Step_Rev ' rotate counter-clockwise
    NEXT
    PAUSE 500 ' wait 1/2 second
    GOTO Main
    END

    ' -----[ Subroutines ]-----------------------------------------------------

    Step_Fwd:
    stpIdx = stpIdx + 1 // 4 ' point to next step
    GOTO Do_Step

    Step_Rev:
    stpIdx = stpIdx + 3 // 4 ' point to previous step
    GOTO Do_Step

    Do_Step:
    READ (Steps + stpIdx), Phase ' output new phase data
    PAUSE stpDelay ' pause between steps
    RETURN

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Hi kiwipiper,
    No Dirs in PBP so DIR = 1111 becomes TRISB = %0000 ' make lower B ports outputs
    change NIB to BYTE as no NIBs in PBP
    Phase VAR OUTB ' phase control outputs - not sure what to do here . . . what does this do in stamp lingo?
    stpDelay = 5 would be stpDelay CON 5
    Last edited by Archangel; - 26th November 2007 at 03:25.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    It has been awhile since I stamped, but this should get you going with PIC BASIC.
    http://www.picbasic.co.uk/forum/show...hlight=stepper
    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    Oct 2007
    Posts
    26


    Did you find this post helpful? Yes | No

    Default Solved

    Thanks for that, got it working not as elegantly as the first program but it does the job.
    Here is the code, any suggestions on making it a bit more elegant wouild be appreciated.

    DEFINE OSC 4

    TRISB = %00000000

    speed var word
    i var byte
    speed = 10

    Main:
    FOR i = 1 TO 50 ' one revolution
    GOSUB Step_Fwd ' rotate clockwise
    NEXT i
    PAUSE 500 ' wait 1/2 second
    FOR i = 1 TO 50 ' one revolution
    GOSUB Step_Rev ' rotate counter-clockwise
    NEXT i
    PAUSE 500 ' wait 1/2 second
    GOTO Main
    END

    Step_Fwd:
    portb = %1001
    pause speed
    portb = %1100
    pause speed
    portb = %0110
    pause speed
    portb = %0011
    pause speed
    return

    Step_Rev:
    portb = %0011
    pause speed
    portb = %0110
    pause speed
    portb = %1100
    pause speed
    portb = %1001
    pause speed
    return

Similar Threads

  1. 18f4431; driving a stepper IN HARDWARE mode
    By DDDvvv in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 21st January 2010, 16:49
  2. Replies: 11
    Last Post: - 6th November 2008, 10:27
  3. Controlling stepper motor with PIC
    By The Master in forum Off Topic
    Replies: 3
    Last Post: - 1st July 2008, 10:21
  4. Driving Stepper Motor with PBL3717
    By crhomberg in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 8th November 2007, 20:59
  5. problem with stepper!!
    By ibra in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 7th August 2007, 16:41

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

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