I think you may be right. Here's a listing of my polling version of the code:Is it possible you are trying to read more pulses than the PIC can keep up with?
I ran this code for 4s and counted 69 outputs on my terminal program. So I reckon that works outCode: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
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.
I'm going to draw up a schematic of the hardware setup and post it shortly.Yes we want to see everything. Code, schematic etc etc etc




Bookmarks