Altera_Forum
Honored Contributor
8 years agoGeneric One-Hot Multiplexer
I am looking for a way to dynamic instantiate a multiplexer of N channels which has a one-hot encoded select. My current hard-coded version for a 3 channel system looks like this:
signal ChannelSelect : unsigned(CHAN_SEL_BITS-1 downto 0);
signal EventOneHotFlag : std_logic_vector(NUM_CHANNELS-1 downto 0);
.....
ChannelSelect <= "00" when EventOneHotFlag(0) = '1' else
"01" when EventOneHotFlag(1) = '1' else
"10" when EventOneHotFlag(2) = '1' else
"00";
MuxOutputData <= MuxInputArray(to_integer(ChannelSelect))
However, I also have up to 32 channels in some systems that result in the following:
ChannelSelect <= '0'&x"0" when EventOneHotFlag(0) = '1' else
'0'&x"1" when EventOneHotFlag(1) = '1' else
'0'&x"2" when EventOneHotFlag(2) = '1' else
'0'&x"3" when EventOneHotFlag(3) = '1' else
.... Sparing you the whole list......
'1'&x"D" when EventOneHotFlag(29) = '1' else
'1'&x"E" when EventOneHotFlag(30) = '1' else
'1'&x"F" when EventOneHotFlag(31) = '1' else
'0'&x"0";
MuxOutputData <= MuxInputArray(to_integer(ChannelSelect))
Both work correctly, but I have not found a synthesize solution to parameterize the mux to make it generic for use across system builds. I have been unsuccessful trying Generate statements or For Loops to handle the One-Hot select case. Thanks, Aaron