I have a bidirectional bus and I can read the inputs from it into wires, but I have a hard time do logic with them and assign them back on the BUS as an output, or connecting them into registers so I could work with the values.
All help and response is appreciated.
Jozsó
There are two basic classes of variables in verilog: net
s and reg
s. reg
is used to do calculations in procedural blocks, net
s are used to connect different entities such as module instances or UDPs.
So, they have different functions and different rules and operators. So, wires are connected through module instance ports and/or a continuous assign
operators, which ideally represent wire connections.
The basic rule are
net
value can be used as a rhs of a register expression. So, it can be assigned to a register within a procedural (e.g. always) block.reg
value can be assign to a net in a continuous assign
operator, or in an output port connection.net
cannot be assigned any value within an always blockreg
cannot be assigned with a continuous assignmentThe basic scheme to work around it is the following:
wire --> always block ( reg ) --> assign (wire)
Here is an example:
module top (bus, en);
inout wire bus;
input wire en;
reg tmp;
always @*
tmp = bus;
assign bus = en ? tmp : 1'bz;
endmodule