Estoy teniendo problemas con este código VHDL donde el valor de new_state no se transfiere a la señal state_cnt y, en cambio, se está volviendo indefinido.
¿Qué necesito cambiar para que esto funcione?
Library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_signed.all;
use ieee.std_logic_arith.all;
entity test_controller is
port (
clk, reset, wr : in std_logic;
wr_data : in std_logic_vector(31 downto 0)
op_a, op_b, op_c : out std_logic_vector(31 downto 0)
);
end test_controller;
architecture rtl of test_controller is
signal busy : std_logic := '0';
signal state_cnt : std_logic_vector(1 downto 0) := "00";
begin
input_proc : process(wr)
variable new_state : integer;
begin
if rising_edge(wr) then
if busy = '0' then
if state_cnt = "00" then
op_a <= wr_data;
new_state := 1;
elsif state_cnt = "01" then
op_b <= wr_data;
new_state := 2;
elsif state_cnt = "10" then
op_c <= wr_data;
busy <= '1';
new_state := 0;
end if;
state_cnt <= conv_std_logic_vector(new_state,2);
end if;
end if;
end process;
end rtl;
Testbench
Library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_signed.all;
use ieee.std_logic_arith.all;
entity tb_test_controller is
end tb_test_controller;
architecture exercise of tb_test_controller is
component test_controller
port (
clk, reset, wr : in std_logic;
wr_data : in std_logic_vector(31 downto 0);
op_a, op_b, op_c : out std_logic_vector(31 downto 0)
);
end component;
signal clk_i : std_logic;
signal reset_i : std_logic;
signal wrdata_i : std_logic_vector(31 downto 0);
signal op_a_i : std_logic_vector(31 downto 0);
signal op_b_i : std_logic_vector(31 downto 0);
signal op_c_i : std_logic_vector(31 downto 0);
signal wr_i : std_logic;
constant CLK_PERIOD : time := 20 ns;
constant DLY : time := CLK_PERIOD*2;
begin
clkmeProc : process
begin
clk_i <= '1';
wait for CLK_PERIOD/2;
clk_i <= '0';
wait for CLK_PERIOD/2;
end process;
resetmeProc : process
begin
wait for DLY;
reset_i <= '1';
wait for CLK_PERIOD;
reset_i <= '0';
wait;
end process;
inputDataProc : process
begin
wait on reset_i until reset_i = '0';
for i in 0 to 10 loop
wrdata_i <= conv_std_logic_vector(i, 32);
wr_i <= '1';
wait for CLK_PERIOD;
wr_i <= '0';
wait for CLK_PERIOD;
end loop;
end process;
DUT : test_controller
port map
(
clk =>clk_i,
reset => reset_i,
wr_data => wrdata_i,
wr => wr_i,
op_a => op_a_i,
op_b => op_b_i,
op_c => op_c_i
);
stimProc : process
begin
wait;
end process;
end exercise;