PDA

View Full Version : Using a wheel-mouse sensor as a motor speed sensor.



lsteele
- 9th December 2007, 19:33
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/mouse/mouseHackBeforeWeb.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

mister_e
- 9th December 2007, 20:02
Yes we want to see everything. Code, schematic etc etc etc

Archangel
- 10th December 2007, 00:49
Hello Luke,
Is it possible you are trying to read more pulses than the PIC can keep up with? What is your OSC speed? The wheel I counted had 36 slots . . . 36 * 8,000 = 288,000. Maybe the pulse width is too narrow at high RPM? Also try keeping the sensor in the dark so ambiant light does not weaken your pulse and 60 HZ does not affect it. The 7414 hex inverter has schmitt trigger inputs, probably why they used it.

lsteele
- 11th December 2007, 11:42
Is it possible you are trying to read more pulses than the PIC can keep up with?

I think you may be right. Here's a listing of my polling version of the code:


Device 16F876a
Config WDT_OFF,CPD_OFF,CP_OFF, LVP_OFF, BODEN_OFF, HS_OSC
Xtal = 20

HSERIAL_BAUD = 57600 ' Set baud rate to 9600
HSERIAL_RCSTA = %10010000 ' Enable serial port and continuous receive
HSERIAL_TXSTA = %00100100 ' Enable transmit and asynchronous mode
HSERIAL_CLEAR = ON ' Enable Error clearing on received characters


dim lastsens1 as byte
dim lastsens2 as byte
dim sens1Tcks as word
dim sens2Tcks as word
dim i as word

'CMCON = 7
TRISB = %11111111
trisc = %00000000
gosub flashled
hserout [$0D, $0A, "Polling speed test"]
sens1Tcks=0
sens2Tcks=0
lastsens1=0
lastsens2=0
i=0

while 1=1
if portb.4 <> lastsens1 then
inc sens1Tcks
lastsens1=portb.4
endif
if portb.5 <> lastsens2 then
inc sens2Tcks
lastsens2=portb.5
endif
inc i
if i = 10000 then
hserout [$0D, $0A, #sens1Tcks, " ", #sens2Tcks]
sens1Tcks=0
sens2Tcks=0
i=0
endif
wend

flashled:

dim lp
lp=0
for lp = 0 to 10 step 1
portc.5=1
delayms 30
portc.5=0
delayms 30
next
return



I ran this code for 4s and counted 69 outputs on my terminal program. So I reckon that works out

10000 x 69 /4 cycles per second = 172500 cycles per second

The motor specs say the output does 221 rpm at 7.2V through a 75:1 gearbox. I'm giving it 4.8V right now, so that's

221x75x4.8/7.2 rpm = 11050rpm (motor shaft) *MADE A MISTAKE HERE - SEE POST BELOW*

~40 spokes on encoder wheel. Two ‘transitions’ per spoke, so 80 changes in state per revolution. So

80 x 11050 = 884000 events per second (per sensor)!

Which if I've done my sums right (admittedly, a big assumption) is considerably more that I can measure.


Yes we want to see everything. Code, schematic etc etc etc

I'm going to draw up a schematic of the hardware setup and post it shortly.

lsteele
- 11th December 2007, 12:53
Sorry, I forgot to divide rpm by 60 to get revolutions per second.

Here is (I hope) the correct calculation:

motor shaft is running at 11050rpm

That's 184.17 rotations per second

40 spokes, which I have to measure on and off, so 80 transitions per second.

80 x 184.17 = 14733 changes in state per second.

I think.

Which seems perfectly measurable. Or am I wrong...?

GrandPa
- 11th December 2007, 18:56
Did you consider using PIC18F2431/4431? They have a built-in motion feedback module that includes a quadrature encoder interface and noise filters. Works great!


J-P

selbstdual
- 18th January 2008, 08:17
Something completely different. I love those:


while 1=1
I am using them by myself on a regular basis - no irony.

:D