TransWikia.com

Clock usage in the always block and in the event

Electrical Engineering Asked by Animesh Srivastava on December 15, 2021

In general, if we are working on a sequential circuit, say a Flip Flop (e.g. D Flip Flop)
The code we write for the always block part is:

 always @(posedge clk or posedge reset)
  begin
    if (reset) begin
      // Asynchronous reset when reset goes high
      q <= 1'b0;
    end else begin
      // Assign D to Q on positive clock edge
      q <= d;
    end
  end

I am confused on the point – Why the line if(clk) is not used/written/introduced before q <= d in our always block.
Motivation:
Posedge transition corresponds to transition from:

  • 0 to 1
  • x to 1
  • z to 1
  • 0 to x
  • 0 to z

So, why in most of the sequential codes, we don’t confirm that the positive edge of the clock has appeared after the edge transition from low to high.
I’ve searched the forum for this topic but can’t find a specific answer on this. I am a newbie and will appreciate your guidance.

2 Answers

You have a valid point. If we were being very careful we would want to know if the clock or reset was actually in the X state, and we would probably set Q to X if that was the case.

So why don't we do those checks? The clock and reset are signals that we design very carefully to ensure that they are solid digital signals, with fast transitions from 0 to 1. So, it is often safe to assume that they are never X for a significant length of time.

If you do want to be a careful designer, it is usually better to check for unknown values of clock and reset at their point of origin rather than everywhere they are used. Adding assertions for these signals in just one part of the design allows the simulations to be much for efficient than adding complex if/then/else checks in millions of flip flops.

Answered by Elliot Alderson on December 15, 2021

It's implied that if the block triggered, and reset is not high, that clock rising edge must have triggered the always block (because the always block triggered either because posedge reset or posedge clk). Basically if reset is high, you want to behave like a reset no matter what in the always block, otherwise you want to behave like a flip flop.

Answered by vicatcu on December 15, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP