Title: Game of Life
1Game of Life
2Game of life
A cellular automaton devised by British
mathematician John Conway in 1970. It is believed
to be the most-programmed computer game .
3Simple Rules of Life
4An example
Interactive
Gosper Glider Gun
5The Project
Implement the Game of Life on a 16X16 dotmatrix
LED display
Since the universe is limited, the edges wrap
around
6Game features
Note the following features have been written
and simulated in software. But due to currently
incomprehensible hardware (electrical) issues and
erratic behavior of the microprocessor, some of
it has not been implemented.
- Games speed can be altered
- The game has memory of 4 past generations. When
in pause mode, the - user is able to navigate back in time for a max
of 4 generations
- When in pause mode, the user is able to move a
cursor across the screen - and toggle individual cells on and off
- The color of the cells is a function of the
current population. - Red -gt large population Green -gt small population
7Things which worked
Infrared communication A cursor can be controlled
by the infrared remote and moved across the
screen. The toggle button changes the color of
the cursor. Witness Steven, Adam
Generation computation Given the current
universe, the next universe can be calculated.
Witness all of you will be
Displaying current universe Given a initialized
universe in 20 consecutive bytes (as we have seen
just now), the system is able to display the
pattern on the screen. Witness Dr. Board
8The Project
Processor of choice Microchip PIC18F4520
- Large code space 32K of Flash
- Large number of I/O Ports
- Come in DIP packages, easy for breadboard
prototyping
- Low power and sleep mode features enable
efficient power consumption
- Popular and well supported
9Hardware
Top switch needs to source the peak current for
potentially 16 LEDs 1/16 of the time
Bottom switch needs to sink the peak current for
1 LED all the time
Since the peak current for an LED with a 3 duty
cycle is about 90 mA, both the current source and
current sinks need to be pretty strong
Current Source 2N2907 PNP BJT Current Sink
ULN2001 Darlington transistor arrays
10Slight Complication
The ULN2001 Darlington Arrays are perfect current
sinks, except for theres a slight problem
The chips do not come with an ENABLE pin. This
makes is impossible to select between the left
and the right half of the screen, since they are
all wired up to the same output pins.
Of course, the signals can be put through 7405
inverters or 74244 buffers, but due to the
delicate breadboard setup and other random
reasons, another solution was devised (get ready)
Another two PICs were programmed to function as
8-bit multiplexers (a solution Im not
particularly proud of).
11Hardware Infrared Communication
Remote Control Radioshack Universal IR Remote
programmed to operate with Sony Protocol.
Decoder Off-the-shelf infrared decoder, which is
actually a low-end preprogrammed PIC
microprocessor
12PIC Memory overview
12-bit memory addressing maximum of 4Kb data ram
To save code space, the data ram is divided into
Banks, each having 256 bytes. Only one byte is
needed to select the content within a bank.
A BSR (Bank Selector Register) contains upper 4
bits of the memory address. BSR can be modified
through software.
13Software Implementation
This feature enables relatively easy
implementation of the Game of Life.
Each generation occupies a different bank. To
move onto the next generation, simply increment
the value of BSR. To go back in time, only need
to decrement the value of BSR.
All the variables are 8-bit so they occupy the
same relative position within different banks. To
pass variables between banks, the stack is used.
Disadvantage space is wasted. Each bank contains
256 bytes but only about 80 are used before
moving onto the next bank. More generation can
be remembered if data ram is used more
efficiently.
Oh, well
14Flow-Chart
Just a very high level overview. Each of the
blocks contains lots of code.
15Polling or Interrupt
Consideration constant brightness of each cell
Since each half-row only has a duty cycle of 3,
entering an Interrupt Service Routine before
moving on may double the duty cycle (and in turn,
brightness) of the current half-row.
This, of course, can be overcome by lengthen the
display time of each half-row with respect to the
IRS, but that might introduce flickering.
And also, Im not too familiar with the
Interrupts on the PIC.
Decision Using Pollling.
16Generation Computation
0x00 0x50 0x24 0x50 0x00 0x00 0x00 0x32 0x02 0x02
0x02 0x02 0x7e 0x00 0x38 0x00
0x00 0x00 0x70 0x00 0x08 0x1c 0x08 0x00 0x00 0x04
0x04 0x64 0x06 0x02 0x02 0x00
17Generation Computation
0x00, 0x00, 0x20, 0x20, 0x58, 0x20, 0x20, 0x30,
0x00, 0x1c, 0x00, 0x14, 0x00, 0x1c, 0x00,
0x00 0x07, 0x00, 0x07, 0x00, 0x07, 0x0e, 0x3b,
0x0c, 0x3e, 0x06, 0x40, 0x03, 0x10, 0x00, 0x10,
0x00
0x00 0x20 0x58 0x20 0x00 0x00 0x00 0x00 0x07 0x07
0x07 0x3b 0x3e 0x40 0x10 0x10
0x00 0x20 0x20 0x30 0x1c 0x14 0x1c 0x00 0x00 0x00
0x0e 0x0c 0x06 0x03 0x00 0x00
18Generation Comparison
Generation 1
Generation 0
19Problems Encountered (Solved and Unsolved)
Initially, most of the development time was
expected to be spent on software. But in reality,
all of the problems encountered during the
project are hardware related issues.
Brown-out Problem Due to the large current
spikes from the LED display, the Vdd value
supplied to the PIC changes randomly, which
caused the program to reset. Solution Adding
large decoupling capacitors and lower Brown-out
threshold voltage through software.
20Problems Encountered
LED Brightness Since every 8 LEDs only get
turned on 1/32 of the time (about a 3 duty
cycle), the peak current needs to be ideally
532160mA. So for the common anode current
source, potentially it needs to source A LOT OF
current.
The absolute maximum rating of IOH of the 2N2907
is 500mA.
A relatively large current limiting resistor was
chosen at each common cathode (to ensure constant
brightness).
21Problem Encountered
The one unsolved problem that is stalling further
progress of the project
When the PIC is programmed to display every pixel
through the whole screen, every works fine. When
the PIC is programmed to display a certain
pattern through the whole screen, most PICs dont
work, only one works, marginally.
What does that mean?
When the same program is downloaded onto
different PICs, each one displays a different
random pattern, except for one PIC, which
displays the right pattern but is missing one
column.
22Problem Encountered
Actions Taken
Checked and simulated software. Make sure all
variables are initialized.
Added more capacitors to ensure a constant supply
voltage
Added a separate power supply for the PIC
Check wire connections
all of them.
Result Problem still unsolved
23Conclusion
Final project compared to the proposal
One of the major compromise made was the use of
an off-the-shelf infrared decoder chip. Too much
time was spent on debugging hardware, which made
it impossible to write my own decoder program
Not a success but not a total failure either.
Despite the mysterious problem described earlier,
most of the features described in the initial
project proposal (such as changing cell colors
according to population) were implemented in
software and simulated. So its not THAT bad.
24What Ive learnt
Specific knowledge Architecture and most of the
common functions of Microchip PIC processors.
In general
Breadboard before soldering!!!!!!!
Hardware before software!!!
THE END