当前位置:文档之家› VHDL与Verilog HDL的对比以及三中建模方式

VHDL与Verilog HDL的对比以及三中建模方式

本文将以二选一多路器为例,分别用Verilog HDL 和VHDL 描述电路。

二选一多路器的门级结构:HDL 建模时,除了可以用不同层次的基本描述方式建模外,还可以根据七对信号描述方式的不同划分为三种:数据流建模,行为建模,结构化建模;在模块中对信号资源分配(或组合逻辑的连接)的描述称为数据流描述或数据流建模。

在模块中对信号的行为进行描述,称为行为描述或行为建模。

将特定功能的模块组织成更大的模块,其描述方式称为结构化描述或结构化建模。

下面是用VHDL 描述的二选一多路器,采用数据流建模方式。

library ieee;use ieee.std_logic_1164.all;entity mux_dataflow is port (a : in std_logic;b : in std_logic;sel : in std_logic; c : out std_logic);end mux_dataflow;architecture dataflow of mux_dataflow is beginA 图2 二选一多路器的门级结构(国外常用符号) VHDL 所用的库和标准 实体和端口说明,加粗的是关键字 结构体,说明建模方式,加粗是关键字端口声明和类属声明c<=(a and not sel) or (b and sel);end dataflow;●下面是用Verilog HDL描述的二选一多路器,采用数据流建模方式。

module mux_dataflow (a,b,sel,c);input a,b,sel;output c;wire c;assign c= (a & ~sel) | (b & sel);endmodule●下面是用VHDL的行为建模方式描述二选一多路器。

library ieee;use ieee.std_logic_1164.all;entity mux_behaviour isport( a : in std_logic;b : in std_logic;sel : in std_logic;c : out std_logic);end mux_behaviour;architecture behaviour of mux_behaviour isbeginmux_process: process (a,b,sel)beginc<=(a and not sel) or (b and sel);end process ;end behaviour;●下面是用Verilog HDL描述的二选一多路器,采用行为建模方式。

module mux_behaviour(a,b,sel,c);input a,b,sel;output c;reg c;always @(a,b,sel)beginc<= (a& ~sel) |(b&sel);endendmodule虽然表达式几乎相同,但是他们有本质的不同。

数据流建模方式侧重于信号怎么做。

行为建模方式侧重于信号做什么。

下面是用VHDL描述的二选一多路器,采用结构体建模方式。

library ieee;use ieee.std_logic_1164.all;entity mux_structure isport( a : in std_logic;b : in std_logic;sel : in std_logic;c : out std_logic);end mux_structure;architecture structure of mux_structure iscomponent and_gateport( a : in std_logic;b : in std_logic;c : out std_logic);end component;component or_gateport( a : in std_logic;b : in std_logic;c : out std_logic);end component;component inverterport( a : in std_logic;c : out std_logic);end component;signal x0,x1,x2 : std_logic;结构体信号声明beginu0 : inverter port map(a => sel, c => x0);u1 : and_gate port map(a => b, b => sel, c => x1);u2 : and_gate port map(a => x0, b => a, c => x2);u3 : or_gate port map(a => x1, b => x2, c => c);end structure;---------------------and_gate-----------------------library ieee;use ieee.std_logic_1164.all;entity and_gate isport( a : in std_logic;b : in std_logic;c : out std_logic);end and_gate;architecture dataflow of and_gate isbeginc<=a and b;end dataflow;----------------------or_gate------------------------library ieee;use ieee.std_logic_1164.all;entity or_gate isport( a : in std_logic;b : in std_logic;c : out std_logic);end or_gate;architecture dataflow of or_gate isbeginc<= a or b;end dataflow;----------------------inverter----------------------library ieee;use ieee.std_logic_1164.all;entity inverter isport( a : in std_logic;c : out std_logic);end inverter;architecture dataflow of inverter isbeginc<= not a;end dataflow;下面是用Verilog HDL描述的二选一多路器,采用结构体建模方式。

module mux_structure(a,b,sel,c);input a,b,sel;output c;wire x0,x1,x2;and_gate a1(.a(a),.b(x0),.c(x1));and_gate a2(.a(sel),.b(b),.c(x2));实例化模块or_gate o1(.a(x1),.b(x2),.c(c));inverter i1(.a(sel),.c(x0));endmodulemodule and_gate(a,b,c);//双输入与门模型input a,b;output c;and(c,a,b);endmodulemodule or_gate(a,b,c);//双输入或门模型input a,b;output c;or (c,a,b);endmodulemodule inverter(a,c);//双输入非门模型input a;output c;reg c;always @(a) beginc<=~a;endendmodule由下图3和下图4可以看出结构化建模的不同之处原语 原语行为描述 图3 由Verilog HDL 行为建模综合出的电路模型图4 由Verilog HDL 结构化建模综合出的电路模型三个种VERILOG 建模方式共同的测试平台。

`timescale 1ns/1nsmodule tb;reg a,b,sel;wire c;mux_behaviour m1(.a(a),.b(b),.sel(sel),.c(c));initialbeginsel=0; a=0; b=0;foreverbegin#0 sel=0; a=0; b=0;#10 sel=0; a=1; b=0;#10 sel=0; a=0; b=1;#10 sel=0; a=1; b=1;#10 sel=1; a=0; b=0;#10 sel=1; a=1; b=0;#10 sel=1; a=0; b=1;#10 sel=1; a=1; b=1;#10;endendendmodule三种VHDL建模方式共同的测试平台。

library ieee;use ieee.std_logic_1164.all;entity mux_tb isend mux_tb;architecture behaviour of mux_tb iscomponent mux_behaviour isport(a : in std_logic;b : in std_logic;sel : in std_logic;c : out std_logic);end component;signal a : std_logic:= '0';signal b : std_logic:= '0';signal sel : std_logic:= '0';signal c : std_logic;beginu1: mux_behaviour port map( a => a,b => b,sel => sel,c => c );test_process: processbeginwait for 0 ns ; sel<='0' ; a<='0' ; b<='0';wait for 10 ns ; sel<='0' ; a<='0' ; b<='1';wait for 10 ns ; sel<='0' ; a<='1' ; b<='0';wait for 10 ns ; sel<='0' ; a<='1' ; b<='1';wait for 10 ns ; sel<='1' ; a<='0' ; b<='0';wait for 10 ns ; sel<='1' ; a<='0' ; b<='1';wait for 10 ns ; sel<='1' ; a<='1' ; b<='0';wait for 10 ns ; sel<='1' ; a<='1' ; b<='1';wait for 10 ns ;end process;end behaviour;图5 三种建模方式的关系在一个工程中,这三种建模方式可以灵活使用。

相关主题