I need help on using a rotary encoder with 16F628A. I have set the pic running with the internal oscilator on 4mhz. I have a loop constantly checking Rb1 and Rb2 for movent and i properly get the direction of the encoder. My problem is that when i turn the encoder very fast i miss some transition bits. The encoder sends 50 full pulses per rotation (200 tansitions) and it is supposed to turn with up to 300 rpm. My code needs no more that 50 cycles to check the encoder state and loop back but still it seems that i get slippage errors. Do you have any suggestions?
I had similar problems some years ago.
I tried faster and faster clock speeds but it still missed steps.
The answer is to use interupts, when RB1 or RB2 change go to the interupt service routine and read their state and do the calculations and then go back to the main program and wait for the next interupt.
thanks a lot!
I have already gave a try using a simulator hacking Rb4 and RB5 using ints but haven't tried it on the bread board. How can i calculate the max input frequency so as to avoid slippage again? I mean how can i find the max speed or better the rotations per minute of the encoder knowing that it gives 200 transitions per rotations?