I'm doing a VHDL program in Vivado, using a zyboz7 20, which would have 2 teams, each of them with different buttons and led lights. The idea is to use one button to obtain when a team scores a goal, so it will be displayed in the 7 segment-display (for example, if the button is pressed once, the display will show a one, and so on). When any of the team gets to 3, the led light given to that team will turn on.
Right now, I just have one team in the program and the constraints. Also, I have trouble understanding the debouncing of the button, I don't know if I'm using the wrong algorithm to attack the debounce issue, but it's as if the clock was delayed or it's not taking some of the input, I have been looking to a lot of tutorials but I can't find a way in which the programs can work without any issue. I will show my code here and the constraint, I will also explain the code so it will be easier to modify it if anyone can help me with the debounce issue.
Program's code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use IEEE.NUMERIC_STD.ALL;
entity sevenSementDis is
Port (
C : out STD_LOGIC;
won1: out STD_LOGIC;
team1, clk,reset: in STD_LOGIC;
SevenSD: out STD_LOGIC_VECTOR (6 downto 0));
end sevenSementDis;
architecture Behavioral of sevenSementDis is
type statetype is (Init,Gol,AnotherGol,victory);
signal state, nextstate: statetype;
signal clk_bit : INTEGER := 4;
signal clk_bit2 : INTEGER := 4;
signal count : STD_LOGIC_VECTOR (4 downto 0) := "00000";
signal clk_div : STD_LOGIC_VECTOR (4 downto 0) := "00000";
signal count_reset : STD_LOGIC_VECTOR (4 downto 0) := "00000";
signal clk_reset : STD_LOGIC_VECTOR (4 downto 0) := "00000";
begin
C<='0';
process (clk)
begin
if (clk='1' and team1='1') then
clk_div <= clk_div + '1';
end if;
end process;
process (clk_div)
begin
if (clk='1' and clk_div(clk_bit) = '1') then
count <= count + '1';
end if;
end process;
process(clk)
--variable Count : natural range 0 to 5 := 0;
begin
if rising_edge(clk) then
case(nextstate) is
when Init =>
SevenSD<="0111111";
won1<='0';
if count="00010" then
nextstate<=Gol;
else
nextstate<=Init;
end if;
when Gol =>
SevenSD<= "0000110";
if count="00011" then
nextstate<=AnotherGol;
else
nextstate<=Gol;
end if;
when AnotherGol =>
SevenSD<= "1001011";
if count="00100" then
nextstate<=victory;
else
nextstate<=AnotherGol;
end if;
when victory =>
SevenSD<= "1001111";
won1<= '1';
end case;
end if;
end process;
end Behavioral;
Explanation:
The ports: Won1 is the led light assigned to team 1. team1 is the button that I want to use when team 1 scores. The reset is also a button but I haven't been implemented. SevenSD is the 7-segment display. Clk is the clock and C is another led light that hasn't been implemented.
There are 4 states, Init(where the code starts), Gol (the team scores the first goal, which would also change the display), AnotherGol(team scores again and the display changes), and Victory (the display changes one last time and led light turns on). There are also state (which would take the actual state) and nextstate(which will tell the next state).
count is an integer that will be added when the button is 1 and the clk_div is also 1, it's the one that determines when to move to the next state. clk_bit is just the bits of the clock. clk_div is diving the clock to try to attack the debouncing issue. clk_bit2, count_reset,clk_reset are not implemented, they were created when trying to add the reset button, but when I erase them, the code just stops working at all.
the rest are some process to fight the debounce and the last one is the actual code, which goes around the different states until the victory state.