Have you observed the encoder output at the higher speeds? The pullup resistor has to charge the line capacitance, and this takes time. Try making the value of the pullup resistor smaller by a factor of two, and see if that improves the high speed response. Fr. Thomas McGahee ----- Original Message ----- From: "Patrick J" To: Sent: Tuesday, January 08, 2002 7:52 AM Subject: Re: [PIC]: Max speed of an rotary encoder and '877 ? > > >I am wondering, have anyone tested max speed for a polled program > > >decoding an rotary encoder ? Would an interrupt driven program > > >do better ? > > > > > >PIC16F877 @ 20 MHz. Approx 50 instructions in the active loop > > >Encoder is 100 pulses/rotation, quadrature decoding (400 flanks/rotation) > > >I have reached around 2000-2500 rpm. 3000 rpm gives overspeed error. > > > Let's see, 3000 rpm is 60 rps, with 400 counts per revolution, that is > > about 24k counts per second. With some code tweaks, I think you could > > 3000 rpm/60 = 50 rps, right ? > 50 rps * 400 counts = 20k counts/s > > > easily be doing more than 5x better than that as I got at least that many > > counts per second out of a 4MHz part before tweaking my code a bit more and > > using it on a 20MHz part - but I didn't test its performance after > > that. I think polled mode has a _slight_ edge if you aren't doing much > > else, I do recommend doing interrupts on encoders if accuracy is important, > > just make sure that all your other interrupts are kept to a minimum. > > I am not doing anything besides polling the encoder to find the max speed it > will handle so I can have 2-3X safety marginal when designing the mechanics. > Its supposed to handle 4 encoders and rs232/485 later on. > > Hmm, 5x faster eh ? Then I wonder... might it be possible that the encoder > itself gives up at <3000 rpm ? Unfortunately I dont have the datasheet for it. > > > Here are several examples you can look over to compare with your code: > > http://www.piclist.com/techref/microchip/qenc.htm > > I got the code idea from there; first program on that page. I've been on the > piclist so many years I know where to start looking ;-) > I really like the structured layout of that asm, just needed a little rewrite to compile > > -- > http://www.piclist.com hint: The list server can filter out subtopics > (like ads or off topics) for you. See http://www.piclist.com/#topics > > -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics