I have not yet understood completely how it decodes the encoder
it looks like a cruel hoax to me, maybe you need to sign up to get the working version.
if the encoder is static [on detent] after 12 polls state=0xffff
you then need 12 polls in a row where the clk pin is 0 to reach the
0xf000 state , since the polling is asynchronous I cannot see how that can happen
reliably ,so I tried it in my example

' enstate = (enstate<<1 )| enc_a | $e000
' if enstate == $f000 then
' enstate=0


' if enc_b then
and it fails as I expected when polled @5mS
the example polls @100uS , if you need that much horse power I can't see the point