作者ksmrt0123 (ksmrt)
看板Electronics
标题Re: [问题] 关於verilog signal&varieble问题
时间Sun Apr 12 22:17:34 2009
推 ksmrt0123:在sequential ckt用nonblocking (<=), 在combinational 04/11 23:47
→ ksmrt0123:ckt用blocking(=)是 coding style, 而且是很好的coding 04/11 23:47
→ ksmrt0123:style, 应该要 follow. 04/11 23:48
※ 引述《zxvc (修行)》之铭言:
: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: 又如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。
这样的写法, 合成出的硬体与verilog不能直接对应,
程式写的是(c==3), 但合成出来的应该是 (c+1==3),
这让写code与读code的人更不容易掌握硬体.
: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: 如果改成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。
以C来想这可能很怪, 但以电路来想这很自然.
而且code写(c==3)合成出来就是(c==3).
=========================================================
支持采纳此coding style 最重要的理由,
如上面的例子所示, 采用此 coding style,
可让 code 与电路更容易对照.
还有很多其它理由. 有篇paper可参考:
http://www.sunburst-design.com/papers/CummingsSNUG2000SJ_NBA.pdf
最後还有一个很实际的理由,
应徵 ic design 的 logic design engineer 时若有考 verilog,
不 follow 此 coding style 的上的机会应该不大...
不知zxvc实验室是否有学长姐进 ic design 写 verilog的,
可问问他们的意见.
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 219.68.71.218
1F:→ acelp:说的好 04/12 23:32
2F:推 zxvc:你那篇解释的很好。combinational circuits用blocking 04/12 23:38
3F:→ zxvc:assignment的理由跟我当初猜测的一样,simulator模拟速度会 04/12 23:39
4F:→ zxvc:比较快。用non-blocking assignment可以model一样的 04/12 23:40
5F:→ zxvc:combinational circuits,但有时候有sensitivy list要多触发 04/12 23:42
6F:→ zxvc:几次结果才会跟用blocking assignment一样。 04/12 23:42
7F:→ zxvc:(Example 19) 04/12 23:44
8F:→ zxvc:看来似乎较多人认为用non-blocking model sequential circuit 04/12 23:45
9F:→ zxvc:较好,我又找不出一个用blocking assignment强大的好理由, 04/12 23:46
10F:→ zxvc:我想以後会follow用non-blocking。而且用blocking assignment 04/12 23:47
11F:→ zxvc:model sequential circuits有一个很大的缺点,我之前有提到 04/12 23:48
12F:→ zxvc:,就是不能写shift registers。 04/12 23:49
13F:→ zxvc:这在你那篇paper有提到(Example 15)。 04/12 23:50
14F:推 zxvc:多谢你的资讯。 04/13 00:05
15F:→ ksmrt0123:感谢回应 :) 04/13 01:35
16F:→ sneak: m 11/11 15:04