The game of life - the cellular automaton already seems written in all possible programming languages.
I am interested in the FPGA technology - and therefore once I made the implementation of life for the Alter FPGA Cyclone III. The truth is then very small: only 32x16 cells. On such a small field it is quite difficult to experience complex shapes. ')
Now I have another board in my hands: Altera MAX10 is already there with 50 thousand logical elements. It was interesting, can I expand the field at least 4 times? In general, I decided to make at least 64x32.
The result is presented in this video, I call this picture: "the Gosper's gun kills itself."
Below are the implementation details. Actually, the implementation of the game I already had in my previous project for the third cyclone. The whole project consists of several parts.
The field of life is made up of interconnected modules-cells written in Verilog HDL so that it is possible to calculate the next generation of cells in 1 clock cycle. I would like to have just such an implementation, because it is a FPGA, which means there can and should be done. This is a model of multiple calculators that operate simultaneously in parallel and pass parameters to each other. This parallelism is just amazing. The game field is 64x32 = 2048 parallel computers working in FPGA synchronously! The module and all the logic of a single cell is written in Verilog HDL:
Then, instances of this module are repeatedly created and interconnected by wires into a single flat field using the generate-endgenerate construction of the Verilog HDL language.
The second most important module in the project is the module loading the initial state of the game through the serial port. The state is transmitted as a text file of approximately the following form:
one------**------------------------ 2 ----- * - * ----------------------- 3 ---- * ---- * ---------------------- four---*------*--------------------- five---*------*--------------------- 6 ---- * ---- * ---------------------- 7 ----- * - * ----------------------- eight------**------------------------ 9-------------------------------- A -------------------------------- B -------------------------------- C -------------------------------- D -------------------------------- E -------------------------------- F --------------------------------
Meaningful characters are only '*' (living cell) and '-' (no life). The transfer rate is 115200, 8 bits, 1 stop, no parity. During the loading of the project, you need to hold the button on the board - then the field of life will be sown with the new state described in the text file.
And finally, the module displays the current state of the game. This is a text video adapter, in which the state of cells-cells is periodically copied. All cells are connected in a cyclic shift register, so you can read the entire game field and make an entry in the video adapter for WIDTH * HEIGHT cycles.
Well, of course, this all together turns out to be quite surprising - after all, the very logic of the game “life” is simple, but the serving modules, loading and display modules turn out to be almost more complicated than the “life” itself.
And now about the display on the screen. To port the old project to MAX10 and for a completely different motherboard Mars Rover3 will have to tinker a bit. The fact is that the board no longer has a VGA connector, which was so easy and pleasant to work with. Now the board has an HDMI connector and the HDMI lines go straight to the FPGA chip.
HDMI uses serial transmission over a differential pair. Just four pairs. Three pairs transmit 8-bit R, G, B colors plus HSYNC and VSYNC control signals. Because of the serial transmission, TMDS coding requires a working frequency 10 times higher than the pixel frequency on the screen. If the pixel frequency is 74 MHz with a resolution of 1280x720, then 740 MHz is already required for signal encoding, which is a lot. The situation is saved by the fact that the FPGA outputs have built-in DDIO interface, that is, a two-to-one serializer. This means that the maximum frequency in the project can be reduced to 370 MHz.
The source code for the HDMI module is shown below.
Altera Quartus Prime compiler report: Flow Status Successful - Thu Apr 28 16:08:48 2016 Quartus Prime Version 15.1.0 Build 185 10/21/2015 SJ Lite Edition Revision Name max10_50 Top-level Entity Name top Family MAX 10 Device 10M50SAE144C8GES Timing Models Preliminary Total logic elements 29,432 / 49,760 (59%) Total combinational functions 28,948 / 49,760 (58%) Dedicated logic registers 2,238 / 49,760 (4%) Total registers 2254 Total pins 23/101 (23%) Total virtual pins 0 Total memory bits 147,456 / 1,677,312 (9%) Embedded Multiplier 9-bit elements 0/288 (0%) Total PLLs 1/1 (100%) UFM blocks 0/1 (0%) ADC blocks 0/1 (0%)
Probably the game "life" is already tired of many. However, in my opinion there is something to think about. Despite its simplicity, it contains interesting principles of interconnected calculators. Probably, similar ideas can be used in special classes of tasks. For example, placing components on a printed circuit board is a complex combinatorial problem that must take into account many factors, including the length of the connections between components. One can imagine that the components on the printed circuit board are cells fighting for a better location on the field of life under the influence of the forces of the connections between the components. I think that over time such tasks will be calculated using FPGA.