Quadrature-counting smartpins; is it possible to separately determine their state?
Mickster
Posts: 2,693
in Propeller 2
Ideally, I'd like to be able to detect them in the low-state to gate them with another low-going input but without having to use extra pins
Craig
Comments
You could read the low-level states of the quadrature pins by setting the AAA input-selector bits of a nearby smart pin. Then the IN bit of the nearby smart pin would reflect the input state of the quadrature pin it points to.
And the nearby smart pin wouldn't then be dedicated to this purpose, right? I only need to do this to set the home position of a servo motor after initial power-up.
No problem at all. It's easy to switch between different pin modes with one instruction, WRPIN. A nearby pin input can be momentarily diverted to a neighbouring pin to check its level then immediately switched back to regular mode in a blink. The smartpin doing the incremental counting isn't impacted.
If you can be sure that the encoder is not moving at startup you can record the state of the A and B pins before you set up the smart pin quadrature counter mode. Then simply examine the lowest two bits of the counter. The pattern of the A and B pins repeats every 4 counts.
Say, you startup in the A=0 and B=0 state with counter=0. Then A and B are simultanously 0 every time the two counter LSBs are low. If the counter starts at 0 while A=1 and B=1 then A and B will be low whenever the LSBs are equal to %10.
Thanks guys, this is great stuff