From b3c0cdc082e04a39b0129e00cf6442b93df1c03e Mon Sep 17 00:00:00 2001 From: Andreas Olofsson Date: Wed, 20 Jan 2016 17:22:05 -0500 Subject: [PATCH] Adding generic N:1 mux --- common/hdl/oh_mux.v | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 common/hdl/oh_mux.v diff --git a/common/hdl/oh_mux.v b/common/hdl/oh_mux.v new file mode 100644 index 0000000..873cbc0 --- /dev/null +++ b/common/hdl/oh_mux.v @@ -0,0 +1,38 @@ +//######################################################################### +//# GENERIC "ONE HOT" N:1 MUX +//# See also oh_mux2.v, oh_mux3.v, etc +//######################################################################### +module oh_mux (/*AUTOARG*/ + // Outputs + out, + // Inputs + sel, in + ); + + //##################################################################### + //# INTERFACE + //##################################################################### + parameter DW = 32; // width of data inputs + parameter N = 99; + + input [N-1:0] sel; // select vector + input [N*DW-1:0] in; // concatenated input {..,in1[DW-1:0],in0[DW-1:0] + output [DW-1:0] out; // output + + //##################################################################### + //# BODY + //##################################################################### + reg [DW-1:0] out; + + //parametrized mux + integer i; + always @* + begin + out[DW-1:0] = 'b0; + for(i=0;i