Hello,

I'm trying to use a wheel mouse optical sensor as a quadrature encoder for a small DC motor. I have the small patterned disc from the mouse epoxied onto the back of the motor, and the led/sensor pair positioned as close as I can get it to the original positioning in the mouse.

At the moment I have two test programs, one which uses the interrupt-on-change feature on my 164876a to increment one of two counters (one for each output from the sensor) when one of the outputs (plugged into b4 and b5) from the sensor changes state. In my main program loop I periodically send the values of the two counters to my pc via serial, then reset the counter. The other version of the program does exactly the same thing, but polls the port instead of using the port b interrupt. Right now I'm just taking these two values as an indication of speed, not worrying about decoding the quadrature signal.

All this works at low speeds fine, but as the motor gets above what I'd guess is 8000rpm I start getting erratic results -- apparently random results jumping all over the place, even as the motor speed remains steady.

My instinct is that this is due to some kind of noise in the output from the sensors. One of the websites I've been reading on this subject - http://www.boondog.com/tutorials/mou...kBeforeWeb.htm - uses a hex inverter in between the sensor and and pic, although the author (as far as I can see) doesn't say why. Nonetheless I've tried hooking up my sensors in the same way, and have observed an apparent improvement. I am still getting the erratic results, however.

Does anyone have any idea how I might proceed? I've tried to keep this brief, but if anyone wants more information (schematics etc), please say and I will try to provide it.

Any suggestions are appreciated!

Luke