encoders
are used to encode discrete data into a coded form
inputs
a3 a2 a1 a0 |
outputs
=> x1 x0 |
0..0..0..1
0..0..1..0 0..1..0..0 1..0..0..0 |
=> 0..0
=> 0..1 => 1..0 => 1..1 |
library IEEE;
use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity encod_4to2 is
|
architecture
data_flow_1 of
encod_4to2 is
signal tmp_in: unsigned(3 downto 0); signal tmp_out: unsigned(1 downto 0); begin
-- conditional signal assignment tmp_out <= "00" when tmp_in="0001" else
"10" when tmp_in="0100" else "11" when tmp_in="1000" else "XX"; -- default value x0<= tmp_out(0); |
architecture
data_flow_2 of
encod_4to2 is
signal tmp_in: unsigned(3 downto 0); signal tmp_out: unsigned(1 downto 0); begin
with tmp_in select tmp_out <= "00" when "0001" else
"10" when "0100" else "11" when "1000" else "XX"; -- default value x0 <= tmp_out(0); |
architecture
process_enc of
encod_4to2 is
begin process(a3,a2,a1,a0) variable tmp_in: unsigned(3 downto 0); variable tmp_out: unsigned(1 downto 0); begin
case tmp_in is
when "0010" => tmp_out := "01"; when "0100" => tmp_out := "10"; when "1000" => tmp_out := "11"; when others => tmp_out := "XX"; x1 <= tmp_out(1); x0 <= tmp_out(0); end process; |