根据“报告”声明,VHDL 重新分配整数信号不起作用
VHDL reassigning integer signal does not work according to `report` statement
我有这个简单的 VHDL 代码 aufg4.vhd
:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity aufg4 is
Port (
clock : in std_logic
);
end aufg4;
architecture Behavioral of aufg4 is
signal tut_counter : integer range 0 to 90 := 0; -- counts tutorial time
begin
do_process :process(clock)
begin
if(rising_edge(clock)) then
report "tut_counter " & integer'image(tut_counter);
if(tut_counter >= 90) then
tut_counter <= 0;
report "tut_counter reset";
end if;
tut_counter <= tut_counter + 1;
end if;
end process;
end Behavioral;
和测试平台aufg4_tb.vhd
:
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY aufg4_tb IS
END aufg4_tb;
ARCHITECTURE behavior OF aufg4_tb IS
COMPONENT aufg4
PORT(
clock : IN std_logic
);
END COMPONENT;
--Inputs
signal clock : std_logic := '0';
-- Clock period definitions
constant clock_period : time := 10 ns;
BEGIN
-- Instantiate the Unit Under Test (UUT)
uut: aufg4 PORT MAP (
clock => clock
);
-- Clock process definitions
clock_process :process
begin
clock <= '0';
wait for clock_period/2;
clock <= '1';
wait for clock_period/2;
end process;
END;
当我模拟行为模型时 report
输出:
...
at 885 ns(1): Note: tut_counter 88 (/aufg4_tb/uut/).
at 895 ns(1): Note: tut_counter 89 (/aufg4_tb/uut/).
at 905 ns(1): Note: tut_counter 90 (/aufg4_tb/uut/).
at 905 ns(1): Note: tut_counter reset (/aufg4_tb/uut/).
at 915 ns(1): Note: tut_counter 91 (/aufg4_tb/uut/).
at 915 ns(1): Note: tut_counter reset (/aufg4_tb/uut/).
at 925 ns(1): Note: tut_counter 92 (/aufg4_tb/uut/).
at 925 ns(1): Note: tut_counter reset (/aufg4_tb/uut/).
at 935 ns(1): Note: tut_counter 93 (/aufg4_tb/uut/).
...
所以if
-语句正常工作,但信号tut_counter
的重新分配不起作用。
那是为什么?
为什么模拟没有通过错误,因为 tut_counter
的范围从 0 to 90
?
使用 else
可以很好地解决问题![=13=]
do_process :process(clock)
begin
if(rising_edge(clock)) then
report "tut_counter " & integer'image(tut_counter);
if(tut_counter >= 90) then
tut_counter := 0;
report "tut_counter reset";
else
tut_counter := tut_counter + 1;
end if;
end if;
end process;
否则你可以使用一个变量:variable tut_counter : integer range 0 to 90 := 0; -- counts tutorial time
我有这个简单的 VHDL 代码 aufg4.vhd
:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity aufg4 is
Port (
clock : in std_logic
);
end aufg4;
architecture Behavioral of aufg4 is
signal tut_counter : integer range 0 to 90 := 0; -- counts tutorial time
begin
do_process :process(clock)
begin
if(rising_edge(clock)) then
report "tut_counter " & integer'image(tut_counter);
if(tut_counter >= 90) then
tut_counter <= 0;
report "tut_counter reset";
end if;
tut_counter <= tut_counter + 1;
end if;
end process;
end Behavioral;
和测试平台aufg4_tb.vhd
:
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY aufg4_tb IS
END aufg4_tb;
ARCHITECTURE behavior OF aufg4_tb IS
COMPONENT aufg4
PORT(
clock : IN std_logic
);
END COMPONENT;
--Inputs
signal clock : std_logic := '0';
-- Clock period definitions
constant clock_period : time := 10 ns;
BEGIN
-- Instantiate the Unit Under Test (UUT)
uut: aufg4 PORT MAP (
clock => clock
);
-- Clock process definitions
clock_process :process
begin
clock <= '0';
wait for clock_period/2;
clock <= '1';
wait for clock_period/2;
end process;
END;
当我模拟行为模型时 report
输出:
...
at 885 ns(1): Note: tut_counter 88 (/aufg4_tb/uut/).
at 895 ns(1): Note: tut_counter 89 (/aufg4_tb/uut/).
at 905 ns(1): Note: tut_counter 90 (/aufg4_tb/uut/).
at 905 ns(1): Note: tut_counter reset (/aufg4_tb/uut/).
at 915 ns(1): Note: tut_counter 91 (/aufg4_tb/uut/).
at 915 ns(1): Note: tut_counter reset (/aufg4_tb/uut/).
at 925 ns(1): Note: tut_counter 92 (/aufg4_tb/uut/).
at 925 ns(1): Note: tut_counter reset (/aufg4_tb/uut/).
at 935 ns(1): Note: tut_counter 93 (/aufg4_tb/uut/).
...
所以if
-语句正常工作,但信号tut_counter
的重新分配不起作用。
那是为什么?
为什么模拟没有通过错误,因为 tut_counter
的范围从 0 to 90
?
使用 else
可以很好地解决问题![=13=]
do_process :process(clock)
begin
if(rising_edge(clock)) then
report "tut_counter " & integer'image(tut_counter);
if(tut_counter >= 90) then
tut_counter := 0;
report "tut_counter reset";
else
tut_counter := tut_counter + 1;
end if;
end if;
end process;
否则你可以使用一个变量:variable tut_counter : integer range 0 to 90 := 0; -- counts tutorial time