Microsoft Word - Digital Logic Design v_4_6a

(lily) #1
Below is usage example in a module:

 Always statement “always ”
Always block not only executes always (on going) as the name implies but it also allows for
selective execution based on the sensitivity list.


In the following example input Ain is always assigned to Cout. As you can see this is similar
function to assign with the difference that we have to specify a delay. In the following example
we are using a delay of 5 time unit (time unit are defined at the beginning of code). The value of
delay is written after the “#” symbol.

`timescale 1ns/100ps // time unit is 1 ns with precision of 100 ps

module example(Ain, Bin, Cout);

input Ain, Bin;
wire Ain, Bin;
output Cout;
reg Cout;
integer i, count;

initial // set the initial value of variables.
begin
i = 0;
count =0;
Ain =0;
Bin =0;
end //initial

assign Cout = Ain; // Cout is always equal to Ain
assign #5 Cout=Bin; // 5 unit delay (5 ns) before assignment

endmodule // end of module
Free download pdf