Microstepping with optical feedback
April 17, 2010 04:07PM
My repstrap uses stepper motors and optical feedback on both the X and Y axis. The stepper motors are microstepped. I do this by driving them with a PWM (pulse width moduled) waveform) that makes a sinewave.

I have put details on a wiki page.


Re: Microstepping with optical feedback
October 06, 2010 01:52PM
dear fdavies, i want build it
i have some question

Re: Microstepping with optical feedback
October 07, 2010 09:24PM
Sorry for the delay in replying.

I would suggest starting by getting the optical sensor and strip from a non-working inkjet printer. I would go to garage sales or recycling centers and get two or three. Do not get laser printers, since they do not have the right optical components in them.

Start taking the printer apart and you will soon see a grey plastic strip close to the shiny metal rod and running parallel to it. You may be able to see the strip without taking the printer apart. The strip runs through the optical sensor, which may be quite hidden. It is on the assembly that holds the ink cartridges. Keep disassembling, but be careful about ink. The printers that people sell cheaply or recycle generally are somewhat inky inside. Do not get ink on the optical strip.

You will soon have the optical strip free. Save the shiny rod, too. If you are lucky, it will have a diameter of 8mm, and be suitable for use in a mendel type printer. If it is smaller, it may be suitable for a mini-mendel, but I am not sure.

You should be able to see the optical sensor. It will have a black plastic case with a slot for the strip. It will be soldered to a small printed circuit board. Do whatever you have to in order to get this circuit board free of everything else without damaging the sensor. Now, you should try to unsolder the sensor from the circuit board. It will have either 4 or 6 pins. If it has six pins, the pins will be in a group of 4 and a group of 2. The following are common desoldering techniques. Other members of the community may have advice in this matter, too.

a. I like to make a big blob of solder that covers all 4 pins and will stay molten long enough that the sensor can be pulled free of the board (because all 4 pins are loose at the same time).
b. Remove the solder from around the pins with a solder socking device or solder wick.
c. Since you do not care about the circuit board, nibble away at it (but not with your sharpest wire cutters) until the pins are separated from each other and they can be unsoldered from the circuit board remnants one at a time.

Now comes a tricky part. You must figure out which pins are which. I have some notes on the matter, but I must find them.

I hope that this information is useful to you.


Re: Microstepping with optical feedback
October 08, 2010 10:55AM
thanks fdavies, i'll finding old printer have encoder strip

i have a question your code

1.code is 1/256 microstep?

PHASE = PHASE + c*19; /* feedforward term. This may be different for different steppers */

why c*19?

err = xenc - COMMAND;
integ = integ + err;
if (integ >3200) integ = 3200;
if (integ < -3200) integ = -3200;
frq = err; //+ integ/128; // feedback
if (frq < -30) frq = -30; // maximum rate motor turns
if (frq > 30) frq = 30; // machine dependent
PHASE = PHASE + frq;

what is integ use for?


Re: Microstepping with optical feedback
October 09, 2010 11:09AM
Let's see if I can remember...

1. Incrementing 'PHASE' by 256 will take the stepper motor through one full cycle (4 steps). Of course, if you just increment PHASE by 256, the motor will not move. The jumps must be smaller.

2. Each pulse that the arduino receives on pin ADC4 (PC4) is supposed to move the linear stage by one optical encoder increment (this is one quarter of the line-to-line spacing on the strip, xenc is the variable that is incremented or decremented for each change in optical encoder state). Now, one stepper motor step does not correspond to one optical encoder increment, since it depends on the mechanical details of how the stepper motor is connected to the optical encoder or strip. The feedback loop will change PHASE until COMMAND and xenc are equal, but it may take too long. The process can be sped up with what is known as a 'feedforward term'. This is what the 19 is. Whenever the arduino gets a command pulse, it is going to end up changing PHASE by a certain amount due to the feedback loop. You will get better prints if the arduino makes this change as soon as possible. Since it is set by the mechanics, we may as well have the firmware make it directly and leave teh feedback loop to do any fine tuning necessary (or to make up for skipped steps).
What is the best way of finding out what number to use for your mechanism? Set the 19 to zero. The feedback loop will still work, but not optimally. The code outputs the values of PHASE, xenc and COMMAND on the serial port. Use a serial port terminal or the Arduino program to watch it in real time. Send in command pulses (maybe 1000) to make your mechanism move. The feedforward factor (currently 19) should be approximately the change in PHASE divided by the change in COMMAND.

3. INTEG is the integral part of the feedback (the I in PID). If the feedback loop did not have this, there would have to be a non-zero error to drive the PHASE. Obviously, we want the error to be zero, so this term is used. It is hard for me to explain in a sentence. See below.

I think that a good way of getting all of this going is to get all the parts working individually befor closing the feedback loop.

a. Make sure that the optical encoder is working. You should be able to put a voltmeter on its outputs and see them change when you block the slot.. You should be able to run the encoder strip through the slot and see this, too. I suggest putting LEDs with 2000 ohm resistors in series on the sensor outputs so that you can see them work as you set up the mechanics of the sensor and strip. The two LEDs should blink 90 degrees out of phase.
b. Disable the feedback loop by commenting out the 'PHASE = PHASE + frq; ' line.
c. Using a serial port monitor, look at the PHASE, xenc and COMMAND numbers sent out of the serial port.
d. You should be able to see xenc change when you move the optical strip through the sensor. It should count cleanly. If it is at a number at one end of the mechanical travel, you should be able to move the mechanism to the other end and back and end up with the same number. This is a very satisfying thing to be able to do.
e. Make sure that you can send pulses to the command pin and see COMMAND change accordingly. If it does not, the pulses may be too short.

There is more, but this is what I have time for now.

Re: Microstepping with optical feedback
October 11, 2010 07:11AM
i found sanyo stepper motor, it had shaft encoder 200p/r , could i use it?

Edited 1 time(s). Last edit at 10/11/2010 07:22AM by tivoi.
Re: Microstepping with optical feedback
October 11, 2010 02:25PM
That looks like a nice piece of hardware!

See if you can figure out how to power the unit before you take it off of the motor. If you can get a data sheet based on a part number, you could figure it out that way. Otherwise, there may be one or more large polarized (electrolytic) capacitors on the board. If you find one, it is probably on the power rail. This may suggest how to power it. If you are lucky, then the LED light source in it will be visible, and you can tell that you have the power connected properly.

Once you have that, turn the motor shaft slowly by hand and use a voltmeter to see which point in the circuit change voltage. For my firmware you will need two 90 degree out-of-phase signals.

You will need to decide to use the encoder with the optical wheel that it came with (probably the best idea), or make your own linear strip.

Re: Microstepping with optical feedback
October 11, 2010 09:03PM
I have added the following page to the wiki about scavenging sensors:


Re: Microstepping with optical feedback
October 11, 2010 09:20PM
thanks fdavies
Sorry, only registered users may post in this forum.

Click here to login