SWITCHED ON

By CLIVE JONES

Switch Matrix Basics:

Switches fall into two catagories - 'electro-mechanical' and 'solid state'. Most switches used in pinball machines are electro-mechanical. Microswitches, blade switches, tilt bobs etc. These switches have moving mechanical parts and are subject to the laws of physics governed by the materials they are made of - steel, copper, brass etc.

There is one inherent problem with interfacing microprocessor based systems and mechanical switches - it's called 'bounce' (yes the thing that goes 'boing... boing'). When a mechanical switch closes, the contacts do not settle immediately, instead they 'bounce' a number of times before they come to rest in their final closed position.A microprocessor (MPU) running at high clock speeds (typically executing a million plus instructions per second) is fast enough to detect each of these bounces as a real (valid) 'make and break' action, and each will be acted upon independantly. However, this was not always the case. Early Bally solid state electronics could not process some switch closures reliably because the switch would close and open very quickly producing a fast 'switch edge'.To overcome this, a capacitor was installed across the switch to time stretch the switch closure and to give the MPU enough time to reliably sample the switch closure.

To overcome this multiple contact problem, a switch 'debounce time' is introduced.

What's debounce timing? Well, when the MPU detects a valid switch closure, lets say, a stand-up target worth 1000 points, the MPU makes a note of it, then waits for a period of time (which is usually governed by 'debounce' software timer) and then checks the switch again. If the MPU finds the switch is *still* closed, it processes the switches action (it adds the target value to the score). If you removed the debounce timing and shot the 1000 point target - you may well rack up more than 3000 points for a single hit!

Solid state switches are switches with no moving mechanical parts. Opto (short for 'optical' ) sensors are a prime example and are used commonly on current tables. They have their plusses and their minuses. They are more expensive than mechanical switches due to the additional circuitry required to decode them but do not suffer the contact wearing problems of mechanical switches. Also, because they have no moving parts they do not require 'debouncing' which makes for less 'house keeping' software and more overall switch processing speed.

I should explain what an Opto-sensor is. An opto sensor 'sees' or 'detects' light. To be more specific, the sensor has two parts - the 'emitter' which is the source of light and the 'reciever' which detects light. The emitter usually takes the form of a light-emitting diode (an LED) and the receiver, - a light-sensitive transistor. Together they form an optical switch, performing exactly the same function as a mechanical switch except that they use a beam of light rather than a mechanical actuator. Most (but not all) opto sensors use infra-red light which is not visable to the human eye. Most opto's have a transmitter and a reciever which is seperated by air.

I've knocked up a little circuit here to explain how the opto-sensors works;

 

+5 volts
^
|
+------[180]-------------.             |\
|                        |          (a)| \
'------[270]--.          +----[2k2]----|[]>O------ on (low)
              |          |             | /
              |          .             |/
              |        |/
         LED _v_ --->  |\. NPN Tran.
              |          | receiver Schmitt Invertor
              |          | (74LS14 or similar)
              '----------+

                         |
                         |
                         |
                         v
                      0 volts

The beam of infra-red light ( signalled by the arrow between the LED transmitter and NPN transistor receiver - sorry I couldn't draw the emitter arrow) is unbroken - not interrupted, the current can flow through the transistor because it's switched on via the infra-red sensitive base which is receiving light from the LED. This deprives point 'A' of enough voltage to actually trigger the Schmitt trigger inverter. The invertors output is high (inverse of it's input). If the beam of light is broken, the voltage at point 'A' rises as it's no longer flowing through the transistor (which is now 'off'), this triggers the inverter into action forcing the output to change state (now goes low) which will be detected by any electronics 'scanning' the circuits output. This is commonly known as an 'Opto-interrupter' - where the beam of light is interrupted and causes a state change (don't get this confused with MPU interrupts - they are not related). A schmitt trigger is used to provide a 'clean' pulse (well, here in my design anyway).

 

The Switch Matrix: What is it? Why use it? How does it work?

Well, we need our targets, ball troughs, ball locks, tilt and other switches to be read by the MPU so we can have them acted upon when they close (their exact function is determined in software). If we have 64 switches in a pinball machine, then we need 64 seperate inputs that can be looked at. The first problem arises - this costs us a lot in hardware and a lot in PCB space (and ultimately a lot out of our pockets), so a compromise is reached - read the switches on an 8 x 8 matrix which reduces the overall cost but gives us the minor problems of a more complex switch system.

There's nothing wrong with a matrix (be it switch or lamp), it solves the problem very elegantly and is fairly easy to troubleshoot. However, if we loose row or column due to a broken switch wire or IC failure, it could mean that up to 8 switches will no longer respond.

The switches are arranged in a series of 8 x 8 as we've already mentioned - there are 8 'rows' and 8 'columns'. If you draw 8 horizontal lines on a peice of paper - these are the rows. If you then draw 8 verticle lines down the page intersecting the row lines (a grid) - these are the columns (like the columns that hold buildings up!). If you now count the number of times the lines intersect - you will get 64. Each of these intersections represents one switch in the matrix.

         col1  col2  col3  col4  col5  col6  col7  col8

row1>-----+-----+-----+-----+-----+-----+-----+-----.
      sw1 | sw2 | sw3 | sw4 | sw5 | sw6 | sw7 | sw8 |
          |     |     |     |     |     |     |     |
row2>-----+-----+-----+-----+-----+-----+-----+-----+
      sw9 | ... |     |     |     |     |     |     |
          |     |     |     |     |     |     |     |
row3>-----+-----+-----+-----+-----+-----+-----+-----+
          |     |     |     |     |     |     |     |     
          |     |     |     |     |     |     |     |     
row4>-----+-----+-----+-----+-----+-----+-----+-----+
          |     |     |     |     |     |     |     |
          |     |     |     |     |     |     |     |
row5>-----+-----+-----+-----+-----+-----+-----+-----+
          |     |     |     |     |     |     |     |
          |     |     |     |     |     |     |     |
row6>-----+-----+-----+-----+-----+-----+-----+-----+
          |     |     |     |     |     |     |     |
          |     |     |     |     |     |     |     |

row7>-----+-----+-----+-----+-----+-----+-----+-----+
          |     |     |     |     |     |     |     |
          |     |     |     |     |     |     |     |

row8>-----+-----+-----+-----+-----+-----+-----+-----+
     sw57 |sw58 |sw59 |sw60 |sw61 |sw62 |sw63 |sw64 |
          |     |     |     |     |     |     |     |
          |     |     |     |     |     |     |     |

ret1<-----'     |     |     |     |     |     |     |
ret2<-----------'     |     |     |     |     |     |
ret3<-----------------'     |     |     |     |     |
ret4<-----------------------'     |     |     |     |
ret5<-----------------------------'     |     |     |
ret6<-----------------------------------'     |     |
ret7<-----------------------------------------'     |
ret8<-----------------------------------------------'

(just for the tech's - the switch numbers are 'physical' not 'logical' (11-88))

Each area identified SW'nn' - would look like this;

               Column
                  | 

                  |
                  |
                \ O
        |\ |     \   switch   
  Row---| >|------O
        |/ |

        Diode

You will notice a blocking diode in the switch path between the row and the switch column this is extremely important as we'll see. The arrangement for the switch and the diode is common throughout the whole matrix (the diode is not always connected to the switch - Gottlieb used 'diode strips' which were located under the playfield) Now then, a couple more points to clear up before we push on. You may have noticed the signal input arrows (>) at the row insert points this is where the inputs to the matrix are - there are obviously 8 of them. They are often refered to as 'strobes' or 'sends', personally I like the term 'send' as the other end has 'returns' (<), true the signals do 'strobe' on and off sequentially (much the same as a strobe light) but whatever you call the signal it is purely subjective (you could call it the 'row on pulse' for example). Also, only 16 different coloured wires are required, again - 8 for the rows (or 'sends' or 'strobes') and 8 for the columns (or returns). Simple eh? Now all we have to do is 'drive' some power through the rows and check the switch returns the other end to see if we get anything back for the uP to read (indicating a closed switch).

 

Interfacing the Matrix with the Microprocessor

The switch matrix cannot be directly connected to the uP - it doesn't have the power to 'drive' the matrix (and if the matrix shorted - you'd probably be picking the CPU out of the back of your head), so we have to provide a suitable interface between the uP and the matrix - enter the most common interface chip for pinball machines on the planet - the 6820/1 PIA (Peripheral Interface Adaptor).

The 6820/1 has two 8-bit bidirectional ports which can have any of their 16 pins configured as an input or an output. What a coincindence! We need one 8 way output port ('sends' or 'strobes') and one 8 way input port ('returns' - to read).

One port is called 'port a' and the other 'port b'. The uP can write to the output port which in turn will drive a higher voltage through the rows ('sends' or 'strobes') which will return into the input port of the PIA which our uP can safely read without burning up!

The PIA doesn't usually drive the matrix directly from it's output pin's either, instead, a driver of some form is used (a pull-up resistor or driver transistor is common). The PIA 'b' port can actually output more current than the 'a' port (2.5mA) which would probably be enough, but, would offer no protection to the PIA if the matrix shorted and would significantly shorten the life of the chip (you'd be 'loading' the output), so it would be good pratice to protect the output stages using drivers as it also adds more power to push through the matrix too which gives us a healthy signal.

If higher current drivers are used - current limiting resistors need to be added to the input pins to reduce the current to a safe level for the PIA to read, otherwise the PIA port input stage would burn up.

Another use of drivers involves not sending 5 volts through the matrix but higher voltages - 12 or 24 volts springs instantly to mind. A driver transistor can be switched on with a 'pre-driver' transistor which, in turn is switched on by our PIA (port 'b' only - port 'a' does not have enough output current), the pre-driver runs from the 5 volt rail whilst the driver runs volt from the 12 or 24 volt rail, which then pushes the higher voltage through the matrix. This method is known as 'level- shifting' - we're 'stepping' or 'shifting' up to higher voltage/current.

Similarily, our PIA cannot read 12 volts or there abouts (don't try this at home, otherwise you may be picking another chip out of the back of your head!), so the input has to be shifted back down again to a safe level (5 volts or less). You could use zener diodes, potential dividers or comparators (as with the WPC system).

So when the uP 'writes' data to the output port of the PIA it is effectively 'driving' via proxy the switch matrix;

 row8 row7 row6 row5 row4 row3 row2 row1 ('sends' or 'strobes') |bit7|bit6|bit5|bit4|bit3|bit2|bit1|bit0| - the PIA output port (byte)

The uP then reads the *input* port to look for an *active* return line which will appear as an active *bit* in the input port register, which then would indicate a closed (or 'jammed' if in self test) switch. The uP would then initiate the debounce time, after which it would then check the input port register again to see if it was still closed.

 ret8 ret7 ret6 ret5 ret4 ret3 ret2 ret1 - ('returns')
|bit7|bit6|bit5|bit4|bit3|bit2|bit1|bit0| - the PIA input port (byte)

Finally (if it is closed) the uP executes the process associated with the switch - scoring, tilt, ball in lock or whatever. The diodes remain in the matrix to prevent the voltage leaking back onto another line and giving a false switch registration when a switch closes.

 

Scanning Method

The uP via the PIA + driver electronics sends a voltage down row1. It then checks the returns for an active bit - this would indicate that a switch or switches (1-8) are closed. It would then turn row1 off and row2 on and check the input port again for closures (switches 9-16 this time) and so on until all 8 rows and been turned on an all 8 returns had been read.

The uP has to obviously perform this scanning routine 'x' number of times per second checking for new switches closing and previously closed switches opening again.

 

Well, I think that's it,there are a couple of loose ends - not all matrix's use PIA's, some use transistors, comparators, pull-up resistors to push a higher current through the matrix as well as other interface methods to the uP etc.

Hopefully, there's a bit of an insight into how the switch matrix functions.

 

Back to the learn page

Back to the front page

© Pinball News 2002