I found a verilog implementation of a mux using tri-state buffers in the document UMD Lab Tutorial on Verilog (I'm not a student, graduated 2 years ago :))
module mux(input wire [7:0] in0,
input wire [7:0] in1,
input wire [7:0] in2,
input wire [7:0] in3,
input wire [1:0] sel,
output reg [7:0] out)
assign out = (sel == 2'b00) ? in0 : 8'bZ ,
out = (sel == 2'b01) ? in1 : 8'bZ ,
out = (sel == 2'b10) ? in2 : 8'bZ ,
out = (sel == 2'b11) ? in3 : 8'bZ ;
endmodule
When I tried this with SystemVerilog, I got the multiple driver error.
Can someone show me alternate code? I know using case statement will simplify things. I'm just wondering if its possible with tri-state and if we can physically implement mux with tri-state buffers on an Fpga platform.
1 Answer 1
You can fix the compiler error by changing output reg
to output wire
. See this post explaining why multiple drivers are not allowed to the same variable.
But FPGAs typically do not support tri-state drivers within the device. You can certainly do this on a bus between FPGA devices.
-
\$\begingroup\$ It works now thanks!! I was also seeing if fpgas use tri-state buffers, found that these units are mostly used at output bidirectional pins and buses. I guess I was intending to use this kind of implementation when I encounter designing bus logic. \$\endgroup\$nebuchadnezzar_II– nebuchadnezzar_II2021年10月14日 00:14:09 +00:00Commented Oct 14, 2021 at 0:14
Explore related questions
See similar questions with these tags.
output out
, which meansoutput var logic out
, which doesn't support multiple drivers. What you need isoutput wire logic out
or simplyoutput wire
. \$\endgroup\$