0

我正在编写我认为是相当标准的 VHDL 代码,但执行不断地回到我身上。

该代码旨在成为 Nexsys 3 板上的简单游戏。第一个玩家选择一个开关,当他们在开关本身上方时,LED 从它向下滚动显示一个空白。当滚动条到达选定的开关时,第二个玩家按下按钮。我的游戏部分是让 LED 滚动。我的代码可以在下面查看:

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;

现在我已经单独检查了这些部件并且它们可以工作。该only_one信号仅在一个开关打开时为真。计数器在正确的时间开始,第一个开关也在正确的时间触发。出于某种原因,我仍然无法弄清楚,但是,它拒绝滚动。我已经尝试在板上和模拟中运行它,但我无法弄清楚为什么滚动不起作用。原始设置仅在特定时间发生,而串联应以固定时间间隔发生。我知道问题出在

shifter <= shifter(0) & shifter(7 downto 1);

但到目前为止,我没有尝试过修复它。

任何意见是极大的赞赏。

谢谢,
尤西夫·努里扎德

4

1 回答 1

1

我想在模拟中你只需要等待;-)

当您使用100MHz时钟时,大约需要 335ms 直到发生任何事情(count(25) 很高)。只要 count(25) 为高,LED 就会在接下来的 335ms 内快速移动,并在与它们开始时相同的位置结束。--> 因此调整你的计数器

对于游戏本身,请重新考虑“shift while count(25)='1'”这件事!仅在一个相对位置移动更有意义(例如,如果 count=X"01000000"...)

顺便说一句:对于综合来说,实现门控时钟并不是一个好习惯

elsif (clk'event and  clk='1' and count(25) = '1')) then

你应该使用例如:

elsif (clk'event and  clk='1') then
   if count(25) = '1' then
      ...
于 2013-03-30T07:27:31.453 回答