Step motor control


Closed Thread
Results 1 to 23 of 23

Hybrid View

  1. #1
    Join Date
    May 2010
    Posts
    43


    Did you find this post helpful? Yes | No

    Default Re: Step motor control

    This code work very nice!
    Is very precision!
    I testing yes-today!

    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
    But I don't now what is happens,
    work well 5-6 min,and in the moment stop,like some reset happened,I don't now ,
    and start over again,I don't why!

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


    Did you find this post helpful? Yes | No

    Default Re: Step motor control

    Hi,
    If it looks like a reset it probably is. There's no bypass capacitor in the schematic, if you don't have that in your circuit make sure you add one. 0.1uf right across the Vdd/Vss pins.

  3. #3
    Join Date
    May 2010
    Posts
    43


    Did you find this post helpful? Yes | No

    Smile Re: Step motor control

    Thks man!
    I make this, you mean across + an -,from power!
    I see that many time in shema,why is that nessery?


    Now I testing this code:
    Code:
    Delay VAR BYTE
    i VAR WORD
    
    TRISB = 0           ' All outputs.
    
    Delay = 8           
    pause 1000
    For i = 1 to 512    '512 steps forward.
      PORTB =9
      Pause Delay
      PORTB =3
      Pause Delay
      PORTB =6
      Pause Delay
      PORTB =12
      Pause Delay
      
    NEXT
    pause 2500
    
    
    For i = 1 to 256    '256 steps reverse.
      PORTB =12
      Pause Delay
      PORTB =6
      Pause Delay
      PORTB =3
      Pause Delay
      PORTB =9
      Pause Delay
    NEXT
    Pause 2500
    
    For i = 1 to 256    '256 steps reverse.
      PORTB =12
      Pause Delay
      PORTB =6
      Pause Delay
      PORTB =3
      Pause Delay
      PORTB =9
      Pause Delay
    NEXT
    Pause 1500
    For now, working 2 hour fine,is precison,and dont have some reset,we will se for now!

    And one more question,is possible make some code for picbasic for this:

    If step motor work some,go to left,go to right,.......
    and I stop power,and turn again,is possible,motor back in some start position,(some zero posicion),and continue work same function,before stoping!
    Last edited by dragan77; - 6th September 2011 at 16:42.

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


    Did you find this post helpful? Yes | No

    Default Re: Step motor control

    Yes, between pin 14 and 5 on the PIC as close to the chip as possible.
    It's needed because as the current thru the circuit fluctuates (rises and falls) quickly (which it does in digital circuits, not to mention motor control and other "high power" circuits) the resistance and inductance of the wires and/or PCB traces that "feeds" the chip makes the voltage at the chip unstable.

    If you look at ANY profesional PCB/circuit you'll see a bypass capacitor right next to EVERY chip for this particular reason.

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


    Did you find this post helpful? Yes | No

    Default Re: Step motor control

    You will need some kind of reference switch on the shaft (microswitch, hall, proximity, whatever) to detect when the shaft is the "home position". Then, at startup, take a step check the input, and keep doing that in a loop until the switch is detected.

  6. #6
    Join Date
    May 2010
    Posts
    43


    Did you find this post helpful? Yes | No

    Default Re: Step motor control

    I wrong for last questin,I mean:
    And one more question,is possible make some code for picbasic for this:

    If step motor work some,go to left,go to right,.......
    and I stop power,and turn again,is possible,motor back in some start position,(some zero posicion),and continue work same function,FROM START CODE!

  7. #7
    Join Date
    May 2010
    Posts
    43


    Did you find this post helpful? Yes | No

    Default Re: Step motor control

    THANKS,I mean only some switch can make this,I think in write code not impossible,Thks anyway!

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


    Did you find this post helpful? Yes | No

    Default Re: Step motor control

    Hi,
    There is no inherent feedback on a step-motor so without some kind of reference switch (or position encoder etc) it's not possible to know where "home" is.

    Here's a somewhat expanded version of the code. It's a bit more "modular" than earlier, you can select drive-type and just set the direction and number of steps before calling the Drive subroutine. I've not tested it here (no hardware) so you're on your own there if you decide to use it.

    As you might see, I've added a FindHome routined which moves one step at a time until it finds the switch. Just remove it if you're not going to use it.
    Code:
    '****************************************************************
    '*  Name    : StepIndexer.pbp                                   *
    '*  Author  : Henrik Olsson                                     *
    '*  Notice  : Copyright (c) 2011 Henrik Olsson                  *
    '*          : All Rights Reserved                               *
    '*  Date    : 2011-09-07                                        *
    '*  Version : 1.0                                               *
    '*  Notes   : Very simple step motor indexer for unipolar drive.*
    '*          :                                                   *
    '****************************************************************
    
    Direction   VAR BYTE    ' Forward=1, Back=254
    Distance    VAR WORD    ' Number of steps to move
    DriveType   VAR BYTE    ' WaveDrive=0, HiTorque=1, HalfStep=2
    StepCount   VAR WORD    ' Counts the number of steps moved
    Delay       VAR BYTE    ' Delay between steps
    
    HomeSwitch  VAR PORTA.0 ' Reference/home switch connected here
    
    Index       VAR BYTE    ' Index "pointer" used for the lookup tables.
    Temp        var BYTE    ' General purpose
    
    FORWARD     CON 1
    BACK        CON 254
    WaveDrive   CON 0
    HiTorque    CON 1
    HalfStep    CON 2
    
    
    TRISB = 0               ' All PortB pins are outputs.
    TRISA.0 = 1             ' Reference/home switch connected to RA0
            
    pause 1000
    
    CLEAR
    
    DriveType = HiTorque   ' Use the two phase on high torque mode
    
    '---------------------------------------------------------------------------
    FindHome:
    ' Take one step at a time untill the reference switch connected
    ' to PortA.0 is found, stop there.
      Direction = FORWARD   ' Move forward
      Distance = 1          ' step by step
      Delay = 20            ' at roughly 50Hz
      While HomeSwitch = 0
         GOSUB Drive
      Wend
    '---------------------------------------------------------------------------
     
    Pause 2500
     
    Cycle:
      Direction = FORWARD   ' Go forward...
      Distance = 512        ' for 512 steps...
      Delay = 20            ' at roughly 50Hz...
      Gosub Drive           ' do it
    
      Pause 2500
    
      Direction = BACK      ' Go back...
      Distance = 512        ' for 512 steps...
      Delay = 10            ' at roughly 100Hz...
      GOSUB DRIVE           ' do it.
    
      Pause 2500
    Goto Cycle
    
    
    '---------------------------------------------------------------------------
    Drive:
    ' Move Distance number of steps. Direction gets added to Index each iteration,
    ' this makes Index count up (when direction=FORWARD (1)) or down
    ' (when direction=BACK (254)). Then, depending on the desired drive type we
    ' either mask the lower two or lower three bits in temp and use those as the
    ' actual pointer into the Lookup-tables for the three different drive sequences
    ' (Wave drive, Hi-Torque and Half step). The result of the table lookup is put
    ' on PortB.
    
      For StepCount = 1 to Distance
         Index = Index + DIRECTION
    
         Select Case DriveType
    
           Case WaveDrive
              Temp = Index & 3
              Lookup Temp, [1, 2, 4, 8], PortB
           
           Case HiTorque
              Temp = Index & 3
              Lookup Temp, [3, 6, 12, 9], PortB
           
           Case HalfStep
              Temp = Index & 7
              Lookup Temp, [1, 3, 2, 6, 4, 12, 8, 9], PortB
            
            END SELECT
            
         Pause Delay
      NEXT
    Return
    '---------------------------------------------------------------------------
    /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