Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
14 years ago

why does ModelSim capture at the same edge

Hi All!

Currently I'm seeking for understanding why ModelSim 6.6d is capturing my data partly at the following (as expected) and the same edge of the clock: I'm trying to simulate the behaviour of a source synchronous interface (in VHDL) and generated some data in a testbench which I feed into the UUT. The unit is only expected to capture the data:

process (ep_clk, nreset)
begin
  if nreset = '0' then
    local_data  <= (others => '0');
    local_de    <= '0';
    local_hsync <= '0';
    local_vsync <= '0';
  elsif rising_edge(ep_clk) then
    local_data  <= ep_data;
    local_de     <= ep_de;
    local_hsync <= ep_hsync;
    local_vsync <= ep_vsync;
  end if;
end process;
All signals are std_logic(_vector), ep_* are inputs, local_* are outputs. Running the simulation using a 166MHz clock shows that de, hsync and vsync are captured at the same clock edge (which i did not expected). The 48bit ep_data is split: the upper 24 are captured at the next edge while the lower 24 bits are at the same. (If I delay the ep_* signals at the generator the capture is all at the following edge.)

Can anymore please explain this behaviour to me? I would have expected that all data is captured always at the following edge in behaviour simulations. What can I do to force capture at the following edge?

Thank You!

Pauliman

9 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    As expected, your code should be capturing all of ep_data in the same clock edge as everything else.

    There's no black magic VHDL behaviour there.

    Are you running a RTL or gate level simulation?

    If it's gate level, there's a (unlikely) possibility it's due to delays.

    But I'd wager it's a subtle bug somewhere before that's delaying half of ep_data one more clock -- been there, done that. :)

    Are you looking at the actual ep_data and local_data signals in Modelsim?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    You are probably experiencing simulation 'delta' delays, where the simulator is evaluating several simulation events during zero elapsed time, and the cycle where the rising edge is detected is occurring when not all signals are in their new (or old) state.

    You should launch ep_clk slightly before or after the other ep_xx signals to ensure that its simulation cycle is unique, eg., use an after 1 ns delay.

    Cheers,

    Dave
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    This can be easy to do an annoying when you first see it - but a common problem can be the testbench. Can I guess you have something like this?

    
    ep_clk <= not ep_clk after 10 ns; --or whatever it is for 166MHz
    ep_hsync <= '0', '1' after 10ns;
    
    You see the problem is here is that hsync will change at the same time as the clock. BUT - because the rising edge function (and 'event detection) take that extra delta to fire, when local_hsync is assigned it has already changed to '1'.

    So, the best thing to do is synchronise the hsync input to the clock in the testbench, and dont use direct time amounts.

    
    process
    begin
      ep_hsync <= '0';
      
      wait until rising_edge(ep_clk);
      ep_hsync <= '1';
      wait;
    end process;
    
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Many thanks for all your answers and suggestions.

    rbugalho: I'm doing just gate level simulations.

    dwh: is there any way to force this delay everywhere?

    Tricky: I'm launching the data using ep_clk (actually an equivalent signal in the testbench). So launch and latch clock are the same.

    Yesterday I thought I'd found the problem: ep_clk was generated using ep_clk <= clk and nReset, so that ep_* is launched at clk and latched at ep_clk. Unfortunately feeding ep_clk directly by clk does not change the situation.

    Adding a delay between launch and clock leads to the expected result, data is latched one cycle after launch.

    What puzzles me most is, that if the launch/latch conditions are unexpected at this point in code, is it the same elsewhere? If so, my simulations results would be quite useless...

    Is there any way to force more precise evaluation or add a general delay to all data assignments so that latching is always one clock cycle after launch?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    are you aware that asignments add 1 delta cycle? so assigning clocks from other clocks can cause the same problem.

    was the data input using clk or ep_clk? if you used clk, then it would be 1 delta before ep_clk, and cause the problem you are describing.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi Tricky! How can I avoid this problem when simulating source synchronous interfaces? I've got the tb clock (clk) which I use to launch the simulation data (ep_*). Then I need to assign this clock to ep_clk to feed the UUT. I can't see how to avoid this assignment.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    run the testbench from, ep_clk

    or align the clk with ep_clk by creating an assigned version (to add a delta)

    clk_d1 <= clk;
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    hm... this extra assignment is difficult: in this case it cures the problem but in the next stage in my code (the clock is again forwarded with an assignment from input-port to output-port) it causes it again. I need to latch the data directly from the input port to get the desired latched-one-cycle-after-launch behaviour.

    Is my assumption right that I need to do all handling on local signals and assign this (incl. the clock) to the output-port to have equal amount of assignments on all data and clock signals?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I would never forward a clock through an entity as it will cause the problem we have been describing (port maps are like signal assignments and add a delta delay). Just connect the clock of the second module to the same clock as the first. ie - all entities on the same level get the same clock input.

    This problem wouldnt occur on real hardware because all these clocks refer to the same clock net, but it gets silly in simulation.