Öncelikle counter kısmında counter ın istenen değere ulaşıp ulaşmadığına bakmalı ,sonra 1 artırmalısın.
Ve bunlar aynı if state inin içinde olmalı ,Yoksa counter 1 fazla saymış olur ki bu zaman kaybı.1 clk_period gecikme olur.
Son olarak bu iş için bence 2 module kullanmalısın.Ki hatırladığım kadarıyla sequential ve combinational işlemleri bu şekilde aynı modulde kullanamzsın.
Sen benim yazdığımı bi denede olmadı başka bişi ayarlarız.Normalde çok basit bi işlem fakat nerdeyse 1 sene oldu bende vhdl ile uğraşmayalı.
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity kyn is
port ( clk : in std_logıc;
ky : out std_logıc_vector (2 downto 0));
end kyn;
architecture behavioral of kyn is
signal kyt :std_logic_vector(1 downto 0):="00";
begin
process(clk)
begin
if (clk='1' and clk'event) then
if kyt="10" then
kyt<="00";
else
kyt <= kyt +1;
end if;
case kyt is
when "00"=> ky <="001";
when "01"=> ky <="010";
when "10"=> ky <="100";
when others => ky <= "001";
end case;
end if;
end process;
end behavioral;
--BU da test bench i ;
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.std_logic_unsigned.all;
USE ieee.numeric_std.ALL;
ENTITY kyn_tb_vhd IS
GENERIC( clk_period: delay_length:= 1 ms); --added by user, the clock timeperiod
END kyn_tb_vhd;
ARCHITECTURE behavior OF kyn_tb_vhd IS
-- Component Declaration for the Unit Under Test (UUT)
COMPONENT kyn
PORT(
clk : IN std_logic;
ky : OUT std_logic_vector(2 downto 0)
);
END COMPONENT;
--Inputs
SIGNAL clk : std_logic := '0';
--Outputs
SIGNAL ky : std_logic_vector(2 downto 0);
signal EndTest: std_logic:='0';
BEGIN
-- Instantiate the Unit Under Test (UUT)
uut: kyn PORT MAP(
clk => clk,
ky => ky
);
tb : PROCESS
BEGIN
while EndTest = '0' loop
clk <= '0';
wait for 0.5*clk_period; -- Wait for half the clock period
-- defined in the entity
clk <= '1';
wait for 0.5*clk_period; -- Wait for half the clock period
-- defined in the entity
end loop;
wait; -- Will wait forever
end process;
-- ********************************************
-- Process for generating the other inputs
-- ********************************************
process
begin
wait for 1*clk_period; -- enable the counter
assert ky = "001" report "Failure!" severity failure;
wait for 1*clk_period; -- enable the counter
assert ky = "010" report "Failure!" severity failure;
wait for 1*clk_period; -- enable the counter
assert ky = "100" report "Failure!" severity failure;
wait for 1*clk_period; -- enable the counter
assert ky = "001" report "Failure!" severity failure;
wait for 1*clk_period; -- enable the counter
assert ky = "010" report "Failure!" severity failure;
wait for 1*clk_period; -- enable the counter
assert ky = "100" report "Failure!" severity failure;
report"tested succcesful!!";
EndTest <= '1'; -- Stop the clock process
wait; -- Will wait forever
end process;
END;
Başa dön