您的位置 首页 传感器

深入分析verilog堵塞和非堵塞赋值

深入分析verilog阻塞和非阻塞赋值-学verilog 一个月了,在开发板上面写了很多代码,但是始终对一些问题理解的不够透彻,这里我们来写几个例子仿真出阻塞和非阻塞的区别

原文链接:学verilog 一个月了,在开发板上面写了许多代码,可是一向对一些问题了解的不行透彻,这儿咱们来写几个比如仿真出堵塞和非堵塞的差异,咱们先上代码module LED ( CLK, RSTn, scan, flag , c, ,one,two,three,four); input CLK; input RSTn; input scan; output flag,c; output [3:0] one,two,three,four;/***********************************************************/ reg F1,F2; reg a,b; reg [3:0] one,two,three,four;/********************信号传递之间的非堵塞赋值***************************************/ always @ ( posedge CLK or negedge RSTn ) // if( !RSTn ) begin F1 = 1b1; F2 = 1b1; end elsebeginF1 = scan;F2 = F1; end/*******************信号传递之间的堵塞赋值****************************************/ always @ ( posedge CLK or negedge RSTn ) // if( !RSTn ) begin a = 1b1; b = 1b1; end elsebegina = scan;b = a; end/******************数据加 非堵塞赋值 先判别后计数*****************************************/always @ ( posedge CLK or negedge RSTn ) //one =if( !RSTn )beginone=0;endelsebeginif(one==14)one=0;else one=one+1;end/***************数据加 非堵塞赋值 先计数后判别********************************************/ always @ ( posedge CLK or negedge RSTn ) // two=if( !RSTn )begintwo=0;endelsebegintwo=two+1;if(two==14)two=0;end/**************数据加 堵塞赋值 先判别后计数*********************************************/always @ ( posedge CLK or negedge RSTn ) //three =if( !RSTn )beginthree=0;endelsebeginif(three==14)three=0;elsethree=three+1;end/*************数据加 堵塞赋值 先计数后判别**********************************************/always @ ( posedge CLK or negedge RSTn ) //four =if( !RSTn )beginfour=0;endelsebeginfour=four+1;if(four==14)four=0;end/****************信号之间传递***********************/assign flag = F2 !F1;assign c = b !a;/***************************************/endmodule 2、我运用modesim 仿真,下面为我的 test bench`TImescale 1 ps/ 1 psmodule LED_vlg_tst();// constants// general purpose registersreg eachvec;// test vector input registersreg CLK;reg RSTn;reg scan;// wireswire c;wire flag;wire [3:0] four;wire [3:0] one;wire [3:0] three;wire [3:0] two;// assign statements (if any)LED i1 (// port map – connecTIon between master ports and signals/registers.CLK(CLK),.RSTn(RSTn),.c(c),.flag(flag),.four(four),.one(one),.scan(scan),.three(three),.two(two));/*iniTIalbegin// code that executes only once// insert code here –> begin// –> end$display(Running testbench);endalways// opTIonal sensitivity list// @(event1 or event2 or …. eventn)begin// code executes for every event on sensitivity list// insert code here –> begin@eachvec;// –> endendendmodule*/initial beginCLK = 0;forever#10 CLK = ~CLK;endinitial beginscan = 0;forever#100 scan = ~scan;endinitial beginRSTn = 0;#1000 RSTn = 1;#1000;#1000;#1000;#1000;#1000;#1000;#1000;#1000;$stop;endendmodule首要便是初始化一个CLK 和scan的信号,然后便是初始化一下复位,最终便是设置仿真时刻,这样modesim 就不会一向处于仿真状况,耗费资源,也能够便利仿真。其间quartus 与modesim 相互调用调试,能够重视我的博客,这儿我就不详细讲解了!3、modesim 波形图我们注意到红线框内的数据改变,就能很清楚的了解 堵塞与非堵塞了!微观剖析 堵塞与非堵塞1、上代码,详细调查,a,b,c与F1,F2,flage 的改变module LED( CLK, RSTn, scan, flag , a,b,c,F1,F2,); input CLK; input RSTn; input scan; output flag,a,b,c; output F1,F2;/***********************************************************/ reg F1,F2; reg a,b;/***********************************************************/ always @ ( posedge CLK or negedge RSTn ) // if( !RSTn ) begin F1 = 1b1; F2 = 1b1; end elsebeginF1 = scan;F2 = F1; end/***********************************************************/ always @ ( posedge CLK or negedge RSTn ) // if( !RSTn ) begin a = 1b1; b = 1b1; end elsebegina = scan;b = a; end/***********************************************************/assign flag = F2 !F1;assign c = b !a;/***************************************/endmodule 代码寓意就不讲解了2、test bench 代码,与上面相同,这儿不重复了3、上图 看波形

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/yingyong/chuanganqi/179632.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部