Reputation: 133
I am writing what I thought would be a fairly standard VHDL code but the execution keeps coming back on me.
The code is meant to be a simple game on a Nexsys 3 board. The first player selects a switch and the LEDs scroll down from it showing a blank when they are over the switch itself. The second player presses a button when the scroll gets to the switch selected. My part of the game is to get the LEDs scrolling. My code can be viewed below:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use IEEE.NUMERIC_STD.ALL;
entity Two_Player_3_24_2013 is
port( clk: in std_logic;
rst: in std_logic;
switches: in std_logic_vector(7 downto 0);
led_indic: out std_logic_vector(7 downto 0)
);
end Two_Player_3_24_2013;
architecture Behavioral of Two_Player_3_24_2013 is
signal count: std_logic_vector(31 downto 0):= "00000000000000000000000000000000";
signal only_one: std_logic := '0';
signal shifter: std_logic_vector(7 downto 0) := "00000000";
begin
only_one <= '1' when switches = "10000000" else
'1' when switches = "01000000" else
'1' when switches = "00100000" else
'1' when switches = "00010000" else
'1' when switches = "00001000" else
'1' when switches = "00000100" else
'1' when switches = "00000010" else
'1' when switches = "00000001" else
'0';
counting: process(clk, rst, only_one)
begin
if (rst = '1') then
count <= "00000000000000000000000000000000";
elsif (clk'event and clk='1' and only_one = '1') then
count <= count + '1';
end if;
end process counting;
shifting: process(clk, rst, count, shifter)
begin
if (rst = '1') then
shifter <= "00000000";
elsif (clk'event and clk='1' and count = "00000000000000010000000000000000") then
shifter <= switches;
elsif (clk'event and clk='1' and count(25) = '1') then
shifter <= shifter(0) & shifter(7 downto 1);
end if;
end process shifting;
led_indic <= shifter;
end Behavioral;
Now I've checked the parts individually and they work. The only_one
signal is true only when one switch is on. The counter begins at the right time and the first switch is triggered at the right time as well. For some reason I still can't figure out, however, it refuses to scroll. I've tried running this both on the board and in simulation, but I can't figure out why the scrolling doesn't work. The original setting only happens at a specific time, while the concatenation should occur at regular time intervals. I know the problem is with the
shifter <= shifter(0) & shifter(7 downto 1);
but so far nothing I've tried has fixed it.
Any advice is greatly appreciated.
Thanks,
Yusif Nurizade
Upvotes: 0
Views: 885
Reputation: 1387
I guess in simulation you just have to wait ;-)
when you use a 100MHz clock, it takes ~335ms until anything happens (count(25) is high). as soon and as long as count(25) is high, the LEDs will shift very fast for the next 335ms ending at the same position as they started. --> therefore adjust your counters.
for the game itself re-think the "shift while count(25)='1'" thing! it makes more sense to shift only at one counterposition (e.g. if count=X"01000000"...)
btw: for synthesis it is not good practice to implement gated clocks like
elsif (clk'event and clk='1' and count(25) = '1')) then
you should rather use e.g.:
elsif (clk'event and clk='1') then
if count(25) = '1' then
...
Upvotes: 1