hi im programming a unipolar stepper motor in c for a pic18458 device, in full step mode.
one task is to get the position of the Rotor, and i just can’t seem to figure out a way to do it, can someone please help me on this, im in need of professional help from u guys.
You can't "get" the position of the motor (rotor). You can keep track of the position and therefore know where the motor is.
As a second thought, your question is a little vague. Finding the position of the rotor (instead of the motor) could be as simple as knowing if it's at a half step position.
Some Ham Radio projects I've seen use an optical coupler and a disc mounted onto the stepper motor shaft to detect a 'home' position... After moving the stepper to the 'home' position they simply keep track of the number of steps in either direction...
A stepper motor. normally being an open loop device, require a "present position" counter to keep track of its position. This counter is, depending upon direction, either incremented or decremented for very step taken.
Assuming you are generating the steps pulses from software, you'd use a 16-24 bit counter in one of the general purpose registers.
Below is a sample assembly code for the PIC18 family:
Code:
MOVLW 0
;
BTFSC DIRECTION
BRA DIR_NEG
;
INCF PP+0,F
ADDWFC PP+1,F
ADDWFC PP+2,F
;
BRA CALC_PP_END
DIR_NEG:
DECF PP+0,F
SUBWFB PP+1,F
SUBWFB PP+2,F
CALC_PP_END:
PP is a 3-byte general purpose file register area to hold the 24-bit present position counter.
An open loop "position counter" has the one drawback of being completely useless should the motor stall or slip. If you are powering a low speed low torque application then a position counter can be very useful and inexpensive. For any project that requires lots of torque, high speeds, fast accelerations, and abrupt direction changes, a rotary encoder is the way to go.