To test whether modules we have written are doing what we intended them to, we have a way of applying stimulus to the inputs and checking whether the outputs correspond. This is called a stimulus module. The syntax is exactly the same as the modules seen already, but a stimulus module does not have a port list because it has no input and explicit outputs. We would like to apply waveforms to the clock, enable and reset to see how the output of the module e_ffbehaves
module e_ffStimulus;
reg data, enable, reset, clock;
wire q;
e_ff mod1 (q, data, enable, reset, clock);
initial begin
clock = 1'b0;
forever clock = #5 ~clock;
end
initial begin
enable = 1'b0; // initialize enable variable
reset = 1'b1; // the E type has an active high reset, so
#20 reset = 1'b0; // we begin by resetting.
data = 1'b1; // set the data HIGH
#10 enable = 1'b1; // and then enable data latching
#10 data = 1'b1; // change the data value
#20 data = 1'b0; // change the data value
#30 data = 1'b1; // change the data value
#10 data = 1'b0; // change the data value
#10 data = 1'b1; // change the data value
#20 enable = 1'b0; // disable data latching
#10 data = 1'b0; // change the data value - no effect?
#10 reset = 1'b1; // reset again
#20 $finish; // finally we must end the simulation using
end // $finish this also stops the clock
initial begin
$display($time, " reset, enable, data, q ");
$display($time, " %d %d %d %d",
reset, enable, data, q);
forever #10 $display($time, " %d %d %d %d",
reset, enable, data, q);
end
endmodule // e_ffStimulus
a) Run the stimulus using, cut and paste, with the code from the previous section - interpret the output
b) Write a single behavioural module for the E-type flipflop and test it using the above stimulus Answers