VHDLVerilogmixedsimulation.docx

上传人:b****5 文档编号:3268721 上传时间:2022-11-21 格式:DOCX 页数:12 大小:116.90KB
下载 相关 举报
VHDLVerilogmixedsimulation.docx_第1页
第1页 / 共12页
VHDLVerilogmixedsimulation.docx_第2页
第2页 / 共12页
VHDLVerilogmixedsimulation.docx_第3页
第3页 / 共12页
VHDLVerilogmixedsimulation.docx_第4页
第4页 / 共12页
VHDLVerilogmixedsimulation.docx_第5页
第5页 / 共12页
点击查看更多>>
下载资源
资源描述

VHDLVerilogmixedsimulation.docx

《VHDLVerilogmixedsimulation.docx》由会员分享,可在线阅读,更多相关《VHDLVerilogmixedsimulation.docx(12页珍藏版)》请在冰豆网上搜索。

VHDLVerilogmixedsimulation.docx

VHDLVerilogmixedsimulation

1.VHDL调用Verilog模块

VHDL调用Verilog模块的时候,要在实例化模块前,加上“verilogmodelGM:

VHDL调用verlog

verilogmodule:

modulem(a,b,c);

inputa,b;

outputc;

...

endmodule

调用如下:

compoentm

port(

                a:

instd_logic;

                b:

in  std_logic;

                c:

outstd_logic

              );

endcompoent

begin

verilogmodelGE:

m

portmap

(...

...

end

在VHDL里调用Verilog的话:

例化+映射

在Verilog里调用VHDL的话:

只要映射

2.一个VHDLtestbench的实例

以下为文件名为testbench.vhd的文件,

libraryIEEE;

useIEEE.std_logic_1164.all;

entitytestbenchis

endentitytestbench;

architecturetest_regoftestbenchis

componentdffis

PORT(d,clk,rst:

INSTD_LOGIC;

q:

OUTSTD_LOGIC);

endcomponent;

signalclock:

std_logic:

='0';

signald,rst:

STD_LOGIC;

signalq:

STD_LOGIC;

constantClockPeriod:

TIME:

=50ns;

begin

UUT:

dffportmap(d=>d,clk=>clock,rst=>rst,q=>q);

generate_clock:

PROCESS(clock)

BEGIN--process

clock<=NOTclockAFTERClockPeriod/2;

ENDPROCESS;

processbegin

d<='0';

rst<='1';

waitfor100ns;

d<='1';

waitfor50ns;

rst<='0';

waitfor50ns;

d<='0';

waitfor100ns;

d<='1';

waitfor50ns;

rst<='1';

wait;

endprocess;

endarchitecturetest_reg;

以下为文件为的异步dff.vhd文件:

LIBRARYieee;

USEieee.std_logic_1164.ALL;

ENTITYdffIS

PORT(d,clk,rst:

INSTD_LOGIC;

q:

OUTSTD_LOGIC);

ENDdff;

ARCHITECTUREbehaviorOFdffIS

BEGIN

PROCESS(rst,clk)

BEGIN

IF(rst='1')THEN

q<='0';

ELSIF(clk'EVENTANDclk='1')THEN

q<=d;

ENDIF;

ENDPROCESS;

ENDbehavior;

以上两个文件放在同一个project下,仿真结果如下图所示:

以下为文件为的同步dff.vhd文件:

LIBRARYieee;

USEieee.std_logic_1164.ALL;

ENTITYdffIS

PORT(d,clk,rst:

INSTD_LOGIC;

q:

OUTSTD_LOGIC);

ENDdff;

ARCHITECTUREbehaviorOFdffIS

BEGIN

PROCESS(rst,clk)

BEGIN

IF(clk'EVENTANDclk='1'')THEN

If(rst=’1’)q<='0';

Elseq<=d;endif;

ENDIF;

ENDPROCESS;

ENDbehavior;

3.VHDL描述D-latch

libraryIEEE;

useieee.numeric_bit.all;

entityD_latchis

port(D,CLK:

inbit;

Q,:

outbit);

endD_latch;

architectureD_latch_insideofD_latchis

begin

process(D,CLK)

begin

ifCLK=‘1’then

Q<=D;

endif;

endprocess;

endD_latch_inside;

4.在时钟上升分支中存在选择语句的情况:

LIBRARYieee;

USEieee.std_logic_1164.ALL;

ENTITYdffIS

PORT(d,clk,rst,cs:

INSTD_LOGIC;

q:

OUTSTD_LOGIC);

ENDdff;

ARCHITECTUREbehaviorOFdffIS

signaltemp:

STD_LOGIC;

BEGIN

PROCESS(rst,clk)

BEGIN

IF(rst='1')THEN

temp<='0';

ELSIF(clk'EVENTANDclk='1')THEN

if(cs='1')thentemp<=d;

elsetemp<=temp;endif;

ENDIF;

q<=temp;

ENDPROCESS;

ENDbehavior;

原理图如下:

实现的器件图如下:

由上面两图可见,在时钟上升沿中出现的选择分支的选择条件cs成为触发器的使能端。

 

5.VHDL描述D-flip-flop

libraryIEEE;

useieee.numeric_bit.all;

entityD_latchis

port(D,CLK:

inbit;

Q:

outbit);

endD_latch;

architectureD_latch_insideofD_latchis

begin

process(D,CLK)

begin

if(clk'EVENTANDCLK='1')then

--ifCLK='1'then

Q<=D;

endif;

endprocess;

endD_latch_inside;

6.看synplify报告文件

怎么样看懂综合,布线之后的各种报告!

我觉得不是所有的报告都是非看不可的。

根据我的工作经验,只有一部分报告需要仔细关注,然后就是多关注一些Error和Warning信息。

但是大部分warning都无需特别注意。

1.综合完成后应该看得报告:

*.srr这是综合的log文件。

该文件主要搜索“slack”和“latch”即可。

看看有哪些路径的slack是负的,那就意味着该路径需要进一步优化,以达到时序要求。

如果发现综合出来latch,也要判断一下这是否是自己需要的。

作为一般的同步时序电路,latch是要避免的。

2.*.ncf这是P&Rconstraints文件。

是synplify自动生成的供不同techniche(Xilinx,altera...)等器件直接调用的约束文件。

我们通常以ncf为基础,然后做适当修改,保存为UCF文件即可

其他文件我一般不看,而且迄今为止,没有遇到什么问题。

当然遇到具体问题的时候,这些文件也可以作为辅助的资料帮助进一步了解综合后的结果。

对于synplify生成的文件,我给他归类如下

--synthesisresult文件

6srs:

综合后的schematic类型的网表文件,是RTL的结构视图

*.srd:

是综合后的data类型的网表文件。

看不懂:

5*.srm:

是综合后的mapped到具体techniche的网表文件。

是个机构视图。

*.srr:

是综合后的report文件,所有的error,warning,timing都在这里了。

5srr*:

这类文件有三个,格式不同内容一致。

是关于area综合结果的report。

--*.edf:

edif格式的网表。

4ncf:

tech相关的约束文件。

我估计是netlistconstraintfile之类名称的缩写。

--*.tlg:

记录了整个综合过程的具体操作。

比如做了何种优化,去掉了哪个比特之类。

PAR应该看得报告。

map报告,看看map结果是否和自己预测的一致,比如useioff是否起了作用,那些iff/off是不是map出来了。

postparstatictiming报告,看看时序是否meet,如果没有,哪些路径出了问题,都要确认。

可以拷贝*.twx出来,然后用ise的accessory中的timinganalyzer仔细分析。

也可以在process窗口中implementatin-->PAR-->PostPARstatictiming-->analyze**timing来看,两者一样。

其他的待续。

 

IPAR应该看得报告。

map报告,看看map结果是否和自己预测的一致,比如useioff是否起了作用,那些iff/off是不是map出来了。

postparstatictiming报告,看看时序是否meet,如果没有,哪些路径出了问题,都要确认。

可以拷贝*.twx出来,然后用ise的accessory中的timinganalyzer仔细分析。

也可以在process窗口中implementatin-->PAR-->PostPARstatictiming-->analyze**timing来看,两者一样。

 

7.VHDL输出数据到指定文件

Example1:

usestd.textio.all;

entityiois

endio;

architecturegedragofiois

begin

process

fileOUTFILE:

textisout"C:

\dataout.txt";

variabletemp:

line;

begin

forjin1to9loop

write(temp,j);

writeline(OUTFILE,temp);

endloop;

wait;

endprocess;

endgedrag;

example2

--hello_world.vhdlJustoutputtothescreen

--ThisshouldbeindependentofwhoseVHDLyouuse

--WhenusingsomevendorsGUI,youhavealearningcurve

--UsingportableVHDL,itwillrunonallvendors

--withimplementationsconformingtoIEEEStd.1076-1993

 

entityhello_worldis--testbench(toplevellike"main")

endentityhello_world;

librarySTD;--youdon'tneedSTD,itisautomatic

libraryIEEE;--butmayneedotherlibraries

useIEEE.std_logic_1164.all;--basiclogictypes

useSTD.textio.all;--basicI/O

useIEEE.std_logic_textio.all;--I/Oforlogictypes

architecturetestofhello_worldis--wheredeclarationsareplaced

subtypeword_32isstd_logic_vector(31downto0);--simplename

signalfour_32:

word_32:

=x"00000004";--justfourinhex

signalcounter:

integer:

=1;--initializedcounter

begin--whereparallelcodeisplaced

my_print:

processis--aprocessisparallel

variablemy_line:

line;--type'line'comesfromtextio

begin

write(my_line,string'("HelloWorld"));--formatting

writeline(output,my_line);--writeto"output"

write(my_line,string'("four_32="));--formatting

hwrite(my_line,four_32);--formattypestd_logic_vectorashex

write(my_line,string'("counter="));

write(my_line,counter);--format'counter'asinteger

writeline(output,my_line);--writetodisplay

write(my_line,string'("attime"));

write(my_line,now);--formattime

writeline(output,my_line);--writetodisplay

wait;

endprocessmy_print;

endarchitecturetest;

--compile/analyzethisfile,thensimulate

--theoutputonthescreenshouldcontainthefollowinglines(without"--")

--HelloWorld

--four_32=00000004counter=1attime0NS

run10000000

#HelloWorld

#four_32=00000004counter=1

#attime0ns

Thewritefunctionisusedtoappendtextinformationattheendofalinevariablewhichisemptywhenthesimulatorisinitialized.Thefunctiontakestwoarguments,thefirstisthenameofthelinetoappendto,andthesecondistheinformationtobeappended.Intheexample,sissetto"Counteroverflow-",andthenthecurrentvalueofcntisconvertedtotextandaddedtotheendofthat.Thewritelinefunctionoutputsthecurrentvalueofalinetothemonitor,andemptiesthelineforre-use.Thefirstargumentofthewritelinefunctionjustindicatesthatthetextshouldbeoutputtothescreen.IfMAX_COUNTwereaconstantequalto15andmorethan15risingedgesoccuronthesignalx,thenthemessagewouldbeprintedonthescreen.

 

8.一个VHDL中的时钟信号实例

libraryIEEE;

useIEEE.std_logic_1164.all;

entitytestbenchis

endentitytestbench;

architecturetest_regoftestbenchis

componentand2vhdlis

PORT(w11:

INSTD_LOGIC;

w2:

INSTD_LOGIC;

wvec:

OUTSTD_LOGIC_VECTOR(3DOWNTO0));

endcomponent;

signalclock:

std_logic:

='0';

signalw1,w2:

std_logic;

signalwvec:

std_logic_vector(3downto0);

constantClockPeriod:

TIME:

=50ns;

begin

UUT:

and2vhdlportmap(w11=>w1,w2=>w2,wvec=>wvec);

generate_clock:

PROCESS(clock)

BEGIN--process

clock<=NOTclockAFTERClockPeriod/2;

ENDPROCESS;

processbegin

--clock<='1';

w1<='1';

w2<='0';

waitfor200ns;

w1<='1';

w2<='1';

waitfor200ns;

endprocess;

endarchitecturetest_reg;

 

LIBRARYieee;

USEieee.std_logic_1164.ALL;

ENTITYand2vhdlIS

PORT(w11:

INSTD_LOGIC;

w2:

INSTD_LOGIC;

wvec:

OUTSTD_LOGIC_VECTOR(3DOWNTO0));

ENDand2vhdl;

ARCHITECTUREmyand2OFand2vhdlIS

BEGIN

wvec(0)<=w11ANDw2;

wvec

(1)<=w11ORw2;

wvec

(2)<=w11XORw2;

wvec(3)<=w11XNORw2;

ENDmyand2;

 

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 小学教育 > 英语

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1