Altera_Forum
Honored Contributor
8 years agoEdge detection asynchronous signal fails
Hello,
I am working on a fairly simple VHDL design where I am trying to detect the rising_edge of an input. Whenever a rising_edge is detected I want to multiply another input by 2 and output it. The input that serves the "start" siginal is data_ready and it changes asynchronously. Since data_ready is not a clock it is my understanding that I cannot use rising_edge( data_ready ) so I store the previous value of data_ready. in an internal signal previous_value and compare it to the current value data_ready. It feel my code should work but during simulation it fails. What am I doing wrong?entity mul is port(
my_input : in std_logic_vector( 7 downto 0 );
data_ready : in std_logic;
my_output : out std_logic_vector( 8 downto 0 )
);
end mul;
architecture behavior of mul is
signal previous_value : std_logic := '0';
begin
mul_2 : process( data_ready )
begin
if data_ready = '1' AND previous_value = '0' then -- detect rising edge
previous_value <= data_ready; -- set previous value
my_output <= my_input( 7 downto 0 ) & "0"; -- mul by 2, shift left
else
my_output <= "111000111";
end if;
end process;
end behavior;
Testbench: BEGIN
-- code that executes only once
dataReady <= '0';
heading_in <= "11100011";
wait for 40ns;
dataReady <= '1'; -- generate rising edge
wait for 40ns; -- expected output 111000110
dataReady <= '0';
WAIT;
END PROCESS init;
Thanks for your help!