Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 23:01 20 Nov 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Rotary Encoders

Author Message
Rickard5

Guru

Joined: 31/03/2022
Location: United States
Posts: 463
Posted: 07:45am 25 Apr 2022
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 1646
Posted: 07:57am 25 Apr 2022
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 1646
Posted: 08:05am 25 Apr 2022
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 10620
Posted: 08:17am 25 Apr 2022
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 8298
Posted: 08:17am 25 Apr 2022
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 1646
Posted: 10:03am 25 Apr 2022
Copy link to clipboard 
Print this post

  Mixtel90 said  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.


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 Kingdom
Posts: 8298
Posted: 11:15am 25 Apr 2022
Copy link to clipboard 
Print this post

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 States
Posts: 3480
Posted: 12:01pm 25 Apr 2022
Copy link to clipboard 
Print this post

  Rickard5 said  Has anyone played with Rotary encoders on the PicoMite?


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 Kingdom
Posts: 292
Posted: 07:43am 27 Apr 2022
Copy link to clipboard 
Print this post

  Rickard5 said  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.


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 States
Posts: 463
Posted: 11:58pm 27 Apr 2022
Copy link to clipboard 
Print this post

  circuit said  
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'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 Kingdom
Posts: 86
Posted: 09:11pm 28 Apr 2022
Copy link to clipboard 
Print this post

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
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025