VHDL组合逻辑过程---Processes

组合过程

你可以用一个进程来建模VHDL组合逻辑,该进程显式地为信号分配一个新的值。

重要!任何信号都不应隐式保留其当前值,并且进程可以包含本地变量。

内存元素

从组合过程推断出的硬件不涉及任何存储器元件。当一个过程中所有分配的信号总是组合的时,存储元件过程是组合的在过程块内的所有可能路径中显式分配。没有在if或case语句的所有分支中显式分配的信号通常会导致闩锁推理。

重要!如果Vivado合成推断出意外的Latches,请查看HDL源代码中的信号未显式分配。

灵敏度列表

组合过程有一个敏感度列表。灵敏度列表显示在后面的括号内PROCESS关键字。如果事件(值更改)出现在灵敏度列表信号。对于组合过程,此敏感度列表必须包含:

•条件下的所有信号(例如,if和case)。

•任务右侧的所有信号。

缺少信号

敏感度列表中可能缺少信号。如果缺少一个或多个信号敏感度列表:

•综合结果可能与初始设计规范不同。

•Vivado综合发布警告信息。

•Vivado合成将丢失的信号添加到灵敏度列表中。

重要!为了避免模拟过程中出现问题,在HDL源中显式添加所有丢失的信号代码并重新运行合成

变量和信号分配

Vivado合成支持VHDL变量和信号分配。进程可以包含本地变量,这些变量在流程中声明和使用,通常在外部不可见过程

过程示例中的信号分配

Filename: signal_in_process.vhd
-- Signal assignment in a process
-- signal_in_process.vhd
entity signal_in_process is
port(
A, B : in BIT;
S : out BIT
);
end signal_in_process;
architecture archi of signal_in_process is
begin
process(A, B)
begin
S <= '0';
if ((A and B) = '1') then
S <= '1';
end if;
end process;
end archi;
Variable and Signal Assignment in a Process Example
(VHDL)
Filename: variable_in_process.vhd
-- Variable and signal assignment in a process
-- variable_in_process.vhd
--
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity variable_in_process is
port(
A, B : in std_logic_vector(3 downto 0);
ADD_SUB : in std_logic;
S : out std_logic_vector(3 downto 0)
);
end variable_in_process;
architecture archi of variable_in_process is
begin
process(A, B, ADD_SUB)
variable AUX : std_logic_vector(3 downto 0);
begin
if ADD_SUB = '1' then
AUX := A + B;
else
AUX := A - B;
end if;
S <= AUX;
end process;
end archi;

使用if-else语句

if-else和if-elsef-else语句使用TRUE和FALSE条件执行声明。

•如果表达式的计算结果为TRUE,则执行If分支。

•如果表达式的计算结果为FALSE、x或z,则执行else分支。

○ 在if或else分支中执行多个语句的块。

○ 开始和结束关键字是必需的。

○ if-else语句可以嵌套。

Example of if-else Statement (VHDL)
library IEEE;
use IEEE.std_logic_1164.all;
entity mux4 is port (
a, b, c, d : in std_logic_vector (7 downto 0);
sel1, sel2 : in std_logic;
outmux : out std_logic_vector (7 downto 0));
end mux4;
architecture behavior of mux4 is begin
process (a, b, c, d, sel1, sel2)
begin
if (sel1 = '1') then
if (sel2 = '1') then
outmux <= a;
else outmux <= b;
else
end if;
if (sel2 = '1') then outmux <= c;
else
outmux <= d;
end if;
end if;
end process;
end behavior;

使用案例陈述

案例陈述:

•对表达式执行比较,以计算多个并行分支中的一个。

•按照分支的编写顺序对其进行评估。

•执行第一个评估为TRUE的分支。

如果没有一个分支匹配,则case语句将执行默认分支。

Example of case Statement (VHDL)
library IEEE;
use IEEE.std_logic_1164.all;
entity mux4 is port (
a, b, c, d : in std_logic_vector (7 downto 0);
sel : in std_logic_vector (1 downto 0);
outmux : out std_logic_vector (7 downto 0));
end mux4;
architecture behavior of mux4 is begin
process (a, b, c, d, sel)
begin
case sel is
when "00" => outmux <= a;
when "01" => outmux <= b;
when "10" => outmux <= c;
when others => outmux <= d; -- case statement must be complete
end case;
end process;
end behavior;

使用for循环语句

Vivado合成循环语句支持:

•恒定界限

•使用以下运算符停止测试条件:<、<=、>和>=。

•下一步计算符合以下规范之一:

○ var=var+步骤

○ var=var-步长

哪里

-var是循环变量

-步长是一个常数值

•下一步和退出语句

Example of for-loop Statement (VHDL)
Filename: for_loop.vhd
--
-- For-loop example
--
-- for_loop.vhd
--
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
entity for_loop is
port(
a : in std_logic_vector(7 downto 0);
Count : out std_logic_vector(2 downto 0)
);
end for_loop;
architecture behavior of for_loop is
begin
process(a)
variable Count_Aux : std_logic_vector(2 downto 0);
begin
Count_Aux := "000";
for i in a'range loop
if (a(i) = '0') then
Count_Aux := Count_Aux + 1;
end if;
end loop;
Count <= Count_Aux;
end process;
end behavior;
  • 24
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

cckkppll

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值