Design of A Cricket Game Using FPGAs
Design of A Cricket Game Using FPGAs
FPGAs
June 2020
Design of a Cricket Game Using FPGAs 1
Acknowledgements
We would like to thank Worcester Polytechnic Institute for giving us the opportunity to
conduct our Major Qualifying Project research on the “Design of a Cricket Game Using
FPGAs”.
The Completion of this project could not have been made possible without the guidance
and support we have received throughout our time at WPI. A special thanks is owed to Dr.
Maqsood Mughal for overseeing our efforts throughout this project.
Abstract
Within this project, we have broken down our approach to implementing a realistic
cricket game onto a Basys 3 FPGA board. Using Verilog, we created a pseudorandom number
generator using an LFSR (Linear Feedback Shift Register) and assigned probabilities to the
outcomes in order to closely reflect a real cricket game. Through various logical elements, we
have utilized components such as push buttons to take in user input and have developed a lifelike
cricket scoreboard to keep track of things like number of runs, current ball count etc. You will
find explanations on various aspects of digital design such as button debouncing, using a
pseudorandom number generator, slowing a clock using a counter, converting data for
seven-segment led display and of course how to tie them all together in order to form a
functioning circuit. All code written for this project is referenced in text and can be found in the
appendix at the end of the paper.
Table of Figures
Figure Number Figure Name Page Number
21 Design Utilization 23
Appendix Figures
Appendix Number Figure name Page Number
A-2 debounce.v 28
A-3 D_FF.v 28
A-4 cricketGame.v 29
A-5 lfsr.v 30
A-6 score_and_wickets.v 31
A-8 score_comparator.v 33
A-9 led_controller.v 34
A-10 Scroll_leds.v 35
A-11 slow_Clock_10Hz.v 35
A-12 bcd_Display.v 36
A-13 binary_to_BCD.v 37
A-14 slow_Clock_1KHz.v 38
A-15 two_bit_Counter.v 38
A-16 decoder2to4.v 39
A-17 mux4to1.v 39
A-18 bcd7seg.v 40
Table of Contents
Section Name and Number Pg. Number
TITLE PAGE
Acknowledgments 1
Abstract 1
Table of Figures 2
Table of Appendix Figures 4
Table of Contents 5
1. Introduction 6
2. The Game Of Cricket 7
2.1 Overview 7
2.2 Structure of the Game 7
2.3 Scoring Runs 8
2.4 Wickets 8
3. Implementation 9
3.1 Scope 9
3.2 Game Flow 11
3.3 Modules 13
3.3.1 Slow Clock Module 13
3.3.2 Debounce Module 14
3.3.3 Cricket Game Module 15
3.3.4 LFSR Module 17
3.3.5 Score, Wickets and Comparator 18
3.3.6 BCD to Display Module 20
4. Results and Conclusion 21
4.1 Design Simulation 21
4.2 Design Utilization 23
4.3 Final Scoreboard Snapshots 23
5. References 26
6. Appendix 27-40
1. Introduction
With the ability to become any digital circuit, the FPGA (Field Programmable Gate
Array) allows for tighter security, lower power consumption, higher data reliability as well as
being the fastest way to integrate a specific digital design into a device. It is no wonder that
many of the leading technology fields such as industrial, medical, aerospace, and defense have
all been finding more and more ways to utilize them. Whether you are programming a rocket or
simulating the wonderful game of cricket each of these complex tasks can be broken down into
their many simpler parts. The goal of this project is to combine basic digital circuits such as
flip-flops, decoders, comparators, counters etc. in order to create a functioning simulation of the
sport cricket. This project is intended for anyone with basic knowledge of digital design and can
aid as a detailed project for both students and individuals excited to jump into programming
FPGAs.
The board used throughout this project is the Digilent Basys 3 prototyping board which
contains the Xilinx Artix-7 FPGA. All programming has been completed using Verilog
Hardware Description Language (HDL) through Vivado Design Suite. A Digital Schematic Tool
(DSCH) was also used in order to create timing waveforms to help us validate the architecture of
the logic circuit prior to moving into design.
To provide a breakdown of the project and understand the steps we have taken, in the
following sections you will find a brief overview of the important aspects of the game of cricket,
various block diagrams and RTL (Register Transfer Level) schematics representing the Verilog
modules to help you understand how the logic is interconnected, a flowchart to explain the full
functionality of the game and what to expect, all of our code is included in the appendix with
detailed comments to further explain functionality, as well as DSCHs to visualize the game
functioning properly.
Figure 1: Cricket Scoreboard Shows Runs(177), Wickets (6), and Balls Left (74)
2.4 Wickets
Just like there is more than one way to score runs as a batsman, there are also multiple
ways for the fielders to get the batsman out. To list a few common ways a fielder can get a
batsman out there is ‘Bowled’, ‘Caught’, run out, and ‘Leg Before Wicket’. If a batsman is
bowled out it means that the ball has knocked the stumps behind the batsman shown in figure 2.
If the batsman hits the ball and it is caught before touching the ground it is referred to as
‘Caught’. ‘Leg Before Wicket’ refers to when a batsman is hit by the ball without it touching the
bat but only if the ball was going to hit the wickets had it not been obstructed by the body of the
player. As a reminder going forward, when a batsman gets out for whatever reason it is counted
as a ‘wicket’ against their team. If the wicket count reaches 10 the inning ends and the other
team gets to bat no matter how many balls have been delivered [7].
3. Implementation
Within this section, you will find the scope of the project where we have laid out what
components on the Basys 3 board we will be using for the game. You will find detailed
explanations with flowcharts and diagrams that express the overall game functionality as well as
thorough breakdowns of the individual modules. All commented code for these modules can be
found in the appendix section.
3.1 Scope
1. We are using the micro-USB port for both programming and powering the board. The
two blue jumpers you see along the top of the board will be set to ‘USB’ and ‘JTAG’
from left to right respectively. You should notice that the image shown in figure 3 does
NOT have both jumpers in the proper position.
2. The first three digits on the seven segment display is used to display a team's current
number of runs in decimal and can range from 0 runs to 255 runs.
3. The last digit on the seven segment display is used to display the number of wickets
against the same team that has their runs displayed.
4. The row of sixteen leds will be used to display the current teams ball count in binary.
Since the maximum ball count is 120 balls, we will only need the right most seven leds
for this, however the remainder of the leds will be used for an end of game celebration.
5. The up pushbutton is used to simulate a delivery from the bowler. When the up button is
pressed, depending on the outcome of the bowl the displays will change accordingly.
6. The middle button is used as a game reset. At any point in the game you can hit the reset
button and the game will start over.
7. The rightmost switch is used as a ‘team switch’. When the switch is in the up position it
means that team 1 is batting and the displays will present team 1’s current score, wicket
and ball count. This is the same functionality in the bottom position for team 2.
● The team switch should be in the up position at the beginning of the game and should be
switched to the bottom position when the display says ‘ IO ‘ which denotes ‘inning over’.
This means that team 1 has reached their maximum ball or wicket count and it is time for
the teams to switch. Failure to do this will result in an unfair game and it is recommended
that the reset switch be applied.
● Once both teams have gone the game will automatically compare the two scores and
display the team with the higher score (the winner) on the three rightmost digits of the
seven segment display in the form ‘t01’ or ‘t02’ and at the same time the leds will scroll
in a celebratory fashion.
● If the game results in a tie game the same three digits will display ‘tIE’. The switch will
then be switched back to the team 1 position and the game will be replayed the exact
same way, except this time each team will only receive 6 balls before the score is
compared again.
3.3 Modules
The system clock for the Basys 3 runs at a frequency of 100 MHz. Sometimes we are
able to use this frequency for our applications but for others we need to slow this frequency
down to produce the results we need. For instance, in the Basys 3 board reference manual [3]
you will find that the seven segment display leds should run at a frequency between 60 Hz and
1,000 Hz. Anything higher than that can result in unstable transitions and anything lower will
result in a noticeable flicker to the human eye. In order to obtain the desired frequency of the
clocks we can use a simple up-counter. When we give a counter a certain value to reset itself, we
can then count the number of clock ticks of the system clock and generate a different clock pulse
that transitions when we reach the maximum count. Depending how we set the max count value
will determine the frequency of the slower clock. For example, if we set the max count to a value
of 2 it will create a slower clock at half the system clock frequency, as shown in figure 7. Slow
clock modules are shown in figures A-11 and A-14.
There are multiple ways of implementing this in a digital circuit but we chose to use a
series of D-flip-flops that are fed with a slower clock frequency making it so the
debouncedButton signal doesn’t change states for multiple .1 second clock periods represented in
figure 9.
Figure 12: Block Diagram of LFSR Module for Random Number Generation [9]
A linear feedback shift register is used in lfsr.v (figure A-5) to provide a pseudorandom 4
bit number for the assignment of scores and wickets. Shown in figure 12 above, a shift register of
length 6-bits is used to increase the period, where the maximum period of an n-bit long lfsr is
equal to 2n - 1 [8]. Figure 13 shows the result of a linear feedback shift register that uses an
XOR sum and starts with a seed of 6’b1111111(15d). The period of this sequence is 31 :
(15,15,7,3,9,12,6,11,5,2,9,4,2,1,0,8,4,10,5,10,13,14,7,11,13,6,3,1,8,12,14).
The pseudorandom number sequence generated by lfsr.v (figure A-5) is used to assign the
score and wickets for each delivery of a ball(up push button). The scores for Twenty 20 cricket
tend to rarely exceed 256, as seen in figure 14 [10]. Teams also usually end their innings because
they reached 120 balls, rather than by losing 10 wickets. The random number assignment
shown in figure 15 below was carefully chosen in order to achieve realistic scores [2].
Figure 15: Score Results with Probability of Occuring from LFSR Output
Figure 16: Block Diagram of Data from Game Module to Seven Segment Display [1]
The bcdDisplay.v module shown in figure A-12 along with its submodules (figures A-13
to A-18) convert the binary runs and wickets from cricketGame.v (figure A- 4) to BCD (Binary
Coded Decimal) and display them on the seven segment leds on the Basys 3 board [5]. The block
diagram and verilog schematic of the bcd display system are shown in figures 16 and 17 above.
Figure 19 below shows what happens when the teams are switched. The second team’s
runs, wickets and balls all start from zero.
Figure 20 below shows the second team completing their inning, which ends the game.
Team 2 (sw = 1) delivers 120 balls and thus their inning is over (updated on next clock cycle in
simulation). The game ends immediately because both teams' innings are over (team 1 took 10
wickets and team 2 delivered 120 balls). Gameover goes to 1 and since Team 2 had 203 runs
while Team 1 had 184 runs, Team 2 is declared the winner(‘winner’ changes from don’t care(x)
to 1, instead of going to 0) [6].
Figure 20: Timing Waveform - End of Team2’s Inning and the End of the Game
Figure 22: Team 1 with 198 runs, 5 Wickets and 119 Balls (leds = 7b1110111)
Figure 23: ‘IO’ Indicating Team 1’s ‘Inning Over’ (notice ball count = 120)
Figure 25: Team 2 with 136 Runs, 9 Wickets and 112 Balls
5. References
[1] Chakraborty Rajat Subhra, and Palchaudhuri Ayan. “ARCHITECTURE AND DESIGN
AUTOMATION OF HIGH PERFORMANCE LARGE ADDERS AND COUNTERS ON FPGA
THROUGH CONSTRAINED PLACEMENT.” 18 May 2017: n. pag. Print.
[2] Fokhrulislam, Md., M. A. Mohd. Ali, and Burhanuddin Yeop Majlis. “FPGA Implementation
of an LFSR Based Pseudorandom Pattern Generator for MEMS Testing.” International Journal
of Computer Applications 75.11 (2013): 30–34. Web.
[3] Digilent, “Basys3 Reference Manual,” Basys3 Rev.c Datasheet, August 2014.
[4] Girard III Hilton W, and Christenson Keith A. “Debounce strategy for validating switch
actuation.” 15 Feb. 2012: n. pag. Print.
[5] Chu, Pong P. FPGA Prototyping by Verilog Examples Xilinx Spartan -3 Version . Hoboken,
N.J: J. Wiley & Sons. Print.
[6] Salemi, Ray. FPGA Simulation : A Complete Step-by-Step Guide . S.l: Ray Salemi. Print.
[7] Orr, Graeme. “Test Cricket Versus One-Day Cricket: Regulations and Rhythms.” Alternative
Law Journal 31.1 (2006): n. pag. Print.
[8] Ghelani, Harsh H. et al. “FPGA Implementation of Configurable Linear Feedback Shift
Register Using Verilog.” International Journal of Computer Sciences and Engineering 6.4
(2018): 143–146. Web.
[9] Cerda, J. C et al. “An Efficient FPGA Random Number Generator Using LFSRs and Cellular
Automata.” 2012 IEEE 55th International Midwest Symposium on Circuits and Systems
(MWSCAS). IEEE, 2012. 912–915. Web.
[10] ESPN. “Records: Twenty20 Internationals: Team Records: Highest Innings Totals:
ESPNcricinfo.com.” Cricinfo, stats.espncricinfo.com/ci/content/records/283218.html. Web.
6. Appendix