VHDL并行语句

相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
generic(len:integer); port(a:in std_logic_vector(len-1 downto 0);
b:out std_logic_vector(len-1 downto 0));
end new_not; architecture rtl of new_not is
begin
end if;
c<=temp; end maximum;
signal tmp1,tmp2:
std_logic_vector(7 downto 0); begin maximum(in1,in2,tmp1); maximum(tmp1,in3,tmp2); q<=tmp2; end rtl;
16
17
例 一个列出选择条件为不同取值范围的4选1多路选择器,当不 满足条件时,输出呈高阻态。 ... WITH selt SELECT muxout <= a WHEN 0|1 , -- 0或1 b WHEN 2 TO 5 , -- 2或3,或4或5 c WHEN 6 , d WHEN 7 , 'Z' WHEN OTHERS ; ...
7
signal e,f:std_logic;
u2:new_and2 port map(c,d,f);
u3:new_inv port map(e,f,z);
end rtl;
a u1:new_and2 port map(a,b,e);
u2:new_and2 port map(c,d,f);
u3:new_inv port map(e,f,z);
entity new_max is port(in1:in std_logic_vector(7 downto 0); in2:in std_logic_vector(7 downto 0); in3:in std_logic_vector(7 downto 0); q:out std_logic_vector(7 downto 0)); end new_max; architecture rtl of new_max is procedure maximum( signal a,b:in std_logic_vector; signal c:out std_logic_vector)is variable temp:std_logic_vector(a'range);
11
6.4.3 选择信号赋值语句 WITH 选择表达式 SELECT 赋值目标信号 <=表达式 WHEN 选择值, 表达式 WHEN 选择值, ... 表达式 WHEN 选择值;
12
例 根据a、b、c 3个位构成的不同指令码,由data1和data2输入的两个值将进行 不同逻辑操作 LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.ALL; USE IEEE.STD_LOGIC_UNSIGNED.ALL; ENTITY decoder IS PORT ( a, b, c : IN STD_LOGIC; data1,data2 : IN STD_LOGIC; dataout : OUT STD_LOGIC ); END decoder; ARCHITECTURE concunt OF decoder IS SIGNAL instruction : STD_LOGIC_VECTOR(2 DOWNTO 0) ; BEGIN instruction <= c & b & a ; WITH instruction SELECT dataout <= data1 AND data2 WHEN "000" , data1 OR data2 WHEN "001" , data1 NAND data2 WHEN "010" , data1 NOR data2 WHEN "011" , data1 XOR data2 WHEN "100" , data1 XNOR data2 WHEN "101" , 'Z' WHEN OTHERS ; 13 END concunt ;
b c d
&
e z
&
f
可以写成
u1:new_and2 port map(a=>a,b=>b,c=>e);
u2:new_and2 port map(a=>c,b=>d,c=>f);
u3:new_inv port map(e,f,c=>z);
component new_and2 port(a,b:in std_logic;
第六章 VHDL并行语句
1
结构体中的并行语句主要有七种: 1、并行信号赋值语句(Concurrent Signal Assignments)。 2、进程语句(Process Statements)。 3、块语句(Block Statements)。 4、条件信号赋值语句(Selected Signal Assignments)。 5、元件例化语句(Component Instantiations),其中包括类属配置语句。 6、生成语句(Generate Statements)。 7、并行过程调用语句(Concurrent Procedure Calls)。
14
6.5 并行过程调用语句
并行过程调用语句可以作为一个并行语句直接程序在结构体中,或块语句中。 并行过程调用语句的功能等效于包含了同一个过程调用语句的进程。调用格
式与顺序调用语句相同:
过程名(关联参量名);
例 编写一个程序,完成如下功能。
பைடு நூலகம்
输入三个矢量,in1,in2,in3,均为8位标准逻辑位矢量。找出最大的矢量,通过8位 标准逻辑位矢量q输出。
end rtl;
19
6.6 类属映射语句
类属映射语句可用于设计从外部端口改变元件内部参数或结构规模的元件, 这些元件在例化中特别方便。 GENERIC MAP(类属表); 例 输入矢量长度可变的元件及其调用
20
library ieee;
use ieee.std_logic_1164.all;
entity new_not is
18
作如下修改后,结果也正确 architecture rtl of new_max is procedure maximum( a,b:in std_logic_vector;
-- signal a,b:in std_logic_vector;
signal c:out std_logic_vector)is variable temp:std_logic_vector(a'range); …… signal tmp1,tmp2:std_logic_vector(7 downto 0); begin maximum(in1,in2,tmp1); maximum(tmp1,in3,tmp2); q<=tmp2;
9
6.4.2 条件信号赋值语句
赋值目标 <= 表达式 WHEN 赋值条件 ELSE 表达式 WHEN 赋值条件 ELSE ... 表达式 ;
10
例 四选一电路 entity mux4 is port(i0,i1,i2,i3,a,b: in std_logic; q: out std_logic); end mux4; architecture rtl of mux4 is signal sel:std_logic_vector(1 downto 0); begin sel<=b & a; q<=i0 when sel="00" else i1 when sel="01" else i2 when sel="10" else i3 when sel="11" else 'X'; end rtl;
要求编写一个过程,该过程可以完成两个矢量的比较,然后调用该过程完成任务。 (根据实际情况决定调用该过程的次数。)
15
library ieee; use ieee.std_logic_1164.all;
begin if(a>b) then temp:=a; else temp:=b;
use ieee.std_logic_unsigned.all;
component new_inv port(a,b:in std_logic;
c:out std_logic);
end component;
c:out std_logic);
end component;
8
6.4 并行信号赋值语句
6.4.1 简单信号赋值语句
赋值目标 = 表达式
以下结构体中的五条信号赋值语句的执行是并行发生的。 ARCHITECTURE curt OF bc1 IS SIGNAL s1, e, f, g, h : STD_LOGIC ; BEGIN output1 <= a AND b ; output2 <= c + d ; g <= e OR f ; h <= e XOR f ; s1 <= g ; END ARCHITECTURE curt;
a
b c d & e z & f
5
library ieee;
use ieee.std_logic_1164.all;
library ieee; use ieee.std_logic_1164.all;
entity new_and2 is port(a,b:in std_logic; c:out std_logic); end new_and2; architecture rtl of new_and2 is begin c<=a and b;
entity new_inv is port(a,b:in std_logic; c:out std_logic); end new_inv; architecture rtl of new_inv is begin c<=not (a and b);
end rtl;
end rtl;
6
library ieee;
PROCEDURE 过程名 ([对象种类] 参数名[,参数名…] : [方式] 类型; [对象种类] 参数名[,参数名…] : [方式] 类型;
……
); 方式(课本中称为 流向模式)为 in out 和 inout 三种 对象种类为constant variable signal 三种 variable variable signal ,如果未指定,默认为 signal ,如果未指定,默认为 方式 in 对应的对象种类可为 constant constant 。 方式 out 和 inout 对应的的对象种类可为 variable 。 variable和signal型的对象均可代入 constant
ARCHITECTURE 说明语句
结构体名
OF
实体名
IS
BEGIN
并行语句 END ARCHITECTURE 结构体名
2
6.1
进程语句
6.2
块语句
3
6.3 元件例化语句
1在结构体中用元件说明语句component说明要使用的元件
2用元件例化语句把元件端口信号映射成高层电路中的信号(port map)
元件定义语句
COMPONENT 元件名 IS GENERIC (类属表); PORT (端口名表); END COMPONENT 文件名;
元件例化语句
-- 元件定义语句
例化名 :元件名 PORT MAP( -- 元件例化语句 [端口名 =>] 连接端口名,...) ;
4
例 实现如图所示的电路,要求与门和非门全部单独编写程序
component new_inv port(a,b:in std_logic; c:out std_logic);
use ieee.std_logic_1164.all;
entity test_comp is
end component;
port(a,b,c,d:in std_logic;
z:out std_logic); end test_comp; architecture rtl of test_comp is begin u1:new_and2 port map(a,b,e); component new_and2 port(a,b:in std_logic; c:out std_logic); end component;
b<=not a; end;
21
library ieee; use ieee.std_logic_1164.all; begin u1:new_not generic map(4) entity test_gene is port (a: in std_logic_vector(3 downto 0); z: out std_logic_vector(3 downto 0)); end test_gene; architecture rtl of component new_not generic(len:integer); test_gene is end rtl;
相关文档
最新文档