java question

profileder34
attachment_123.pdf

1

Programmable Logic Devices CMPE 415 Fall 2021

Homework 3 Due: Oct 12, 2021

In this homework you are going to design and implement a simple game on NEXYS 4 DDR FPGA

boards. The Boards include eight 7-segments, 16 Switches, 16 LEDs, and (5+2) push buttons as

below. (CPU RESET and PROG are also push buttons)

Fig.1. NEXYS 4 DDR FPGA

Game Description: In this game you play the role of a police to arrest a thief. Police’s and the

thief’s locations are shown with (XP,YP) and (Xt,Yt) coordinates, where all indexes are in range of

[0,15] (inclusive).

First you need to initialize the coordinate of police and thief. The thief’s location should be entered

via the 8 switches (SW[15:8]) and police's location is entered by other 8 switches (SW[7:0]).

• SW[15:12] ==> Xt

• SW[11:8] ==> Yt

• SW[7:4] ==> XP

• SW[3:0] ==> YP

After you set the switches to the desired locations, the locations of police and thief should be shown

in the 7-segments as below. The seven segment #7 shows the X index of the thief’s location and

7-segments #6 shows his Y location. The 7-segments #5 and #4 show the police location (Xp,Yp),

respectively. All these four 7-segments should show the location in hexadecimal format. For

example, if the location of thief and police are (14,9), and (3,10), respectively the number that each

7-segment should show are:

2

• 7-segnent #7 ==> E

• 7-segnent #6 ==> 9

• 7-segnent #5 ==> 3

• 7-segnent #4 ==> A

Fig.2. Location of Police and Thief

The game starts by pushing reset button (BTNC). The locations should be loaded in appropriate

registers in your design after BTNC is pushed. Now you can move the police by pushing BTNU

(move up), BTND (move down), BTNR (move right), and BTNL (move left). Each push moves

the police one location in the related direction.

• The number of steps (moves) the police takes should be counted. To do so, there should be

a counter in your design that whenever you push one of the BTNU, BTND, BTNR, and

BTNL it counts up by 1. This value of this counter should be shown in 7-segment #1 and

#0 (in Fig. 2) in decimal format. For example, if the move buttons have been hit for 15

times totally, the 7-segments should be turned on like this:

o 7-segnent #1 ==> 1 o 7-segnent #0 ==> 5

• Not that the thief's location is constant, but the police's location should be updated

whenever each move happens, and so the related seven-segments needs to be updated

accordingly. In fact, the thief location doesn’t change but the police location and the

number of moves (number of pushed buttons counter) should be updated dynamically and

their 7- segment should show the current status.

• In each move, the police can go 1 location to left, right, bottom or up using the push buttons.

If Police reaches to the thief location, then game is over. However, you need to follow the

following rules:

3

o The aim is that the police arrest the thief using shortest path or near shortest paths,

i..e, if shortest path needs N moves (N times pressing push buttons) for police, then

if police reaches to the thief location with at most N+5 push, the police wins and

all the LES are blinking with 1Hz frequency.

o If the police reaches to the thief's location with more than N+5 pushes (where N is

the shortest path between them), the game is over but with a failure so all LEDs

should show turn off.

o If police has not reached to the thief's location yet but the path so far, he moved is

more than N+5 then again he fails and all LEDs should turn off.

• Note that it is assumed that after starting the moves, the center button and switches are not

pushed (you do not need to consider the case that center button is pushed after the first

move started).

• If the police is on the borders, i.e., Xp = 15, Xp = 0 , Yp = 0, or Yp = 15 and the new

movement is towards out of the shown grid in Fig. 3, , the police will stuck in his current

position. However, the pushed buttons counter should be increased by 1 by any push (even

if not move because of reaching to the boarder). To make it more obvious, suppose that the

police is on (15,6), and you push the PTNR, so he cannot go further than 15 and will still

in (15,6). See the Fig.3.

Fig.3. Stucking in the border

NOTE: You should use ALWAYS BLOCKS in your design and avoid using continuous

assignment.

Deliverables:

• Complete project including all files before and after synthesis.

• A report explaining your design.

4

Useful hints your implementation

• Seven-segments

o You have eight 7-segment controlled by AN[7:0] and CA, CB, CC, CD, CE, CF,

CG, DP. In practice, AN indicates which 7-segmnets should be enabled. CA, CB,

CC, CD, CE, CF, CG, DP are 1 bit each and are transferred simultaneously via a

data bus common between all 7-segments (Fig. 4).

Fig.4. Data and Enable of 7-segment

o At each time, you can enable just one of the 7-segments and get the appropriate

data on data bus. To enable one 7-segment, the enable bit of related 7-segment

should be 0 and other enable bits should be 1. Based on the following picture turn

each segment in one of the 7-segments.

Fig.5. The relation of each bit of data bus with the segments.

Assume you are going to turn on 7 in 7-segment # 5. First you need to enable this 7-segment by

placing AN[5] = 0 and all other AN[i] values to “1”, i.e., AN [7:0] = 8'b11011111. In the next step

according to Fig.5, to illustrate number 7, we should activate CA, CB, CC. So, CA, CB, CC all get

“0” and CD, CE, CF, and CG get 1. In addition, DP = 1. Therefore, in this case {CA, CB, CC, CD,

CE, CF, CG, DP} = 8'b00011111;

5

Note that to turn on all 7-segments simultaneously, you have to enable each 7-segment one by one

and load the related number on it. As this sequence is so fast, human eyes cannot detect that at

each time just one 7-segment is on, i.e., all are considered as on. Accordingly, in your design

consider 4ms to enable one 7-segment and repeat this for other ones, one by one in a daisy chain.

When each 7-segment is on, load the CA, CB, CC, CD, CE, CF, CG, DP with the appropriate value

(as shown in Fig. 6).

Fig.6. Enabling 7-segments

For more information, you can check Section 10.1 in the following link:

https://reference.digilentinc.com/reference/programmable-logic/nexys-4-ddr/reference-manual

• Push Buttons

When you push a button, the signal that comes into FPGA is similar to the following figure.

Fig.7. Transient signal in push buttons

As shown, the signal may have a number of glitches that may adversely affect your implementation

such that it doesn’t work properly. You need to remove the glitches in the transient step and obtain

a signal similar to the one shown Fig.8 and use that signal as needed.

6

Fig.8. Push button signal after filtering

To remove these glitches, you are to use some filters on push buttons. The filter has been designed

and given to you in blackboard (the same folder). So, add Filter.v code in your project and

instantiate it in your design as below:

The data_in can be any of the push button signals and data_out is its filtered counterpart that you

should use in your design. You should instantiate this module 5 times for your 5 push buttons.

Note: In addition, you should consider that when you push one of the push buttons, it should show

one transition only (related to one move). For the next try (next move of police), you should relax

the button and then push it again. To realize this, you can detect the positive edge of a push button

signal by the circuit shown in Fig. 9. Then, you can use Signal out as an enable for the police

moves.

Fig.9. Detecting push button bouncing

• Blinking LED

According to the game rule, if the police can catch the thief with less than N+6 moves, he wins. In

this situation, LEDs should blink. To make a blinking LED, you can design a 27-bit counter (you

can design it in behavioral level). The counter is clocked with the system clock

(frequency:100Mhz). When the MSB of the counter is “1” the LEDs can be on, otherwise LEDs

can be off. Note that blinking is only for the case that the police wins.