Course: Snake game on FPGA: Real-time VHDL simulation with GUI

Implement the classic Snake game on an FPGA with a 128×32 OLED display. Create a custom GUI to play the game in real-time using the Questa VHDL simulator.

Category: Tags: , ,

Description

This course teaches how to implement the classic Snake game on an FPGA with a 128×32 OLED display. You will learn to set up a system from VHDL modules and projects already available in the VHDLwhiz library.

Furthermore, you will create VHDL simulations that interact with other systems in real-time, such as C or Python programs. We will do both by using Questa/ModelSim’s Foreign Language Interface (FLI) API.

See how to set up a VHDL testbench in Questa to actually play the game on a GUI in the simulator. It will be a custom graphical user interface (GUI) complete with buttons and a display that looks like the real thing.

This course is only available in the VHDLwhiz Membership.

The membership subscription gives you access to this and many other courses and VHDL resources.

You pay monthly to access the membership and can cancel the automatic renewal anytime. There is no lock-in period or hidden fees.

Hardware used in the course

Software used in the course

I am using Windows 11 in the course. All the other software is available for free for Windows and Linux:

You don’t need any hardware to do the course because I’ll give you a hardware simulator GUI in a later lesson. It should work on Windows and Linux. There’s one downloadable for each platform in the course.

Course outline

Number of lessons:
15
Average video duration:
13m30s
Total video duration:
3h22m

The overview below shows the lessons in this course.

video lesson icon/default Created with Sketch.

1 - Introduction

Join me in implementing "Hardware Snake" on this FPGA board! Let me tell you what lies ahead in this course.

video lesson icon/default Created with Sketch.

2 - Project starting point

We'll base the new project on an existing VHDLwhiz implementation of a Pmod OLED display controller. Download the files to get started!

video lesson icon/default Created with Sketch.

3 - Creating the Vivado project

See how to set up the Vivado project from scratch for the Arty S7-50 or any Digilent/Xilinx/AMD board.

video lesson icon/default Created with Sketch.

4 - Bit write enable in block RAM

We must manipulate single bits in the byte-addressable frame buffer to update individual pixels on the display. Here's how to do it without affecting the other bits.

video lesson icon/default Created with Sketch.

5 - Pixel writer module

Let's create a module that can change individual pixels on the display using row and column addresses. It will make it easier to implement the Snake gameplay.

video lesson icon/default Created with Sketch.

6 - Simulation graphical user interface (GUI)

Using Questa/ModelSim's Foreign Language Interface (FLI) API, a C program, and a Python script, we can create a GUI to play the Snake game on while simulating our VHDL design.

video lesson icon/default Created with Sketch.

7 - Timer tick module

This module produces a pulse at a given interval, allowing us to control the speed of the gameplay in real time. We need it to limit the frame rate of the game.

video lesson icon/default Created with Sketch.

8 - Button reader module

This module will read pushbuttons on the FPGA board, synchronize them to avoid metastability, and output the latest clicked key: Left, Up, Right, or Down.

video lesson icon/default Created with Sketch.

9 - Game controller module and testbench

Finally, it's time to start on the Snake game control logic. Let's create the module entity and testbench using the simulation GUI to interact with the game in real time.

video lesson icon/default Created with Sketch.

10 - Snake movement

In this lesson, we connect the GUI buttons to the game controller to move the snake head on the display in the Questa simulation. We'll use a finite-state machine (FSM) to achieve that.

video lesson icon/default Created with Sketch.

11 - Snake tail tracking

We'll use a ring buffer implemented in block RAM as a FIFO to store the snake's path so that we can erase the tail pixels when it grows.

video lesson icon/default Created with Sketch.

12 - Snake eats its tail

If the snake eats its own tail, it's game over. To implement that, we must store all tail coordinates in block RAM and check if the new head location is part of the body.

video lesson icon/default Created with Sketch.

13 - Snake food and FPGA randomness

The point of the Snake game is to eat the food/fruit/dots that appear on the screen, which causes the snake to grow in length. Let's create logic to place it in pseudo-random locations.

video lesson icon/default Created with Sketch.

14 - Game over

Now, it's time to move from the simulator to the FPGA board and play the Snake game on real hardware. Let's also show some nice graphics on Game Over.

video lesson icon/default Created with Sketch.

15 - BRAM reset

After clearing all block RAM content, we finally have the game working, also after a reset. Now, it's gaming time!

This course is only available in the VHDLwhiz Membership.

The membership subscription gives you access to this and many other courses and VHDL resources.

You pay monthly to access the membership and can cancel the automatic renewal anytime. There is no lock-in period or hidden fees.

Reviews

There are no reviews yet.

Be the first to review “Course: Snake game on FPGA: Real-time VHDL simulation with GUI”

Your email address will not be published. Required fields are marked *