Re: [問題] 關於verilog signal&varieble問題

看板Electronics作者 (修行)時間17年前 (2009/04/11 21:24), 編輯推噓4(402)
留言6則, 4人參與, 最新討論串3/10 (看更多)
※ 引述《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)

04/11 22:37, , 1F
真的了解很多~很清楚
04/11 22:37, 1F

04/11 23:47, , 2F
在sequential ckt用nonblocking (<=), 在combinational
04/11 23:47, 2F

04/11 23:47, , 3F
ckt用blocking(=)是 coding style, 而且是很好的coding
04/11 23:47, 3F

04/11 23:48, , 4F
style, 應該要 follow.
04/11 23:48, 4F

04/11 23:51, , 5F
感謝指導^^
04/11 23:51, 5F

04/12 12:45, , 6F
推c=3 c=4那一段 初學者這邊很容易混淆
04/12 12:45, 6F
文章代碼(AID): #19u9dw8Z (Electronics)
討論串 (同標題文章)
本文引述了以下文章的的內容:
以下文章回應了本文 (最舊先):
完整討論串 (本文為第 3 之 10 篇):
文章代碼(AID): #19u9dw8Z (Electronics)