DE0 Board Paper

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

ECEN 2350: FALL 2012

The Uncover Game


Final Project
Group 7: Joseph Bundrant, Diana Olsen, and Colton Willoughby

ECEN 2350

The Uncover Game

Group #7

Introduction
As a final project for ECEN 2350, a game called the Uncover Game was programmed onto the DE0 board with the following specifications: When the start button BUTTON0 (BUT0 for short) is pushed, a 10-bit binary number B is generated at random and displayed using the green LEDS LEDG[0]...LEDG[9]. At the same time a timer starts counting in 1/10'th of seconds, and the error count is set to zero. Internally, the binary number B is converted to a 3-digit BCD representation D. The main goal of the game is to uncover this number on the 7-segment displays HEX0HEX2 as quickly and with as few errors as possible. To uncover one of the digits of D, first select the digit by pressing BUTTON1 (BUT1 for short) repeatedly until the desired digit in the sequence HEX0,HEX1,HEX2,HEX0,... is reached. To show that a digit is selected, one of the not yet uncovered segments will start blinking. Initially, all digits of D are covered, which means that they are blank. To light up a segment that should be lit up on a selected digit (according to the random BCD number D), press BUT0 when that segment is active, i.e., when it is blinking. If BUT0 is pressed on a segment that should be turned off, then 1 is added to the error count, otherwise the segment lights up and stays lit. The segments of a particular digit become active (i.e., they are blinking and can be lit up by pressing BUT0) in the sequence D[0], D[1], ..., D[6], D[0], D[1], ..., using a clock signal generated within the Verilog code for the game. Segments that have already been identified as being turned on stay lit and are excluded from the sequencing of active segments. Once all segments of a digit that should be turned on are identified, the sequencing of active segments stops and the player can move on to another digit (if any) that needs to be uncovered. When all digits are uncovered the timer stops and BUT0 can now be used to toggle between the display of the uncovered number, the number of errors that have been made, and the time that elapsed from beginning to end. To reset all counters and start a new round of the game, push BUTTON2 (BUT2 for short) at any time during the game or after a game is finished.

Overall Game Implementation Structure


To start out with, a general state diagram was developed in order to be able to comprehend all the stages the game would go through. This is shown is Diagram 1.

Fall 2012

ECEN 2350

The Uncover Game

Group #7

Wait State: Game


hasnt started yet, all displays/timers/coun ts set to 0, action depends on BUT0 BUT2 pressed, Game reset

Diagram 1: State Diagram

BUT0 pressed

Game State: Timer started, random number B generated


and displayed using LEDG0-9, blinking digit shown

BUT0 pressed BUT1 pressed State g1: Next uncovered digit shown Yes

Should the digit be lit?

No

Digit stays lit, marked as uncovered

Error count incremented by 1, digit marked as uncovered

No Yes

Is the number fully uncovered?

Display State: Timer stopped,


toggle between three different displays State d3: State d1: Time to uncovered BUT0 pressed complete number game displayed displayed BUT0 pressed
State d2: total error count displayed

BUT0 pressed

Fall 2012

ECEN 2350 CURRENT STATE Wait G1 D1 D2 D3

The Uncover Game NEXT STATE BUT1 BUT2 Auto X Wait X G1 Wait X X A X X A X X A X Output LEDs X Random # Random # Random # Random #

Group #7

BUT0 G1 G1 D2 D3 D1

No Done Yes X X G1 D1 X X X X X X

7 Segment X Blinking Digit Uncovered Number Final error count Final clock time

Table 1: State Transition Table


As is shown in the state diagram, there are 10 states for our game. The transition between states is also shown in Table 1. Game Clock For the game design, the DE0s 50MHz clock was used to keep track of time. This frequency was divided down into two separate clocks, a 100Hz clock and a 1Hz clock. The 1Hz clock was used to keep track of time. For clock division, toggle flip flops were used. The module had been created in previous homework assignments with the 50MHz clock being prescaled by a factor of 5; that is, being divided by 25 or 32. After being scaled down to 1.5625MHz, a series of T-flip flops were then used to sequentially step-down the clock signal to its desired frequency. Random Number Generation To generate a random number, a linear feedback shift register was used. The result is a pseudorandom number generator. For simulation purposes, the $random function in Verilog was sufficient; however, attempting to translate the code to Quartus II compiler resulted in an error due to the hardware being unable to synthesize the function. In order to generate a random 10-bit number, the LFSR had XOR taps coming off the registers th 6 and 9th digits. Being a 10-bit number, this allowed for the possibilities of random numbers up to 1024, which would have taken all four of the 7-segment displays to fully express. However, according to the games requirements, the player was supposed to only cycle between HEX0, HEX1, and HEX2, using only three of the 7-segment displays. As a solution, the decimal point in the fourth, unused sevensegment display was used to indicate whether the number being uncovered has any overflow: if the decimal point is lit, the random number being uncovered is greater than 1000; otherwise, the number is less than 1000. Game Reset At any time during the game, should BUT2 be pressed, a reset signal was to be sent to all components. The result was to have the game prepped to start over with all displays (the green LEDs and the 7-segment displays) cleared, all counts set to 0, and the system in a waiting state in anticipation of BUT0 being pressed to restart the game. This was accomplished by having an always block sensitive to changes in BUT2s state: should BUT2 be detected as a low signal (which occurred when it was pressed), then the next state of the game was to be the reset state. Game States To manage what effect a buttons press should have, the game was divided into four states: wait_state, game_state, display_state, and reset_state. The game was initialized to wait_state which is

Fall 2012

ECEN 2350

The Uncover Game

Group #7

also shown on the state diagram. In wait_state, the game is waiting for the player to start the game by pressing BUT0. At this time, all displays are blanked out and the game timer has not been started. After BUT0 is pressed in this state, the game transitions to the next state, game_state, which simply means that the game has been started and is in progress. The clock timer has started, the LEDs display a binary code for the number the player is attempting to uncover, and an error count is keeping track of how many mistakes have been made. The player can use either BUT1 to toggle between available uncovered segments or BUT0 to decide to uncover a selected, blinking segment. A segment is made to blink by having it set equal to the inverse of the 1Hz clock wire. Each time a correct segment is uncovered, registers HEX and uncovered are updated to reflect that the player made the correct decision and that segment remains lit up. Even if the player makes an incorrect decision, the uncovered register still marks that segment as being uncovered and the error count is incremented by 1. After each choice, the HEX register is compared to what the correct output should be as stored on a Hex_on wire. Should the two match, a signal is sent from gamestop to move the game to the next state, display_state. In display_state, there are no actions associated with BUT1. With BUT0, the only change is toggling the 7-segment from displaying the uncovered number, the final game time, or the final error count. The display_state is only reached after a game is completed and does not transition to any other state by itself. The reset_state automatically clears all displays, counts, and timers and returns the game to the wait_state. As stated earlier, the reset_state can be reached at any time in the game by pressing BUT2. Displays In order to have the 7-segment displays driven by different binary counts, a binary-to-BCD converter was used in conjunction with a BCD-to-7 Segment converter. This double-translation converted the original 10-bit random number and the error count for display.

Current Game Version


The submitted version of the game works well in reset_state and wait_state. There were several difficulties encountered. The first was with the random number generation. Initially, during simulation, the Verilog function $random was used. While this gave no errors during simulation and during compilation on ModelSim, once the program was attempted to be compiled in Quartus II for synthesis on the DE0 board this function incurred errors in the Quartus II compiler. The solution was to use a LFSR, as stated above. A second error was in the form of multiple drivers. Initially, the code incorportated several different always blocks meant to drive registers at different times. For instance, moving from one segment being selected and actively blinking could occur from having pressed BUT1 during game_state or could occur after making a selection using BUT0 as to whether that segment should remain lit. Having two separate always blocks detect for changes in BUT0 and BUT1 made for good code but threw out errors during compilation. The solution to this problem was to separate the game into distinct states and, during a particular state, check for specific changes in the two buttons. This resulted in have duplicate lines of code, which is an unfortunately inelegant solution.

Fall 2012

ECEN 2350

The Uncover Game

Group #7

There was also some lingering confusion about the allowable types of assignments, with several instances of blocking, non-blocking, procedural, and continuous assignments being mixed up and errors being generated when a compilation was attempted. The code was originally set up to have several subcircuits driving main registers. This, however, causes a syntax error as Verilog does not allow for outputs to be attached to variables. The subcircuits were mostly done away with, implementing register changes in the main function instead. Errors At the time of the project being due, there were still errors involved in the code. The BUT2 function worked as desired; however, many of the other functions in the code did not work. There is still some bug-fixing to be done before it is a functional product. The initial block of the code sets the LEDs to a logical 0. According to the DE0 manual, this should turn all the LEDs off. For some reason, though, the DE0 doesnt seem to implement the initial block and so initially all LEDs are actually lit. This is fixed by pressing the reset button BUT2.

Suggested Improvements
One suggested improvement for the game is to change the button assignments such that BUT0 did not take on such different tasks. Perhaps having BUT0 act as the reset, having a delayed but automatic start, and then using BUT1 to toggle through the blinking segments while BUT2 acted as the light-on decider would have worked out better. Or having one of the boards switches behave as the reset switch, BUT0 as the start button, BUT1 as the toggle, and BUT2 as the light-on decider in this case, the game could be switched on or off and the check for a clear/reset signal would be easier to detect. The remaining switches could also be used to determine the length of the random number being generated. This could allow a user to start out with a smaller number and then gradually increase his or her ability to decoding what number the LEDs mean and knowing what segments should or shouldnt be lit up on the 7-segment display.

VERILOG CODE
Due to length, code has been submitted to D2L only and will not be printed here.

Fall 2012

You might also like