library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity sandbox is
end entity sandbox;
architecture bhv of sandbox is
constant cClkPeriod : time := 1 us;
constant cMaxControlCnt : positive := 5;
constant cMaxCalcCnt : positive := 7;
signal clk : std_ulogic := '0';
signal nReset : std_ulogic;
signal controlCnt, nextControlCnt : unsigned(2 downto 0);
signal calcCnt, nextCalcCnt : unsigned(2 downto 0);
signal enCalc : std_ulogic;
signal calcCpl : std_ulogic;
begin -- architecture bhv
clk <= not(clk) after (cClkPeriod/2);
seq : process (clk, nReset) is
begin
if (nReset = '0') then
controlCnt <= to_unsigned(0, controlCnt'length);
calcCnt <= to_unsigned(0, calcCnt'length);
elsif (clk'event and clk = '1') then
controlCnt <= nextControlCnt;
calcCnt <= nextCalcCnt;
end if;
end process seq;
controlComb : process (controlCnt, calcCpl) is
begin
nextControlCnt <= controlCnt;
enCalc <= '0';
if (controlCnt = cMaxControlCnt) then
enCalc <= '1';
if (calcCpl = '1') then
nextControlCnt <= to_unsigned(0, nextControlCnt'length);
end if;
else
nextControlCnt <= controlCnt + 1;
end if;
end process controlComb;
calcComb : process (calcCnt, enCalc) is
begin
nextCalcCnt <= calcCnt;
calcCpl <= '0';
if (enCalc = '1') then
nextCalcCnt <= calcCnt + 1;
if (calcCnt = cMaxCalcCnt) then
calcCpl <= '1';
nextCalcCnt <= to_unsigned(0, nextCalcCnt'length);
end if;
end if;
end process calcComb;
stimulus: process is
begin
nReset <= '0';
wait for (5*cClkPeriod + 1 ns);
nReset <= '1';
wait;
end process stimulus;
end architecture bhv;