|
Forum Index : Microcontroller and PC projects : Rotary Encoders
| Author | Message | ||||
| Rickard5 Guru Joined: 31/03/2022 Location: United StatesPosts: 463 |
Has anyone played with Rotary encoders on the PicoMite? I was digging though the parts and found 2 that I want to work in to a project and I really need help figuring out how to make them work. Also has anyone ever messed with the encoders out of mice? that would be cool, I got a ton of sacrificial mice I could gut for sensors and microswitches :) ![]() I may be Vulgar, but , while I'm poor, I'm Industrious, Honest, and trustworthy! I Know my Place |
||||
| Tinine Guru Joined: 30/03/2016 Location: United KingdomPosts: 1646 |
I use rotary encoders all the time but for motor speed/position control. One needs to decode the quadrature of the 90deg out-of-phase signals of the channels A and B. This sounds like a good task for the Pico's PIO if anyone has figured-out how to use it. I use other processors that read constantly without the need for interrupts. Craig |
||||
| Tinine Guru Joined: 30/03/2016 Location: United KingdomPosts: 1646 |
This is a method that I came up with. Non-conventional but I wanted speed and I haven't seen anything that can beat this. I submit this because it is probably the best explanation of how these things work. It's in PropBasic, ignore the "wrlong" because that is a Parallax Propeller thing. 'Decide where to start If Chan_A = 1 And Chan_B = 1 Then Goto A1B1 Endif If Chan_A = 0 And Chan_B = 0 Then Goto A0B0 Endif If Chan_A = 1 And Chan_B = 0 Then Goto A1B0 Endif If Chan_A = 0 And Chan_B = 1 Then Goto A0B1 Endif 'Keep hopping between these labels A1B1: If Chan_A = 0 Then Dec Counter Wrlong HubCTR,Counter Goto A0B1 Elseif Chan_B = 0 Then Inc Counter Wrlong HubCTR,Counter Goto A1B0 Endif Goto A1B1 A0B0: If Chan_A = 1 Then Dec Counter Wrlong HubCTR,Counter Goto A1B0 Elseif Chan_B = 1 Then Inc Counter Wrlong HubCTR,Counter Goto A0B1 Endif Goto A0B0 A1B0: If Chan_A = 0 Then Inc Counter Wrlong HubCTR,Counter Goto A0B0 Elseif Chan_B = 1 Then Dec Counter Wrlong HubCTR,Counter Goto A1B1 Endif Goto A1B0 A0B1: If Chan_A = 1 Then Inc Counter Wrlong HubCTR,Counter Goto A1B1 Elseif Chan_B = 0 Then Dec Counter Wrlong HubCTR,Counter Goto A0B0 Endif Goto A0B1 End Craig |
||||
| matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 10620 |
See here for my bounce immune rotary encoder I/F code. Haven't tested on recent releases but should work with minimum change |
||||
| Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 8298 |
You shouldn't need a PIO for a rotary encoder. MMBasic is almost certainly plenty fast enough if you are turning one by hand. The fastest way, I think, is to feed the inputs into interrupt pins. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
| Tinine Guru Joined: 30/03/2016 Location: United KingdomPosts: 1646 |
Spoil-sport I'd really like to see a real-world example of PIO in use Craig |
||||
| Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 8298 |
Look at the PicoMite VGA then. :) 2nd CPU feeds a PIO with video data, PIO produces the syncs etc. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
| lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3480 |
Right here using Peter's code. Rotary encoder is the black module, top middle. I used it to navigate a menu on the little LCD, and to select menu options. ~ Edited 2022-04-25 22:02 by lizby PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
| circuit Senior Member Joined: 10/01/2016 Location: United KingdomPosts: 292 |
See the section "Rotary Encoders" - Page 56 of Geoff's excellent manual "Getting Started with the Micromite" that is supplied in the documentation section of the standard Micromite download. That is the simplest and quickest way to start with these devices. |
||||
| Rickard5 Guru Joined: 31/03/2022 Location: United StatesPosts: 463 |
That's it , the deeper I get in to this the more like I feel like a way late to the party, but going back to Micromite Manual is a Great reference Thanks I may be Vulgar, but , while I'm poor, I'm Industrious, Honest, and trustworthy! I Know my Place |
||||
| DaveJacko Regular Member Joined: 25/07/2019 Location: United KingdomPosts: 86 |
I bought one of these a few years ago, and they're a nice tactile thing to play with. The difference between Gray code and Quadrature is important to know! I've attached my code, which the reader might agree, is impressively concise. However, it also demonstrates really bad programming style.. I can not understand how it works, and I coded it ! 'test prog for useful little rotary encoder 'quite clever use of array, bin$, int 'one detent gives 2 increments -why? ' 12 apr 2020 Dave J Option autorun on Option default integer Dim g(15)=(0,-1,1,0,1,0,0,-1,-1,0,0,1,0,1,-1,0) 'gray code 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 SetPin 3,din SetPin 2,din SetTick 1000,dspac mnlp: ni=Pin(3)+Pin(2)*2 If ni=oi Then GoTo mnlp gi=(oi<<2)+ni Print Bin$(oi,2),Bin$(ni,2),Bin$(gi,4) oi=ni Print g(gi) Pause 10 ac=ac+g(gi) GoTo mnlp Sub dspac Print ,ac End Sub Try swapping 2 and 3 over |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |