What I'm trying to achieve is to control a stepper motor with user defined number of steps, through the use of an optical encoder that is mechanically linked to the stepper motor.
The motor should rotate until the encoder reads the number of steps is equal to the user defined number of steps
I'm aware that stepper motors, if run within rated values should not slip and thus do not need feedback - even for precise stepping
I've written some simple code, speed is not an issue - thus pulsing outpin directly in a while loop- but it seems to be flawed
For a practical program delayMicroseconds() is unsuitable beacuse it blocks the Arduino from doing other stuff - such as reading the encoder. See the second example in this Simple Stepper Code
Actually, that may be your problem. You are using the blocking WHILE when you probably should move the motor just one step between readings of the encoder.
When the encoder turns the full number of specified steps, the motor simply slows down slightly and then continues to rotate.
If I rotate the encoder by hand, whilst the motor is rotating, a full of rotation which should stop the motor, the motor again simply slows down when the encoder is turning and then when the I stop rotating the encoder it speeds up again and continues to run.
It seems as though the encoder is interrupting the pulsing of the motor, hence the decrease in motor speed.
I will try implement your method to delay the pulsing of the motor
Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.
How many steps is the stepper, link to specifications, please.
What stepper controller are you using, link to specifications, please.
How many step is the encoder, link to specifications, please.
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
WHY???
You have the project infront of you, we don't.
You know how it is wired, we don't.
You know how you are powering the servo, contoller and arduino, we don't.
A picture, a circuit diagram and a sketch is worth a thousand words and can save a thousand ill informed posts.