Introduction: Whack a Mole Game Verilog CPE 133

Introduction

In our final project for CPE 133, we created a whack a mole game using SystemVerilog on the Basys3 board. We used Verilog (a hardware description language) within the Vivado program to create a circuit and send it to the Basys3 board. Materials for this project include a computer able to run the Vivado program, Basys3 board, and a micro USB to connect the computer to board. In addition, we referenced heavily on two online projects, Nexys 2 - Whack a Mole by akcorp2003 as well as Wacky Gator by Michael_Lexa both from instructables.com (link below). In addition, we used open AI such as ChatGPT to generate ideas and outlines to assist us with this project. 


How The Game Works

As mentioned above, we create a Whack a Mole game through the Basys3 board. In order to play this game, we first incorporated buttons to Start/Reset the game as well as Pause. On the Basys3 board they include 5 push pin buttons and we used BTND (U17) as Reset/Start and BTNC (U18) and Pause. As the program is started, 8 LEDs (0 through 7) are switched on and a wave design is included to signify the connection of the board to the program. As the Reset button is pressed, all 8 LEDs are switched off and begin to light up in random sequences. In addition, the seven-segment display starts at 0:0:0 to show the score and goes up as points are scored. In order to score points, the LEDs corresponding switch must be flicked and if flicked correctly, the seven-segment display will increase by 1. Final 4 lives we added and when used up, the game will end.


This project was created by Ethan Magpoc and Joseph Robinson for our CPE 133 final project at Cal Poly San Luis Obispo June 2023

Supplies

  • Basys 3 Board
  • Micro USB
  • Computer/Laptop Device
  • Vivado Software

Step 1: Module #1 LED and Digital Display

In this module, the LED and seven-segment display are being created and controlled. The wam_led module represented the LED output and took 8-but inputs (hole) and assigned them in output (ld). The wam_obd was a 1 bit output which took a 4-bit input (num) and outputted its 7-bit output (a2g) controlling the seven-segment display. Wam_Lst handled the random flashing LEDs and took a variety of inputs. These inputs included the clock signal, “tap”, “Lft”, “rgt”, and “cout0”. Then the output signal “Lstn” which controlled whether the LED was on or off. Finally the wam_dis module changed the scores on the seven-segment display. This code was created by github user akcorp2003 in their project Whack a Mole.

Step 2: Module #2 Mole Generator

In module #2 Mole Generator, the mole attributes are being controlled. Wam_rdm controls the randomness the LEDs  appear at as they represent the moles. Which LED is turned on or the speed at which it remains on for is randomly determined in this module. The wam_gen module controls the lives of the moles taking inputs from the clock signal, clear signal, 32-bit clock counter, 8-bit hit value, and 4-bit hardness value. This module represents which LED constraints a ‘mole’. This code was created by github user akcorp2003 in their project Whack a Mole.

Step 3: Module #3 Switch Input and Hit Control

In this module, switch inputs are controlled using 2 modules wam_tap and wam_hit. The first module wam_tap takes inputs from the switches in use and detects whether they’re on or off. The module uses a sw_cnt to count the state of each switch while filtering them. Wam_hit detects whether those switch hits are successful or not. If both the switch is active and the corresponding LED has a mole then the switch is considered and tracked. While working together, these two modules track whether or not successful moles are being whacked. This code was created by github user akcorp2003 in their project Whack a Mole.

Step 4: Module #4 Hardness Control

In Module #4, the hardness control module uses 3 different modules wam_tch, wam_hrd, and wam_par. Wam_tch takes inputs from the clock signals and button signals and outputs a touch signal. The wam_hrd module takes inputs of the clock signal, clear signal, left button, right button, and carry signal while outputting the hardness control signal. Finally the wam_par module takes the hardness control signals and outputs parameters for the hardness of the moles. Overall, this module controls the hardness level of the game through the left and right buttons on the Basys3 board. This code was created by github user akcorp2003 in their project Whack a Mole.

Step 5: Module #5 Top Level Module

In Module #5, the Top Level Module works to bring together all the modules before and implement them together. This module takes the inputs and outputs from the clock signals, user inputs from switches or buttons, generates moles, controls randomness of them, counts the score, and displays. This module is required in order for each module to work with each other. This code was created by github user akcorp2003 project Whack a Mole.

Step 6: Module #6 Scorekeeper

In this module, the score of the whack a mole game is being tracked based on information from the previous wam_cnt module. This module takes inputs such as clock, clear signal, and hit while outputting information such as num and cout0 (carry out signal). This module uses a Binary-Coded Decimal counter which represents the digits of the score. In the module wam_cnt, the BCD allows scoring to be kept.

Step 7: Modules for Finite State Machine and Life Tracker

  • Finite State Machine

In this module, we create a finite state machine to accompany our program. Within our FSM we had 3 possible outcomes. The 3 places were idle, hit_detected, and hit_confirmed. In idle, when tap was 1, the FSM transitioned to hit_detected.  In hit_detected when tap was 0, the FSM transitioned to idle, if tap and hole were 0 then it transitioned to hit_confirmed. In hit_confirmed when tap was 0 FSM went to idle, when hit was not zero the FSM stayed in hit_confirmed, however when hit was 0, FSM transited to hit)detected.

  • Life Tracker

In the life module of the whack a mole game, this module keeps track of the number of lives and determines whether or not the game is over based on the remaining lives. Using inputs such as clock, start, and whack (controls which mole has been whacked) the module outputs game_over if non activated moles are being hit. 



Step 8: DEMO

Video 1: Shows the start of the game, when reset is pressed game is started, 3 successful mole hits show score increasing to 3. Pause button than reset back to zero.

Video 2: Shows the right button increasing the speed of the moles and left button decreasing the speed or hardness of the game.

Step 9: Bibliography

As we created this game, we relied heavily on 2 users to create the first 6 modules. 


Github User akcorp2003 “Whack a Mole”

  • https://github.com/akcorp2003/Whack-a-Mole


Autodesk Instructables by User Michael_Lexa “Wacky Gator”

  • https://www.instructables.com/Wacky-Gator/


Step 10: Constraints

Constraints below which assign values to LEDs 0 through 7, switches 0 through 7, the seven segment display, left/right buttons for changing hardness, reset, pause, and clock signals. Constraints were sourced from the GitHub master doc for Basys3 constraints.


Source:

https://github.com/Digilent/digilent-xdc/blob/master/Basys-3-Master.xdc