Step motor control


Closed Thread
Results 1 to 23 of 23

Hybrid View

  1. #1
    Join Date
    May 2010
    Posts
    43

    Default Step motor control

    Can someone write me code in picbasic for stepper motor control!

    I would like to control a stepper motor, for example:
    to turn through 360 degrees, and to stop, go back 180 degrees, and to stop, and so on,
    I would need a program that works fine, I have tried with some, but always the first mistake and the engine moves a step forward for some step,is not precision.
    I use pic 16f628,I forgot say that!

    I use this code,but make some mistake after few circle work,not back in same point:

    i var byte
    k var byte
    symbol brz=900 'speed



    '360 circle-----------------------------------------
    allcircle:
    pause 500
    For k = 1 to 4
    For i = 1 to 128

    PULSOUT PORTB.0,brz
    PULSOUT PORTB.1,brz
    PULSOUT PORTB.2,brz
    PULSOUT PORTB.3,brz
    next i
    next k

    pause 2500
    goto halfcircle
    '-----------------------------------------

    '180circle-----------------------------------------
    halfcircle:
    For k = 1 to 2
    For i = 1 to 128

    PULSOUT PORTB.3,brz
    PULSOUT PORTB.2,brz
    PULSOUT PORTB.1,brz
    PULSOUT PORTB.0,brz

    NEXT I
    next k

    pause 2500
    goto minushalfcircle
    '-----------------------------------------

    'minus180circle-----------------------------------------
    minushalfcircle:
    For k = 1 to 2
    For i = 1 to 128

    PULSOUT PORTB.3,brz
    PULSOUT PORTB.2,brz
    PULSOUT PORTB.1,brz
    PULSOUT PORTB.0,brz

    NEXT I
    next k

    pause 2500
    '-----------------------------------------
    GOTO allcircle
    Last edited by dragan77; - 5th September 2011 at 11:33.

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,115


    Did you find this post helpful? Yes | No

    Default Re: Step motor control

    Is your motor loaded?

    Have you tried to test it with no load at all?

    Ioannis

  3. #3
    Join Date
    May 2010
    Posts
    43


    Did you find this post helpful? Yes | No

    Default Re: Step motor control

    How do you think you loaded?
    I tried to test it and no-load, but it is the same.
    problem is that when running the operation is complete, not return to the same starting point, but perhaps the real fault of a few steps, and I really should be the precise.

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


    Did you find this post helpful? Yes | No

    Default Re: Step motor control

    Going by your code it seems that you have a unipolar motor (6 wires) and 4 switches (transistors or whatever). If so, using pulsout is not the best way since there will be a short delay between each pulsout statement where no current is flowing in any of the coils. When no current is flowing the torque drops and the rotor can "jump" to the closest natural step (magnetic pole).
    Code:
    Delay VAR BYTE
    i VAR WORD
    
    TRISB = 0  ' All outputs.
    
    Delay = 10   ' ~100steps / second
    
    For i = 1 to 1000    '1000 steps forward.
      PORTB = %00000001
      Pause Delay
      PORTB = %00000010
      Pause Delay
      PORTB = %00000100
      Pause Delay
      PORTB = %00001000
      Pause Delay
    NEXT
    
    Pause 2500
    
    For i = 1 to 1000    '1000 steps reverse.
      PORTB = %00001000
      Pause Delay
      PORTB = %00000100
      Pause Delay
      PORTB = %00000010
      Pause Delay
      PORTB = %00000001
      Pause Delay
    NEXT
    Now, there are other ways to "produce" the step sequence than this rather crude one but try this and see if it helps.

  5. #5
    Join Date
    May 2010
    Posts
    43


    Did you find this post helpful? Yes | No

    Default Re: Step motor control

    Thks for help HenrikOlsson,
    is work but is not precision,make mistake every 5-6 circle working.
    I use this step motor,ST-28 have 5 wire uni polar step motor,
    this is specification:

    Rated voltage: 12VDC
    Current: 32mA
    Resistance/phase: 280
    Fases: 4
    Angle/step: 5.625 deg
    Gear ratio: 1:64
    detent torque: 350gfcm (0.034Nm)
    pull-in torque: 6360g (0.059Nm)
    max. starting pulse rate:700pps
    max. slewing pulse rate:1400pps
    max. speed: 20.5 rpm
    steps/rev: 2048 (tested!!)
    connector order:

    B2: Blue
    B1: Pink
    A2: Yellow
    A1: Orange
    GND: Red

    And one more question in your code I will see you dont use this like in my code:
    Delay VAR BYTE
    i VAR WORD

    TRISB = 0 ' All outputs.

    Delay = 10 ' ~100steps / second

    For i = 1 to 1000 '1000 steps forward.
    PORTB = %00000001
    Pause Delay
    PORTB = %00000010
    Pause Delay
    PORTB = %00000100
    Pause Delay
    PORTB = %00001000
    Pause Delay
    NEXT here dont have i whay

    Pause 2500

    For i = 1 to 1000 '1000 steps reverse.
    PORTB = %00001000
    Pause Delay
    PORTB = %00000100
    Pause Delay
    PORTB = %00000010
    Pause Delay
    PORTB = %00000001
    Pause Delay
    NEXT
    and tell is when I change speed of motor maybe I must change some number of steps,of some else... I dont now!!!
    Last edited by dragan77; - 5th September 2011 at 19:02.

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


    Did you find this post helpful? Yes | No

    Default Re: Step motor control

    Can you post the wiring diagram?

    Al.
    All progress began with an idea

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    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.

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