Motor Stepper Example


Results 1 to 40 of 135

Threaded View

  1. #11
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Default Re: Motor Stepper Example

    Code:
    DEFINE OSC 4              ' not compulsory because default value ...
    StepCount VAR BYTE   ' Distance to move ' No need a word as Stepcount is < 255 !
    Delay VAR WORD          ' Time, in 2ms steps, between each step-pulse
    i VAR WORD                 ' General purpose index/counter variable
    
    But VAR PortB.2
    Dir_Pin VAR PortB.4
    Step_Pin VAR PortB.5
    
    CW CON 0
    CCW CON 1
    
    CMCON = 7
    ANSEL = 0
    PORTB = 0                'Reset PortB to be sure
    TRISB = %11001111   ' PortB4-5 outputs, rest are inputs.
    
    Main:
      If But = 0 THEN
         StepCount = 200   ' Distance to move motor
         Delay = 2      ' 2ms between each step 
         Dir_Pin = CCW    
         Gosub MoveMotor
      ENDIF
    Goto Main
    
    END
    
    MoveMotor:
      For i = 0 to (StepCount - 1)
         PULSOUT Step_Pin, 1 'Gosub StepIt
        PauseUs Delay
      NEXT
    RETURN
    Here are some ideas ...

    Alain
    Last edited by Acetronics2; - 5th March 2013 at 07:34.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Members who have read this thread : 5

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