help me

Thread Starter

mehtab102

Joined Jun 21, 2011
62
SIR!
BUT HOW CAN I MAKE A CONTINOUS SEQUENCE IN CLOCK WISE DIRECTION..??
Mov a,#66h
back:
Mov p2,a
rr a
acall delay
mov P2, #0CH
acall delay
mov P2, #06H
acall delay
mov P2, #03H
acall delay
mov P2, #09H
ACALL DELAY

sjmp back

delay:
Mov r0,#255
m1:
Mov r1,#255
m2:
Djnz r1,m2
djnz r0,m1
ret
end
I MADE THIS SEQUENCE BUT ITS NOT RUNNING IN ONE DIRECTION IN PROTEOUS.
I UPLOAD THE SCHEMATICS..
THNX
 

Attachments

SgtWookie

Joined Jul 17, 2007
22,230
Try this:
Rich (BB code):
	Mov a,#66h	; Initialize a to #01100110b
	Mov r2,#255	; we're going to step the motor 255 times in one direction
back:
	Mov p2,a	; Output a's bit pattern to port 2
	rr a		; Rotate a's bit pattern to the right: 01100110 -> 00110011
	acall delay	; delay a bit
	Djnz r2,back	; Do it again if not zero
	
	Mov r2,#255	; Step the motor 255 times the other direction
fwd:
	Mov p2,a	; Output a's bit pattern to port 2
	rl a		; Rotate a's bit pattern to the left: 01100110 -> 11001100
	acall delay	; delay a bit
	Djnz r2,fwd	; Do it again if not zero

	Mov r2,#255	; We're going to repeat the process again
	sjmp back
    
delay:
	Mov r0,#255
m1:
	Mov r1,#255
m2:
	Djnz r1,m2
	djnz r0,m1
	ret
	end
Your wires connecting from the uC to the motor are too long, and you wound up without enough room on the right of the schematic so I can't really see how it's connected.

Anyway, you can't drive a stepper motor directly from a microcontroller; you will need to use transistors or logic level MOSFETs to sink current from the stepper motor, or you will burn up the microcontroller.
 
Last edited:

SgtWookie

Joined Jul 17, 2007
22,230
i want to run my motor such as...
http://www.8051projects.net/stepper-motor-interfacing/programming-microcontroller.php
i run this code but motor is not moving completely.
The code you linked to will output on port P1:
Rich (BB code):
MSB    LSB
 |      |
 00001100
 00000110
 00000011
 00001001
...repeating indefinitely (continuously), which should cause your stepper motor to rotate in one direction, IF you have it connected properly.

Did you try the example assembler code that I posted? It even has some notes in it to help you understand what it is doing.

That code I posted should cause the motor to step 255 times in one direction, then 255 times in the other direction.

I do not know how many steps your motor has per revolution. It would help if you posted a link to your stepper motors' datasheet, or at least provide the manufacturer and part number.

I want to make complete rotation.
In order to do so, you will need to provide some documentation on your stepper motor. Stepper motors usually have a fixed amount of rotation per step, normally given in degrees; such as 7.5°, 3.6°, 1.8°, etc. That information may be provided on a label on the motor itself, but usually on smaller motors you have to look at the datasheet to make certain.

Note that you have to connect the stepper motors' wires in a specific order for it to rotate. If the motor simply oscillates back and fourth, you may have the wiring connected in the wrong order, or you may be attempting to step the motor too quickly for it to respond.

and i want to ask that can a stepper motor can run as dc motor???
No. Stepper motors require some sort of controller in order to cause the motor to rotate.

and how i use transistors and mosfet's
is there any ic??
i also use uln 2003 but didn't get benefit
The ULN2003 has seven Darlington channels, and can be used for sinking up to around 350mA per channel. The ULN2803 is very similar, but has eight channels instead of seven.

Both have integrated base resistors and protection diodes. They reduce the number of components that are required to sink current from loads.

Here is an example of how to connect it up:



Note that you do not have to use all of the ULN2003 channels; and you can skip over channels if you would like to. However, you must connect pin 8 to GND in order for it to be able to sink current, and pin 9 must be connected to your positive supply in order for the built-in diodes to work.

You can also use logic-level MOSFETs. One MOSFET I like to suggest is the IRLD024; it comes in a 4-pin DIP package which is great for breadboarding, has a Vdss of 60v, and is rated to sink up to 2.4A current. I don't know where you are (you should put your country in your profile, click on the "User CP" link on the menu bar, and enter your country in the Location field, and click the "Save" button at the bottom of the page) so I don't know if you can get them where you are.
 

Attachments

Last edited:

SgtWookie

Joined Jul 17, 2007
22,230
Here is one way that you could use N-channel logic level MOSFETs to drive your stepper motor:



The drain terminals sink current from the motors' wires.
The gates are connected to the uC's I/O pins.
The source terminals are connected to ground.
The body diodes of the MOSFETs take care of the reverse-EMF when the MOSFETs turn off.

Transistors would be connected up similarly; but would require current-limiting resistors on each base (~220 Ohms or more), and would also require individual protection diodes for each transistor. I'm not going to draw that out for you.
 

Attachments

SgtWookie

Joined Jul 17, 2007
22,230
Once you get the circuit, software and stepper working together, something that you may wish to experiment with is called "half-stepping".
The full step sequence is similar to this:
0110
1100
1001
0011
...and repeats.

A half-step sequence is like this:
0110
0100
1100
1000
1001
0001
0011
0010
... and repeats.

The easiest way to make that happen with what has been posted already, is to change one line (the very first one) in the assembler code that I posted in reply #22 above:
Rich (BB code):
	Mov a,#38h	; Initialize a to #00111000b
And change the circuit to use every other I/O pin in port 2; eg: P2.0, P2.2, P2.4, P2.6, like this:



Since every other port is used with the accumulator initialized to #3Ch, when the bits in "a" are rotated right, you will get this sequence (just the bold columns) output:
Rich (BB code):
 P P P P
 2 2 2 2
 . . . .
 6 4 2 0
 | | | |
 v v v v
00111000
00011100
00001110
00000111
10000011
11000001
11100000
01110000
...repeat
This method is actually wasting half of the I/O port, but it is a very easy way to get something working with making very few changes.
 

Attachments

Last edited:

Thread Starter

mehtab102

Joined Jun 21, 2011
62
Sir Thsnks a lot..
the schematic you have attached to me i made this in proteous as it is...
and i made the sequence of full step and half step according to your hint.i wrote code fot full step sequence is given in the bottom

The full step sequence is similar to this:
0110
1100
1001
0011
...and repeats.

A half-step sequence is like this:
0110
0100
1100
1000
1001
0001
0011
0010
... and repeats.
///////////////////////////////////////////////////////////////////////////
ORG 00H
main:
MOV a,#38h

mov p2,a

rr a

mov P2, #06H
acall delay
mov P2, #0cH
acall delay
mov P2, #09H
acall delay
mov P2, #03H
acall delay
sjmp main
bt the motor is not rotating completly as i show you in the link
http://www.8051projects.net/stepper-...controller.php
what are the reasons..??
and m telling you that i am working in proteous software not implementing practically...
i uploaded the schematic which i made in proteous....
plz check it in proeous..
 

Attachments

Last edited:

Thread Starter

mehtab102

Joined Jun 21, 2011
62
actually sir i want to make obstacle detector rebot.....
stepper motor will use in it..
for example to take turn..
thats why i want to learn stepper motor in a good manner..
and i hope that your responce will make me able to make this rebot...
thnx..
 

SgtWookie

Joined Jul 17, 2007
22,230
OK, the program code from the page you linked to will cause the uC to output these bit patterns:

#06h = 00000110b
#0Ch = 00001100b
#09h = 00001001b
#03h = 00000011b
So, how do you think you need to connect the ULN2003A to the microcontroller?
Or, what do you think you need to do to the program code to address the I/O pins?

You did not connect U2, the ULN2003A, properly.
COM, pin 9, needs to be connected to ground. You have it connected to a motor wire that should be on U2 pin 16 (1C).
You have U1 P2.0 (pin 22) connected to U2, pin 1 (1B), but pin 16 (1C) is not connected.
There is no connection to U2 pin 2 (2B), but you have a motor wire connected to 2C.

There are more problems. You need to find and fix them.
 

Thread Starter

mehtab102

Joined Jun 21, 2011
62
sir if u using proteous software then send me the sketch that u want to make me understand,,.
now i made this sketch according to ur schematic
 

Thread Starter

mehtab102

Joined Jun 21, 2011
62
sir tell me the the software that you are using to test the code ...
because the code u send me is not working properly
 

Thread Starter

mehtab102

Joined Jun 21, 2011
62
sir problem is that motor is not running in one direction...
its run clockwise and clock wise..
i want to run it in full sequence in clockwise direction..
 

SgtWookie

Joined Jul 17, 2007
22,230
Where is your schematic? Post your current schematic.

The last one you posted was not correct.

I am betting that you still have the connections on the right side of the motor reversed.

That will cause the simulated motor to step a little bit in one direction, and then step the other direction.
 
Last edited:

SgtWookie

Joined Jul 17, 2007
22,230
Just so that you know, I tested the software that I posted in reply #22 using EdSim51, and it works as I thought it would.
http://www.edsim51.com/
I reduced the number of steps in each direction from #255 to #5, and reduced the delay loop values from #255 to #1 so that it would not take very long to run.
 

SgtWookie

Joined Jul 17, 2007
22,230
Here is the most simple program that will get your motor running in one direction continuously, with no delay loops. It may run too fast for you to see it work, and it would be much too fast for a real uC and stepper:

Rich (BB code):
	Mov a,#66h	; Initialize a to #01100110b
back:
	Mov p2,a	; Output a's bit pattern to port 2
	rr a		; Rotate a's bit pattern to the right: 01100110 -> 00110011
	sjmp back	; Repeat indefinitely
	end
To change the direction of the stepper motor, you can change the "rr a" to "rl a"
 

Thread Starter

mehtab102

Joined Jun 21, 2011
62
sir!
i have made my stepper motor rotation according to my own code...th schematics you send me .there was connections error .now i change the connection.its working in clockwise and anti clockwise direction according to my own will.
now tell me next task....
 
Top