Encoding input from 8-position switch to use 3 pins

Go To Last Post
20 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I want to use an ordinary 8-position rotary switch to select one of eight modes in the AVR. Instead of using an entire port I'm thinking I can use an external logic IC to encode 8 to 3 so it'll only use 3 pins on the AVR. The part I identified to do this would be a 74LS148 or 74LS348. However these seem to be antiquated parts and are relatively expensive. I have no reason to think this wouldn't work but is there an easier way to do this?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Use a quadrature encoder? They come with different pulses per rev and some have detents and some dont. Some have a push switch. 3 inputs: channl a, channel b, and the switch.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Look for a 74HC148. You should be able to find them for less than 50 cents US.

 

In consideration of others, please RTFM!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Use a quadrature encoder?
The industrial design and function calls for a switch w/ fixed positions as opposed to an endless encoder. I would use an absolute encoder but those are ridiculously expensive and I couldn't even source one reliably in the configuration I need.

Quote:
Look for a 74HC148.
yes I looked hastily on mouser to get an idea of pricing... I see they are cheap.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Use a set of resistors and ADC, then you will need only one input pin.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Use an 8-position switch with BCD (octal?) output?

http://nl.mouser.com/Electromech...

http://www.digikey.com/scripts/d...

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Use a set of resistors and ADC, then you will need only one input pin.
thanks. yes I considered but the onboard adc is already used.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Use an 8-position switch with BCD (octal?) output?
That was the initial idea but absolute encoders cost more than the entire product (ok exhagerating but too expensive). Also I have never been able to source one with a standard 6mm d-shaft (can't afford to add another knob part# to the BOM just for a stupid encoder). Thanks for the input.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
thanks. yes I considered but the onboard adc is already used.

I don't know of any AVR with only one ADC!
which AVR do you use?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
I don't know of any AVR with only one ADC!
You mean more than one ADC input. Most have only one actual ADC.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A 3 deck grayhill 8 position rotary switch will work.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
I don't know of any AVR with only one ADC!
which AVR do you use?
ATMega2560 I'm using all 16 channels.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

codemode wrote:
Quote:
I don't know of any AVR with only one ADC!
which AVR do you use?
ATMega2560 I'm using all 16 channels.
Wow.

Have you thought about charlieplexing?

JJ

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The pic attached is basically what I'm proposing. Using a rotary switch and logic saves (5) GPIO and is cheaper than using an absolute encoder (incremental encoder is not an option).

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

codemode wrote:
The pic attached...
Ah. SP8T switch would make charlieplexing difficult...

Can you substitute a 3P8T rotary switch?

JJ

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Can you substitute a 3P8T rotary switch?
possibly as long I can source one that's not significantly more than the SP8T

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How about a tiny24? All inputs on PORTA, output on PORTB. It can even do your debounce.
Edit: Actually, looking at Digikey, the tiny44 is cheaper.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

codemode wrote:
Quote:
Can you substitute a 3P8T rotary switch?
possibly as long I can source one that's not significantly more than the SP8T
I must be going senile. Twelve diodes are cheaper than a 3P8T switch. Please excuse the hand-drawn schematic (attached). Any (i.e. the cheapest) diodes will do. Don't forget to enable internal pullups.

This is easier than charlieplexing, which would require a polling routine. Charlieplexing is handy for larger arrays of switches, where the schematic below would grow to include unmanageable numbers of diodes, or where more than one switch can be closed at the same time (although ghosting is a problem for more than 2).

Edit: Not on the schematic, but the common pin on your SP8T switch goes to ground.

JJ

Attachment(s): 

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Lorlin make a binary encoded rotary switch which should be price competitive with the standard 8 pole item. Pcb mount and standard shaft.
http://www.newark.com/lorlin/bck...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

They have em at skycraft for a buck

Imagecraft compiler user