ad_mux: fix cases where channel number is not power of mux size

main
Laszlo Nagy 2020-05-29 19:54:58 +01:00 committed by Laszlo Nagy
parent 3dd370a27c
commit 0badfdfa31
2 changed files with 3 additions and 2 deletions

View File

@ -57,7 +57,8 @@ module ad_mux #(
localparam MUX_SZ = CH_CNT < REQ_MUX_SZ ? CH_CNT : REQ_MUX_SZ;
localparam CLOG2_CH_CNT = $clog2(CH_CNT);
localparam CLOG2_MUX_SZ = $clog2(MUX_SZ);
localparam NUM_STAGES = $clog2(CH_CNT) / $clog2(MUX_SZ);
localparam NUM_STAGES = ($clog2(CH_CNT) / $clog2(MUX_SZ)) + // divide and round up
|($clog2(CH_CNT) % $clog2(MUX_SZ));
wire [NUM_STAGES*DW+CH_W-1:0] mux_in;
wire [NUM_STAGES*CLOG2_CH_CNT-1:0] ch_sel_pln;

View File

@ -9,7 +9,7 @@ module ad_mux_tb;
parameter EN_REG = 1; // Enable register at output of each mux
localparam MUX_SZ = CH_CNT < REQ_MUX_SZ ? CH_CNT : REQ_MUX_SZ;
localparam NUM_STAGES = $clog2(CH_CNT) / $clog2(MUX_SZ);
localparam NUM_STAGES = $clog2(CH_CNT) / $clog2(MUX_SZ) + |($clog2(CH_CNT) % $clog2(MUX_SZ));
localparam DW = CH_W*CH_CNT;
`include "tb_base.v"