Gate Modelling
Gate Modelling
in Verilog.
buf not
Gate Instantiations of Buf/Not Gates :
// basic gate instantiations.
buf b1(OUT1, IN);
not n1(OUT1, IN);
// More than two outputs
buf b1_2out(OUT1, OUT2, IN);
// Gate instantiations
// Create s1n and s0n signals.
not (s1n, s1);
not (s0n, s0);
// choose IN0
S1 = 0; S0 = 0;
#1 $display("S1 = %b, S0 = %b, OUTPUT
= %b \n", S1, S0, OUTPUT);
// choose IN1
S1 = 0; S0 = 1;
#1 $display("S1 = %b, S0 = %b, OUTPUT
= %b \n", S1, S0, OUTPUT);
// choose IN2
S1 = 1; S0 = 0;
#1 $display("S1 = %b, S0 = %b, OUTPUT
= %b \n", S1, S0, OUTPUT);
// choose IN3
S1 = 1; S0 = 1;
#1 $display("S1 = %b, S0 = %b, OUTPUT
= %b \n", S1, S0, OUTPUT);
End
endmodule
The output of the simulation is shown below.
endmodule
4-bit Ripple Carry Full Adder
Verilog Description for 4-bit Ripple Carry Full Adder
// Define a 4-bit full adder
module fulladd4(sum, c_out, a, b, c_in);
// Internal nets
wire c1, c2, c3;
endmodule
Stimulus for 4-bit Ripple Carry Full Adder
// Define the stimulus (top level module)
module stimulus;
// Set up variables
reg [3:0] A, B;
reg C_IN;
wire [3:0] SUM;
wire C_OUT;
initial
Begin
$monitor($time," A= %b, B=%b, C_IN= %b, ---
C_OUT= %b,
SUM= %b\n",A, B, C_IN,
C_OUT, SUM);
end
// Stimulate inputs
initial
Begin
A = 4'd0; B = 4'd0; C_IN =
1'b0;
#5 A = 4'd3; B = 4'd4;
#5 A = 4'd2; B = 4'd5;
#5 A = 4'd9; B = 4'd9;
#5 A = 4'd10; B = 4'd15;
#5 A = 4'd10; B = 4'd5; C_IN =
1'b1;
end
endmodule
The output of the simulation is shown below.
Turn-off delay
The turn-off delay is associated with a gate output transition to the high impedance
value (z) from another value.
Types of Delay Specification
// Delay of delay_time for all transitions
and #(delay_time) a1(out, i1, i2);
EX:- and #(5) a1(out, i1, i2); //Delay of
5 for all
// Rise and Fall Delay Specification.
and #(rise_val, fall_val) a2(out, i1, i2);
Ex:- and #(4,6) a2(out, i1, i2); // Rise = 4,
Fall = 6
//One delay
// if +mindelays, delay= 4
// if +typdelays, delay= 5
// if +maxdelays, delay= 6
and #(4:5:6) a1(out, i1, i2);
// Two delays
// if +mindelays, rise= 3, fall= 5,
turn-off = min(3,5)
// if +typdelays, rise= 4, fall= 6,
turn-off = min(4,6)
// if +maxdelays, rise= 5, fall= 7, turn-off =min(5,7)
and #(3:4:5, 5:6:7) a2(out, i1, i2);
// Three delays
// if +mindelays, rise= 2 fall= 3 turn-off = 4
// if +typdelays, rise= 3 fall= 4 turn-off = 5
// if +maxdelays, rise= 4 fall= 5 turn-off = 6
and #(2:3:4, 3:4:5, 4:5:6) a3(out, i1,i2);
Delay Example
Figure : Module D
Verilog Definition for Module D with Delay
// Internal nets
wire e;
// Instantiate primitive gates to build the circuit
and #(5) a1(e, a, b); //Delay of 5 on gate a1
or #(4) o1(out, e,c); //Delay of 4 on gate o1
endmodule
Stimulus for Module D with Delay
// Declare variables
endmodule
The waveforms from the simulation are shown