Build a Game Gizmo
|
Remember the dark ages, the time before video games? Remember a time when board games ruled? Maybe you still have a few of these relics stored away someplace? You will want to find them and dust them off, this project is sure to breath some life into them!
|
|
The trouble with those old board games is that the don't have any bells and whistles, or in this case LEDs and speakers. Sure there have been attempts to bring board games to the PC, but somehow something is missing. It's just not the same crowding around a keyboard, and reaching across the old family card-table.
The Game Gizmo changes all that, it brings the bells and whistles to the card table using modern electronic components to spice up those old board games.
How it works
The Game Gizmo uses very few components to perform a lot of work. To do this the parts have to be pretty intelligent. In this case a PIC 16F877P microcontroller from MicroChip is used. This is a very capable device that contains 8k of flash program memory, timers, lots of I/O pins etc. It was chosen because of it's high performance, availability and popularity with hobbyists.
The hardware design is fairly simple. It consists of IC1, the microcontroller, D1 a 5x7 LED matrix, 2 push button switches, a small speaker and various support components. The microcontroller is responsible for time multiplexing the LED display, scanning switches, producing audio wave forms and general game play. The whole thing is powered by a couple of AA batteries.
The Game Gizmo has several modes of operation, allowing it to support the needs of various types of games. The modes include:
- Spinner - This mode "spins" fast, and slows to a random number between 0-9.
- Count down timer - This mode can count down to 0 from 90, 60, 30, or 15 seconds. It displays two digits sideways!
- Hourglass - This mode animates sand falling in an hour glass. If can count down from 60, 30 or 15 seconds.
- Dice - This mode rolls and displays not as numbers, but two dice.
- Decision maker - This mode helps make decisions. Ask it a question, and it will answer with Yes, No, Maybe, or doesn't know.
- Coin toss - Just what you need to decide who goes first, heads or tails.
- Spin-the-bottle - Randomly select one of eight.
- Random pattern display - Just fun to watch, this mode lights random LEDs.
Hardware details
|
Two I/O ports of the microcontroller are used to time multiplex the LED display. The display is a 5x7 Cathode Column, Anode Row type made by LiteOn. Each LED in the matrix can consume up to 20 mA. The microcontroller I/O ports are can source/sink up to 25 mA.
As you can see from the schematic there are no row/column drivers, this means that the microcontroller must directly drive the LED matrix. Normally in a LED matrix such as this, several LEDs would be driven at the same time, either a entire column or entire row. The microcontroller I/O pins do not have enough drive to do this, so how does it work?
|
Click on image for a larger view
|
Because this is a low power device intended to be used for long periods of time, and to keep the part count low, the LED matrix is driven one LED at a time. In other words at any point in time only one LED will be on. This means the microcontroller can drive the matrix, although it must scan the LEDs very quickly to avoid flicker. More on this later. It also means that because only one LED is on at a time, power consumption is low.
The Game Gizmo also uses a couple of switches to control the various modes and functions. These switches are scanned and debounced by the microcontroller. The details of debouncing will be discussed in the software section.
Finally, in order to add the all important audio element to the Game Gizmo, the design includes a speaker. The speaker is driven by, yes you guessed it the microcontroller. You might have noticed from the schematic, that there what seems like a lot of resistors as part of the speaker drive. These resistors comprise a 3 bit digital to analog converted. Not only can the Game Gizmo make sounds, but it can also control the volume and wave form of the output.
As I'm sure you can see, the Game Gizmo does a lot of things, with very few components. The software in the microcontroller does most of the work.
The Software
The software in the Game Gizmo has a lot of work to do, one of the tasks that it needs to do is to time multiplex the LED display.
Display Multiplexing
As we discussed earlier, only one LED can be on at a time. This is done much like a TV screen is scanned, one line at a time. A small memory array maintains what will be displayed. A “1” or logic high is rotated across the Column (LED Anode) while a "0" or logic low is rotated across the Row (LED Anode). The Row signal is masked by values in the display memory. In order for an LED to light, a High must be present on the Cathode, and a 0 must be present on the Anode. To ensure that the eye does not see the multiplexing, it has to be performed faster than around 60 times per second. The Game Gizmo treats the display update as an idle or background activity. It does this when ever there is nothing else going on, which is most of the time. As long as the display is updated frequently the eye will not detect the times when the Game Gizmo has other things to do. The ear is not as easy to trick, the ear is pretty good at detecting fairly small changes in frequency, so audio is handled differently.
Audio Output
The Game Gizmo audio section maintains a small 8 byte memory array. The memory array contains numbers that represent the shape of the waveform we wish to generate. One of the microcontroller timers is loaded with a value. The counter counts down, when the value reaches 0, an interrupt is generated. Each time on interrupt occurs, the interrupt handler increments a pointer into the waveform table, a value is obtained from the array, which is output on port A of the microcontroller. The frequency of the resultant audio is determined by the value loaded into the timer. By changing the shape of the waveform, the Game Gizmo can give more character to the sound generated. For example a sine wave like waveform can be generated, resulting in a softer less buzzy sound. If the desired sound is more like a mechanical buzz, like the spinner mode uses, a saw tooth waveform can be used.
A three bit digital to analog converter is formed using a R-2R resistor ladder network connected to port A of the microcontroller. This circuit enables eight levels of voltage output; 0, 1/8, 1/4, 3/8, 1/2, 5/8, 3/4 or 7/8 of a logic high signal. The result directly drives a small speaker.
Switch Debounce
To select between the various modes of operation, the Game Gizmo has a couple of switches. These switches are scanned periodically to see if their state has changed. If all that we did was scan the switches, we run into a problem. Mechanical switches like those used here, do not open and close as cleanly as we would like. They tend to “bounce” or open and close before settling into a state. A bounce might last from 5 to 30 mS! The process of scanning might detect these “bounces” and treat them as multiple switch closures, not what we want.
To avoid this situation the Game Gizmo uses a technique called "debouncing". This amounts to scanning for a switch state change, then waiting for a period and testing to see if the switch has changed. If it has, it is assumed to be bouncing, so we start over. If the switch state has not changed, we assume that the switch is stable.
If this process were done independently for each switch, even with only two switches things get complicated, fortunately there is a way that we can debounce all of the switches as once, using some Boolean arithmetic:
Read the switches, store them in memory as current.
These the current state against the previous state by an exclusive-or of the current and previous states, the result is what changes, save this in memory as Delta.
The exclusive-or indicates changes, it does not tell us if the change was an open of closure of the switch. To determine that the switch is closed we perform a logical and of the Delta and the Previous state. This tells us that a switch that was closed has been debounced and has been released, a qualified switch closure.
Finally we save the current state in memory as Previous.
The process is repeated at about 30 mS.
Random Numbers
An important aspect of the Game Gizmo, is that many of it's functions require a random number to operate. The Game Gizmo uses a 32 bit linear feedback shift register to implement a pseudo random number. Implemented in software, an exclusive-or between bits 31 and 18 of a 32 bit number is performed. The result is fed back into the shift register at bit 0. Then they entire 32 bit value is rotated left.
Construction and Checkout
The Game Gizmo is simple enough that it can be constructed on a piece of perfboard using standard construction techniques. Get the Firmware.
If you are using the pre-made board, note that the LED display and switches are mounted on the bottom of the board. This is to accommodate the enclosure used.
When assembling the board, double-check the polarity of IC1, it is best to use a socket for this component.
After you have completed assembly, it's a good idea to double check for bad or missed solder joints, and reversed polarity of components. If all is well, it's time to “let the smoke out”.
After applying a source of 3 volt source to the board, (a pair of AA batteries is a good choice), the LED display should show an animated test pattern, and a series of tones should be heard from the speaker. If not, disconnect power and check over your work. There are no calibrations or special procedures.
Operation
As mentioned before, the Game Gizmo has multiple modes. A mode is selected by pressing and releasing switch S1. Continue to do this until the desired mode is selected. Some modes require input to start the mode's operation, for example the countdown timer. The switch S2 performs this action. Some modes have multiple sub-modes. Again using the countdown timer as an example, sub modes allow countdown from 90, 60, 30 and 15 seconds. To access these mode, press both switches at the same time. Like mode selection, you can step though the available sub modes.
| Mode | Function | Sub-mode |
| 1 |
Spinner - This mode "spins" fast, and slows to a random number between 0-9. A saw tooth waveform is used to simulate the buzz if a spinner, slowing to a stop. |
None |
| 2 |
Count down timer - This mode can count down to 0 . It displays two decimal digits sideways on the LED Display. When 0 is reached a tone is sounded to indicate the timeout. |
90, 60, 30 and 15 seconds |
| 3 |
Hourglass - This mode animates sand falling in an hour glass. When the sand runs out, a tone is sounded to indicate the timeout. |
60, 30, 15 and 10 seconds |
| 4 |
Dice - This mode rolls and displays not one, but two dice. A spinning animation, is augmented by cycling through note on the musical scale. |
None |
| 5 |
Decision maker - This mode helps make decisions. Ask it a question, and it will answer with Yes, No, Maybe, or doesn't know. Interesting animation adds to the fun of this mode. |
None |
| 6 |
Coin toss - Just what you need to decide who goes first, heads or tails. Watch and hear the coin spin, then show a 'H' for Heads, or a 'T' for Tails. |
None |
| 7 |
Spin-the-bottle - Randomly select one of eight. The "bottle" spins ever slower while minor keys are played from the musical scale. Who will it point to? |
None |
| 8 |
Random pattern display - Just fun to watch, this mode lights random LEDs. |
None |
PARTS LIST FOR THE GAME GIZMO
| SEMICONDUCTORS |
| IC1 | PIC16F877P MicroChips microcontroller |
| D1 | LTP-757 - 5x7 LED Matrix Display |
| RESISTORS |
| R1-R5 | 15-ohm 1/8-watt |
| R6,R7 | 1000-ohm 1/8-watt |
| R8-R11 | 2000-ohm 1/8-watt |
| CAPACITORS |
| C1,C2 | 4.7-mf 16-WVDC, tantalum |
| ADDITIONAL PARTS |
| X1 | 10 Mhz crystal |
| L1 | 1000 mH inductor |
| S1,S2 | Single-pole, momentary contact, PC mount |
| SP1 | PCB mount speaker |