Re: Rotary encoder with DT interrupts
oneway to count detents divide the absolute raw cnt value by the number of edges/detent ,then restore the sign
eg
sb= cnt.15
detents = abs(cnt)<<2; four edges
if sb then detents= ~detents+1
another is to just poll the rotation direction at an acceptable rate
if clockwise add a count if anticlockwise subtract
poll: ; call this sub say 5 times / sec or whatever
if cnt>lastcnt then
detent=detent+1
elseif cnt<lastcnt
detent=detent-1
endif
lastcnt=cnt
return
another way is to only inc/dec detent counter only when enca and encb both = 1 (ie at detent pos)
in the re isr
Warning I'm not a teacher
Bookmarks