The project was created for Sparkfun's microcontroller competition 2011 and aims to demonstrate an number of useful design techniques which can be used when working with low-pin count microcontrollers. The code is written entirely in C and fits neatly into the 2K of available program flash on the chip. The PCB is only 1.5 inches square and uses both SMD and through-hole components, however it is perfectly possible to recreate the project using larger components on a breadboard or a small piece of strip-board.
The game is powered by a standard CR2032 3V lithium cell which is mounted on the underside of the game. The design uses the ultra low power standby feature of the microcontroller meaning that no power switch is required. Overall power consumption is kept to a minimum by using the internal oscillator of the PIC running at 4Mhz.
You can see a video of it in action over on youtube
Step 1: Parts List
The MicroSimon hardware consists of the following parts:
* 1 x PIC12F683 SOIC 8-pin microcontroller
* 5 x 10K resistors (1206 SMD)
* 1 x BC817 NPN Transistor
* 1 x 100nF capacitor (0805 SMD)
* 4 x 3mm LEDs
* 1 x CR2032 battery holder
* 5 x Tactile push-button switches
* 1 x QMX-05 speaker
* 1 x 6 pin 2.54" right angled header
Step 2: Circuit Schematic and PCB
Step 3: 4 Switches on 1 ADC Pin
Step 4: Charlieplexing the LEDs
Step 5: Hardware (the Rest Of...)
The sound circuitry consists of a miniture QMX-05 speaker with a single NPN transistor which makes the sound louder and also avoids placing a high load on the microcontroller's output pin. It is possible to drive the speaker directly from the PIC without using the resistor or transistor, however this results in a much weaker sound. If you want to build the circuit using larger components the BC817 can be replaced with any compatible small-signal transistor such as a BC547 or BC337.
Step 6: Firmware Design
This module is responsible for reading the button state via the PICs ADC. The ADC is read and the pressed button is determined using a small range of possible input voltage for each button. The code also provides button debounce on and off to ensure that the button action is 'positive' and noisy switches do not result in false readings (which would not be fun during your epic winning game!).
This module provides the charlieplexed LED control which sets the PIC's port directions and power output in order to light the correct LED.
This module contains the commands to put the PIC into low-power sleep mode.
This module contains functions which allow the sound to be turned on (at a specified frequency) and turned off. It also contains the interrupt service request (ISR) function which is called using a timer1 based interrupt and toggles the output pin on and off to generate the required sound.
This module contains the game's state-machine which is polled by the main looping function every 10 milliseconds. The game is implemented as a polled state-machine to allow accurate timing of the game whilst avoiding using interrupts (which would interfere with the sound generation since the PIC12F does not have multi level prioritised interrupts). The polling technique also allows the PIC to constantly read the game's button states and perform debounce without preventing the game from waiting for time-outs and user input during the game.
The game itself is based on the original game 1 from the MB Electronics Simon game. The game outputs an ever increasing number of colours in a sequence which you must repeat in order to win. The number of colours in the winning sequence is determined by the selected skill level.
The main.c module initialises the PIC ready for use and then allows the user to select a required skill level before starting the game. Once the start button has been pressed the firmware 'chases' the LEDs to indicate it is waiting for skill level selection. The user selects skill level 1 to 4 by pressing the blue button for level 1, the red button for level 2, the green button for level 3 or the blue button for level 4.
The main module is also responsible for generating a random number which selects the next colour in the sequence. This is done using the simple technique of continuously incrementing a counter between 1 and 4 as the game poll loops. Since the game reads the counter based on when the user presses a button the result is a random number being picked every time. Since the time between pressing the reset button and the PIC being ready is constant, the initial skill level selection is used to get the random first colour for the game.
Step 7: Project Files
MB Electronics Simon is one of my favourite games and I love the idea of being able to have a truly pocket-sized version. As a next step I will probably build a small case for the game and mount in neatly to protect the electronics. I'd been thinking about building a version of the game using an 8-pin PIC for a while, so thank-you to Sparkfun's microcontroller competition for giving me the encouragement to get it built and working!