Загрузка данных
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity slow_generator is
port (
clk : in std_logic;
reset : in std_logic;
slow : out std_logic;
counter : out integer range 0 to 9 -- для отладки в SignalTap
);
end slow_generator;
architecture rtl of slow_generator is
signal cnt : integer range 0 to 9 := 0;
begin
process(clk)
begin
if rising_edge(clk) then
if reset = '1' then
cnt <= 0;
else
if cnt = 9 then
cnt <= 0;
else
cnt <= cnt + 1;
end if;
end if;
end if;
end process;
-- slow = 1 только когда cnt = 0 (1 такт из 10)
slow <= '1' when cnt = 0 else '0';
counter <= cnt; -- для отладки
end rtl;
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity mult_test_controller is
port (
clk : in std_logic;
reset : in std_logic;
slow : in std_logic;
result_valid : out std_logic;
mult_result : out std_logic_vector(15 downto 0);
reg_a_dbg : out std_logic_vector(7 downto 0); -- для SignalTap
reg_b_dbg : out std_logic_vector(7 downto 0); -- для SignalTap
display_reg_dbg: out std_logic_vector(15 downto 0) -- для SignalTap
);
end mult_test_controller;
architecture rtl of mult_test_controller is
constant NUM_A : unsigned(7 downto 0) := to_unsigned(12, 8);
constant NUM_B : unsigned(7 downto 0) := to_unsigned(15, 8);
-- Сигналы после мультиплексоров
signal mux_a_out : unsigned(7 downto 0);
signal mux_b_out : unsigned(7 downto 0);
-- Регистры на входах умножителя
signal reg_a : unsigned(7 downto 0);
signal reg_b : unsigned(7 downto 0);
-- Выход IP-умножителя
signal mult_ip_result : std_logic_vector(15 downto 0);
-- Регистры для синхронизации
signal slow_d1 : std_logic;
-- Основной регистр результата (обнуляется)
signal reg_c : unsigned(15 downto 0);
signal res_valid_reg : std_logic;
-- Регистр БЕЗ СБРОСА для отладки
signal display_reg : unsigned(15 downto 0);
begin
-- 1. Мультиплексоры (комбинационные)
mux_a_out <= NUM_A when slow = '1' else (others => '0');
mux_b_out <= NUM_B when slow = '1' else (others => '0');
-- 2. Регистры после мультиплексоров (входы умножителя)
process(clk)
begin
if rising_edge(clk) then
if reset = '1' then
reg_a <= (others => '0');
reg_b <= (others => '0');
else
reg_a <= mux_a_out;
reg_b <= mux_b_out;
end if;
end if;
end process;
-- 3. IP-ядро умножителя
u_mult_ip : entity work.mult_ip
port map (
dataa => std_logic_vector(reg_a),
datab => std_logic_vector(reg_b),
result => mult_ip_result
);
-- 4. Задержка slow на 1 такт
process(clk)
begin
if rising_edge(clk) then
slow_d1 <= slow;
end if;
end process;
-- 5. Основной выходной регистр (обнуляется по Варианту B)
process(clk)
begin
if rising_edge(clk) then
if reset = '1' then
reg_c <= (others => '0');
res_valid_reg <= '0';
elsif slow_d1 = '1' then
reg_c <= unsigned(mult_ip_result);
res_valid_reg <= '1';
else
reg_c <= (others => '0');
res_valid_reg <= '0';
end if;
end if;
end process;
-- 6. Регистр БЕЗ СБРОСА для отладки
process(clk)
begin
if rising_edge(clk) then
if slow_d1 = '1' then
display_reg <= unsigned(mult_ip_result);
end if;
end if;
end process;
-- Выходы для SignalTap
result_valid <= res_valid_reg;
mult_result <= std_logic_vector(reg_c);
reg_a_dbg <= std_logic_vector(reg_a);
reg_b_dbg <= std_logic_vector(reg_b);
display_reg_dbg <= std_logic_vector(display_reg);
end rtl;
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity test_mult_top is
port (
clk : in std_logic;
reset : in std_logic; -- можно от кнопки или переключателя
result_valid : out std_logic;
mult_result : out std_logic_vector(15 downto 0);
slow : out std_logic;
counter_dbg : out integer range 0 to 9;
reg_a_dbg : out std_logic_vector(7 downto 0);
reg_b_dbg : out std_logic_vector(7 downto 0);
display_reg_dbg: out std_logic_vector(15 downto 0)
);
end test_mult_top;
architecture rtl of test_mult_top is
signal slow_sig : std_logic;
signal counter_sig : integer range 0 to 9;
begin
-- Генератор slow (автоматически каждые 10 тактов)
u_slow_gen : entity work.slow_generator
port map (
clk => clk,
reset => reset,
slow => slow_sig,
counter => counter_sig
);
-- Контроллер умножения
u_mult_ctrl : entity work.mult_test_controller
port map (
clk => clk,
reset => reset,
slow => slow_sig,
result_valid => result_valid,
mult_result => mult_result,
reg_a_dbg => reg_a_dbg,
reg_b_dbg => reg_b_dbg,
display_reg_dbg => display_reg_dbg
);
-- Выходы для SignalTap
slow <= slow_sig;
counter_dbg <= counter_sig;
end rtl;