Arduino Forum

Using Arduino => LEDs and Multiplexing => Topic started by: FreebirdRising on Mar 10, 2012, 03:40 am

Title: Rotary encoders and shift registers?
Post by: FreebirdRising on Mar 10, 2012, 03:40 am
Hi! I'm still very new to all of this and diving in to learning about electronics with a custom midi controller project, so please bear with me. :)

I'm looking to put 8 rotary encoders on a Teensy++ without using the two I2C pins (so I have 6 interrupt pins to work with). I'm a little unclear as to how this will work with shift registers... Will I need two shift registers and wire one pin to the first shift register and the other pin to the 2nd shift register, or would I wire 4 to one and 4 to the other?

Edit: Or can I make some sort of matrix and do it all with one shift register?

Thanks! :)
Title: Re: Rotary encoders and shift registers?
Post by: Grumpy_Mike on Mar 11, 2012, 06:24 pm
Reading rotary encoders through shift registers is not a good idea.
It is not clear how you are proposing to use them.
Title: Re: Rotary encoders and shift registers?
Post by: FreebirdRising on Mar 12, 2012, 04:28 am
Quote
It is not clear how you are proposing to use them.


They are part of an HID design - controlling music software.

One person I've been conversing with suggested that I may be able to use all of the PORTB pins on the Teensy++ as interrupts as well, but we're not 100% sure about that. Do you know?

Though, I wanted to avoid using pin 0 & 1 because of the potential for linking units...

Quote
Reading rotary encoders through shift registers is not a good idea.


I've read things along these lines a few times, but I haven't found anything explaining why. Would you mind explaining (or pointing me to an explanation?)
Title: Re: Rotary encoders and shift registers?
Post by: Grumpy_Mike on Mar 12, 2012, 12:12 pm
Quote
but I haven't found anything explaining why

Because the outputs from a shaft encoder change rapidly and so you need to continually read in the shift register in case you miss a change. Even then you will probably miss a change if your sketch has something else to do.
A safer way is to use a port expander like a 23S17 or a 23016, these are very much like a shift register but with extra circuitry. These have a single output that can signal if a change has occurred in any of the up to 16 inputs. Then when you know a change has happened you can then spend the time to read in the levels and work out what has changed.

Quote
I may be able to use all of the PORTB pins on the Teensy++ as interrupts as well,

Yes on all AVR processors there is a "pin change interrupt mode", where by an interrupt is generated when ever any pin changes state.
An example of using this is in this project I did.
http://www.thebox.myzen.co.uk/Hardware/Crazy_People.html (http://www.thebox.myzen.co.uk/Hardware/Crazy_People.html)
Title: Re: Rotary encoders and shift registers?
Post by: FreebirdRising on Mar 12, 2012, 04:19 pm
Another person I was talking with described why the only way shift registers would work is if I was using absolute encoders... Unfortunately I already have a handfull of incremental types that were gifted to me for the project. :\

Will a port expander work with incremental encoders?
Title: Re: Rotary encoders and shift registers?
Post by: Grumpy_Mike on Mar 12, 2012, 04:27 pm
Quote
Will a port expander work with incremental encoders?

Yes that is why I told you about it.

Quote
if I was using absolute encoders

Have you seen the price of these!!!!
http://uk.farnell.com/pepperl-fuchs/fvs58-011k2ragb-0013/encoder-absolute/dp/3778022 (http://uk.farnell.com/pepperl-fuchs/fvs58-011k2ragb-0013/encoder-absolute/dp/3778022)
Title: Re: Rotary encoders and shift registers?
Post by: FreebirdRising on Mar 13, 2012, 04:34 pm
They're not *all* that expensive: http://www.mouser.com/ProductDetail/ALPS/EC18AGB20401/?qs=sGAEpiMZZMvS%2fYaWaOF37xnRn301lCUI

Anyway, thanks for letting me know about port expanders - I'll end up using that since it goes with what I already have. :)
Title: Re: Rotary encoders and shift registers?
Post by: Grumpy_Mike on Mar 13, 2012, 04:42 pm
Yes but that is only a low resolution mechanical switch one. Good for some things but not for others. For example I would not put it on the end of a motor, for that you need optical encoders not mechanical ones. With only 16 steps per revolution you are limited to simple front panel controls , which might be what you wanted but you didn't say.
Title: Re: Rotary encoders and shift registers?
Post by: FreebirdRising on Mar 13, 2012, 04:54 pm
Ah - yes, a MIDI controller is an HID.  It's for controlling music software, so a high resolution isn't necessary.  Either way, I already have the EN11-HSM's so I'll just stick with that and the port expander suggestion.