Skip to content

Problems with 'tperiod_Clk' #9

Open
@Paebbels

Description

@Paebbels

Thanks for yesterdays live debugging session.
We found our mistake in the usage of Axi4Manager and Axi4Memory.

The frequency of the OSVVM verification components was not matching the period of our testbench clocks.
We have 2 suggestions to prevent others from doing the same mistake:

  1. Don't set a default value to tperiod_Clk, so users are forced to map a clock period.
  2. Measure the clock period in the model.
    => We would prefer this method.

How can the latter be implemented in a save and reliable way?

  1. Measure the clock period on Clk and save it in a local variable/signal.
  2. When reset is done (rising_edge(nReset), assign tperiod_Clk.

What does this method achieve?

  • No need for a generic / no dependency to the parent instance.
  • Clock period can be changed in the testbench, while reset is high or retriggered.
    • Anyhow, clock must be stable before reset is released and it can't change frequency afterwards unless reset is asserted again.
  • When reset is deasserted, tperiod_Clk can be used immediately.

Sketch of the solution:

architecture a of e is
  signal tperiod_Clk  : time := -1 ns;
begin
  process(Clk, nReset)
    variable LastRise : time :=  0 ns;
    variable Period   : time := -1 ns;
  begin
    if rising_edge(nReset) then
      tperiod_Clk <= Period;
    end if;

    if rising_edge(Clk) then
      Period   := now - LastRise;
      LastRise := now;
    end if;
  end process;
  
  -- ...
end architecture;

Note:

  • negative times are intended, so simulation fails on uninitialized / unmeasured clocks.

/cc @stefanunrein

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions