Encoder Modeling
인코더 모델링
* Encoder (URL)
Inputs | Outputs | ||||
\(i_3\) | \(i_2\) | \(i_1\) | \(i_0\) | \(o_1\) | \(o_0\) |
0 | 0 | 0 | 1 | 0 | 0 |
0 | 0 | 1 | 0 | 0 | 1 |
0 | 1 | 0 | 0 | 1 | 0 |
1 | 0 | 0 | 0 | 1 | 1 |
1) Using \(\texttt{if}\) Statement
Library ieee;
USE ieee.std_logic_1164.all;
ENTITY encoder4x2 IS
PORT( i : IN std_logic_vector(3 DOWNTO 0);
o : OUT std_ logic_vector(1 DOWNTO 0) );
END encoder4x2;
ARCHITECTURE arch_encoder4x2_if OF encoder4x2 IS
BEGIN
PROCESS(i)
BEGIN
IF (i = "0001") THEN
o <= "00";
ELSIF (i = "0010") THEN
o <= "01";
ELSIF (i = "0100") THEN
o <= "10";
ELSIF (i = "1000") THEN
o <= "11";
ELSE
o <= "--";
END IF;
END PROCESS;
END arch_encoder4x2_if
2) Using \(\texttt{case}\) Statement
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY encoder4x2 IS
PORT( i : IN std_logic_vector(3 DOWNTO 0);
o : OUT std_logic_vector(1 DOWNTO 0) );
END encoder4x2;
ARCHITECTURE arch_encoder4x2_case OF encoder4x2 IS
BEGIN
PROCESS(i)
BEGIN
CASE(i) IS
WHEN "0001" => o <= "00";
WHEN "0010" => o <= "01";
WHEN "0100" => o <= "10";
WHEN "1000" => o <= "11";
WHEN OTHERS => o <= "--";
END CASE;
END PROCESS;
END arch_encoder4x2_case;
3) Using with-select-when Statement
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY encoder4x2 IS
PORT( i : IN std_logic_vector(3 DOWNTO 0);
o : OUT std_logic_vector(1 DOWNTO 0) );
END encoder4x2;
ARCHITECTURE arch_encoder4x2_with OF encoder4x2 IS
BEGIN
WITH i SELECT
o <= "00" WHEN "0001",
"01" WHEN "0010",
"10" WHEN "0100",
"11" WHEN "1000",
"--" WHEN OTHERS;
END arch_encoder4x2_with;
4) Using when-else Statement
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY encoder4x2 IS
PORT( i : IN std_logic_vector(3 DOWNTO 0);
o : OUT std_logic_vector(1 DOWNTO 0) );
END encoder4x2;
ARCHITECTURE arch_encoder4x2_when OF encoder4x2 IS
BEGIN
o <= "00" WHEN (i = "0001") ELSE
"01" WHEN (i = "0010") ELSE
"10" WHEN (i = "0100") ELSE
"11" WHEN (i = "1000") ELSE
"--";
END arch_encoder4x2_when;
Priority Encoder (우선순위 인코더)
Inputs | Outputs | ||||
\(i_3\) | \(i_2\) | \(i_1\) | \(i_0\) | \(o_1\) | \(o_0\) |
0 | 0 | 0 | 1 | 0 | 0 |
0 | 0 | 1 | X | 0 | 1 |
0 | 1 | X | X | 1 | 0 |
1 | X | X | X | 1 | 1 |
1) Using \(\texttt{if}\) Statement
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY encoder_p4x2 IS
PORT( i : IN std_logic_vector(3 DOWNTO 0);
o : OUT std_logic_vector(1 DOWNTO 0) );
END encoder_p4x2;
ARCHITECTURE design_if OF encoder_p4x2 IS
BEGIN
PROCESS(i)
BEGIN
IF (i(0) = '1') THEN
o <= "00";
ELSIF (i(1) = '1') THEN
o <= "01";
ELSIF (i(2) = '1') THEN
o <= "10";
ELSIF(i(3) = '1') THEN
o <= "11";
ELSE
o <= "--";
END IF;
END PROCESS;
END design_if;
2) Using \(\texttt{case}\) Statement
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY encoder_p4x2 IS
PORT( i : IN std_logic_vector(3 DOWNTO 0);
o : OUT std_logic_vector(1 DOWNTO 0) );
END encoder_p4x2;
ARCHITECTURE design_case OF encoder_p4x2 IS
BEGIN
PROCESS(i)
BEGIN
CASE(i) IS
WHEN "0001" | "0011" | "0101" | "0111" |
"1001" | "1011" | "1101" | "1111" => o <= "00";
WHEN "0010" | "0110" | "1010" | "1110" => o <= "01";
WHEN "0100" | "1100" => o <= "10";
WHEN "1000" => o <= "11";
WHEN OTHERS => o <= "--";
END CASE;
END PROCESS;
END design_case;
3) Using \(\texttt{with-select-when}\) Statement
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY encoder_p4x2 IS
PORT( i : IN std_logic_vector(3 DOWNTO 0);
o : OUT std_logic_vector(1 DOWNTO 0) );
END encoder_p4x2;
ARCHITECTURE design_with OF encoder_p4x2 IS
BEGIN
WITH i SELECT
o <= "00" WHEN "0001" | "0011" | "0101" | "0111" |
"1001" | "1011" | "1101" | "1111",
"01" WHEN "0010" | "0110" | "1010" | "1110",
"10" WHEN "0100" | "1100",
"11" WHEN "1000",
"--" WHEN OTHERS;
END design_with;
4) Using \(\texttt{when-else}\) Statement
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY encoder_p4x2 IS
PORT( i : IN std_logic_vector(3 DOWNTO 0);
o : OUT std_logic_vector(1 DOWNTO 0) );
END encoder_p4x2;
ARCHITECTURE design_when OF encoder_p4x2 IS
BEGIN
o <= "00" WHEN (i(0) = '1') ELSE
"01" WHEN (i(1) = '1') ELSE
"10" WHEN (i(2) = '1') ELSE
"11" WHEN (i(3) = '1') ELSE
"--";
END design_when;