Problem Solutions – Chapter 4
39
4-61.
There are a number of ways to model the timing behavior, but since the book has not gone into great detail
about modeling timing and some of the features of Verilog and VHDL for modeling timing (e.g., Verilog’s
$specify block) and checking for setup/hold time violations, the example below illustrates a simple approach
that does not require knowledge of these features.
`timescale 1ps/1ps
module problem461(Clock, Reset, X, Y);
input Clock, Reset, X;
output Y;
always @(posedge CLK or posedge RESET)
begin
if (RESET)
Q <= 1’b0;
else
Q <= #80 D;
end
endmodule
`timescale 1ps/1ps
module problem461_tb();
reg x, clk, reset;
wire y;
end
always
#(PERIOD/2) clk = ~clk;
endmodule
Incorrect behavior with the clock period set to 125 ps (Output y should toggle between 0 and 1 on every clock cycle with x
set to 0):
Correct behavior with the clock period set to 175 ps: