Step motor control


Closed Thread
Results 1 to 23 of 23

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: Step motor control

    Hi,
    It's not easy to say what the problem is. It might be that you need to start even slower than ~100Hz and then ramp up the step frequency, in order to see if that is the case increase the pause time between each step to something like 25ms.

    The above is also the answer to how you change the speed. There's the DELAY variable which, in my example gets assigned the value of 10. Between each step there's a delay of 10ms, change that and the motor speed changes.

    A schematic of how you have it wired would help too. Usually you run step motors at much higher voltage than what they are rated for and then limit the current. For unipolar drive this was usually done by big series resistors. In todays bipolar drives it's done thru chopping/PWM.

    With PBP you don't need to specify anything with the NEXT statement. It automatically belongs to the FOR that is "closest to it". You CAN definitely add a variable to the NEXT for added clarity but it's not needed.

    Finally, you say the motor has a step angle of 5.625 degrees, that's 360/5.625=64 steps/rev. Then you have a gearbox with a ratio of 1:64, so 64*64 is 4096 and not 2048 as you've stated....something isn't correct there but it's not related to your problem so it doesn't really matter right now.

    /Henrik.

  2. #2
    Join Date
    May 2010
    Posts
    43


    Did you find this post helpful? Yes | No

    Default Re: Step motor control

    HI,
    do you now what is hapend,
    when I write this code:

    Delay VAR BYTE
    i VAR WORD

    TRISB = 0 ' All outputs.

    Delay = 10 ' ~100steps / second

    For i = 1 to 512
    PORTB = %00000001
    Pause Delay
    PORTB = %00000010
    Pause Delay
    PORTB = %00000100
    Pause Delay
    PORTB = %00001000
    Pause Delay

    NEXT

    Pause 1500

    For i = 1 to 512
    PORTB = %00001000
    Pause Delay
    PORTB = %00000100
    Pause Delay
    PORTB = %00000010
    Pause Delay
    PORTB = %00000001
    Pause Delay
    NEXT
    My motor turn round 360 degrees, and back - 360 degrees ,1 time!!!

    and when I write this code:

    Delay VAR BYTE
    i VAR WORD

    TRISB = 0 ' All outputs.

    Delay = 10 ' ~100steps / second

    For i = 1 to 4096
    PORTB = %00000001
    Pause Delay
    PORTB = %00000010
    Pause Delay
    PORTB = %00000100
    Pause Delay
    PORTB = %00001000
    Pause Delay

    NEXT

    Pause 1500

    For i = 1 to 4096
    PORTB = %00001000
    Pause Delay
    PORTB = %00000100
    Pause Delay
    PORTB = %00000010
    Pause Delay
    PORTB = %00000001
    Pause Delay
    NEXT
    my motor turn round 360 degrees,and back - 360 degrees, 4 time is correct?
    Last edited by dragan77; - 5th September 2011 at 20:32.

  3. #3
    Join Date
    May 2010
    Posts
    43


    Did you find this post helpful? Yes | No

    Default Re: Step motor control

    this is schema:
    Attached Images Attached Images  

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: Step motor control

    Hi,
    Yes, if the motor/gearbox requires 4096 steps to turn one revolution the first piece of code will move 360 degrees forward and then 360 degrees back. There are 4 "steps" each time thru the FOR-NEXT loop so 512*4=4096.

    In the second piece of code it'll move 1440 degrees forward and then 1440 degrees back.

  5. #5
    Join Date
    May 2010
    Posts
    43


    Did you find this post helpful? Yes | No

    Default Re: Step motor control

    thks,but sorry I don't understood,is not problem to write code to I tested,pls.

  6. #6
    Join Date
    May 2010
    Posts
    43


    Did you find this post helpful? Yes | No

    Default Re: Step motor control

    Can you looking this page,
    my motor is ST-28.MAYBE YOU FIND ANSWER!
    http://www.khwelling.nl/cnc/hardware/motor_test.html

  7. #7
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: Step motor control

    You can improve your motor performance in two ways:

    1) Use half step sequence ( here a sample code)

    Code:
    HStep           var byte    [8]     ' Half step sequence array
    B0              var byte
    C0              var byte
    P0              var byte
    W0              var word
    
    TRISB = 0
    
    
    P0 = 50   ' incrementing the delay will reduce the motor speed  (max 255)
    C0 = 0
    B0 = 0
    
    HalfMode:                      
    If C0 = 0 then gosub CW
    C0 = C0 + 1
    if C0 = 2 then C0 = 0
    If C0 = 0 then gosub CW
    If C0 = 1 then gosub CCW
    
    for W0 = 0 to 8192   ' one turn of the gear shaft ( 64 motor turns)
    PortB = HStep[B0]
    B0 = B0+1   
    if B0 = 8 then B0=0
    pause P0
    next W0
    
    Goto HalfMode
    
    CW:        ' half step sequence (clockwise)
    HStep[0] = 1
    HStep[1] = 3
    HStep[2] = 2
    HStep[3] = 6
    HStep[4] = 4
    HStep[5] = 12
    HStep[6] = 8
    HStep[7] = 9
    return
    
    CCW:       ' half step sequence (counter clockwise)
    HStep[0] = 9
    HStep[1] = 8
    HStep[2] = 12
    HStep[3] = 4
    HStep[4] = 6
    HStep[5] = 2
    HStep[6] = 3
    HStep[7] = 1
    return
    
    end
    2) Use a constant current setup to your motor. The simple way is to use a LM317 configured as costant current supply. See the attached schematic (Resistor 33 Ohms 1 watt. Use 24 V dc as an input to the LM317)

    cheers

    Al.
    Attached Images Attached Images  
    Last edited by aratti; - 5th September 2011 at 22:31.
    All progress began with an idea

Members who have read this thread : 0

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