Input and Output from single uC pin

GroupDIY Audio Forum

Help Support GroupDIY Audio Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.

ruffrecords

Well-known member
Joined
Nov 10, 2006
Messages
16,244
Location
Norfolk - UK
I am considering a small micro-controller project that has a number of push buttons and associated LEDs. Rather than use a port pin per per switch and another per LED I wondered if it is possible to combine an LED and switch on each port pin. The LED would be wired from the port pin to the supply via the usual current limit resistor. The push button would go from the port pin to 0V. With the port set as an output the LED can be turned on/off. With it set as an input the switch can be read. The port would normally be set as an output. The switch scan routine would flip the port pin to an input, read the switch condition and return the port pin to an output. This should happen quickly enough not to introduce a notice able flicker in the LED.

Is this common practice? Will it work?

Cheers

Ian
 
ruffrecords said:
I am considering a small micro-controller project that has a number of push buttons and associated LEDs. Rather than use a port pin per per switch and another per LED I wondered if it is possible to combine an LED and switch on each port pin. The LED would be wired from the port pin to the supply via the usual current limit resistor. The push button would go from the port pin to 0V. With the port set as an output the LED can be turned on/off. With it set as an input the switch can be read. The port would normally be set as an output. The switch scan routine would flip the port pin to an input, read the switch condition and return the port pin to an output. This should happen quickly enough not to introduce a notice able flicker in the LED.

Is this common practice? Will it work?

Cheers

Ian

The microprocessor family I use and am most familiar with has lost LED drive capability since dropping down to 3.3V rails or lower.  I have found it pretty practical to use an LED driver latch IC... you can load the latch driver using SPI....    In my current drum tuner product I use one 16 line LED driver and then multiplex the output side with high side mosfet drivers to control 30 something LEDs from that one driver in combination with 3x pull up MOSFETs. (I drive the MOSFETS with the same LED driver so, 12 LEDs x 3 with one bit left over for expansion.)

For a later design (that for unrelated reasons didn't make it into production) I multiplexed 6 input channels worth of switches (4 switches per channel) onto only 4 input ports. the input ports have current source pull-ups built in. I used 6 lines of LED driver to generate per channel strobe lines. These strobes have only one channel low at a time. All of the same switches but from the different channels connect together and to the input port. If one of the input ports detects a low, it generates an interrupt and since it knows which strobe line was low when the interrupt happened it knows which channel the switch closure was from.  The prototype worked like a charm.

My first generation tuner used a 5V microprocessor that could drive the LEDs directly, IIRC I matrixed the LEDs in an  8x6 array...That old processor was an 8 bitter so byte wide data organizations was efficient.  If I haven't said it lately I really hate 8 bit processors.  :eek:

JR
 
I've never seen this, but I haven't done a comprehensive survey!

Thinking aloud here. On the one hand, the output side, the LED is connected to the positive rail through the usual resistor, and the port pin is driven low to turn it on and driven high to turn it off.

On the other hand, the read side, assume a button press grounds the pin. But what is the logic state when the button is not pressed? You don't have a pull-up. I suppose that you could configure it such that the switch connects the pin to VDD when pressed, and then you need a pull-down to establish the unpressed logic level, but doing so would keep the LED on all the time (although dimmer, perhaps).

Perhaps there's a way to get it to work with a DPDT switch and a clever use of the NC and NO connections.  I started to think about this, and then realized I needed more coffee.

PS: addressing JR's drive concerns, use super-duper-brite LEDs that blind you at 4 mA forward current ;)
 
Couldn't it be made to work if the uC has configurable internal pullups, as some of them do?
 
dfuruta said:
Couldn't it be made to work if the uC has configurable internal pullups, as some of them do?
re-read his post he has a LED and resistor already pulling up the input.  The only issues I see are #1 the led will light when he presses the switch (probably OK), and #2 the resistance of the switch needs to be low enough to deliver a logic low while shunting the LED current.

I have encountered some issues with dome switches (metal) shorting across screened carbon ink footprints where the switch resistance (due to carbon ink) was not always reliable, to deliver a logic low (and I was sinking less than a LED needs..

So answer as usual is it depends. .

JR
 
Thanks JR; your thinking mirrors mine. The LED lighting when you press the button is fine because that LED will be turned on (or off) when the button press has been detected. The button is a momentary action type. As this is in a mixer, the buttons will probably be the usual ALPS which should handle current easily.

Cheers

Ian
 
ruffrecords said:
Thanks JR; your thinking mirrors mine. The LED lighting when you press the button is fine because that LED will be turned on (or off) when the button press has been detected. The button is a momentary action type. As this is in a mixer, the buttons will probably be the usual ALPS which should handle current easily.

Cheers

Ian
Agreed,,, In my first generation tuner I used gold plated PCB switch patterns, and conductive rubber  switches, my current version uses screened carbon ink and metal dome switch discs. Most of the switches just have to shunt the weak pull-up current source built into the micro and work perfectly, but the on/off switch, also has to jump start my power supply and has to pull down more current. It can become marginal when worn from a lot of cycles. 

JR
 
I discover mu chosen micro has no open drain outputs so this method is a non-starter. I think I will make the ports all inputs, use mechanically latching switches and use the LED plus its resistor as a pull up.

Cheers

Ian
 
JohnRoberts said:
Rochey said:
Charlieplexing?

I never knew it had a name? Still not sure it does, besides multi-plexing.

I multi-plexed my LEDs in both my tuner designs.  I Johnny-plexed them.

JR

It was invented by a guy called Charlie from one of the micro companies. It goes one stage further than mutliplexing by using the third state of a port pin (tristate or input) to achieve more LEDs per pin than multiplexing. Has its limits but OK for mosest numbers.

Cheers

Ian
 
ruffrecords said:
JohnRoberts said:
Rochey said:
Charlieplexing?

I never knew it had a name? Still not sure it does, besides multi-plexing.

I multi-plexed my LEDs in both my tuner designs.  I Johnny-plexed them.

JR

It was invented by a guy called Charlie from one of the micro companies. It goes one stage further than mutliplexing by using the third state of a port pin (tristate or input) to achieve more LEDs per pin than multiplexing. Has its limits but OK for mosest numbers.

Cheers

Ian
I read the google article and even it says he wasn't first to do it...

JR
 
ruffrecords said:
I discover mu chosen micro has no open drain outputs so this method is a non-starter.

They don't have to be open drain. You just need to be able to switch them between input and output on the fly (with a register write).

-a
 
Andy Peters said:
ruffrecords said:
I discover mu chosen micro has no open drain outputs so this method is a non-starter.

They don't have to be open drain. You just need to be able to switch them between input and output on the fly (with a register write).

-a

Hmm, I think I see what you mean. If I want the LED off I switch the output to an input rather than setting the output high. I think that may well work. That way I do not risk shorting a high driven output to ground. Thanks for the tip.

Cheers

Ian
 
ruffrecords said:
Andy Peters said:
ruffrecords said:
I discover mu chosen micro has no open drain outputs so this method is a non-starter.

They don't have to be open drain. You just need to be able to switch them between input and output on the fly (with a register write).

-a

Hmm, I think I see what you mean. If I want the LED off I switch the output to an input rather than setting the output high. I think that may well work. That way I do not risk shorting a high driven output to ground. Thanks for the tip.

Cheers

Ian

You can set the I/O pin to "input" to make it the third state (high impedance)... But there is another gotcha...  Some micro family logic inputs get very unhappy if asked to sit at 1/2 supply... think two MOS transistors, one pulling up and one pulling down at the same time.  If not a chip killer, not good for battery life. :eek: The work around for this is to set the I/O pin as an a/d input if the micro family supports that.

Then you toggle between logic output and A/D input for the third state.

This kind of stuff is in the fine print...  and perhaps TMI...for an obscure application.

JR
 
Back
Top