Motor Stepper Example


Closed Thread
Results 1 to 40 of 135

Hybrid View

  1. #1
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: Motor Stepper Example

    sorry for uploading pictures of the design, but would like before starting with the simple code, to give you a feeling of the jig and fixture model.

    So what you see is a model that has 200 steps inside the circle, and 16 points outside (8 sharp and 8 with a hole)

    Those can represent basic angles on a 360.

    When i have them ready then i can start to right one or two lines of program to play with.

    After that i will improve the code with your help

    thanks a lot.
    Attached Images Attached Images  

  2. #2
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: Motor Stepper Example

    Dear All,

    I dont Know if the following Code will MAKE the Motor To rotate.

    I would like to have your opinion.

    Code:
    '****************************************************************
    '*  Name    : UNTITLED.BAS                                      *
    '*  Author  : [Leonardo Bilalis]                                *
    '*  Notice  : Copyright (c) 2013                                *
    '*          : All Rights Reserved                               *
    '*  Date    : 3/3/2013                                          *
    '*  Version : 1.0                                               *
    '*  Notes   : Stepper Motor                                     *
    '*          :                                                   *
    '****************************************************************
    define osc 4
    Include "MODEDEFS.BAS"
    ANSEL = 0
    cmcon = 7
    
    TRISB = %1111011
    
        but var PORTB.2
        Motor_Step VAR PORTB.5 ; ASIGN THE PIC16F88 PORTB.5 TO STEP PIN ON THE BIG EASY DRIVER
        DIRECTION VAR PORTB.4  ; ASIGN THE PIC16F88 PORT.4 TO DIR PIN ON THE BIG EASY DRIVER
    
    BEGIN: 
        LOW PORTB.4 ; WE CAN START BY MAKING LOW THE PORTB.4
        LOW PORTB.5 ; WE CAN START BY MAKING LOW THE PORTB.5
        PAUSE 1000 ; THEN WE GIVE 1 SECOND DELAY
        
        if but = 0 then ;WE HAVE CONNECTED A PUSH BUTTON AT PORTB.2
        goto rotation   ;IF WE PRESS IT THEN PROGRAM GOES TO ROTATION LABEL 
        else            ;IF WE DO NOT PRESS IT THE PROGRAM RETURN TO BEGIN
        goto begin
            endif
      
      ;THE FOLLOWING CODE SUPPOSE TO ROTATE THE SHAFT 500 STEPS 
      ;AS FROM THE CALCULATION THE SECOND HAS 1000 MILI SECONDS
      ;AND WE ONLY GIVE 2 MILI SECONDS DELAY, SO WE GET 500 STEPS.
      ;IN CASE WE WOULD LIKE TO HAVE ONE REVOLUTION, THE WE NEED
      ;TO GIVE EXACTLY 200 STEPS FOR THIS SPECIFIC MOTOR.
      ;IN THIS CASE WE NEED WE NEED 5 MILI SECONDS FOR A PAUSE OF HIGH AND LOW TOGETHER
           
    ROTATION:
        HIGH MOTOR_STEP ; HERE WE MAKE HIGH THE PORT.B WHICH IS CONNECTED TO step PIN ON THE BED
        PAUSE 1         ; DELAY ONE ms
        low MOTOR_STEP ; HERE WE MAKE low THE PORT.B WHICH IS CONNECTED TO step PIN ON THE BED
        PAUSE 1         ; DELAY ONE ms
        
        GOTO BEGIN
        END

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Motor Stepper Example

    Hi,
    If you want to move the motor 500 steps you need to send 500 pulses. The frequency of the pulsetrain, ie the delay between pulses, controls the speed of the motor.
    The way you currently have it will move ONE step when the button is pressed, then it will start over, wait a second, move ONE step and so on - as long as the button is pressed.

    Finally, you should try to avoid using GOTO. As the program grows it tends to get really hard to follow when there's a lots of GOTOs all over. Instead make your program into subroutines and use GOSUB/RETURN.
    Code:
    Main:
      If But = 0 THEN
         GOSUB StepIt
      ENDIF
    Goto Main
    
    END
    
    StepIt:
      High Motor_Step
      Pause 1
      Low Motor_Step
      Pause 1
    RETURN
    /Henrik.

  4. #4
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: Motor Stepper Example

    Hi Henrik,

    thanks a lot for the advice.

    in order to send for example 200 pulses for one revolution, do i need to give for i = 200 to do the revolution label so many times as the i ?

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Motor Stepper Example

    Yes, exactly!
    By the way, you seem to have your TRIS settings backwards, a set bit makes the pin an input, a cleared bit makes it an output.

    I haven't actually tested the following so please see it as an overall idea and not verified/working code:
    Code:
    DEFINE OSC 4
    
    StepCount VAR WORD   ' Distance to move
    Delay VAR WORD          ' Time, in us, 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
    TRISB = %11001111   ' PortB4-5 outputs, rest are inputs.
    
    Main:
      If But = 0 THEN
         StepCount = 200   ' Distance to move motor
         Delay = 2000        ' 2000us between each step
         Dir_Pin = CCW    
         Gosub MoveMotor
      ENDIF
    Goto Main
    
    END
    
    MoveMotor:
      For i = 0 to (StepCount - 1)
        Gosub StepIt
        PauseUs Delay
      NEXT
    RETURN
    
    StepIt:
        Step_Pin = 1     ' Generate a 10us wide pulse on the step pin.
        PauseUs 10
        Step_Pin = 0
    RETURN
    /Henrik.

  6. #6
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: Motor Stepper Example

    ops my bad, you are right, TRISB must be otherway round.

    1 is inpupt and 0 is output.

    Apart from than i will compile the code and try to run it and test it tomorrow.

    will keep you updated. Let me print first the jig and fixture models so i can test the steps easier.

    thanks a lot.

  7. #7
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: Motor Stepper Example

    today i will try to build the models but will be ready for testing tomorrow. So please give me some time. thanks a lot.

Members who have read this thread : 4

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