作者zxvc (修行)
看板Electronics
标题Re: [问题] 关於verilog signal&varieble问题
时间Sat Apr 11 21:24:08 2009
※ 引述《sasako (只想把你留在心中)》之铭言:
: ※ 引述《n052111089 (QQ)》之铭言:
: : a = b + c; varieble
: : a <= b + c; signal
: : 我看书上又提到seqential statemment跟concurrent statement
: : 然後又写得很矛盾= =
: : 让我搞不清楚哪一个是哪一个了..........
: : 烦请大大解惑
: 一个用法是用在sequential circuit的always中...
: ex:always(posedge clk or negedge n_rst)
: 另一个是用在combinational circuit的always中...
: ex:always(*)
non-blocking与blocking不是这样分的。
都可以用来model sequential或combinational circuits。
例如:
module Test(d, c, e, f, b, a);
output reg d, c;
input e, f, b, a;
always@(*)
if(a == 1 & b == 1)
c = 1;
else
c = 0;
always@(*)
if(e == 1 & f == 1)
d <= 1;
else
d <= 0;
endmodule
c跟d都会合出AND gates。
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
又如sequential circuit:
module Test(c, d, Clock , Reset1);
output reg [2:0] c;
output reg d;
input Clock, Reset1;
always@(posedge Clock)
if(Reset1)
c = 0;
else
begin
c = c+1;
if(c == 3)
d = 1;
else
d = 0;
end
endmodule
这个用blocking的写法会造成c = 3的那个(clock) cycle,d = 1。
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
如果改成non-blocking的写法:
module Test(c, d, Clock , Reset1);
output reg [2:0] c;
output reg d;
input Clock, Reset1;
always@(posedge Clock)
if(Reset1)
c <= 0;
else
begin
c <= c+1;
if(c == 3)
d <= 1;
else
d <= 0;
end
endmodule
会造成c = 4的那个cycle,d = 1。
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
但请不要混用:
module Test(c, d, Clock , Reset1);
output reg [2:0] c;
output reg d;
input Clock, Reset1;
always@(posedge Clock)
if(Reset1)
c <= 0;
else
c = c+1;
endmodule
这大多数的合成器是合不出来的(至少我还没看过有)。
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
这种混用是OK的(我确定ISE OK),因为同一变数用一致的assignment。
module Test(c, d, Clock , Reset1);
output reg [2:0] c;
output reg d;
input Clock, Reset1;
always@(posedge Clock)
if(Reset1)
c <= 0;
else
begin
c <= c+1;
if(c == 3)
d = 1;
else
d = 0;
end
endmodule
--
西方三圣:
http://p8.p.pixnet.net/albums/userpics/8/3/553683/1193661731.jpg
《佛说阿弥陀经》
http://web.cc.ncu.edu.tw/~93501025/amtf.doc
十一面观音咒:
http://file.buda.idv.tw/music/DBZFY04.mp3
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 122.126.142.97
※ 编辑: zxvc 来自: 122.126.142.97 (04/11 21:28)
1F:推 papa2958:真的了解很多~很清楚 04/11 22:37
2F:推 ksmrt0123:在sequential ckt用nonblocking (<=), 在combinational 04/11 23:47
3F:→ ksmrt0123:ckt用blocking(=)是 coding style, 而且是很好的coding 04/11 23:47
4F:→ ksmrt0123:style, 应该要 follow. 04/11 23:48
5F:推 n052111089:感谢指导^^ 04/11 23:51
6F:推 rlpolo123:推c=3 c=4那一段 初学者这边很容易混淆 04/12 12:45