5.2 Входной блок
Ниже представлен листинг входного блока устройства: library ieee; use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all; entity BlockIn is
port (
input, C_ext, CLR: in std_logic;
Q_reg: out std_logic_vector(5 downto 0); OPERATION: out std_logic_vector(1 downto 0); cnt: out std_logic_vector(4 downto 0));
end;
architecture synth of BlockIn is
signal reg: std_logic_vector(7 downto 0); signal counter0: std_logic_vector(2 downto 0); signal counter1: std_logic_vector(4 downto 0); begin
Q_reg <= reg(7 downto 2); OPERATION <= reg (1 downto 0); cnt <= counter1;
process(C_ext, CLR) begin
if CLR = '1' then
reg <= (others => '0'); counter0 <= (others => '0'); elsif rising_edge(C_ext) then
reg <= input & reg(7 downto 1); counter0 <= counter0 + '1';
end if;
end process;
26
process(C_ext, CLR) begin
if CLR = '1' then
counter1 <= (others => '0'); elsif counter0 = "000" then if rising_edge(C_ext) then
counter1 <= counter1 + '1'; end if; end if;
end process;
end;
Во входном блоке входящие сигналы делятся на две категории: первые два сигнала будут записаны в OPERATION как код операции, а последующие шесть
– в Q_reg. Также с помощью сигнала CLR реализован асинхронный сброс.
Счетчик выполненных операций срабатывает, когда счетчик сигналов C_ext на выходе имеет ноль и приходит активный уровень сигнала C_ext. Счетчик оснащен асинхронным сбросом CLR.
На рисунке 5.6 представлена схема из RTL viewer.
Рисунок 5.6 – Схема из RTL viewer
27
5.3Операционный блок
Ниже представлен листинг операционного блока устройства: library ieee; use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all; entity BlockOP is
port (
Q_reg: in std_logic_vector(5 downto 0); OPERATION: in std_logic_vector(1 downto 0); cnt: in std_logic_vector(4 downto 0);
result: out std_logic_vector(4 downto 0)); end;
architecture synth of BlockOP is begin
process(OPERATION) begin
case (OPERATION) is when "00" =>
result <= cnt; when "01" =>
case (Q_reg (3 downto 0)) is
when "0000" => result <="01101"; when "0001" =>result <= "11101"; when "0010" =>result <= "11001"; when "0011" =>result <= "10000"; when "0100" =>result <= "01010"; when "0101" =>result <= "00001"; when "0110" =>result <= "10101"; when "0111" =>result <= "11100"; when "1000" =>result <= "01100";
28
when "1001" =>result <= "00011"; when "1010" =>result <= "00010"; when "1011" =>result <= "01000"; when "1100" =>result <= "11111"; when "1101" =>result <= "11011"; when "1110" =>result <= "00100"; when "1111" =>result <= "00000"; end case;
when "10" =>
result <= "00" & ( (not Q_reg(5 downto 3)) and Q_reg(2 downto 0)); when "11" =>
result <= "00" & (Q_reg(5 downto 3) - Q_reg(2 downto 0)); when others =>
result <= cnt; end case; end process; end;
В операционном блоке при помощи модуля case считывается значение
OPERATION, и на основе этого значения производится конкретная операция с данными, так при подаче 00 в качестве результата будет выдано значение счетчика команд, при подаче 01 в зависимости от двоичного числа на входе в качестве результата будет выдан аналог в коде МТК-2 и т.д.
На рисунке 5.7 представлена схема из RTL viewer.
29
Рисунок 5.7 – Схема из RTL viewer
5.4Выходной блок
Ниже представлен листинг выходного блока устройства: library ieee; use ieee.std_logic_1164.all;
entity BlockOut is port (
C_int, CLR, nreadd: in std_logic; result: in std_logic_vector(4 downto 0); outt: out std_logic_vector(4 downto 0); C_out: out std_logic);
end;
architecture synth of BlockOut is signal read_s: std_logic;
30