the order in which some switches are turned on

Apr 23, 2008 25 Replies

Hi all,



I have an array of N switches . Initially all are OFF.



Somebody turns them ON in some order. It is possible that more switches are turned ON in the same moment.



I need a device which shows me the order in which the switches were turned ON. For instance the device should give me: 4,3,1,5,2 (this is the order in which the switches were turned ON).



The way in which the output is shown in not important. It must be simple to read (by a human, computer, etc).



It is important that the device is able to handle the turned ON (in the same moment) of the multiple switches.



thanks, Laura


Sounds like a simple job for a microprocessor.AVR, pic or 8051.

When 2 switches are turned on at the same time, how would you want to decode that?

martin

You could use a microprocessor with enough interrupt lines to have one per switch. Switches trigger the interrupts in order and you could then get each interrupt routine to display the corresponding number on an LCD in sequence. As each interrupt routine is processed you end up with your sequence of numbers on the LCD in the order they were pressed.

Dave.

A logic-only way could be to have each switch trigger a latched gate on the free-running clock to a separate counter for each switch. All counters are clocked the same, and a common reset line clears all counters to begin with. Each counter could have it's own display, and the displays which are stopped have been triggered. The count value indicates the order in which they were triggered. That's a messy display system, but the counters could also be read by a micro or whatever. There is likely an easier way, but this one came to mind.

Using a micro is easiest though. But the final implementation depends upon whether this is a "theory" question or a "practical" question? In a theoretical situation you could have the "switch" come on for only a nanosecond or whatever. That means you can't rely on a fast micro like you could with a practical solution where the "switch" would come on for much longer period which is easier to detect.

Dave.

martin,

if 2 switches are turned on in the same time, the order is not important. I mean both sequences 4,5 and 5,4 (for the 4th and 5th switches) are OK.

how do I use the microprocesor for my task?

how do I connect the switches to processor ?

thanks, Laura

You will need to learn to write programs, I'm afraid. If you have ever done any basic programming ( I haven't, for 25years) this may be of help

formatting link

I'm sure other people will chip in with alternatives

martin

The easiest way for a beginner is with a PICAXE:

formatting link
You don't even need to write source code, you can use flowcharts.

Simply from the microcontroller pin to ground, for micros that have built-in pullup resistors that is.

Dave.

Have each switch release a marble with its number on it, into a transparent plastic tube. Then later you can read the tube. This will save you from studying electronics first.

Remove pcb from old PC keyboard. Connect your switches in place of the keys.

Geo

is this a real life problem, or are you learning about meta-stability?

Mark

That's a pretty good solution. Here's another idea:

formatting link

or this for PIC code:

formatting link

and this for a complete PIC project:

formatting link

You could also possibly hack a telephone with an LCD display, but I don't know how well it handles simultaneous keypresses.

I just did a

formatting link
search (don't use Google!), for keyboard decoder.

HTH,

Paul

I'd forgotten about Dogpile, thanks for the reminder that other search engines exist

martin

An old PC for 10 bucks or less PC basic / Gwbasic Use the printer port which can directly connect to 8 or more switches - If you need more switches - ??? bg

s.

Hi Geo,

What happens if I press multiple keys in the same time ? What if I press 50 keys in the same time? Do I get signals from all of them?

I just made a test by pressing 4 keys of my keyboard ... and no character was printed on the screen...

thanks, Laura

What if 2 marbles are released in the same time ? My main problem is what happens when multiple switches are pressed in the same time.

thanks, Laura

David,

How a processor detects an interrupt? Does it iterate through all interrupts and checks which one(s) are active? Does that check multiple times per second?

thanks, Laura

Interrupts are detected by dedicated hardware within the processor. When the interrupt occurs the processor automatically calls a software routine to deal with it.

See here:

formatting link

Multiple interrupts can happen and are captured simultaneously, that is the whole point of having them. The one that comes along first gets served first. The other interrupts are usually cued for later processing. Using hardware interrupts you don't miss any inputs.

A simpler (software based) system uses "polling" where each input is checked in turn. The problem with this approach is that an input can be missed if your polling rate is not fast enough. For a practical circuit with a human flicking input switches, this will be easily fast enough though. No need to deal with interrupts.

Dave.

David,

How a processor detects an interrupt? Does it iterate through all interrupts and checks which one(s) are active? Does that check multiple times per second?

====================================================================

For a PIC, such as the PIC18F2420, only four pins can be set up for interrupt on change. And this seems to be true for several others I looked at. There is one interrupt vector used for any change, and you must check to see which one triggered the interrupt.

So it may be better to poll the state of one or two 8-bit I/O ports (for up to 16 switches) and check for change, which can be done perhaps 1,000 to

10,000 times a second in a timer ISR. You might need some debouncing, so that should be fast enough if these switches are being pressed by humans. Upon any change, you can decode the switch number and put it into a queue that can send it out on a serial port or USB to a computer or display.

If you have more switches, you can get PICs with higher pin and IO count, which will give you the best speed, or you will need to use a matrix, which is a bit slower, but can handle 64 switches with an 8x8 matrix. Diodes are then required to isolate each bank of switches to avoid "crosstalk".

Paul

On a sunny day (Wed, 23 Apr 2008 22:58:44 -0700 (PDT)) it happened laura wrote in :

You get 50 / 50, so say if 4 and 6 are pressed, you could get 4,6 or 6,4. In fact there is almost no such thing as 'at the same time', especially in high speed electronics.

If the switches are polled, like in a keyboard, then they are checked after each other, and it is possible that the one that was pressed first will be checked later then the one that was pressed next.

PIC micro controller, many inputs, interupt on change, may work.

If you know no electronics I'd go with the marbles :-)

The eastern European origins and lack of any specifics make it reasonable to assume your project is a furtherance of some criminal criminal attempt to intercept security codes of some kind...

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required