inout with reg type in verilog

蹲街弑〆低调 提交于 2019-12-13 08:29:55

问题


I have used inout with c but for c to be on the LHS of procedural assignment, it needs to be a reg type variable. Can anyone help me out with this code?

module multiedgeclk(input clk ,[7:0] a,b,d, inout [7:0] c, output reg [7:0]f); 
always @(posedge clk)
c <= a + b;
always @(negedge clk)
f = c & d;
endmodule

回答1:


In verilog inout is the direction of the port. wire or reg is the type of the signal. If you want to drive a bi-directional port, it should be declare as inout wire or inout and drive it with enable signal Here is a example of bi-directional port.

module ABC( inout [7:0] c );
reg [7:0] c_out;
reg out_en;
assign c = out_en ? 8'hz : c_out; 
/* something here
... 
*/
endmodule



回答2:


An inout port cannot be procedurally assigned. There is nothing to indicate how long to hold that value on the port. This is the problem for any wire. But wires have a strength mechanism for multiple continuous drivers, highest strength wins. So you can use a continuous assignment to selectively drive a value or turn it off by driving a z value.

wire c; reg c_reg;

assign c = c_reg;

Now you can procedurally assign c_reg to a value or 8'bz

See my article for more info about wires and reg types.



来源:https://stackoverflow.com/questions/50821122/inout-with-reg-type-in-verilog

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!