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


Closed Thread
Results 1 to 7 of 7

Hybrid View

  1. #1
    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

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

  3. #3
    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

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

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