rotary encoder on 16F628A

Status
Not open for further replies.

tcop

New Member
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.

JimB
 
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?
 
300rpm = 5 rev/second
200 transitions/rev gives 1000 transitions per second.
Time between transitions = 1mS

So, your interupt routine needs to do all its processing in significantly less than 1mS, say 500uS.

JimB
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…