Pages: [1]   Go Down
Author Topic: Rotary switch as stepped potentiometer into analog in....?  (Read 1879 times)
0 Members and 1 Guest are viewing this topic.
Manchester, UK
Offline Offline
Sr. Member
****
Karma: 0
Posts: 293
Rodrigo Constanzo is a performer and composer living in Manchester, England. He is an avid improviser and performs regularly using home made electro acoustic, and modified electronic instruments. He is currently working towards a PhD in Composition at th
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I plan on using a 12 position rotary switch into one of the analog in pins (I'm using 6 of these things, so that would gobble a TON of digital pins). I plan on just connecting resistors across the pins to make a ladder sort of thing.

Has anyone done something like this? What value resistors did you use? Increasing in value, or all the same?
Code to recognize all the positions?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 619
Posts: 33989
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

There is a limit to how many switches you can have at the same time on an analogue input port. This depends on the accuracy of your resistors and the accuracy of the A/D. The A/D is only 10 bits so you won't be able to exceed this, you might if you are lucky be able to get 8 switches to read but more likely 6.
The other problem is lack of speed, reading the A/D is quite slow and you will miss pulses if you are too fast turning them.
Quote
Increasing in value, or all the same?
It depends on what sort of D/A you want to implement, a binary weighted adder or an R/2R ladder, each has it's own advantages / disadvantages.
Logged

0
Online Online
Shannon Member
****
Karma: 206
Posts: 12076
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I would go for as simple as possible - 1k resistors between each contact.  Then its easy to convert the ADC input to a switch-position number, and this in turn can be converted to any function you want, linear or otherwise.    For a 12 position switch that comes to 11k in total which is less than 0.5mA per switch which isn't too wasteful.

One issue is that as the switch moves the wiper might be floating briefly (or simultaneously connected to two neighbouring contacts).  The code will have to identify and reject such 'bad' values.  Reduce the 'floating input' problem by a capacitor of 0.1uF or so between the wiper and ground.
Logged

[ I won't respond to messages, use the forum please ]

Manchester, UK
Offline Offline
Sr. Member
****
Karma: 0
Posts: 293
Rodrigo Constanzo is a performer and composer living in Manchester, England. He is an avid improviser and performs regularly using home made electro acoustic, and modified electronic instruments. He is currently working towards a PhD in Composition at th
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I think the kind available locally (maplin) are "break before make" rotary switches, so it would be floating between connections.

Wouldn't that be as easy as making it look for specific ranges only, with the 'floating' ones would give a lower (or is it higher?) value than what it expects for each step.

I guess resolution could be a problem too, I hadn't thought of that.

I suppose it could be a stepped rotary encoder, but I wanted something with absolute positions that I can label and get to easily. Are there encoders that have hard stops at either end?

I should also say that the function of these things will be to switch modes of operation on something, so I won't be going back and forth on them quickly or often, it's just the simplest way I could think of to assign a specific function (1 of 12) to six different inputs.

If I knew enough I could do it with a push to select rotary encoder and a multisegment display, but that's considerably beyond my understanding at the moment.
« Last Edit: June 09, 2011, 06:28:30 pm by kriista » Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 619
Posts: 33989
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry I think I mis understood what sort of switch you had. I it was a rotory encoder. If it is just anrotorynswitch then you don't have to worry about the combination of switches as only one will be on at one time. Therefor you can just have a chain of 12 resistors with the switch shorting out further up the chain each time.
Logged

Manchester, UK
Offline Offline
Sr. Member
****
Karma: 0
Posts: 293
Rodrigo Constanzo is a performer and composer living in Manchester, England. He is an avid improviser and performs regularly using home made electro acoustic, and modified electronic instruments. He is currently working towards a PhD in Composition at th
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

So I'm having a hard time visualizing how this would be connected. 5v going to central pin of 12position switch, then 1k resistors across each pin. An analog pin connected to the 12th pin (or does ground go there?). Where does ground (or analog in) go?

I guess what's the 'wiper' in a 1 to 12 rotary switch?

Oh wait, so pin1 is 5v, pin12 is ground, and the central pin is the analog in, with a .1 cap going from the central pin to pin12/ground to slow the switching rate. Can I go with a bigger value to avoid 'floating' problems altogether? I don't need to switch fast at all, and my hardware skills are much better than my software skills.

I would go for as simple as possible - 1k resistors between each contact.  Then its easy to convert the ADC input to a switch-position number, and this in turn can be converted to any function you want, linear or otherwise.    For a 12 position switch that comes to 11k in total which is less than 0.5mA per switch which isn't too wasteful.

One issue is that as the switch moves the wiper might be floating briefly (or simultaneously connected to two neighbouring contacts).  The code will have to identify and reject such 'bad' values.  Reduce the 'floating input' problem by a capacitor of 0.1uF or so between the wiper and ground.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 619
Posts: 33989
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The so called floating problem will not be an issue, even without an external capacitor the internal capacitance will take cair of it.
Logged

Manchester, UK
Offline Offline
Sr. Member
****
Karma: 0
Posts: 293
Rodrigo Constanzo is a performer and composer living in Manchester, England. He is an avid improviser and performs regularly using home made electro acoustic, and modified electronic instruments. He is currently working towards a PhD in Composition at th
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I found some stepped potentiometers at mouser:

http://www.mouser.com/ProductDetail/Alpha-Taiwan/RV16AF-10-15R1-B10K-OD/?qs=sGAEpiMZZMtxdMMi52izypa54xBHd143Grr7SNwnp5A%3d

Would this be the same as using a rotary switch? (11 detents = 12 positions?)

These are cheaper than 12 position switches is why I'm asking.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 619
Posts: 33989
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I have not come across that type before but it looks like it will do fine.
Logged

Manchester, UK
Offline Offline
Sr. Member
****
Karma: 0
Posts: 293
Rodrigo Constanzo is a performer and composer living in Manchester, England. He is an avid improviser and performs regularly using home made electro acoustic, and modified electronic instruments. He is currently working towards a PhD in Composition at th
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

So does "11 detents" mean there are 11, 12, or 13 positions? I'm always terrible that understanding that kind of thing.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 619
Posts: 33989
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

My guess is 11 clicks, giving 12 different values.
Logged

Manchester, UK
Offline Offline
Sr. Member
****
Karma: 0
Posts: 293
Rodrigo Constanzo is a performer and composer living in Manchester, England. He is an avid improviser and performs regularly using home made electro acoustic, and modified electronic instruments. He is currently working towards a PhD in Composition at th
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The datasheet is a bit confusing as well as it says 11 positions (which would imply 11 positions) where mouser says 11 detents (which would imply 12 positions).

I think I might bite the bullet and try to go for an LCD display + encoders/buttons to try to wrangle all the information (rather than 6 rotary switches, 4 potentiometers, and 2 toggle switches).

It's a bit scary as I've not done LCD stuff before, and nothing will work until I figure that part out (whereas with switches/pots, I can add functionality to the code one switch/pot at a time).

I made this thread here about the woe-is:

http://arduino.cc/forum/index.php/topic,64192.0.html
Logged

UK
Offline Offline
Sr. Member
****
Karma: 7
Posts: 436
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Why would you want to do this?

Is it in order to select one of 20 options or something similar?  If so then this would be easier, you could just use a 5K pot and then use:

selection = ((current value of pot)/1024*(number of options))

If this is what you want then let me know as I have written a menu system based on this very principal and would be happy to let you have code to demonstrate it but this give an idea:


Code:
#define menuitems 9
#define menusensor A0

int menuentry;
int lastmenuentry;

void setup() {
  Serial.begin(9600);
}

void loop() {
    lastmenuentry = menuentry;
    while (menuentry == lastmenuentry){
      int sensorValue = analogRead(menusensor);
      menuentry = sensorValue * menuitems/1024;
    }
    Serial.println(menuentry, DEC);
 
}
Logged

Manchester, UK
Offline Offline
Sr. Member
****
Karma: 0
Posts: 293
Rodrigo Constanzo is a performer and composer living in Manchester, England. He is an avid improviser and performs regularly using home made electro acoustic, and modified electronic instruments. He is currently working towards a PhD in Composition at th
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

It would essentially be that, but the steps would help differentiate positions.

I've sense migrated my idea over to an LCD system as there's so many individual parameters to control anyways.
Logged

Pages: [1]   Go Up
Jump to: