Professional Documents
Culture Documents
DE0 Board Paper
DE0 Board Paper
DE0 Board Paper
ECEN 2350
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.
Fall 2012
ECEN 2350
Group #7
BUT0 pressed
BUT0 pressed BUT1 pressed State g1: Next uncovered digit shown Yes
No
No Yes
BUT0 pressed
Fall 2012
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
Fall 2012
ECEN 2350
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.
Fall 2012
ECEN 2350
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