敏感性列表 VHDL 过程
sensitivity list VHDL process
我正在尝试使用 Peter Ashenden 的书“设计师的 VHDL 指南”来学习 VHDL,但似乎无法摆脱我错过了与敏感度列表相关的基本项目的感觉。
例如问题是"Write a model that represents a simple ALU with integer inputs and output, and a function select input of type bit. if the function select is '0', the ALU output should be the sum of the inputs otherwise the output should be the difference of the inputs."
我的解决方案是
entity ALU is
port (
a : in integer; -- A port
b : in integer; -- B port
sel : in bit; -- Fun select
z : out integer); -- result
end entity ALU;
architecture behav of ALU is
begin -- architecture behav
alu_proc: process is
variable result : integer := 0;
begin -- process alu_proc
wait on sel;
if sel = '0' then
result := a + b;
else
result := a - b;
end if;
z <= result;
end process alu_proc;
end architecture behav;
用测试台
entity alu_test is
end entity alu_test;
architecture alu_tb of alu_test is
signal a, b, z : integer;
signal sel : bit;
begin -- architecture alu_tb
dut: entity work.alu(behav)
port map (a, b, sel, z);
test_proc: process is
begin -- process test_proc
a <= 5; b <= 5; wait for 5 ns; sel <= '1'; wait for 5 ns;
assert z = 0;
a <= 10; b <= 5; wait for 5 ns; sel <= '0'; wait for 5 ns;
assert z = 15;
wait;
end process test_proc;
end architecture alu_tb;
我的问题与流程中的敏感度列表有关。由于它对 select 位的变化很敏感,因此我必须按顺序执行函数,首先是减法,然后是加法,然后在测试台中再次减法。在这个问题中,我觉得你应该能够顺序地做几个加法,而不是减法。当然,我可以添加一个启用信号并让过程对此敏感,但我认为应该在问题中说明这一点。我是不是遗漏了一些语言或者是我的解决方案 "correct"?
ALU进程的问题是wait on sel;
不包含
a
和 b
,因此进程没有唤醒,输出也没有
在更改这些输入时重新计算。解决此问题的一种方法是添加 a
和
‘b’到 wait
语句,例如:
wait on sel, a, b;
但是,为进程编写此代码的常用方法是使用敏感列表,
这是 process
关键字后的信号列表,因此与
wait
声明。
Ashendens book 3rd edition page 68 描述了一个敏感性列表:
The process statement includes a sensitivity list after the keyword process.
This is a list of signals to which the process is sensitive. When any of
these signals changes value, the process resumes and executes the sequential
statements. After it has executed the last statement, the process suspends
again.
敏感列表的使用等同于wait
语句也有描述
在第 152 页的 Ashendens 书中。
如果重写流程以使用敏感列表,它将是:
alu_proc: process (sel, a, b) is
begin -- process alu_proc
if sel = '0' then
z <= a + b;
else
z <= a - b;
end if;
end process alu_proc;
请注意,我删除了 result
变量,因为 z
输出可以像
在这种情况下我们可以直接分配。
以上将重新计算 z
当计算中使用任何值时
更改,因为计算 z
的所有参数都包含在
敏感列表。以这种方式进行这种连续计算的风险,
是如果在敏感性列表中忘记了一个或多个参数,
如果忘记的参数发生变化,则不会重新计算 z
的新值。
VHDL-2008 允许自动将所有信号和端口包含在
如果使用 all
,则敏感度列表如下:
alu_proc: process (all) is
最后的评论,然后是一个简单的异步计算过程,比如
对于所示的 ALU,如果生成
z
写成:
z <= (a + b) when (sel = '0') else (a - b);
像上面那样使用并发赋值,可以跳过
敏感度列表,因此有忘记其中一个信号或端口的风险
这是计算的一部分。
我正在尝试使用 Peter Ashenden 的书“设计师的 VHDL 指南”来学习 VHDL,但似乎无法摆脱我错过了与敏感度列表相关的基本项目的感觉。
例如问题是"Write a model that represents a simple ALU with integer inputs and output, and a function select input of type bit. if the function select is '0', the ALU output should be the sum of the inputs otherwise the output should be the difference of the inputs."
我的解决方案是
entity ALU is
port (
a : in integer; -- A port
b : in integer; -- B port
sel : in bit; -- Fun select
z : out integer); -- result
end entity ALU;
architecture behav of ALU is
begin -- architecture behav
alu_proc: process is
variable result : integer := 0;
begin -- process alu_proc
wait on sel;
if sel = '0' then
result := a + b;
else
result := a - b;
end if;
z <= result;
end process alu_proc;
end architecture behav;
用测试台
entity alu_test is
end entity alu_test;
architecture alu_tb of alu_test is
signal a, b, z : integer;
signal sel : bit;
begin -- architecture alu_tb
dut: entity work.alu(behav)
port map (a, b, sel, z);
test_proc: process is
begin -- process test_proc
a <= 5; b <= 5; wait for 5 ns; sel <= '1'; wait for 5 ns;
assert z = 0;
a <= 10; b <= 5; wait for 5 ns; sel <= '0'; wait for 5 ns;
assert z = 15;
wait;
end process test_proc;
end architecture alu_tb;
我的问题与流程中的敏感度列表有关。由于它对 select 位的变化很敏感,因此我必须按顺序执行函数,首先是减法,然后是加法,然后在测试台中再次减法。在这个问题中,我觉得你应该能够顺序地做几个加法,而不是减法。当然,我可以添加一个启用信号并让过程对此敏感,但我认为应该在问题中说明这一点。我是不是遗漏了一些语言或者是我的解决方案 "correct"?
ALU进程的问题是wait on sel;
不包含
a
和 b
,因此进程没有唤醒,输出也没有
在更改这些输入时重新计算。解决此问题的一种方法是添加 a
和
‘b’到 wait
语句,例如:
wait on sel, a, b;
但是,为进程编写此代码的常用方法是使用敏感列表,
这是 process
关键字后的信号列表,因此与
wait
声明。
Ashendens book 3rd edition page 68 描述了一个敏感性列表:
The process statement includes a sensitivity list after the keyword process. This is a list of signals to which the process is sensitive. When any of these signals changes value, the process resumes and executes the sequential statements. After it has executed the last statement, the process suspends again.
敏感列表的使用等同于wait
语句也有描述
在第 152 页的 Ashendens 书中。
如果重写流程以使用敏感列表,它将是:
alu_proc: process (sel, a, b) is
begin -- process alu_proc
if sel = '0' then
z <= a + b;
else
z <= a - b;
end if;
end process alu_proc;
请注意,我删除了 result
变量,因为 z
输出可以像
在这种情况下我们可以直接分配。
以上将重新计算 z
当计算中使用任何值时
更改,因为计算 z
的所有参数都包含在
敏感列表。以这种方式进行这种连续计算的风险,
是如果在敏感性列表中忘记了一个或多个参数,
如果忘记的参数发生变化,则不会重新计算 z
的新值。
VHDL-2008 允许自动将所有信号和端口包含在
如果使用 all
,则敏感度列表如下:
alu_proc: process (all) is
最后的评论,然后是一个简单的异步计算过程,比如
对于所示的 ALU,如果生成
z
写成:
z <= (a + b) when (sel = '0') else (a - b);
像上面那样使用并发赋值,可以跳过 敏感度列表,因此有忘记其中一个信号或端口的风险 这是计算的一部分。