0
\$\begingroup\$

I want output to equal "11111111" on the first rising edge of the clock but it only happens on the second rising edge when I test the code with ModelSim. The code might look weird as a simplification of a more complex design where I have the same kind of problem.

code:

library ieee;
use ieee.std_logic_1164.all;
entity delay is
port(
clock : in STD_LOGIC;
output : out STD_LOGIC_VECTOR(7 downto 0) := "00000000"
);
end delay;
architecture behavioral of delay is
signal debug : STD_LOGIC_VECTOR(3 downto 0);
begin
process(clock)
begin
if rising_edge(clock) then
 debug <= "0000";
 case debug is
 when "0000" => output <= "11111111";
 when others => output <= "00000000";
 end case;
end if;
end process;
end behavioral; 

testbench:

library ieee;
use ieee.std_logic_1164.all;
entity eentestbench is
end eentestbench;
architecture behavioral of eentestbench is
signal clock : STD_LOGIC := '0';
signal result: STD_LOGIC_VECTOR(7 downto 0) := "00000000";
component delay
port(
 clock : in STD_LOGIC;
 output : out STD_LOGIC_VECTOR(7 downto 0)
);
end component;
begin
uut : delay port map(
clock => clock,
output => result
);
stim_process: process
begin
clock <= '0';
wait for 1 ns;
clock <= '1';
wait for 1 ns;
end process;
end behavioral;
asked Jun 29, 2015 at 17:30
\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

Move the debug assignment outside the if statement with the condition rising_edge(clock).

In the following waveform you can see it's not assigned until the first clock edge and the output assignment is dependent on debug.

eentestbench.png (clickable)

The debug assignment could just as easily be a concurrent statement or have initial value supplied by a generic.

answered Jun 29, 2015 at 18:50
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.