LSU EE 3755 - Fall 2012 - Computer Organization Verilog Notes 3 - Delay
LSU EE 3755 - Fall 2012 - Computer Organization Verilog Notes 3 - Delay
//
/// Verilog Notes 3 -- Delay
/// Contents
/// Delays
/// Ripple Adder and Delays
/// The Event Queue and Verilog Simulation
/// References
// :Q: Qualis, "Verilog HDL Quick Reference Card Revision 1.0"
// :H: Hyde, "Handbook on Verilog HDL"
// :LRM: IEEE, Verilog Language Reference Manual (Hawaii Section
Numbering)
// :PH: Patterson & Hennessy, "Computer Organization & Design"
///////////////////////////////////////////////////////////////////////////
/////
/// Delays
// :H: Not covered for continuous assignments.
// :LRM: 6.1
// :Example:
//
// A module that just passes the signal through, like wire. Suppose
// at t=5 input a changes from 0 to 1, when does x change?
module no_delays(x,a);
input a;
output x;
assign x = a;
wire w = x;
endmodule
// Ans: x changes at 5 + 0 = 5.
// :Example:
//
// A module that just passes the signal through unchanged, though it
// passes through two inverters. Suppose at t=5 input a changes from
// 0 to 1, when does x change?
module no_delays2(x,a);
input a;
output x;
wire b;
not n1(b,a);
not n2(x,b);
endmodule
// Ans: x changes at 5.
// :Example:
//
// Illustration and explanation of delays in assigns and wires.
module delays(x,a);
input a;
output x;
ripple_4 adder1(sum1[3:0],sum1[4],a,b);
ripple_4_d adder2(sum2[3:0],sum2[4],a,b);
another_adder adder3(sum3[3:0],sum3[4],a,b);
task check_sum;
input [4:0] s;
input [79:0] name;
if ( s != shadow_sum ) begin
$display("Wrong sum in %s: %d + %d = %d != %d\n",
name, a, b, shadow_sum, s);
$stop;
end
endtask
initial begin
$display("Tests completed.");
end
endmodule
///////////////////////////////////////////////////////////////////////////
/////
/// The Event Queue and Verilog Simulation
/// The Verilog Simulator Event Queue
//
// Simulator maintains a "to-do list" called an /event queue/.
//
// An entry in the event queue specifies something that the simulator
// needs to do. These include:
//
// (A) Changing the value of a wire [or reg].
//
// (B) Evaluating an expression appearing in an assign statement.
//
// (C) Determining the output of a gate.
//
// (The letters above are used in the example below.)
//
// Each entry has a /timestamp/ which indicates when the action
// specified by the entry is supposed to be done.
//
// Entries are sorted by timestamp.
//
// [Entries with the same timestamp are divided in to five layers.]
// :Example:
//
// Module illustrating timing and event queue. The testbench (shown
// further below) sets a and b equal to 0 at t=0.
module timing(x,y,a,b);
input a, b;
output x,y;
wire d, e;
not #2 n1(d,a);
not #3 n2(e,d);
assign x = b ^ d ^ e;
xor a1(y,b,d,e);
endmodule
// Entry 0 removed.
// Change b from x to 0.
// Add affected items:
// Event Queue at t = 0
//
// Entry 2 timestamp = 8; Resume testbench procedural code.
// Entry 4 timestamp = 0; B: Evaluate: xor a1(y,b,d,e);
// Entry 3 timestamp = 0; B: Evaluate: assign x = b ^ d ^ e;
// Entry 1 timestamp = 0; A: Set a <- 0
// Entry 1 removed.
// Change a from x to 0.
// Add affected items.
// Event Queue at t = 0
//
// Entry 2 timestamp = 8; Resume testbench procedural code.
// Entry 5 timestamp = 0; C: Evaluate: not #2 n1(d,a);
// Entry 4 timestamp = 0; C: Evaluate: xor a1(y,b,d,e);
// Entry 3 timestamp = 0; B: Evaluate: assign x = b ^ d ^ e;
// Entry 3 removed.
// Compute b ^ d ^ e, result wire x does not change (was undefined, still
is)
// Event Queue at t = 0
//
// Entry 2 timestamp = 8; Resume testbench procedural code.
// Entry 5 timestamp = 0; C: Evaluate: not #2 n1(d,a);
// Entry 4 timestamp = 0; C: Evaluate: xor a1(y,b,d,e);
// Entry 4 removed
// Compute xor a1(y,b,d,e). Output y does not change (was x, still is).
// Event Queue at t = 0
//
// Entry 2 timestamp = 8; Resume testbench procedural code.
// Entry 5 timestamp = 0; C: Evaluate: not #2 n1(d,a);
// Entry 5 removed.
// Compute n1(d,a). d is to change from x to 1.
// Insert change to d in event queue for 2 cycles later.
// Event Queue at t = 0
//
// Entry 2 timestamp = 8; Resume testbench procedural code.
// Entry 6 timestamp = 2; Set d <- 1
// Remove entry 6.
// Change time to t = 2.
// Set d to 1.
// Add items affected by d.
// Event Queue at t = 2
//
// Entry 2 timestamp = 8; Resume testbench procedural code.
// Entry 9 timestamp = 2; assign x = b ^ d ^ e;
// Entry 8 timestamp = 2; xor a1(y,b,d,e);
// Entry 7 timestamp = 2; not #3 n2(e,d);
// Remove entry 7.
// Compute n2(e,d). e is to change from x to 0
// Insert change to e in event queue for 3 cycles later.
// Event Queue at t = 2
//
// Entry 2 timestamp = 8; Resume testbench procedural code.
// Entry 10 timestamp = 5; Set e <- 0
// Entry 9 timestamp = 2; assign x = b ^ d ^ e;
// Entry 8 timestamp = 2; xor a1(y,b,d,e);
// Remove entry 8.
// Compute xor(y,b,d,e)
// No change in y. (Was x, still is.)
// Event Queue at t = 2
//
// Entry 2 timestamp = 8; Resume testbench procedural code.
// Entry 10 timestamp = 5; Set e <- 0
// Entry 9 timestamp = 2; assign x = b ^ d ^ e;
// Remove entry 9
// Compute b ^ d ^ e
// No change in x.
// Event Queue at t = 2
//
// Entry 2 timestamp = 8; Resume testbench procedural code.
// Entry 10 timestamp = 5; Set e <- 0
// Event Queue at t = 5
//
// Entry 2 timestamp = 8; Resume testbench procedural code.
// Entry 12 timestamp = 5; assign x = b ^ d ^ e;
// Entry 11 timestamp = 5; xor a1(y,b,d,e);
// Event Queue at t = 5
//
// Entry 2 timestamp = 8; Resume testbench procedural code.
// Entry 13 timestamp = 5; Set x <- 1
// Entry 12 timestamp = 5; assign x = b ^ d ^ e;
// Event Queue at t = 5
//
// Entry 2 timestamp = 8; Resume testbench procedural code.
// Entry 14 timestamp = 5; Set y <- 1
// Entry 13 timestamp = 5; Set x <- 1
// Event Queue at t = 5
//
// Entry 2 timestamp = 8; Resume testbench procedural code.
// Entry 15 timestamp = 5; Some procedural stuff.[always @( a or b or x
or y )]
// Entry 14 timestamp = 5; Set y <- 1
// Remove entry 14
// Set y to 1.
// Add affected items. (The affected item is already there, the always
thing.)
// Event Queue at t = 5
//
// Entry 2 timestamp = 8; Resume testbench procedural code.
// Entry 15 timestamp = 5; Some procedural stuff.[always @( a or b or x
or y )]
// Remove entry 15
// The procedural code prints a message.
// Event Queue at t = 5
//
// Entry 2 timestamp = 8; Resume testbench procedural code.
// :Example:
//
// The testbench for the code above. This module uses procedural
// code which has not been covered yet. It can be ignored for now.
module demo_timing();
reg a, b;
wire x, y;
timing everyones_timing_module_instance(x,y,a,b);
integer i;
always @( a or b or x or y )
$display(" a,b = %d, %d x,y= %d, %d",a,b,x,y);
initial begin
{a,b} = i[1:0];
#8;
end
end
endmodule