Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

stepper motor rotation

Status
Not open for further replies.

Nusrat Mary

Junior Member level 1
Junior Member level 1
Joined
Mar 16, 2012
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Dhaka, Bangladesh
Activity points
1,462
hi ,
can anyone tell me that why stepper motor rotate at opposite direction initially by a small step when it start rotating??

and the device called- ULN2804 ( which we use to interface stepper motor with atmega16 microcontroller) has any market name??

thanks .
 

The rotation direction depends on the applied voltage on the motor , the rotor will turn to when the fired pulls it.
You are probably applying a step that starts from the previous position and then you move forward.

The ULN2804 is a chip you can buy in any store, the market name is not different

www.utc-ic.com/spec/ULN2804.pdf

Alex
 
thank u Alex ,
actually i'v seen it in simulation in Proteus 7.8 sp2 ,when i write the following loop in Mikroc pro, first it rotate opposite direction ,
for(j=4; j>=0 ;j--)
{PORTD=1<<j;
delay_ms(50);

can u explain how i'll remove by code?? i'v used 3 stepper motor , every of them doing the same,
 

I think id you store the last step you have applied and continue from that instead of starting always from the same point then problem will dispensary.

for example when you start the motor

0
1
2
3
0
1
2
and you turn the mcu off, when you restart it you will get

0
1
2
3
...
so from 2 you went to 0 the second time, but if you store the value 2 and then start from 3 the next time there would be no rotation as you describe
 
What I'm saying is that you have a unipolar motor with 4 coils , I name then 0,1,2,3 but you can also see them as A,B,C,D and I assume that you are using a wave drive https://en.wikipedia.org/wiki/File:Drive.png

First you give power to the first coil A, then the second B, the third C, and the fourth D and then you start over

A
B
C
D
A
B
C
D
A
B

All I'm saying is that if you stop at this state and then start from A you may get what you describe, the motor is currently at position B so you should give power to coil C to continue the rotation, if instead of that you start from A then you may get what you describe.
 
again thank u Alex ,
in simulation with- Proteus 7.8sp2 & code in- Mikroc pro how i'll remove the backward rotation ?? or without correction the same code, if i burn the code at atmega16 ,will it work in real world?? u'v told to off the mcu, what is mcu??
 

mcu is the microcontroller.

Do you currently have a button that rotates the motor when pushed?
do you get the problem when you leave the button and then you press it again or every time you start a new simulation from start?

The code you have provided has 5 steps and not four, why have you used more than 4 steps?
Code:
for(j=4; j>=0 ;j--)
{PORTD=1<<j;

Can you post your code?
 
Regarding ULN2804 or 2803 it is package containing Darlington pairs of transistors to provide higher powers with the stipulated ratings. ULN2804 has 8 of those and ULN2803 has seven.
 
Alex ,sure here is my whole project code , i'v used 3 stepper motor & 1 servo motor , i'm not sure that is it ok or not:



Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
int i,j,k,l,m,n,p,q,r,s,t,u,v,w,a;
char current_duty;
void Tone1() {
  Sound_Play(1600, 70);   // Frequency = 1200Hz, duration = 70ms
}
void PWM1_Start();
void PWM1_Stop();
 
void main() {
//DDRA=0xFF;
//DDRB=0xFF;
DDRD=0xFF;        //Base stepper motor
DDRC=0xFF;        // from C0 to C3 bit 2nd stepper motor connected & from C4 bit ti C8 bit 3rd motor connected
  DDB3_bit = 1;                   // Set PORTB pin 3 as output pin for the PWM (according to datasheet)
 
current_duty=32 ;
PWM1_Init(_PWM1_FAST_MODE, _PWM1_PRESCALER_8, _PWM1_NON_INVERTED, current_duty);
 
Sound_Init(&PORTB,1); // Initialize sound pin
delay_ms(50);
 
while(1)
{Tone1();
delay_ms(100);          //wait for a while for 1st working process.
 
PORTD=0x00;
 for(i=0; i<4 ;i++)    //loop for 1st stepper motor to rotate 180
 {PORTD=1<<i;
 delay_ms(50);}
  delay_ms(100);
  
  PWM1_Set_Duty(190);    //loop for servo to pick object
PWM1_Start();
delay_ms(300);
PWM1_Stop();
delay_ms(100);
 Tone1();
delay_ms(50);
 
 for(j=4; j>=0 ;j--)
 {PORTD=1<<j;
 delay_ms(50);}
 
PWM1_Set_Duty(19);       //loop for servo motor to put the object.
PWM1_Start();
delay_ms(300);
PWM1_Stop();
delay_ms(100);
 Tone1();
delay_ms(100);
 
                         //2nd working process
 for(k=0; k<4 ;k++)      //loop for stepper motor to rotate 180 degree.
 {PORTC=1<<k;
 delay_ms(50);}
  delay_ms(100);
   for(l=4; l<=8 ;l++)
 {PORTC=1<<l;
 delay_ms(50);}
  delay_ms(100);
  
PWM1_Set_Duty(190);      //loop for servo motor take the object.
PWM1_Start();
delay_ms(300);
PWM1_Stop();
delay_ms(50);
 Tone1();
delay_ms(50);
 
 for(m=3; m>=0 ;m--)      //loop for stepper motor for to go to 0 degree
 {PORTC=1<<m;
 delay_ms(50);}
  delay_ms(100);
   for(n=8; n>=4 ;n--)
 {PORTC=1<<n;
 delay_ms(50);}
  delay_ms(100);
  
 
PWM1_Set_Duty(25);         //loop for servo motor to put the object.
PWM1_Start();
delay_ms(300);
PWM1_Stop();
delay_ms(50);
 Tone1();
delay_ms(50);
 
 }
 }

 
Last edited by a moderator:

I'm not sure what you are doing in your code

Code:
for(i = 0; i < 4 ; i++) //loop for 1st stepper motor to rotate 180
        {
            PORTD = 1 << i;
            delay_ms(50);
        }
this results in
PORTD=0b00000001
PORTD=0b00000010
PORTD=0b00000100
PORTD=0b00001000




Code:
 for(j = 4; j >= 0 ; j--)
        {
            PORTD = 1 << j;
            delay_ms(50);
        }
this results in
PORTD=0b00010000
PORTD=0b00001000
PORTD=0b00000100
PORTD=0b00000010
PORTD=0b00000001




Code:
for(l = 4; l <= 8 ; l++)
        {
            PORTC = 1 << l;
            delay_ms(50);
        }
this results in
PORTC=0b00010000
PORTC=0b00100000
PORTC=0b01000000
PORTC=0b10000000
PORTC=0b00000000

using PORTC = 1 << 8 is pointless becasue 1<<8 equals 0 for 8bit values





Code:
for(m = 3; m >= 0 ; m--) //loop for stepper motor for to go to 0 degree
        {
            PORTC = 1 << m;
            delay_ms(50);
        }
this results in
PORTC=0b00001000
PORTC=0b00000100
PORTC=0b00000010
PORTC=0b00000001





Code:
for(n = 8; n >= 4 ; n--)
        {
            PORTC = 1 << n;
            delay_ms(50);
        }
this results in
PORTC=0b00000000
PORTC=0b10000000
PORTC=0b01000000
PORTC=0b00100000
PORTC=0b00010000

Do these outputs fit what you want to do?
 
thank u ark5203

---------- Post added at 20:30 ---------- Previous post was at 20:11 ----------

Alex its my project code for- pick & place robot using atmega16, if i set step angle of stepper motor by 22 degree in Proteus 7.8sp2 , then stepper first give backward rotation by 11 degree , whatever i set the step angle stepper just give backward rotation by half , then go for forward rotation , u'v mentioned also that there is some wrong like 1<<8 ; but if i correct the loop:

for(l=4; l<8 ;l++)
{PORTC=1<<l;
delay_ms(50);}
but its doing the same.

thank u.
 

I didn't say that the rotation you describe is because of the codes above but some of them are still wrong giving 5 steps instead of 4, you think that you shouldn't fix them because they don't correct your main problem?

Your code repeats the same code over and over again , do you get the backward rotation during that or only when you start your simulation?

If it is only when the simulation is starting it is probably becasue the proteus motor starts the motor from the same default position so if your first motor step in the code is not in the next position of that default then you get one step back and then steps forward.
 
thank u Alex , its helped me ,

---------- Post added at 21:14 ---------- Previous post was at 21:13 ----------

but in real world how will i remove this backward rotation?
 

I'm not sure, I haven't done any robotics.
One way would be to store the last position is eeprom and next time read it so that you start from the proper step.
Maybe you can have default position for the arm (have the arm move to a default position before you turn off), or maybe always stop your movement in step 3 so that next time when step 0 is applied you get proper movement.

Maybe in the real hardware this small step back wouldn't be a problem.
 
There's a simple point you didn't yet consider. A de-energized stepper motor doesn't exactly keep it's position. Apparently, the Proteus model assumes, that the preferred position is a half-step in advance of the last active controlled position. This assumption may or may not apply to a real motor, but it's at least a possible option. To preserve the motor position exactly, you need to keep the motor energized, at least with reduced current.
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top