NORTH NORTH CAROLINA A&T STA STATE UNIVERSITY
Project 1: Simon Game Part 1 Monique Kirkman-Bey November 6, 2013
Project Overview
3
Top Level
4
Second Level Diagram
5
Data Unit
6
RandomColorGenerator Component
8
RandomColorGenerator Simulations
8
GameRegister Component
9
GameRegister Simulations
10
VGA_Simon_Controller Component
11
Control Unit
12
Control_Unit Finite State Machine
13
Pitfalls and Future Modifications
28
ClkDivider: External Component to Internal Process
28
Slow Start-up
28
Flashing the Same Color Twice
29
Addition of the wrong_color status signal
29
Appendix A: VHDL Code
30
Project Overview
3
Top Level
4
Second Level Diagram
5
Data Unit
6
RandomColorGenerator Component
8
RandomColorGenerator Simulations
8
GameRegister Component
9
GameRegister Simulations
10
VGA_Simon_Controller Component
11
Control Unit
12
Control_Unit Finite State Machine
13
Pitfalls and Future Modifications
28
ClkDivider: External Component to Internal Process
28
Slow Start-up
28
Flashing the Same Color Twice
29
Addition of the wrong_color status signal
29
Appendix A: VHDL Code
30
Project Overview The simon game is a classic memory game. It uses four distinct colors and random combinations of those colors to test a player ’s memory. memory. First, one color is highlighted/flashed. Then, the user is expected to repeat the color c olor.. If the player successfully repeats the color, a second sequen ce will be displayed. This time, it will be the same first first color followed by another. Again, the user is expected to repeat the sequence. This will continue, each time another color added to the sequence until the maximum number of colors has been reached or until the player makes an error when repeating the sequence. The digital system that follows is the beginning of a Simon Game implemented on an FPGA board. Currently, Currently, the system is capable of setting up a random game of 20 colors. It then can output the colors to the VGA display in the same fashion described above. Currently, Currently, the system is capable of monitoring a single signal and an d uses the signal to determine if the sequence should continue or if the player should be notified that an error occurred. In the following pages, the digital system, its current functionality and the manner in which that functionality was achieved will be explained thoroughly. thoroughly. Lastly, the challenges I encountered and suggestions for improvements are explored.
Top Level This is the top level view of my Simon game. You You can see that there are three inputs: clk,
correct_color, and reset. When the correct_color signal is high, the simon game co ntinues to cycle through the random colors. c olors. When it is low, low, the game displays a red screen indicating an error. error. The outputs are: blue, red, green, hs, vs, and led. The red, green, g reen, and blue outputs are used to generate the colors we see on the VGA display. display. The vs and hs outputs correspond to the vertical sync and horizontal sync signals and are responsible as well for writing the colors to the pixels on the display. display. the led output is simply a clock status signal that causes a light to blink on the board in sync with the control unit’s clock signal.
Second Level Diagram
Here is a second level view of the game. You can see above that all three of the external inputs go to the control unit, and that one of the inputs, the clk signal, is shared with the data unit. You can also see that all, but one output comes from the data unit. Hence, the data unit is responsible for what we see on the VGA display. The output, led, is from the control unit. It allows me to monitor the clock cycles since the entire control unit runs a slower clock. The con trol unit and it’s clock will be discussed shortly.
The outputs of the control unit are the enable lines to the components within the data unit, as well as the address and load line to the register within the data unit.
Data Unit
Here is the top level view of my data unit. The data unit has the following 7 inputs: gameAddress_line, clk, error_enable, gameRegister_Load, game_enable, random_enable, and reset, as well as the following 5 outputs: red, green, blu, vs, and hs. A closer look at the routing of these signals can be seen below in the second level diagram of the data unit.
It can be seen that the random_enable input is connected to the RandomColorGenerator component. The gameAddress_line, gameRegister_load, reset and clk, inputs are routed to the GameRegister. component The remaining inputs, error_enable and game_enable are routed to the VGA_SimonController along with the clk and reset signals. It can also be seen that all outputs of the data unit are from the VGA_Simon controller. Further explanations of these signals and the way that their values impact the behavior of the components are to follow.
RandomColorGenerator Component
Above is a block diagram of the RandomColorGenerator component. This component is responsible for ensuring that the simon game remains fresh and fun. It generates color codes in a pseudo-random fashion by implementing a 32-bit Linear Feedback Shift Register. When the RandomEnable signal is high, the random color currently being generated is seen on the color output. When RandomEnable is low, the output is simply “00”, but the gen erator continues to generate random number. This behavior can be seen below in the simulations of the component.
RandomColorGenerator Simulations
It can be seen that at every clock period a new number is generated by the component. When RandomEnable is high, the last two bits of the random number is seen on the output, color. When enable is low, the output is set to “00”, but the random numbers continue to generate. For simulation purposes and demonstration of functionality, the signal which holds the random number is included in the simulation. It is not an input or output of the system.
GameRegister Component
The GameRegister component stores the color codes that will be used for the game. It is a register 2-bits wide and 20 rows long. When the load signal is high, it takes in the 2-bit color value and stores it at the address specified by the 5-bit Gaddr input. When the load signal is low, it outputs the value stored at the address specified by the Gaddr input.
GameRegister Simulations
In the above simulation, the write operation is being demonstrated. It can be seen that when gload = ‘1’, and gaddr = “000111” that the value “01,” seen on the input, is stored at address three of the register. Below, the read operation is demonstrated.
When gload = ‘0’, the value stored at the address specified on gadder is seen on the output. In the above simulation, when glad = ‘0’ and gaddr = “00010”, the value “10” which is stored at address “00010” is passed to the output.
VGA_Simon_Controller Component
This component controls the VGA display, and consequently, the game board. When all enable signals are low, the component will cause the 4 colors to display on the board, each in its respective corner. When game_enable is high, the component will then look at the input game_color to determine which of the four colors to flash. If game_enable is low, the component does not care about the value on the game_color signal. Additionally, if error_enable is high, the entire screen will turn red, indicating an error.
Control Unit
Above, you see the top level of the Control Unit: The control unit has three input: clk, reset, and correct_color. The outputs were explained previously during the discussion of the data unit and its component and are as follows: gameAddress, clock, DataUnit_reset, error_enable, gameRegister_load, game_enable, random-enable, and win_enable. Please note that the win_enable signal is not currently connected to the data unit. Following is the finite state machine inside the con trol unit and a detailed description of the states.
Control_Unit Finite State Machine
State Name: ResetGame Transitions into this state: The Control Unit will transition into this state from any state on the diagram if the reset signal is asserted.
Function: This is the initial/reset state of the circuit. It resets the appropriate enable lines to ensure that all data unit components are ready for a new game Outputs asserted: random_enable = ‘1’, game_enable = ‘0’, error_enable = ‘0, gameAddress_sig = “00000"; Transitions out of State: The Control Unit transitions out of this at the next rising edge of the next clk signal as long as rest = ‘0’. State Name: Setup1 Transitions into this state: The Control Unit will transition into this state when the previous state was ResetGame and Reset is not equal to 0.
Function: This state is responsible for loading the GameRegister with 20 random colors. The control unit will loop through this state 20 times, each time updating the gameAddress_sig so that the next pass through will cause the next register address to be written to. Outputs asserted: random_enable = ‘1’, gameRegister_load = ‘1’, gameAddress_sig = gameAddress_sig +1 Transitions out of State: The Control Unit transitions out of this state when the GameAddress_sig = “10011” State Name: Setup2 Transitions into this state: The Control Unit will transition into this state when the previous state was Setup1 and the GameAddress_sig = “10011.”
Function: This state is responsible for resetting the gameAddress_sig so that the subsequent play state will begin with the zeroth address of the register when reading. It also resets the gameRegister_load signal to 0 so that the GameRegister is not written to again. Outputs asserted: gameRegister_load = ‘0’, gameAddress_sig = “00000” Transitions out of State: The Control Unit transitions out of this state at the next rising clock edge State Name: Play1 Transitions into this state: The Control Unit will transition into this state when the previous state was Setup2.
Function: This state is responsible for displaying the first color stored in the GameRegister Outputs asserted: game_enable = ‘1’, gameAddress_sig = gameAddress_sig + 1 Transitions out of State: The Control Unit transitions out of this state when the GameAddress_sig = “00001” State Name: Check1
Transitions into this state: The Control Unit will transition into this state when the previous state was Play1. Function: When the control unit is in this state, it monitors the correct_color signal. If correct_color = ‘1’, the next state is Play2. Otherwise, the control unit transitions to the error state. It also resets the gameAddress_sig so that the next play state will begin displaying colors from the first address in the GameRegister. Outputs asserted: game_enable = ‘0’, gameAddress_sig = “00000” Transitions out of State: The Control Unit transitions out of this state when a value is received on the correct_color input. State Name: Play2 Transitions into this state: The Control Unit will transition into this state when the previous state was Check1. Function: This state is responsible for displaying the first two colors stored in the GameRegister Outputs asserted: game_enable = ‘1’, gameAddress_sig = gameAddress_sig + 1 Transitions out of State: The Control Unit transitions out of this state when the GameAddress_sig = “00010” State Name: Check2 Transitions into this state: The Control Unit will transition into this state when the previous state was Play2.
Function: When the control unit is in this state, it monitors the correct_color signal. If correct_color = ‘1’, the next state is Play3. Otherwise, the control unit transitions to the error state. It also resets the gameAddress_sig so that the next play state will begin displaying colors from the first address in the GameRegister. Outputs asserted: game_enable = ‘0’, gameAddress_sig = “00000” Transitions out of State: The Control Unit transitions out of this state when a value is received on the correct_color input. State Name: Play3 Transitions into this state: The Control Unit will transition into this state when the previous state was Check2.
Function: This state is responsible for displaying the first two colors stored in the GameRegister Outputs asserted: game_enable = ‘1’, gameAddress_sig = gameAddress_sig + 1 Transitions out of State: The Control Unit transitions out of this state when the GameAddress_sig = “00011” State Name: Check3 Transitions into this state: The Control Unit will transition into this state when the previous state was Play3.
Function: When the control unit is in this state, it monitors the correct_color signal. If correct_color = ‘1’, the next state is Play4. Otherwise, the control unit transitions to the error state. It also resets the gameAddress_sig so that the next play state will begin displaying colors from the first address in the GameRegister. Outputs asserted: game_enable = ‘0’, gameAddress_sig = “00000” Transitions out of State: The Control Unit transitions out of this state when a value is received on the correct_color input. State Name: Play4 Transitions into this state: The Control Unit will transition into this state when the previous state was Check3.
Function: This state is responsible for displaying the first two colors stored in the GameRegister Outputs asserted: game_enable = ‘1’, gameAddress_sig = gameAddress_sig + 1 Transitions out of State: The Control Unit transitions out of this state when the GameAddress_sig = “00100” State Name: Check4 Transitions into this state: The Control Unit will transition into this state when the previous state was Play4.
Function: When the control unit is in this state, it monitors the correct_color signal. If correct_color = ‘1’, the next state is Play5. Otherwise, the control unit transitions to the error state. It also resets the gameAddress_sig so that the next play state will begin displaying colors from the first address in the GameRegister. Outputs asserted: game_enable = ‘0’, gameAddress_sig = “00000” Transitions out of State: The Control Unit transitions out of this state when a value is received on the correct_color input. State Name: Play5 Transitions into this state: The Control Unit will transition into this state when the previous state was Check4.
Function: This state is responsible for displaying the first two colors stored in the GameRegister Outputs asserted: game_enable = ‘1’, gameAddress_sig = gameAddress_sig + 1 Transitions out of State: The Control Unit transitions out of this state when the GameAddress_sig = “00101” State Name: Check5 Transitions into this state: The Control Unit will transition into this state when the previous state was Play4.
Function: When the control unit is in this state, it monitors the correct_color signal. If correct_color = ‘1’, the next state is Play6. Otherwise, the control unit transitions to the error state. It also resets the gameAddress_sig so that the next play state will begin displaying colors from the first address in the GameRegister. Outputs asserted: game_enable = ‘0’, gameAddress_sig = “00000” Transitions out of State: The Control Unit transitions out of this state when a value is received on the correct_color input.
State Name: Play6 Transitions into this state: The Control Unit will transition into this state when the previous state was Check5.
Function: This state is responsible for displaying the first two colors stored in the GameRegister Outputs asserted: game_enable = ‘1’, gameAddress_sig = gameAddress_sig + 1 Transitions out of State: The Control Unit transitions out of this state when the GameAddress_sig = “00110” State Name: Check6 Transitions into this state: The Control Unit will transition into this state when the previous state was Play6.
Function: When the control unit is in this state, it monitors the correct_color signal. If correct_color = ‘1’, the next state is Play7. Otherwise, the control unit transitions to the error state. It also resets the gameAddress_sig so that the next play state will begin displaying colors from the first address in the GameRegister. Outputs asserted: game_enable = ‘0’, gameAddress_sig = “00000” Transitions out of State: The Control Unit transitions out of this state when a value is received on the correct_color input.
State Name: Play7 Transitions into this state: The Control Unit will transition into this state when the previous state was Check6.
Function: This state is responsible for displaying the first two colors stored in the GameRegister Outputs asserted: game_enable = ‘1’, gameAddress_sig = gameAddress_sig + 1 Transitions out of State: The Control Unit transitions out of this state when the GameAddress_sig = “00111” State Name: Check7 Transitions into this state: The Control Unit will transition into this state when the previous state was Play7.
Function: When the control unit is in this state, it monitors the correct_color signal. If correct_color = ‘1’, the next state is Play8. Otherwise, the control unit transitions to the error state. It also resets the gameAddress_sig so that the next play state will begin displaying colors from the first address in the GameRegister. Outputs asserted: game_enable = ‘0’, gameAddress_sig = “00000” Transitions out of State: The Control Unit transitions out of this state when a value is received on the correct_color input.
State Name: Play8 Transitions into this state: The Control Unit will transition into this state when the previous state was Check7.
Function: This state is responsible for displaying the first two colors stored in the GameRegister Outputs asserted: game_enable = ‘1’, gameAddress_sig = gameAddress_sig + 1 Transitions out of State: The Control Unit transitions out of this state when the GameAddress_sig = “01000” State Name: Check8 Transitions into this state: The Control Unit will transition into this state when the previous state was Play7.
Function: When the control unit is in this state, it monitors the correct_color signal. If correct_color = ‘1’, the next state is Play9. Otherwise, the control unit transitions to the error state. It also resets the gameAddress_sig so that the next play state will begin displaying colors from the first address in the GameRegister. Outputs asserted: game_enable = ‘0’, gameAddress_sig = “00000” Transitions out of State: The Control Unit transitions out of this state when a value is received on the correct_color input.
State Name: Play9 Transitions into this state: The Control Unit will transition into this state when the previous state was Check8.
Function: This state is responsible for displaying the first two colors stored in the GameRegister Outputs asserted: game_enable = ‘1’, gameAddress_sig = gameAddress_sig + 1 Transitions out of State: The Control Unit transitions out of this state when the GameAddress_sig = “01001” State Name: Check9 Transitions into this state: The Control Unit will transition into this state when the previous state was Play9.
Function: When the control unit is in this state, it monitors the correct_color signal. If correct_color = ‘1’, the next state is Play10. Otherwise, the control unit transitions to the error state. It also resets the gameAddress_sig so that the next play state will begin displaying colors from the first address in the GameRegister. Outputs asserted: game_enable = ‘0’, gameAddress_sig = “00000” Transitions out of State: The Control Unit transitions out of this state when a value is received on the correct_color input.
State Name: Play10 Transitions into this state: The Control Unit will transition into this state when the previous state was Check3.
Function: This state is responsible for displaying the first two colors stored in the GameRegister Outputs asserted: game_enable = ‘1’, gameAddress_sig = gameAddress_sig + 1 Transitions out of State: The Control Unit transitions out of this state when the GameAddress_sig = “01010” State Name: Check10 Transitions into this state: The Control Unit will transition into this state when the previous state was Play10.
Function: When the control unit is in this state, it monitors the correct_color signal. If correct_color = ‘1’, the next state is Play11. Otherwise, the control unit transitions to the error state. It also resets the gameAddress_sig so that the next play state will begin displaying colors from the first address in the GameRegister. Outputs asserted: game_enable = ‘0’, gameAddress_sig = “00000” Transitions out of State: The Control Unit transitions out of this state when a value is received on the correct_color input.
State Name: Play11 Transitions into this state: The Control Unit will transition into this state when the previous state was Check10.
Function: This state is responsible for displaying the first two colors stored in the GameRegister Outputs asserted: game_enable = ‘1’, gameAddress_sig = gameAddress_sig + 1 Transitions out of State: The Control Unit transitions out of this state when the GameAddress_sig = “01011” State Name: Check11 Transitions into this state: The Control Unit will transition into this state when the previous state was Play11.
Function: When the control unit is in this state, it monitors the correct_color signal. If correct_color = ‘1’, the next state is Play12. Otherwise, the control unit transitions to the error state. It also resets the gameAddress_sig so that the next play state will begin displaying colors from the first address in the GameRegister. Outputs asserted: game_enable = ‘0’, gameAddress_sig = “00000” Transitions out of State: The Control Unit transitions out of this state when a value is received on the correct_color input.
State Name: Play12 Transitions into this state: The Control Unit will transition into this state when the previous state was Check11.
Function: This state is responsible for displaying the first two colors stored in the GameRegister Outputs asserted: game_enable = ‘1’, gameAddress_sig = gameAddress_sig + 1 Transitions out of State: The Control Unit transitions out of this state when the GameAddress_sig = “01100” State Name: Check12 Transitions into this state: The Control Unit will transition into this state when the previous state was Play12.
Function: When the control unit is in this state, it monitors the correct_color signal. If correct_color = ‘1’, the next state is Play13. Otherwise, the control unit transitions to the error state. It also resets the gameAddress_sig so that the next play state will begin displaying colors from the first address in the GameRegister. Outputs asserted: game_enable = ‘0’, gameAddress_sig = “00000” Transitions out of State: The Control Unit transitions out of this state when a value is received on the correct_color input.
State Name: Play13 Transitions into this state: The Control Unit will transition into this state when the previous state was Check12.
Function: This state is responsible for displaying the first two colors stored in the GameRegister Outputs asserted: game_enable = ‘1’, gameAddress_sig = gameAddress_sig + 1 Transitions out of State: The Control Unit transitions out of this state when the GameAddress_sig = “01101” State Name: Check13 Transitions into this state: The Control Unit will transition into this state when the previous state was Play4.
Function: When the control unit is in this state, it monitors the correct_color signal. If correct_color = ‘1’, the next state is Play14. Otherwise, the control unit transitions to the error state. It also resets the gameAddress_sig so that the next play state will begin displaying colors from the first address in the GameRegister. Outputs asserted: game_enable = ‘0’, gameAddress_sig = “00000” Transitions out of State: The Control Unit transitions out of this state when a value is received on the correct_color input.
State Name: Play14 Transitions into this state: The Control Unit will transition into this state when the previous state was Check13.
Function: This state is responsible for displaying the first two colors stored in the GameRegister Outputs asserted: game_enable = ‘1’, gameAddress_sig = gameAddress_sig + 1 Transitions out of State: The Control Unit transitions out of this state when the GameAddress_sig = “01110” State Name: Check14 Transitions into this state: The Control Unit will transition into this state when the previous state was Play14.
Function: When the control unit is in this state, it monitors the correct_color signal. If correct_color = ‘1’, the next state is Play15. Otherwise, the control unit transitions to the error state. It also resets the gameAddress_sig so that the next play state will begin displaying colors from the first address in the GameRegister. Outputs asserted: game_enable = ‘0’, gameAddress_sig = “00000” Transitions out of State: The Control Unit transitions out of this state when a value is received on the correct_color input.
State Name: Play15 Transitions into this state: The Control Unit will transition into this state when the previous state was Check14.
Function: This state is responsible for displaying the first two colors stored in the GameRegister Outputs asserted: game_enable = ‘1’, gameAddress_sig = gameAddress_sig + 1 Transitions out of State: The Control Unit transitions out of this state when the GameAddress_sig = “01111” State Name: Check15 Transitions into this state: The Control Unit will transition into this state when the previous state was Play15.
Function: When the control unit is in this state, it monitors the correct_color signal. If correct_color = ‘1’, the next state is Play16. Otherwise, the control unit transitions to the error state. It also resets the gameAddress_sig so that the next play state will begin displaying colors from the first address in the GameRegister. Outputs asserted: game_enable = ‘0’, gameAddress_sig = “00000” Transitions out of State: The Control Unit transitions out of this state when a value is received on the correct_color input.
State Name: Play16 Transitions into this state: The Control Unit will transition into this state when the previous state was Check15.
Function: This state is responsible for displaying the first two colors stored in the GameRegister Outputs asserted: game_enable = ‘1’, gameAddress_sig = gameAddress_sig + 1 Transitions out of State: The Control Unit transitions out of this state when the GameAddress_sig = “10000” State Name: Check16 Transitions into this state: The Control Unit will transition into this state when the previous state was Play16.
Function: When the control unit is in this state, it monitors the correct_color signal. If correct_color = ‘1’, the next state is Play17. Otherwise, the control unit transitions to the error state. It also resets the gameAddress_sig so that the next play state will begin displaying colors from the first address in the GameRegister. Outputs asserted: game_enable = ‘0’, gameAddress_sig = “00000” Transitions out of State: The Control Unit transitions out of this state when a value is received on the correct_color input.
State Name: Play17 Transitions into this state: The Control Unit will transition into this state when the previous state was Check16.
Function: This state is responsible for displaying the first two colors stored in the GameRegister Outputs asserted: game_enable = ‘1’, gameAddress_sig = gameAddress_sig + 1 Transitions out of State: The Control Unit transitions out of this state when the GameAddress_sig = “10001” State Name: Check17 Transitions into this state: The Control Unit will transition into this state when the previous state was Play17.
Function: When the control unit is in this state, it monitors the correct_color signal. If correct_color = ‘1’, the next state is Play18. Otherwise, the control unit transitions to the error state. It also resets the gameAddress_sig so that the next play state will begin displaying colors from the first address in the GameRegister. Outputs asserted: game_enable = ‘0’, gameAddress_sig = “00000” Transitions out of State: The Control Unit transitions out of this state when a value is received on the correct_color input.
State Name: Play18 Transitions into this state: The Control Unit will transition into this state when the previous state was Check17.
Function: This state is responsible for displaying the first two colors stored in the GameRegister Outputs asserted: game_enable = ‘1’, gameAddress_sig = gameAddress_sig + 1 Transitions out of State: The Control Unit transitions out of this state when the GameAddress_sig = “10010” State Name: Check18 Transitions into this state: The Control Unit will transition into this state when the previous state was Play18.
Function: When the control unit is in this state, it monitors the correct_color signal. If correct_color = ‘1’, the next state is Play19. Otherwise, the control unit transitions to the error state. It also resets the gameAddress_sig so that the next play state will begin displaying colors from the first address in the GameRegister. Outputs asserted: game_enable = ‘0’, gameAddress_sig = “00000” Transitions out of State: The Control Unit transitions out of this state when a value is received on the correct_color input.
State Name: Play19 Transitions into this state: The Control Unit will transition into this state when the previous state was Check18.
Function: This state is responsible for displaying the first two colors stored in the GameRegister Outputs asserted: game_enable = ‘1’, gameAddress_sig = gameAddress_sig + 1 Transitions out of State: The Control Unit transitions out of this state when the GameAddress_sig = “10011” State Name: Check19 Transitions into this state: The Control Unit will transition into this state when the previous state was Play19.
Function: When the control unit is in this state, it monitors the correct_color signal. If correct_color = ‘1’, the next state is Play20. Otherwise, the control unit transitions to the error state. It also resets the gameAddress_sig so that the next play state will begin displaying colors from the first address in the GameRegister. Outputs asserted: game_enable = ‘0’, gameAddress_sig = “00000” Transitions out of State: The Control Unit transitions out of this state when a value is received on the correct_color input.
State Name: Play20 Transitions into this state: The Control Unit will transition into this state when the previous state was Check19.
Function: This state is responsible for displaying the first two colors stored in the GameRegister Outputs asserted: game_enable = ‘1’, gameAddress_sig = gameAddress_sig + 1 Transitions out of State: The Control Unit transitions out of this state when the GameAddress_sig = “10100” State Name: Check20 Transitions into this state: The Control Unit will transition into this state when the previous state was Play20.
Function: When the control unit is in this state, it monitors the correct_color signal. If correct_color = ‘1’, the next state is win. Otherwise, the control unit transitions to the error state. It also resets the gameAddress_sig so that the next play state will begin displaying colors from the first address in the GameRegister. Outputs asserted: game_enable = ‘0’, gameAddress_sig = “00000” Transitions out of State: The Control Unit transitions out of this state when a value is received on the correct_color input.
State Name: Error Transitions into this state: The Control Unit will transition into this state when a zero is received on the correct_color signal
Function: When in this state, the simon game will simply display a bright red screen. Outputs asserted: error_enable = ‘1’, game_Enable = ‘0’ Transitions out of State: The Control Unit transitions out of this state when reset = ‘1’
State Name: Idle
Transitions into this state: The Control Unit will transition into this state after a full game has played and the error state has never been entered Function: This state simply waits for a reset signal to indicate that another game is ready to be played. Outputs asserted: game_enable = ‘0’ Transitions out of State: The Control Unit transitions out of this state when reset = ‘1’
Pitfalls and Future Modifications
ClkDivider: External Component to Internal Process
I experienced difficulty when using my clock divider and I’m not sure why. The clock divider runs as a stand alone component and demonstrates functionality when loaded to the board as a single unit. However, when it was attached to the co ntrol unit as an external component, the system as a whole failed. This issue was resolved by simply making the clkDivider a process inside of the control unit rather than a component in the Data Unit.
Slow Start-up I had difficulty working on the timing in my control unit. In order to flash the colors on the display long enough to be seen by the human eye, the FSM needed to be slowed down. However, I did not want the entire control unit to run on the slower flash clock, because then there would be about a 7 second delay before the game was ready for play. However, my attempts at getting the game to setup in a separate FSM using a faster clock were unsuccessful. It led to errors in the hardware beha vior and in some instances, no behavior at all. For that reason, my control unit runs entirely on the flash clock and there is about a 7 second delay from the time the game is reset to the time it is ready for play. Hopefully, this functionality is something I will have time to add ress in the coming month. If not, I hope to have time to learn to display messages on the screen. Then, I can simply use the 7 second delay to display instructions on the screen for the user.
Flashing the Same Color Twice It will be necessary to add a few states to my FSM to account for the fact that even random colors can have repeats. Unfortunately, when repeat colors are encountered, it is difficult to identify the number of repeats. It will be necessary to flash the colors, then show the board briefly between flashes. Otherwise, repeat colors could easily be mistaken for one flash.
Addition of the wrong_color status signal While testing my simon game, I noticed that it did not wait for an input in the Check states. It either went immediately to the next Play state or immediately went to the error state based on the status of the correct_color signal. I learned that it was because correct_color was either 0 or 1 all the time and, thus, would always cause the state to immediately make a decision. I need to add the wrong_color signal so that instead of making a decision immediately, the Check states will wait for a specific condition (correct_color = ‘1’ or wrong_color = ‘1’) to be met before updating the current_state. This will require modifications to both the Comparator compon ent and the Control Unit.
Appendix A: VHDL Code ClkDivider library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.NUMERIC_STD.ALL; use IEEE.std_logic_unsigned.all;
--This entity takes the 50 MHz board clock and provides a slower clock for the flashing of the colors. --The clock will be high for approximately 0.33 seconds and will be low for approximately 0.33 seconds entity clkDivider is Port ( clk, reset : in STD_LOGIC; flash_clock : out STD_LOGIC); end clkDivider;
architecture Behavioral of clkDivider is --this will be my count signal and will allow me to divide the clock signal count: std_logic_vector(25 downto 0) := "00000000000000000000000000"; begin process(clk) begin
if (reset = '1') then --asynchronous reset count <= "00000000000000000000000000"; elsif ((clk'event) and (clk = '1')) then --on the rising edge of the clock count <= count + 1; --increment the count if count = "11111111111111111111111111" then count <= "00000000000000000000000000"; end if; end if; flash_clock <= count(24); --This divides the 50 MHz clock by 2^24 providing a 2.98023 Hz clock end process; end Behavioral;
RandomColorGenerator entity RandomColorGenerator is port (clk : in std_logic; RandomEnable: in std_logic; color : out std_logic_vector(1 downto 0)); end RandomColorGenerator; architecture Behavioral of RandomColorGenerator is
--these signals are used to both hold and generate the random numbers signal rNumber : std_logic_vector(31 downto 0) := "10110010100011100101000100001101"; signal rtemp : std_logic := '0'; begin Random_Color: process(clk) begin if (clk'event) and (clk = '1') then --This portion of the code is the implementation of the linear feedback shift register. --It will continue to generate random numbers on the rising edge of the clock, even when --it is not enabled. rtemp <= rNumber(0) xor rNumber(1); rNumber(30 downto 0) <= rNumber(31 downto 1); rNumber(31) <= rtemp; --When the RandomEnable line goes high, the Random Number Generator ouputs the values --of the two least significant bits of the the shift register. When it is not enabled, it --outputs a "00", but continues to gnerate random numbers in the background if (RandomEnable = '1') then color <= rNumber(1) & rNumber(0); elsif (RandomEnable ='0') then color <= "00"; end if; end if; end process; end Behavioral;
GameRegister library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity GameRegister is Port ( clk : in STD_LOGIC; reset : in STD_LOGIC; Gload : in STD_LOGIC; color : in STD_LOGIC_VECTOR (1 downto 0); Gaddr : in STD_LOGIC_VECTOR (4 downto 0); GColor_out : out STD_LOGIC_VECTOR (1 downto 0)); end GameRegister; architecture Behavioral of GameRegister is type GameArray is array (0 to 19) of std_logic_vector(1 downto 0);
--creates the register type
signal GameRegister: GameArray; signal index: integer := 0; --this will allow us to program the correct rows of the register begin Program_Register: Process(clk) begin
--these case statements decode the address entered into the corresponding register index --they were necessary to handle invalid inputs on the Gaddr input. case Gaddr is when "00000" => index <= 0; when "00001" => index <= 1; when "00010" => index <= 2; when "00011" => index <= 3; when "00100" => index <= 4; when "00101" => index <= 5; when "00110" => index <= 6; when "00111" => index <= 7; when "01000" => index <= 8; when "01001" => index <= 9; when "01010" => index <= 10; when "01011" => index <= 11; when "01100" => index <= 12; when "01101" => index <= 13; when "01110" => index <= 14; when "01111" => index <= 15; when "10000" => index <= 16; when "10001" => index <= 17; when "10010" => index <= 18; when "10011" => index <= 19; when others => index <= 0; end case;
--these statements control the read/write operations if (clk'event) and (clk = '1') then --on the rising edge of the clock if (reset = '1') then --if reset asserted, fill all rows with 00 GameRegister <= (others => (others => '0')); elsif (Gload = '1') then --if write is enabled, then write data to the address specified GameRegister(index) <= color; elsif (Gload = '0') then --if read is enabled, read from the address specified Gcolor_out <= GameRegister(index); end if; end if; end process; end Behavioral;
VGA_SimonController entity VGA_SimonController is port(mclk, reset: in std_logic; error_enable: in std_logic; game_enable : in std_logic; game_color : in std_logic_vector(1 downto 0); vs, hs: out std_logic; red, grn, blu, led: out std_logic); attribute syn_noclockbuf : boolean; end VGA_SimonController; architecture Behavioral of VGA_SimonController is
--these are the signal declarations signal clkPix: std_logic; --used as the clock signal for the pixel clock signal cntHorz, cntVert: std_logic_vector(9 downto 0); --used to control the horizontal and vertical timing signal sncHorz, clkLine, blkHorz, sncVert, blkVert, blkDisp, clkColor: std_logic; --used to control the scans signal cntImg: std_logic_vector(6 downto 0); signal cntColor: std_logic_vector(2 downto 0); --used to control the color of the screen signal horizontal: std_logic_vector(11 downto 0) := X"1CC"; --used to set the boundaries of the boxes signal vertical: std_logic_vector(11 downto 0) := X"10A"; begin -- Divide the D2XL oscillator down to form the pixel clock -- that is the basis for all of the other timing. process (mclk) begin if mclk = '1' and mclk'Event then --this code sets the clkPix signal so that it is half as clkPix <= not clkPix; --fast as the mclk signal end if; end process; -- Generate the horizontal timing. process (clkPix) begin --these if statements serve two purposes. They incremenrt the cntHorz signal and, at specified intervals, --they set sncHorz and blkHorz to 1 and 0 as needed. if clkPix = '1' and clkPix'Event then --rising edge of the clock signal if cntHorz = "0001011101" then --when cntHorz = 93 cntHorz <= cntHorz + 1; --continue to increment sncHorz <= '1'; --set sncHorz to 1 elsif cntHorz = "0010001100" then --when cntHorz = 140 cntHorz <= cntHorz + 1; --continue to increment blkHorz <= '0'; --set blkHorz to 0 elsif cntHorz = "1100001100" then --when cntHorz = 780 cntHorz <= cntHorz + 1; --continue to increment blkHorz <= '1'; --set blkHorz to 1 elsif cntHorz = "1100011010" then --when cntHorz = 794 cntHorz <= "0000000000"; --reset cntHorz to 0 clkLine <= '1'; --set clkLine to 1 sncHorz <= '0'; --set sncHorz to 0 else cntHorz <= cntHorz + 1; --otherwise continue to increment cntHorz clkLine <= '0'; --set clkLine to 0 end if; end if; end process; -- Generate the vertical timing. process (clkLine) begin --these if statement are governed by the value of the signal clkLine, which is updated --in the previous process. When clkLine is high, the value of cntVert is incremented. Once --cntVert = 524, the count is reset to 0. As cntVert is incremented, the signals sncVert, --blkVert, if clkLine = '1' and clkLine'Event then if cntVert = "0000000001" then --when cntVert = 1 cntVert <= cntVert + 1; --continue to increment sncVert <= '1'; --set sncVert to 1 elsif cntVert = "0000011010" then --when cntVert = 26 cntVert <= cntVert + 1; --continue to increment
blkVert <= '0'; --set blkVert to 0 elsif cntVert = "0111111010" then --when cntVert = 506 cntVert <= cntVert + 1; --continue to increment blkVert <= '1'; --blkVert = 1 elsif cntVert = "1000001100" then --when cntVert = 524 cntVert <= "0000000000"; --reset cntVert to 0 sncVert <= '0'; --set sncVert to 0 else cntVert <= cntVert + 1; --continue to increment cntVert led <= '0'; end if; end if; end process; --This process block sets up the game board process(error_enable) begin if (error_enable = '1') then --if error signal is high, flash the entire board in red cntColor <= "100"; elsif (game_enable = '1') then --if the game is enabled, highlight the colors seen on the input if game_color = "00" then --if input is "00," highlight top left box and leave all others as is if cntHorz < horizontal and cntVert < vertical then cntColor <= "000"; elsif cntHorz > horizontal and cntVert < vertical then cntColor <= "001"; elsif cntHorz < horizontal and cntVert > vertical then cntColor <= "110"; else cntColor <= "010"; end if; elsif game_color = "01" then --if input is "01," highlight the top right box and leave all others as is if cntHorz < horizontal and cntVert < vertical then cntColor <= "100"; elsif cntHorz > horizontal and cntVert < vertical then cntColor <= "000"; elsif cntHorz < horizontal and cntVert > vertical then cntColor <= "110"; else cntColor <= "010"; end if; elsif game_color = "10" then --if input is "10," highlight bottom left box and leave all others as is if cntHorz < horizontal and cntVert < vertical then cntColor <= "100"; elsif cntHorz > horizontal and cntVert < vertical then cntColor <= "001"; elsif cntHorz < horizontal and cntVert > vertical then cntColor <= "000"; else cntColor <= "010"; end if; elsif Game_color = "11" then --if input is "11," highlight bottom right box and leave all others as is if cntHorz < horizontal and cntVert < vertical then cntColor <= "100"; elsif cntHorz > horizontal and cntVert < vertical then cntColor <= "001"; elsif cntHorz < horizontal and cntVert > vertical then cntColor <= "110"; else
cntColor <= "000"; end if; end if; else --if game_enable is not one, simply display the four color blocks if cntHorz < horizontal and cntVert < vertical then cntColor <= "100"; elsif cntHorz > horizontal and cntVert < vertical then cntColor <= "001"; elsif cntHorz < horizontal and cntVert > vertical then cntColor <= "110"; else cntColor <= "010"; end if; end if; end process; --these assign the values of the signals to the outputs blkDisp <= blkVert or blkHorz; vs <= sncVert; --vs gets the value of sncVert hs <= sncHorz; --hs gets the value of sncHorz blu <= cntColor(0) and (not blkDisp); --blue is set to 1 when blkDisp = '0' and cntColor(0) = '1' grn <= cntColor(1) and (not blkDisp); --blue is set to 1 when blkDisp = '0' and cntColor(1) = '1' red <= cntColor(2) and (not blkDisp); --blue is set to 1 when blkDisp = '0' and cntColor(2) = '1 end Behavioral;
Data_Unit library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.NUMERIC_STD.ALL; use IEEE.std_logic_unsigned.all; library UNISIM; use UNISIM.VComponents.all; entity Data_Unit is port(clk: in std_logic; reset: in std_logic; gameRegister_Load: in std_logic; random_enable: in std_logic; game_enable: in std_logic; error_enable: in std_logic; gameAddress_line: in std_logic_vector(4 downto 0); vs: out std_logic; hs: out std_logic; red: out std_logic; green: out std_logic; blue: out std_logic); end Data_Unit; architecture Behavioral of Data_Unit is component RandomColorGenerator port (clk : in std_logic; RandomEnable: in std_logic; color : out std_logic_vector(1 downto 0)); end component; component GameRegister
Port ( clk : in STD_LOGIC; reset : in STD_LOGIC; Gload : in STD_LOGIC; color : in STD_LOGIC_VECTOR (1 downto 0); Gaddr : in STD_LOGIC_VECTOR (4 downto 0); GColor_out : out STD_LOGIC_VECTOR (1 downto 0)); end component; component VGA_SimonController port(clk, reset: in std_logic; error_enable: in std_logic; game_enable : in std_logic; game_color : in std_logic_vector(1 downto 0); vs, hs: out std_logic; red, grn, blu: out std_logic); end component; signal color_sig: std_logic_vector(1 downto 0); signal game_color_sig: std_logic_vector(1 downto 0);
begin RCG: RandomColorGenerator port map (clk, random_Enable, color_sig); GReg: GameRegister port map (clk, reset, gameRegister_Load, color_sig, gameAddress_line, game_color_sig); VGA: VGA_SimonController port map (clk, reset, error_enable, game_enable, game_color_sig, vs, hs, red, green, blue);
end Behavioral;
Control_Unit library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.NUMERIC_STD.ALL; use IEEE.std_logic_unsigned.all;
entity Control_Unit is port(clk: in std_logic; reset: in std_logic; correct_color: in std_logic; gameRegister_load: out std_logic; --R/W signal for the game register gameAddress: out std_logic_vector(4 downto 0); random_enable: out std_logic; --enable line of the random color generator game_enable: out std_logic; --enable line to the VGA Simon Controller error_enable: out std_logic; --error signal to the VGA Simon Controller component win_enable: out std_logic; -userRegister_load: out std_logic; --R/W signal of the user register -userAddress: out std_logic_vector(4 downto 0); --address line of the user register -comp_load: out std_logic; --R/W signal for the comprator -compAddress: out std_logic_vector(4 downto 0); --address line for the comparator DataUnit_reset, clock: out std_logic); --reset signal for the control unit end Control_Unit; architecture Behavioral of Control_Unit is signal gameAddress_sig: std_logic_vector(4 downto 0) := B"00000";
type state_type is ( ResetGame, Setup1,Setup2, Play1, Play2, Play3, Play4, Play5, Play6, Play7, Play8, Play9, Play10, Play11, Play12, Play13, Play14, Play15, Play16, Play17, Play18, Play19, Play20, Check1, Check2, Check3, Check4, Check5, Check6, Check7, Check8, Check9, Check10, Check11, Check12, Check13, Check14, Check15, Check16, Check17, Check18, Check19, Check20, error, idle); signal current_state, next_State: state_type; signal fclk, DataUnit_reset_sig: std_logic; signal count: std_logic_vector(25 downto 0) := "00000000000000000000000000";
begin clkDivider: process(clk, reset, count) begin if (reset = '1') then --asynchronous reset count <= "00000000000000000000000000"; elsif ((clk'event) and (clk = '1')) then --on the rising edge of the clock count <= count + 1; --increment the count if count = "11111111111111111111111111" then count <= "00000000000000000000000000"; end if; end if; fclk <= count(24); clock <= clk;
--This divides the 50 MHz clock by 2^24 providing a 2.98023 Hz clock
end process clkDivider; NextStateLogic: process (Reset, DataUnit_reset_sig, fclk) begin --wait until ; --WAIT FOR RISING EDGE -- INITIALIZATION if (Reset = '1') then DataUnit_reset_sig <= '1'; Current_State <= ResetGame; elsif (Reset = '0') then DataUnit_reset_sig <= '0'; if (fclk'EVENT) and (fclk = '1') then Current_State <= Next_State; end if; end if;
DataUnit_reset <= DataUnit_reset_sig; end process NextStateLogic; SimonGameFSM: process begin wait until fclk'EVENT and fclk = '1'; case current_state is when ResetGame => --DataUnit_reset <= '1'; gameAddress_sig <= "00000"; --color_count <= "00000"; random_enable <= '1'; game_enable <= '0'; error_enable <= '0'; if (Reset = '0') then next_state <= Setup1; --dataUnit_reset <= '0'; else next_state <= ResetGame; end if; when Setup1 => --in this state the GameRegister is written with 20 random colors gameRegister_load <= '1'; random_enable <= '1'; if (gameAddress_sig = "10011") then next_state <= Setup2; elsif (gameAddress_sig < "10011") then next_state <= Setup1; gameAddress_sig <= gameAddress_sig + 1; end if; when Setup2 => gameRegister_load <= '0'; --load signal set to 0 so that register data remains constant --gameAddress_sig updated so that the starting address for read operation is first address in register gameAddress_sig <= "00000"; next_state <= play1; when Play1 => --loops through once and plays the first color in the register game_enable <= '1'; if (gameAddress_sig = "00001") then next_state <= Check1; game_enable <= '0'; elsif (gameAddress_sig < "00001") then gameAddress_Sig <= gameAddress_Sig + 1; next_state <= Check1; end if; when Check1 => --checks if the correct_color signal is high and continues to next play state or to error state game_enable <= '0';
gameAddress_sig <= "00000"; force the "00000" address to be read if (correct_color = '1') then next_state <= Play2; else next_state <= error; end if;
--this modification was made to
when Play2 => --loops through twice and plays the first 2 colors in the register game_enable <= '1'; if (gameAddress_sig = "00010") then next_state <= Check2; game_enable <= '0'; elsif (gameAddress_sig < "00010") then gameAddress_Sig <= gameAddress_Sig + 1; next_state <= Play2; end if; when Check2 => --checks if the correct_color signal is high and continues to next play state or to error state game_enable <= '0'; gameAddress_sig <= "00000"; if (correct_color = '1') then next_state <= Play3; else next_state <= error; end if; when Play3 =>
--loops through 3 times and plays the first 3 colors in the
register game_enable <= '1'; if (gameAddress_sig = "00011") then next_state <= Check3; game_enable <= '0'; elsif (gameAddress_sig < "00011") then gameAddress_Sig <= gameAddress_Sig + 1; next_state <= Play3; end if; when Check3 => game_enable <= '0'; gameAddress_sig <= "00000"; if (correct_color = '1') then next_state <= Play4; else next_state <= error; end if; when Play4 => game_enable <= '1'; if (gameAddress_sig = "00100") then next_state <= Check4; game_enable <= '0'; elsif (gameAddress_sig < "00100") then gameAddress_Sig <= gameAddress_Sig + 1; next_state <= Play4; end if;
when Check4 => game_enable <= '0'; gameAddress_sig <= "00000"; if (correct_color = '1') then next_state <= Play5; else next_state <= error; end if; when Play5 => game_enable <= '1'; if (gameAddress_sig = "000101") then next_state <= Check5; game_enable <= '0'; elsif (gameAddress_sig < "00101") then gameAddress_Sig <= gameAddress_Sig + 1; next_state <= Play5; end if; when Check5 => game_enable <= '0'; gameAddress_sig <= "00000"; if (correct_color = '1') then next_state <= Play6; else next_state <= error; end if; when Play6 => game_enable <= '1'; if (gameAddress_sig = "00110") then next_state <= Check6; game_enable <= '0'; elsif (gameAddress_sig < "00110") then gameAddress_Sig <= gameAddress_Sig + 1; next_state <= Play6; end if; when Check6 => game_enable <= '0'; gameAddress_sig <= "00000"; if (correct_color = '1') then next_state <= Play7; else next_state <= error; end if; when Play7 => game_enable <= '1'; if (gameAddress_sig = "00111") then next_state <= Check7; game_enable <= '0'; elsif (gameAddress_sig < " 00111") then gameAddress_Sig <= gameAddress_Sig + 1; next_state <= Play7; end if; when Check7 =>
game_enable <= '0'; gameAddress_sig <= "00000"; if (correct_color = '1') then next_state <= Play8; else next_state <= error; end if; when Play8 => game_enable <= '1'; if (gameAddress_sig = "01000") then next_state <= Check8; game_enable <= '0'; elsif (gameAddress_sig < "01000") then gameAddress_Sig <= gameAddress_Sig + 1; next_state <= Play8; end if; when Check8 => game_enable <= '0'; gameAddress_sig <= "00000"; if (correct_color = '1') then next_state <= Play9; else next_state <= error; end if; when Play9 => game_enable <= '1'; if (gameAddress_sig = "01001") then next_state <= Check9; game_enable <= '0'; elsif (gameAddress_sig < "01001") then gameAddress_Sig <= gameAddress_Sig + 1; next_state <= Play9; end if; when Check9 => game_enable <= '0'; gameAddress_sig <= "00000"; if (correct_color = '1') then next_state <= Play10; else next_state <= error; end if; when Play10 => game_enable <= '1'; if (gameAddress_sig = "01010") then next_state <= Check10; game_enable <= '0'; elsif (gameAddress_sig < "01010") then gameAddress_Sig <= gameAddress_Sig + 1; next_state <= Play10; end if; when Check10 => game_enable <= '0';
gameAddress_sig <= "00000"; if (correct_color = '1') then next_state <= Play11; else next_state <= error; end if; when Play11 => game_enable <= '1'; if (gameAddress_sig = "01011") then next_state <= Check11; game_enable <= '0'; elsif (gameAddress_sig < "01011") then gameAddress_Sig <= gameAddress_Sig + 1; next_state <= Play11; end if; when Check11 => game_enable <= '0'; gameAddress_sig <= "00000"; if (correct_color = '1') then next_state <= Play12; else next_state <= error; end if; when Play12 => game_enable <= '1'; if (gameAddress_sig = "01100") then next_state <= Check12; game_enable <= '0'; elsif (gameAddress_sig < "01100") then gameAddress_Sig <= gameAddress_Sig + 1; next_state <= Play12; end if; when Check12 => game_enable <= '0'; gameAddress_sig <= "00000"; if (correct_color = '1') then next_state <= Play13; else next_state <= error; end if; when Play13 => game_enable <= '1'; if (gameAddress_sig = "01101") then next_state <= Check13; game_enable <= '0'; elsif (gameAddress_sig < "01101") then gameAddress_Sig <= gameAddress_Sig + 1; next_state <= Play13; end if; when Check13 => game_enable <= '0'; gameAddress_sig <= "00000";
if (correct_color = '1') then next_state <= Play14; else next_state <= error; end if; when Play14 => game_enable <= '1'; if (gameAddress_sig = "01110") then next_state <= Check14; game_enable <= '0'; elsif (gameAddress_sig < " 01110") then gameAddress_Sig <= gameAddress_Sig + 1; next_state <= Play14; end if; when Check14 => game_enable <= '0'; gameAddress_sig <= "00000"; if (correct_color = '1') then next_state <= Play15; else next_state <= error; end if; when Play15 => game_enable <= '1'; if (gameAddress_sig = "01111") then next_state <= Check15; game_enable <= '0'; elsif (gameAddress_sig < "01111") then gameAddress_Sig <= gameAddress_Sig + 1; next_state <= Play15; end if; when Check15 => game_enable <= '0'; gameAddress_sig <= "00000"; if (correct_color = '1') then next_state <= Play16; else next_state <= error; end if; when Play16 => game_enable <= '1'; if (gameAddress_sig = "10000") then next_state <= Check16; game_enable <= '0'; elsif (gameAddress_sig < "10000") then gameAddress_Sig <= gameAddress_Sig + 1; next_state <= Play16; end if; when Check16 => game_enable <= '0'; gameAddress_sig <= "00000"; if (correct_color = '1') then
next_state <= Play17; else next_state <= error; end if; when Play17 => game_enable <= '1'; if (gameAddress_sig = "10001") then next_state <= Check17; game_enable <= '0'; elsif (gameAddress_sig < "10001") then gameAddress_Sig <= gameAddress_Sig + 1; next_state <= Play17; end if; when Check17 => game_enable <= '0'; gameAddress_sig <= "00000"; if (correct_color = '1') then next_state <= Play18; else next_state <= error; end if; when Play18 => game_enable <= '1'; if (gameAddress_sig = "10010") then next_state <= Check18; game_enable <= '0'; elsif (gameAddress_sig < "10010") then gameAddress_Sig <= gameAddress_Sig + 1; next_state <= Play18; end if; when Check18 => game_enable <= '0'; gameAddress_sig <= "00000"; if (correct_color = '1') then next_state <= Play19; else next_state <= error; end if; when Play19 => game_enable <= '1'; if (gameAddress_sig = "10011") then next_state <= Check19; game_enable <= '0'; elsif (gameAddress_sig < "10011") then gameAddress_Sig <= gameAddress_Sig + 1; next_state <= Play19; end if; when Check19 => game_enable <= '0'; gameAddress_sig <= "00000"; if (correct_color = '1') then next_state <= Play20;
else next_state <= error; end if; when Play20 => game_enable <= '1'; if (gameAddress_sig = "10100") then next_state <= Check20; game_enable <= '0'; elsif (gameAddress_sig < "10100") then gameAddress_Sig <= gameAddress_Sig + 1; next_state <= Play20; end if; when Check20 => game_enable <= '0'; gameAddress_sig <= "00000"; if (correct_color = '1') then next_state <= idle; else next_state <= error; end if; when error => game_enable <= '0'; error_enable <= '1'; if (reset = '1') then next_state <= ResetGame; elsif (reset = '0') then next_state <= error; end if;
----
when win => win_enable <= '1'; next_state <= win; when idle => next_state <= idle; game_enable <= '0'; when others => next_state <= idle; end case; gameAddress <= gameAddress_sig; end process SimonGameFSM;
end Behavioral;
TopLevel library IEEE; use IEEE.STD_LOGIC_1164.ALL; entity TopLevel is port(clk, reset, correct_color: in std_logic; vs: out std_logic;