Making a rotary encoder from scratch
Making a rotary encoder from scratch
I have been trying my hand at making a rotary encoder with 2 phototransistors reading light and dark off an encoder wheel. I printed the wheel with alternating sectors of light and dark. Two circles of them, 90 degrees out of phase.
I am having trouble reading the light and dark clearly. I have tried using an IR LED to illuminate the encoder wheel, but that does'nt work very well. The LED's light seems too directional.
The motor does not have an exposed axle on the side away from the tire. This is intended to be mounted on a robot which could be running in rough terrain, so I would prefer that the encoder be relatively strong and resstant to the elements.
But for now, I just want to get it to work at all, preferably without much support electronics.
Right now, I have +5 running through a 10K resistor to the cathode of the phototransistor, and the emitter to ground.
The 10K resistor seems to give the best dynamic range in the output. I have a trace from the cathode to a pin on the ZX. When properly illuminated, the ZX can read the bright and dark areas effectively.
With any change in the illumination, it is not as good.
I have accepted the fact that I may need extra parts to increase the gain. But then if there is a change in ambient lighting, then the gain may push the high or low too far so the ZX always sees high or low. I suppose I would need some sort of adaptive gain on the amplifier, so that it always gives a "low" low, and a "high" high. THis sounds complicated.
Are there any suggestions or success stories on how I should make the encoder, preferably using reflection rather than transmission past an interrupter.
-Tony
I am having trouble reading the light and dark clearly. I have tried using an IR LED to illuminate the encoder wheel, but that does'nt work very well. The LED's light seems too directional.
The motor does not have an exposed axle on the side away from the tire. This is intended to be mounted on a robot which could be running in rough terrain, so I would prefer that the encoder be relatively strong and resstant to the elements.
But for now, I just want to get it to work at all, preferably without much support electronics.
Right now, I have +5 running through a 10K resistor to the cathode of the phototransistor, and the emitter to ground.
The 10K resistor seems to give the best dynamic range in the output. I have a trace from the cathode to a pin on the ZX. When properly illuminated, the ZX can read the bright and dark areas effectively.
With any change in the illumination, it is not as good.
I have accepted the fact that I may need extra parts to increase the gain. But then if there is a change in ambient lighting, then the gain may push the high or low too far so the ZX always sees high or low. I suppose I would need some sort of adaptive gain on the amplifier, so that it always gives a "low" low, and a "high" high. THis sounds complicated.
Are there any suggestions or success stories on how I should make the encoder, preferably using reflection rather than transmission past an interrupter.
-Tony
the wind direction gizmo in my weather station uses infrared diodes/detectors and optical filters to try to ignore ambient light. And it's inside an enclosure.
The coding is a plastic disk with grey-coded black/white patterns.Grey-code is commonly used so that only one bit changes state at a time.
another suggestion: pulse the diodes with a frequency like 38KHz and use cheap ($3) IR remote recever (radio shack, et al) instead of just photo diodes. This modulation allows the receiver to ignore ambient light. And the receiver has a tight bandpass filter to greatly increase the gain.
The coding is a plastic disk with grey-coded black/white patterns.Grey-code is commonly used so that only one bit changes state at a time.
another suggestion: pulse the diodes with a frequency like 38KHz and use cheap ($3) IR remote recever (radio shack, et al) instead of just photo diodes. This modulation allows the receiver to ignore ambient light. And the receiver has a tight bandpass filter to greatly increase the gain.
Good point. I will look into how to get that frequecy. I have a 556 timer sitting around. I guess I then put it thru a transistor to get the current I need.another suggestion: pulse the diodes with a frequency like 38KHz and use cheap ($3) IR remote recever (radio shack, et al) instead of just photo diodes. This modulation allows the receiver to ignore ambient light. And the receiver has a tight bandpass filter to greatly increase the gain.
I will look in RS to see about the IR reciever. I guess I would need 2. One problem is that the sensores are pretty close together. I could put them 180 degrees apart.... I had wanted the apparatur to be conpact....
-Tony
Black / Clear plastic printed disks work best with a transmissive system, where the Black is opaque, and the Clear lets the signal through. For a reflective system you have to be careful that the material of the disk itself, and the pigments painted on it, don't reflect back too much signal themselves, regardless of the presence of absence of pigment or it's color.
Depending on the size of the wheel, and the resolution needed, you might consider a circuit board with shiny copper, and holes drilled (instead of printed black sections), along the circumference of the disk. The copper reflects, the holes let the light source shine through, where presumable it reflects significantly less against a matte black tire. Even what is reflected back is partly diffused, and only a small portion bounces back through the hole on its reverse trip. The difference between + signal and - signal is increased, making it easier to decode.
Note also that magnets and coil pickups can be used, as an alternative to optical systems. Much like the speedometers for bicycles.
Good luck with the project.
JC
Depending on the size of the wheel, and the resolution needed, you might consider a circuit board with shiny copper, and holes drilled (instead of printed black sections), along the circumference of the disk. The copper reflects, the holes let the light source shine through, where presumable it reflects significantly less against a matte black tire. Even what is reflected back is partly diffused, and only a small portion bounces back through the hole on its reverse trip. The difference between + signal and - signal is increased, making it easier to decode.
Note also that magnets and coil pickups can be used, as an alternative to optical systems. Much like the speedometers for bicycles.
Good luck with the project.
JC
Excellent point!!Note also that magnets and coil pickups can be used, as an alternative to optical systems. Much like the speedometers for bicycles.
I had just logged-on to mention this possibility. I think I will try it. I have some experience with this subject because I use a magnetic hall-effect sensor in my rally computer project. This sensor is very forgiving of all sorts of environmental hazards that would wipe out an optical device.
I have a few of the sensors around, and a bunch of little rare-earth magnets. I think I can glue the magnets to the aluminum wheel adapter on the motor's shaft, and then place 8 or so magnets.
I can then space the hall effect sensors so that when one is centered on a magnet, the other is on the edge of the sensor. This will give a nice quadrature signal.
I will have to play with this a little to see how securely I can mount the sensors in the tight space allowed. It must be fairly secure!
The sensors are quite small. Open drain output, so a pull-up is needed. I might be able to use the ZX's own pull-ups, but I think I might need a stronger one just to reduce the possible effect of EM noise. For my Rally computer, a 2200 ohm pull up is used with no trouble (the signal is also low-pass filtered)
I will try it out this week.
There are all sorts of optical encoders out there, but I have not seen the same thing done with hall effect sensors (for speed AND direction). I am sure it has been done, I just have not seen it.
-Tony
If you need just a few ticks per rotation a Hall will work well. If you need some resolution, though, you'll probably need an optical solution. Commercial shaft encoders usually use an opaque disk in transmission mode and can achieve hundreds of counts per revolution.
Home brew is likely to be reflective with maybe a dozen segments. You can find encoder wheel printing utilities online. I found that simple threshold detection of the segments in IR was unreliable, so I use differential edge detection:
http://tech.groups.yahoo.com/group/basicx/message/21482
FWIW.
Tom
Home brew is likely to be reflective with maybe a dozen segments. You can find encoder wheel printing utilities online. I found that simple threshold detection of the segments in IR was unreliable, so I use differential edge detection:
http://tech.groups.yahoo.com/group/basicx/message/21482
FWIW.
Tom
Tom
Well, I might be able to use a commercial encoder. Maybe not. THere is little leeway for tire mounting unless I make some sort of custom adapter, or use different motors. Both are technically possible, but I'd rather go with what I have on hand.GTBecker wrote:If you need just a few ticks per rotation a Hall will work well. If you need some resolution, though, you'll probably need an optical solution.
I did a little testing of the hall sensors. They are pretty good. It seems as if the minimum gap between the magnets can be 4mm or so. The width of the magnts is about 8mm. THis allows 2 sensors to have binary values of 1,2, and 3. No zero. So the usual quadrature decoding will not work, but simple testing of the counting direction and magnitude will work.
I have some more work yet do do!
-TOny
I think I see how the XOR cascade would work.
Since I only have 2 sensors, and the way I plan on arranging the magnets (the sensors are close enough together so that one magnet can activate both when centered between them, and with the magnets separated by half a magnet width apart), I will be reading only 01,10,11 binary. This arrangement will pack more magnets onto the same circumference. I am not sure if I can get more resolution unless I use two rows of magnets offset by 50%.
That is probably equally efficiently (and more clearly) coded by IF.... ElseIf.... Else.... depending on the previous state, and then the odometer is incremented/decremented depending on the new state.
-Tony
Since I only have 2 sensors, and the way I plan on arranging the magnets (the sensors are close enough together so that one magnet can activate both when centered between them, and with the magnets separated by half a magnet width apart), I will be reading only 01,10,11 binary. This arrangement will pack more magnets onto the same circumference. I am not sure if I can get more resolution unless I use two rows of magnets offset by 50%.
That is probably equally efficiently (and more clearly) coded by IF.... ElseIf.... Else.... depending on the previous state, and then the odometer is incremented/decremented depending on the new state.
-Tony
I guess 2 gear tooth sensors aligned the way I will have my hall sensors would be similar. As far as I can tell, the gear tooth sensors need the teeth to pass rather closely. I think I might be able to get 1/8" to 1/4" separation and still discriminate the gaps between the magnets. FOr magnets that are 10mm wide.stevech wrote:I've seen this done using a gear made of ferrous metal and a magentic sensor creates a pulse for each gear tooth passing by.
-Tony
I wonder if it would be possible to hack an optical mouse to read the tire tread. The mouse I am using right now has the optical sensor mounted about .25 inches frm the surface it is reading, so direct contact with the tire wouldn't be necessary. As far as resolution goes, even the lowest cost optical mouse would be better than a good encoder.
Perhaps I should go buy a new mouse so I can dig into this one..
-Don
Edit:
Doing a little poking, and came across this explanation of the PS2 mouse data format. Seems like it wouldn't be too hard to impliment.
http://users.tkk.fi/~then/mytexts/mouse.html
Perhaps I should go buy a new mouse so I can dig into this one..
-Don
Edit:
Doing a little poking, and came across this explanation of the PS2 mouse data format. Seems like it wouldn't be too hard to impliment.
http://users.tkk.fi/~then/mytexts/mouse.html
Hacking an optical mouse is something I had not considered.
I just wonder how error-free it would be. Foreign objects on the tread might cause misreading. The dark/glossy surface might be hard to read, but that is easy to test.
I have heard of deeply hacking a roller-ball mouse to get its encoders out.
It makes sense to use the whole mouse hardware which does the counting and directional stuff for you. You use up a com port, but the ZX offers a bunch of S/W ports, so you really only have used up a pin and an input queue. If you are tricky with the input and output queues, you can might be able to use them for other com ports, but not have them active simultaneously. (I.E. enable a port to an LCD, then when done, disable it, and then re-enable it with a different output pin to communicate with the mouse. )
As an aside, this is another reason I like the ZX platform. It is just so easy to use. I have just, (for the first time!) gotten a plain-old AVR device to communicate via the UART. It sounds silly, but I have never bothered to do it. I have previously interfaced to LCD's using the raw parallel I/O technique. I did not want to mess around with writing circular queue handling routines, then write interrupt-driven UART functions. I NEVER plan on trying to write timer-driven "software" UART functions! On a ZX, all this is totally easy.
The reason I wrote the H/W UART stuff is so that I can try using an RS-485 interface which is supposed to be rather immune to external noise, and can transmit over pretty long distances too.
-Tony
I just wonder how error-free it would be. Foreign objects on the tread might cause misreading. The dark/glossy surface might be hard to read, but that is easy to test.
I have heard of deeply hacking a roller-ball mouse to get its encoders out.
It makes sense to use the whole mouse hardware which does the counting and directional stuff for you. You use up a com port, but the ZX offers a bunch of S/W ports, so you really only have used up a pin and an input queue. If you are tricky with the input and output queues, you can might be able to use them for other com ports, but not have them active simultaneously. (I.E. enable a port to an LCD, then when done, disable it, and then re-enable it with a different output pin to communicate with the mouse. )
As an aside, this is another reason I like the ZX platform. It is just so easy to use. I have just, (for the first time!) gotten a plain-old AVR device to communicate via the UART. It sounds silly, but I have never bothered to do it. I have previously interfaced to LCD's using the raw parallel I/O technique. I did not want to mess around with writing circular queue handling routines, then write interrupt-driven UART functions. I NEVER plan on trying to write timer-driven "software" UART functions! On a ZX, all this is totally easy.
The reason I wrote the H/W UART stuff is so that I can try using an RS-485 interface which is supposed to be rather immune to external noise, and can transmit over pretty long distances too.
-Tony