我正在使用 webPack ISE v 13 使用以下代码对 Nexys 3 板进行编程,并通过在 if elsif 语句中交换语句来注意到完全不同的行为。本质上,我在板上使用了三个按钮:当按下第一个按钮 btn(0) 时,8 个开关的状态存储在一个寄存器中。当我按下 btn(1) 时,开关的状态应显示在 8 个 LED 中,并且 LED 应保持此状态。当我按下 btn(2) 时,我强制点亮所有 LED,如果没有按下 btn 1 或 2,它们应该保持这种状态。通过交换按钮 1 和 2 的 if 和 elsif 下的操作,行为会发生变化:仅当我按下相应的按钮时才会显示开关的状态,一旦松开,所有 LED 都会亮起。
不仅仅是寻找“这是你需要让它工作的东西”,我还在解释为什么 vhdl 的行为与 C++ 如此不同,比如说(在这种情况下,顺序无关紧要)
以下是代码摘录;我指出要评论/取消评论哪些行以获得行为“a”或行为“b”。
行为“一”:
- 按下 btn(0) 时,8 个开关的状态会正确加载到 data_reg
- 当我按下 btn(1) 时,LED 全部亮起(“111...11”)
- 如果我按 btn(2),LED 会显示 data_reg 内容
- 如果未按下任何按钮,则 LED 的状态为最后一次按下按钮所指示的状态
行为'b':
- 按下 btn(0) 时,8 个开关的状态会正确加载到 data_reg
- 当我按下 btn(1) 时,LED 显示 data_reg 内容
- 如果我按 btn(2),LED 全部亮起(“111...11”)
- 如果未按下任何按钮,则所有 LED 都亮起,查看 data_reg 内容的唯一方法是按住 btn(1)。
`
进程(时钟)
开始
if (clk'event and clk='1') then
if (db_btn(0)='1') then --load sw state into data_reg data_reg <= sw; end if;
万一; 结束进程;
process(btn,data_reg)
begin
if btn(1)='1' then
data_s2f <= "1111111111111111"; --behvr a; comment this line for behvr b
-- data_s2f <= "00000000" & data_reg; -- uncomment for behvr b; comment for behvr a
elsif btn(2)='1' then -- read
data_s2f <= "00000000" & data_reg; --behvr a; comment this line for behvr b
--data_s2f <= "1111111111111111"; -- uncomment for behvr b; comment for behvr a
end if;
end process;
-- output
led <= data_s2f(7 downto 0); --display data_s2f in LEDs
仿真试验台
这是我的模拟测试台。每当我执行所有信号的结果都是 UUU..UU 任何评论将不胜感激:
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--USE ieee.numeric_std.ALL;
ENTITY ifstmt_tb IS
END ifstmt_tb;
ARCHITECTURE behavior OF ifstmt_tb IS
-- Component Declaration for the Unit Under Test (UUT)
COMPONENT ram_ctrl_test
PORT(
clk : IN std_logic;
reset : IN std_logic;
sw : IN std_logic_vector(7 downto 0);
btn : IN std_logic_vector(2 downto 0);
led : OUT std_logic_vector(7 downto 0)
);
END COMPONENT;
--Inputs
signal clk : std_logic := '0';
signal reset : std_logic := '0';
signal sw : std_logic_vector(7 downto 0) := (others => '0');
signal btn : std_logic_vector(2 downto 0) := (others => '0');
--Outputs
signal led : std_logic_vector(7 downto 0);
-- Clock period definitions
constant clk_period : time := 10 ns;
BEGIN
-- Instantiate the Unit Under Test (UUT)
uut: ram_ctrl_test PORT MAP (
clk => clk,
reset => reset,
sw => sw,
btn => btn,
led => led
);
-- Clock process definitions
clk_process :process
begin
clk <= '0';
wait for clk_period/2;
clk <= '1';
wait for clk_period/2;
end process;
-- Stimulus process
stim_proc: process
begin
-- hold reset state for 100 ns.
reset <= '1';
sw <= "11001100";
btn<= (others => '0');
wait for 100 ns;
reset <= '0';
wait for clk_period*10;
-- load register
btn<= (0=>'1', others => '0');
wait for clk_period*2;
btn<= (others => '0');
wait for clk_period*10;
-- display with btn 1
btn<= (1=>'1', others => '0');
wait for clk_period*5;
btn<= (others => '0');
wait for clk_period*10;
-- display with btn 2
btn<= (2=>'1', others => '0');
wait for clk_period*5;
btn<= (others => '0');
wait for clk_period*10;
-- change pattern
sw <= "11100111";
wait for clk_period;
-- load register
btn<= (0=>'1', others => '0');
wait for clk_period*2;
btn<= (others => '0');
wait for clk_period*10;
-- display with btn 2
btn<= (2=>'1', others => '0');
wait for clk_period*5;
btn<= (others => '0');
wait for clk_period*10;
-- display with btn 1
btn<= (1=>'1', others => '0');
wait for clk_period*5;
btn<= (others => '0');
-- insert stimulus here
wait;
end process;
END;