Using a wheel-mouse sensor as a motor speed sensor.


+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 2006
    Location
    Reading, UK
    Posts
    15

    Default Using a wheel-mouse sensor as a motor speed sensor.

    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

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

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

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    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.
    Last edited by Archangel; - 10th December 2007 at 00:57.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  4. #4
    Join Date
    Sep 2006
    Location
    Reading, UK
    Posts
    15


    Did you find this post helpful? Yes | No

    Default

    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:

    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.
    Last edited by lsteele; - 11th December 2007 at 12:54. Reason: mistake in calculations

  5. #5
    Join Date
    Sep 2006
    Location
    Reading, UK
    Posts
    15


    Did you find this post helpful? Yes | No

    Default

    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...?

  6. #6
    Join Date
    Jul 2007
    Posts
    53


    Did you find this post helpful? Yes | No

    Thumbs up Pic18fxx31

    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

  7. #7
    Join Date
    Aug 2006
    Location
    In a world of german electrons
    Posts
    102


    Did you find this post helpful? Yes | No

    Default

    Something completely different. I love those:
    Quote Originally Posted by lsteele View Post
    while 1=1
    I am using them by myself on a regular basis - no irony.

    Be well - whoever you are.

Similar Threads

  1. Need a cheap touch sensor idea.. here it is
    By mister_e in forum Code Examples
    Replies: 20
    Last Post: - 16th April 2016, 22:42
  2. MicroCode Studio & the wheel mouse :)
    By nquere in forum General
    Replies: 12
    Last Post: - 1st November 2009, 02:06
  3. PICBASIC PRO-coding for wireless sensor node
    By syazila in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 10th February 2009, 00:05
  4. Wheel speed sensor
    By Wax-um in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 24th January 2009, 01:07
  5. Using the optical sensor from a ball mouse
    By lsteele in forum General
    Replies: 5
    Last Post: - 5th September 2007, 16:45

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts