Forum Discussion
Altera_Forum
Honored Contributor
8 years agoThanks everyone. An updated For Loop function for the One-Hot to Integer conversion worked. In my case I am driving multiple Muxes and have some other logic based on channel number. I ended up with a converting to an integer output to drive Mux selects and that I could also cast to unsigned:
-- Convert One-Hot array to integer channel select
function ONEHOT_TO_INT( OneHotCode : std_logic_vector ) return integer is
constant DefaultReturn: integer := 0;
begin
for NumChan in OneHotCode'range loop
if (OneHotCode(NumChan) = '1') then
return NumChan;
end if;
end loop;
return DefaultReturn;
end function;
........
ChannelSelect <= ONEHOT_TO_INT(EventOneHotFlag);
SomeData_slv <= (others => '0') when (ChannelSelect = LAST_CHANNEL)
else std_logic_vector(OtherData_u(ChannelSelect));
PacketOut_slv <= Header_slv & std_logic_vector(to_unsigned(ChannelSelect, 8)) & PacketData_slv;