kcinimod
Member level 3
Code:
library ieee;
use ieee.std_logic_1164.all;
entity counter is
port(
clk_in : in std_logic;
data : in std_logic;
enable : in std_logic;
dout : out std_logic
);
end counter;
architecture count of counter is
signal data_sync : std_logic_vector(1 downto 0);
signal pre_count : integer;
signal pre_count_1 : integer;
signal pre_count_2 : integer;
signal data_count : integer;
signal trigger : std_logic;
begin
process(clk_in)
begin
if rising_edge(clk_in) then
data_sync <= data_sync(0) & data;
end if;
end process;
count_proc : process(clk_in)
begin
if rising_edge(clk_in) then
if enable = '0' then
data_count <= 0;
pre_count <= 0;
pre_count_1 <= 0;
pre_count_2 <= 0;
trigger <= '1';
elsif (data_sync(1) = '1') then
if (data_count = 0) then
pre_count <= 0;
data_count <= data_count + 1;
elsif (data_count = 1) then
if (pre_count > 5) then
pre_count_1 <= pre_count;
data_count <= data_count + 1;
end if;
elsif (data_count = 2) then
if (pre_count > 5) then
pre_count_2 <= pre_count;
data_count <= data_count - 1;
end if;
end if;
pre_count <= 0;
else
pre_count <= pre_count + 1;
end if;
end if;
end process;
compare_proc : process(clk_in)
begin
if rising_edge(clk_in) then
if (data_count = 1) then
if (pre_count_1 > pre_count_2) then
dout <= '1';
trigger <= '0';
elsif (pre_count_1 < pre_count_2) then
dout <= '0';
trigger <= '0';
end if;
else
trigger <= '1';
end if;
end if;
end process;
end count;
hi all, for the above code, when enable is '0', it will initialise trigger to '1', however when i do this, the trigger signal during is simulation is as shown in the pic the trigger appear with X.
however, when i remove the trigger <= '1' from the code, it appears correctly
may i know why is this so ?