PDA

View Full Version : problem with stepper!!



ibra
- 6th August 2007, 06:46
Hi..

I am trying to use stepper motor, but i face some problems.

I need to save the postion of the stepper in the pic16f84a so the stepper must know the start node and the end node.

The stepper should not continue its moving after end point.If the stepper reverse the direction it should not continue its moving after start point.

I tryed to use EEPROM,write,read instructions, but there is no result.

any ideas?

mackrackit
- 6th August 2007, 17:57
Basically you will need to keep track of how many steps the motor moves. I would guess that the motor will not be allowed to move randomly, so if the "first command" is 20 steps CW " then the second command" of 20 steps CCW would bring it back.

I the motor can be moved by something else and the "start and end" position needs to be found a simple two position Encoder could be rigged. A switch at each position. When the switch is hit the counting of steps begins.

ibra
- 7th August 2007, 12:25
I am locking for method that the stepper know where it stands when the power is on or cut-off.

If the power is cut-off when the stepper -say- at degree 30 cw, if the power turned on , the stepper must know that it stands now at 30 cw degree.

I sayed that i tryed to save the postion in an variable which is stored at the pic16f84a by using read & write instruction..but the stepper just moves in one direction.

my code in attchments, it derive the stepper successfully, but the problem in saving position (( forgive me my code is simple because i am beginner in picbasic, i know there is another code which is more simple))...

any idea??

mackrackit
- 7th August 2007, 16:41
Here is something to try.

Add this to the beginning of your program before MAIN and remove lines:
eeprom 1,[00]
P VAR BYTE
read 1,p
WRITE 1,P
P=P+1
P = P-1


cnt var byte 'A VAR for counting the FOR/NEXT
Pb1 var byte 'The VAR that is being counted and saved
P var byte 'The VAR that the saved data is read into to show position
Plog data 0 'DATA storage area

READ Plog, P 'At program start, reads saved DATA into P

Now for a SUB routine.


POS_1: 'LABEL
for cnt = 1 to 1 'Write DATA one time
Pb1=Pb1+1 'Pb1 is increased by one
write Plog, Pb1 'Write Pb1 into Plog
read Plog, P 'Makes P = to Pb1
pause 100 'Time to write to DATA area
next 'See if FOR/NEXT is finished
RETURN 'Return to SENDER

Put a GOSUB POS_1 inside of all the SUB routines that move the motor. "RIGHT1" for example.