Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 21, 2024, 08:06:25 08:06


Login with username, password and session length


Pages: [1]
Print
Author Topic: stepper motor  (Read 5999 times)
0 Members and 1 Guest are viewing this topic.
hamid9543
Active Member
***
Offline Offline

Posts: 124

Thank You
-Given: 80
-Receive: 7


« on: September 25, 2006, 02:02:46 14:02 »

hi
i drive stepper motor 1.8 with pic16f84a and uln2803 .but i have a problem!
trisb=0
t var byte
c var byte
t=20
for c=0 to 200
start:
portb=1
pause t
portb=2
pause t
portb=4
pause t
portb=8
pause t
next c
end
but stepper motor is  turned 4 full revolution instead of 1 full revolution.
Logged
chandra2sekhar2000
Active Member
***
Offline Offline

Posts: 127

Thank You
-Given: 24
-Receive: 18


« Reply #1 on: September 26, 2006, 01:25:43 13:25 »

hi hamid9543
The code is ok! but the stepper motor revolutes one step for 1 pulse.but your are providing 4 pulses per count.so reduse the count from 200 to 50.i think it may work.
Logged
hamid9543
Active Member
***
Offline Offline

Posts: 124

Thank You
-Given: 80
-Receive: 7


« Reply #2 on: September 26, 2006, 03:25:47 15:25 »

thanks for replay
for steep 1.8 >>1.8*200 = 360
with 50 count is working corect but is not standard
Logged
hemlig
Translator
Active Member
***
Offline Offline

Posts: 168

Thank You
-Given: 26
-Receive: 50



« Reply #3 on: September 27, 2006, 01:44:10 01:44 »

hi
i drive stepper motor 1.8 with pic16f84a and uln2803 .but i have a problem!
trisb=0
t var byte
c var byte
t=20
portb=for c=0 to 200 ' here you have a loop that is repeated 201 times
start:
' the sequence below is four (4) full steps
portb=1    ' this is the first step                   equals to %00000001
pause t     ' this is your delay between step
portb=2    ' this is the second step               equals to %00000010
pause t     ' this is your delay between step
portb=4    ' this is the third step                  equals to %00000100
pause t     ' this is your delay between step
portb=8    ' this is the fourth step                equals to %00001000
pause t     ' this is your delay between step
next c     ' call next loop
end
but stepper motor is  turned 4 full revolution instead of 1 full revolution.

'=========================================================
Hi I put some comments in your code to make it more clear to you what you have done

First you have a loop that is repeated 201 times
the sequence you have below is 4 steps
this means that you will send 201 x 4 full steps to the stepper
and that means 804 full steps to the motor.

Look in the datasheet for your steppermotor how many full steps
it need to make one revolution? (200/revolution)

This means that what chandra2sekhar200 already told you is correct.

50 x 4 = 200 full steps

and as you wrote the stepper have 200 steps at 1.8 degree in one revolution (one rev = 360 degrees)

With the code above unchanged your motor vill turn 4 full revolutions + 4 steps extra

(if you need it to turn exactly 4 revolutions you need to change the for loop
"for c=0 to 200" to "for c=0 to 199" or "for c=1 to 200")
'=========================================================
'(it is also possible to make half steps
'then you will need 400 half steps for one revolution.)
'=========================================================

trisb=0
t var byte
c var byte
t=20
portb=for c=1 to 50 ' this is repeated 50 times
'(50 times 8 half steps = one revolution
' on a 200 step/revolution motor)
start:
' the sequence below is eight ( 8 ) half steps
'a sequence with halfsteps looks like this:
portb=%00000001          ' (decimal 1)
pause t     ' this is your delay between step
portb=%00000011         ' (decimal 3)
pause t     ' this is your delay between step
portb=%00000010         ' (decimal 2)
pause t     ' this is your delay between step
portb=%00000110         ' (decimal 6)
pause t     ' this is your delay between step
portb=%00000100         ' (decimal 4)
pause t     ' this is your delay between step
portb=%00001100         ' (decimal 12)
pause t     ' this is your delay between step
portb=%00001000         ' (decimal 8 )
pause t     ' this is your delay between step
portb=%00001001         ' (decimal 9)
pause t     ' this is your delay between step
next c     ' call next loop
end


'bye
Logged

If it work don't fix it!
hamid9543
Active Member
***
Offline Offline

Posts: 124

Thank You
-Given: 80
-Receive: 7


« Reply #4 on: October 15, 2006, 08:08:30 08:08 »

hi
i appreciate for compelat explanation to my question. Smiley
Logged
mizk_electro
Cracking Team
Active Member
****
Offline Offline

Posts: 133

Thank You
-Given: 5
-Receive: 3


« Reply #5 on: October 15, 2006, 10:08:02 10:08 »

hi
i appreciate for compelat explanation to my question. Smiley

Can you share the schematic please ... thanks  Smiley
Logged
hemlig
Translator
Active Member
***
Offline Offline

Posts: 168

Thank You
-Given: 26
-Receive: 50



« Reply #6 on: October 15, 2006, 09:29:00 21:29 »

hi
i appreciate for compelat explanation to my question. Smiley

Yes,
now you really understand your own question  Wink

Anyway, I hope your project was a success.
« Last Edit: October 16, 2006, 03:08:15 03:08 by hemlig » Logged

If it work don't fix it!
hamid9543
Active Member
***
Offline Offline

Posts: 124

Thank You
-Given: 80
-Receive: 7


« Reply #7 on: October 17, 2006, 12:44:00 12:44 »

hi
if i need it turne 1/4 revoluation (90 degrees).how should i change the FOR loop.(steepr 1.8 and drive with 1 ,2 ,4 , 8 (2bit drive))
i am trying to design a maze robot and your information can help me
Logged
rinderpest
Junior Member
**
Offline Offline

Posts: 41

Thank You
-Given: 23
-Receive: 11

All machines are amplifiers


« Reply #8 on: November 02, 2006, 03:33:52 15:33 »

Hi people, the problem with all these bits of code is that you do not have stepwise control over the motor. This is fine as long as you dont mind moving in blocks of 4 steps (or 8 if half stepping).
I am currently working on a general purpose subroutine which will step in single steps and save state so when the next step command comes the motor starts from where it left off. Otherwise you will lose position when the stepper jerks to an arbitary start pos.
Until mine is finished I leave you this from the PBPro forum. Looks complicated but its worth a look.
regards and thanks to sonsivri for a great forum.


'
   '   zzstepper.bas
   '   =============
   '   Stepper Example Routine V 1.0
   '   By Melanie Newman
   '   Created 9/11/2002
   '   Last Updated 10/11/2002

   '
   '   Hardware Assignments
   '   --------------------
   StepA var PORTB.0
   StepB var PORTB.1
   StepC var PORTB.2
   StepD var PORTB.3

   '
   '   RAM Assignments and Variables
   '   -----------------------------
   CounterA var word
      ' General Counter
   StepDelay var word
      ' Inter-Step Delay (uS)
   StepReverse var bit
      ' 0=Drive Forward
      ' 1=Drive Reverse
   StepOut var byte
      ' a Variable reflecting Stepper Channel Outputs
   StepOnLine var bit
      ' 0=Stepper Off-Line (de-energised)
      ' 1=Stepper On-Line (energised)
   StepMode var Byte
      ' 0=Single Drive A-B-C-D
      ' 1=Two Phase Drive AB-BC-CD-DA
      ' 2=Half-Step A-AB-B-BC-C-CD-D-DA
   StepStatus var byte
      ' Step Status (a value between 0 and 7)
      ' used internally by the StepDrive routine.
      ' Other than presetting at Power-On... do not
      ' otherwise adjust this variable, as it keeps
      ' track of the current coil setting.
      '
      ' Single Step One Phase has FOUR possibilities
      '   0=A
      '   2=B
      '   4=C
      '   6=D
      ' Single Step Two Phase has FOUR possibilities
      '   1=AB
      '   3=BC
      '   5=CD
      '   7=DE
      ' Half-Step has EIGHT Possibles
      ' those eight possibilities are the two single
      ' steps interwoven.
      '   0=A
      '   1=AB
      '   2=B
      '   3=BC
      '   4=C
      '   5=CD
      '   6=D
      '   7=DA

   '
   '   Start Program
   '   =============
   goto JumpStart
   
   '
   '   Subroutine Nest Area
   '   ====================

   '
   '   Subroutine Drives Stepper
   '   -------------------------
   '   From wherever the current step position happens to be
   '   this routine will drive Forwards or Backwards.  If the
   '   Stepper happens to be parked in an illegal step for
   '   the current Mode, then it will ensure that the Stepper
   '   increments a one-half step first... this ensures that
   '   if the stepper is in position AB, and needs to increment
   '   TWO steps forwards in Mode 0, it increments AB-B-C
   '   rather than AB-C-D.
   '
StepDrive:
      '
      '   this section determines what the NEW StepStatus
      '   should be, depending on the Mode and Direction
      '   of step.
      '
   If StepReverse=0 then
      If StepMode=0 then
         Lookup StepStatus,[2,2,4,4,6,6,0,0],StepStatus
         endif
      If StepMode=1 then
         Lookup StepStatus,[1,3,3,5,5,7,7,1],StepStatus
         endif
      If StepMode=2 then
         Lookup StepStatus,[1,2,3,4,5,6,7,0],StepStatus      
         endif
      else
      If StepMode=0 then
         Lookup StepStatus,[6,0,0,2,2,4,4,6],StepStatus
         endif
      If StepMode=1 then
         Lookup StepStatus,[7,7,1,1,3,3,5,5],StepStatus
         endif
      If StepMode=2 then
         Lookup StepStatus,[7,0,1,2,3,4,5,6],StepStatus      
         endif
      endif
StepDriveRAW:
      '
      ' All Stepper Coils Disabled
      ' --------------------------
   Low StepA
   Low StepB
   Low StepC
   Low StepD
   If StepOnLine=1 then
      '
      ' Energise Coils to New Settings
      ' ------------------------------
      ' This Lookup table represents [A,AB,B,BC,C,CD,D,DA]
      Lookup StepStatus,[1,3,2,6,4,12,8,9],StepOut
      StepA=StepOut.0
      StepB=StepOut.1
      StepC=StepOut.2
      StepD=StepOut.3
      endif
   Return

   '
   '   Initialise Hardware
   '   -------------------
JumpStart:
   TRISB=%11110000
   StepOnLine=0      ' Power-Off Stepper
   Gosub StepDriveRAW
   Pause 1000      ' Wait for PSU's and Hardware to settle
   StepStatus=0      ' Preset initial Start Point
   StepMode=0      ' Standard Phase Mode 0
   StepReverse=0      ' Standard Forward Movement
   StepOnLine=1      ' bring Stepper On-Line
   Gosub StepDriveRAW
   '
   '   Application Example
   '   -------------------
   '   Gentle Ramp Up Stepper to 200rpm
   '   Run for about 3 Seconds at 200rpm
   '   Fast Ramp Down Stepper to Zero
   '   Pause 5 seconds and repeat Reversing Direction
   '   once this has been done, the Stepper Mode will
   '   change and the proceedure loops over again.
   '   Once all three Stepper Modes have been run, the
   '   program loops and starts over from Mode 0.
   '   ------------------------------------------
   '   200 step motor at 200 rpm=40000 steps/minute
   '   this is approx 666 steps (3.33 revs) per second
   '   Assuming NO program latenticity that's 1 step every 1.5mS
   '   The program will actually add some delay, probably around
   '   100uS but for now, lets assume this is ZERO.
   '   --------------------------------------------
   '   This entire example is dependant on the mass and inertia
   '   of your stepper and it's load.  The Delays may require
   '   serious consideration to make the Ramp-Up/down more
   '   applicable to the hardware and environment.
ExampleLoop:
      '
      '   Slow Ramp-Up Stepper
      '   --------------------
   For CounterA=0 to 2000 step 4
      Gosub StepDrive
      StepDelay=65500-(CounterA*32)
      PauseUS StepDelay
      Next CounterA
      '
      '   Run at constant Speed of 200 rpm (or so) for 3 Seconds
      '   ------------------------------------------------------
   For CounterA=0 to 2000
      Gosub StepDrive
      PauseUS 1500
      Next CounterA
      '
      '   Fast Ramp-Down Stepper
      '   ----------------------
   For CounterA=2000 to 0 step -20
      Gosub StepDrive
      StepDelay=65500-(CounterA*32)
      PauseUS StepDelay
      Next CounterA
      '
      '   Change Direction/Mode
      '   ---------------------
   If StepReverse=0 then
      StepReverse=1
      else
      StepReverse=0
      StepMode=StepMode+1
      If StepMode>2 then StepMode=0
      endif
      '   
      '   Wait 5 seconds
      '   --------------
   Pause 5000
   Goto ExampleLoop

   End





Logged

Experimentum solum certificat in talibus. 
     Experiment is the only safe guide
johnbharath
Guest
« Reply #9 on: December 11, 2006, 07:35:26 07:35 »

I am working on with this code with some modification acording to my project, Thanks for the code Smiley
Logged
rinderpest
Junior Member
**
Offline Offline

Posts: 41

Thank You
-Given: 23
-Receive: 11

All machines are amplifiers


« Reply #10 on: December 28, 2006, 09:48:31 21:48 »

Thats all right, I didnt write it but Im glad its some use.
I've had to be away from my workshop for 'technical reasons'
but Im back so hopefully my take on this problem will follow soon.
I've just switched to MikroBasic from PBP so Im still at larval stage.
Its verbose compared with PBP but the libraries tempted me.
Happy New Year etc, rinderpest
Logged

Experimentum solum certificat in talibus. 
     Experiment is the only safe guide
hamid9543
Active Member
***
Offline Offline

Posts: 124

Thank You
-Given: 80
-Receive: 7


« Reply #11 on: December 29, 2006, 08:25:26 08:25 »

hi
i write code but the stepper not working properly for 90 deg
 shematic is attach
Logged
hamid9543
Active Member
***
Offline Offline

Posts: 124

Thank You
-Given: 80
-Receive: 7


« Reply #12 on: December 31, 2006, 09:53:49 09:53 »

hi
plaese help
. Cry Cry Cry Cry.palese guide me for drive unibipolar stepper for 90 deg
Logged
rinderpest
Junior Member
**
Offline Offline

Posts: 41

Thank You
-Given: 23
-Receive: 11

All machines are amplifiers


« Reply #13 on: January 04, 2007, 06:19:23 18:19 »

If you post your schematic and code etc we can have a look...
Logged

Experimentum solum certificat in talibus. 
     Experiment is the only safe guide
rinderpest
Junior Member
**
Offline Offline

Posts: 41

Thank You
-Given: 23
-Receive: 11

All machines are amplifiers


« Reply #14 on: January 26, 2007, 07:13:09 19:13 »

Bump...
Logged

Experimentum solum certificat in talibus. 
     Experiment is the only safe guide
kalpakchiev
Active Member
***
Offline Offline

Posts: 137

Thank You
-Given: 34
-Receive: 68



« Reply #15 on: August 31, 2007, 09:12:51 09:12 »

I use a stepper motor for etching PCB's here is the code for it you can use some fragments from the code:

TRISA=%00000000
TRISB=%11110000


'ÏÐÎÌÅÍËÈÂÈ
I           VAR     Word
TT          VAR     Word    'ÏÐÎÌÅÍËÈÂÀ ÇÀ ÈÇÌÅÐÂÀÍÅ ÍÀ ÂÐÅÌÅ
TTT         VAR     Word    'ÏÐÎÌÅÍËÈÂÀ ÇÀ ÈÇÌÅÐÂÀÍÅ ÍÀ ÂÐÅÌÅ
SUM         VAR     Byte
VALUE_UP    VAR     Byte
TTA         VAR     Byte
TTB         VAR     Byte
RUNING      VAR     Byte
PAUS        VAR     Word
'ÈÇÕÎÄÈ
OUT1        VAR     PORTB.0
OUT2        VAR     PORTB.1
OUT3        VAR     PORTB.2
OUT4        VAR     PORTB.3
LED         VAR     PORTA.2
PIEZO       VAR     PORTA.0

'ÂÕÎÄÎÂÅ
IR          VAR     PORTA.1
BU1         VAR     PORTB.4
BU4         VAR     PORTB.5
BU3         VAR     PORTB.7
BU2         VAR     PORTB.6
OUT1=0:OUT2=0:OUT3=0:OUT4=0


LED=0:PIEZO=0:VALUE_UP=20
LOOP:
PAUS=2500
TTT=10*VALUE_UP
RUNING=0
    GoSub CHECK
GoTo LOOP   

START:
RUNING=1
    PIEZO=1:LED=1:        PAUSE 200:        PIEZO=0:LED=1

    For TT=0 To TTT

    For I = 0 To VALUE_UP
    GoSub CHECK
        OUT1=1:OUT2=1:OUT3=0:OUT4=0:        PAUSEUS PAUS
        OUT1=0:OUT2=1:OUT3=1:OUT4=0:        PAUSEUS PAUS
        OUT1=0:OUT2=0:OUT3=1:OUT4=1:        PAUSEUS PAUS
        OUT1=1:OUT2=0:OUT3=0:OUT4=1:        PAUSEUS PAUS
        Next I


     '   OUT1=0:OUT2=0:OUT3=0:OUT4=1:        PAUSEUS PAUS

    For I = 0 To VALUE_UP
    GoSub CHECK
        OUT1=0:OUT2=0:OUT3=1:OUT4=1:        PAUSEUS PAUS
        OUT1=0:OUT2=1:OUT3=1:OUT4=0:        PAUSEUS PAUS
        OUT1=1:OUT2=1:OUT3=0:OUT4=0:        PAUSEUS PAUS
        OUT1=1:OUT2=0:OUT3=0:OUT4=1:        PAUSEUS PAUS
        Next I

    '    OUT1=0:OUT2=0:OUT3=0:OUT4=1:        PAUSEUS PAUS

    Next TT

    For I=0 To 150
    GoSub CHECK
    LED=1:    PIEZO=1:    PAUSE 100
    GoSub CHECK
    LED=0:    PIEZO=0:    PAUSE 100
    Next I

    For I=0 To 4
    GoSub CHECK
    LED=1:    PIEZO=1:    PAUSE 500
    GoSub CHECK
    LED=0:    PIEZO=0:    PAUSE 500
    Next I
    GoTo LOOP

RUNING=0

GoTo LOOP

CHECK:
SUM=BU1+BU2+BU3+BU4
  If SUM<4 Then
 
  If BU1=0 Then
  GoSub START
  EndIf
 
  If BU2=0 Then
  GoSub STOPP
  EndIf
 
  If BU3=0 Then
  If RUNING=1 Then
      If VALUE_UP>240 Then
      PIEZO=1:PAUSE 500:PIEZO=0
      Return
      EndIf
  VALUE_UP=VALUE_UP+10
  TTT=10*VALUE_UP
  PIEZO=1:PAUSE 100:PIEZO=0
  EndIf
 
  If RUNING=0 Then
  For TTA=0 To 1
  PIEZO=1:PAUSE 50:PIEZO=0:PAUSE 40
  Next TTA
   For TTB=0 To 9
        OUT1=1:OUT2=1:OUT3=0:OUT4=0:        PAUSEUS PAUS
        OUT1=0:OUT2=1:OUT3=1:OUT4=0:        PAUSEUS PAUS
        OUT1=0:OUT2=0:OUT3=1:OUT4=1:        PAUSEUS PAUS
        OUT1=1:OUT2=0:OUT3=0:OUT4=1:        PAUSEUS PAUS
        Next TTB
 '       OUT1=0:OUT2=0:OUT3=0:OUT4=1:        PAUSEUS PAUS
  EndIf
  Return
  EndIf
   
  If BU4=0 Then
  If RUNING=1 Then
        If VALUE_UP<10 Then
        PIEZO=1:PAUSE 500:PIEZO=0
        Return
        EndIf
    VALUE_UP=VALUE_UP-10
    TTT=10*VALUE_UP
    PIEZO=1:PAUSE 100:PIEZO=0:PAUSE 100:PIEZO=1:PAUSE 100:PIEZO=0
    EndIf
  EndIf
  If RUNING=0 Then
    For TTA=0 To 1
  PIEZO=1:PAUSE 50:PIEZO=0:PAUSE 40
  Next TTA
     For TTB=0 To 9
        OUT1=0:OUT2=0:OUT3=1:OUT4=1:        PAUSEUS PAUS
        OUT1=0:OUT2=1:OUT3=1:OUT4=0:        PAUSEUS PAUS
        OUT1=1:OUT2=1:OUT3=0:OUT4=0:        PAUSEUS PAUS
        OUT1=1:OUT2=0:OUT3=0:OUT4=1:        PAUSEUS PAUS
        Next TTB
  '      OUT1=0:OUT2=0:OUT3=0:OUT4=1:        PAUSEUS PAUS
EndIf
  EndIf
  Return
     
STOPP:
OUT1=0:OUT2=0:OUT3=0:OUT4=1
LED=1
PIEZO=1
PAUSE 200
LED=0
PIEZO=0
GoTo LOOP
Logged

A known mistake is better than an unknown truth.
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC