HDL Manual 2020 5th Sem E&CE 18ECL58
HDL Manual 2020 5th Sem E&CE 18ECL58
VISHVAKIRAN R C
2 0 2 0
PART A:
PROGRAMMING (Verilog Using Xilinx Tool)
Write a Verilog program for the following combinational designs ............................................ 1-12
1. 2 to 4 decoder using only NAND gates ........................................................................................... 1
2. 8 to 3 encoder without priority ........................................................................................................ 3
3. 8 to 3 encoder with priority ............................................................................................................. 5
4. 8 to 1 multiplexer using case and if statements .............................................................................. 7
5. 4 bit binary to gray converter using 1 bit adder, 1 bit subractor, 1 bit gray to binary ................... 10
6. a. Write a Verilog code to describe the functions of a Full Adder Using 3 modeling styles . 13-18
i. Full Adder Data Flow Description ......................................................................................... 13
ii. Logic Gates AND, OR, XOR, XNOR using Full Adder ........................................................ 15
iii. Full Adder Behavioral Description ........................................................................................ 15
iv. Full Adder Structural Description .......................................................................................... 17
7. Verilog 32-bit ALU shown in figure below and verify the functionality of ALU by selecting
appropriate test patterns. The functionality of the ALU is presented in Table 1. .................... 19-21
a. Write test bench to verify the functionality of the ALU considering all possible input
patterns
b. The enable signal will set the output to required functions if enabled, if disabled all the
outputs are set to tri-state
c. The acknowledge signal is set high after every operation is Completed Write a Verilog
code to model 32 bit ALU using the schematic diagram shown below
OPCODE ALU OPERATION Bin [31:0] Ain [31:0]
32
0. A+B 32
Ack
1. A–B 3
Opcode[2:0] 32
32-bit ALU
2. A OR B Result[31:0]
Enable
3. A AND B ALU top level block diagram
4. A Complement
5. A+1
6. A–1
7. A True
Develop the Verilog code for the following flip-flops, SR, D, JK and T......................................... 22-29
8. SR Flip Flop ................................................................................................................................. 22
9. JK Flip Flop .................................................................................................................................. 24
10. D Flip Flop ................................................................................................................................... 26
11. T Flip Flop .................................................................................................................................... 28
Note: Clock divider Concept
Design a 4 bit binary, BCD counters Synchronous reset counters, using Verilog code ................ 31-34
12. BCD Synchronous Reset 4bit Counter ......................................................................................... 31
13. Binary Synchronous Reset 4bit Counter considering the frequency divider ................................ 33
i
5TH SEM, HDL Lab, 18ECL58 2020-21 DEPT. E&C, CEC, Bengaluru
1. 2 to 4 decoder realization using NAND gates only (structural
model)
2
d_in
inputs 4
Decoder 2 to 4 d_op
outputs
en
Inputs Outputs
en d_in(1) d_in(0) d_op(3) d_op(2) d_op(1) d_op(0)
0 X X Z Z Z Z
1 0 0 1 1 1 0
1 0 1 1 1 0 1
1 1 0 1 0 1 1
1 1 1 0 1 1 1
Truth Table 1: Decoder 2 to 4
𝑑_𝑜𝑝[0] = ̅̅̅̅̅̅̅̅̅̅
𝑑_𝑖𝑛[1] ∙ ̅̅̅̅̅̅̅̅̅̅
𝑑_𝑖𝑛[0] ∙ 𝑒𝑛
𝑑_𝑜𝑝[1] = ̅̅̅̅̅̅̅̅̅̅
𝑑_𝑖𝑛[1] ∙ 𝑑_𝑖𝑛[0] ∙ 𝑒𝑛
𝑑_𝑜𝑝[2] = 𝑑_𝑖𝑛[1] ∙ ̅̅̅̅̅̅̅̅̅̅
𝑑_𝑖𝑛[0] ∙ 𝑒𝑛
𝑑_𝑜𝑝[3] = 𝑑_𝑖𝑛[1] ∙ 𝑑_𝑖𝑛[0] ∙ 𝑒𝑛
endmodule
PART-A: NON-INTERFACING 1 VK
5TH SEM, HDL Lab, 18ECL58 2020-21 DEPT. E&C, CEC, Bengaluru
#10 din = 2’b10;
#10 din = 2’b11;
#10 en = 0; din = 2’b10;
end
endmodule
Waveform 1: Decoder 2 to 4
0 0 xx zzzz
10 1 00 1110
20 1 01 1101
30 1 10 1011
40 1 11 0111
50 0 10 zzzz
Stopped at time : 60 ns
Transcript1: Decoder 2 to 4
PART-A: NON-INTERFACING 2 VK
5TH SEM, HDL Lab, 18ECL58 2020-21 DEPT. E&C, CEC, Bengaluru
2. 8 to 3 encoder without priority (behavioral model)
8
a_in
inputs Encoder 3
y_op
Without Priority
outputs
en
Inputs Outputs
y_op y_op y_op
en a_in(7) a_in(6) a_in(5) a_in(4) a_in(3) a_in(2) a_in(1) a_in(0)
(2) (1) (0)
1 X X X X X X X X Z Z Z
0 0 0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 1 0 0 0 1
0 0 0 0 0 0 1 0 0 0 1 0
0 0 0 0 0 1 0 0 0 0 1 1
0 0 0 0 1 0 0 0 0 1 0 0
0 0 0 1 0 0 0 0 0 1 0 1
0 0 1 0 0 0 0 0 0 1 1 0
0 1 0 0 0 0 0 0 0 1 1 1
Truth Table 2: Encoder Without Priority
Verilog File Name: encd_wo_prior.v
// encoder without priority
module encd_wo_prior( en, a_in, y_op );
input en;
input [7:0] a_in;
output [2:0] y_op;
wire en;
wire [7:0] a_in;
reg [2:0] y_op;
PART-A: NON-INTERFACING 3 VK
5TH SEM, HDL Lab, 18ECL58 2020-21 DEPT. E&C, CEC, Bengaluru
8'b00000010 : y_op = 3'b001;
8'b00000100 : y_op = 3'b010;
8'b00001000 : y_op = 3'b011;
8'b00010000 : y_op = 3'b100;
8'b00100000 : y_op = 3'b101;
8'b01000000 : y_op = 3'b110;
8'b10000000 : y_op = 3'b111;
default : y_op = 3'bZZZ;
endcase
end
end
endmodule
PART-A: NON-INTERFACING 4 VK
5TH SEM, HDL Lab, 18ECL58 2020-21 DEPT. E&C, CEC, Bengaluru
3. 8 to 3 encoder with priority (behavioral model)
8
a_in
inputs Encoder 3
y_op
With Priority
outputs
en
Inputs Outputs
y_op y_op y_op
en a_in(7) a_in(6) a_in(5) a_in(4) a_in(3) a_in(2) a_in(1) a_in(0)
(2) (1) (0)
1 X X X X X X X X Z Z Z
0 1 X X X X X X X 1 1 1
0 0 1 X X X X X X 1 1 0
0 0 0 1 X X X X X 1 0 1
0 0 0 0 1 X X X X 1 0 0
0 0 0 0 0 1 X X X 0 1 1
0 0 0 0 0 0 1 X X 0 1 0
0 0 0 0 0 0 0 1 X 0 0 1
0 0 0 0 0 0 0 0 1 0 0 0
Truth Table 3: Encoder With Priority
Verilog File Name: encd_w_prior.v
// encoder with priority
module encd_w_prior( en, a_in, y_op );
input en;
input [7:0] a_in;
output [2:0] y_op;
wire en;
wire [7:0] a_in;
reg [2:0] y_op;
PART-A: NON-INTERFACING 5 VK
5TH SEM, HDL Lab, 18ECL58 2020-21 DEPT. E&C, CEC, Bengaluru
else if(a_in[0] == 1'b1) y_op = 3'b000;
else y_op = 3'bZZZ;
end
end
endmodule
PART-A: NON-INTERFACING 6 VK
5TH SEM, HDL Lab, 18ECL58 2020-21 DEPT. E&C, CEC, Bengaluru
4. 8 to 1 multiplexer using case statement and if statements
8
i_in
inputs y_out
Multiplexer 8 to 1
output
en
3
sel
Figure 4: Block Diagram of Multiplexer 8 to 1
Inputs Output
sel sel sel i_in i_in i_in i_in i_in i_in i_in i_in
en y_out
(2) (1) (0) (7) (6) (5) (4) (3) (2) (1) (0)
1 X X X X X X X X X X X Z
0 0 0 0 0 0 0 0 0 0 0 1 1
0 0 0 1 0 0 0 0 0 0 1 0 1
0 0 1 0 0 0 0 0 0 1 0 0 1
0 0 1 1 0 0 0 0 1 0 0 0 1
0 1 0 0 0 0 0 1 0 0 0 0 1
0 1 0 1 0 0 1 0 0 0 0 0 1
0 1 1 0 0 1 0 0 0 0 0 0 1
0 1 1 1 1 0 0 0 0 0 0 0 1
Truth Table 4: Mux 8 to 1
Verilog File Name: mux8to1c.v
// Multiplexer 8 to 1 using case statement
module mux8to1(en,i_in,sel,y_out);
input en;
input [2:0] sel;
input [7:0] i_in;
output y_out;
wire en;
wire [7:0] i_in;
wire [2:0] sel;
reg y_out;
always@(en,sel,i_in)
begin
if(en != 0) // Active Low Enabled
y_out = 1'bZ;
else
begin
case(sel)
3'b000: y_out = i_in[0];
3'b001: y_out = i_in[1];
3'b010: y_out = i_in[2];
3'b011: y_out = i_in[3];
3'b100: y_out = i_in[4];
PART-A: NON-INTERFACING 7 VK
5TH SEM, HDL Lab, 18ECL58 2020-21 DEPT. E&C, CEC, Bengaluru
3'b101: y_out = i_in[5];
3'b110: y_out = i_in[6];
3'b111: y_out = i_in[7];
default: y_out = 1'bZ;
endcase
end
end
endmodule
end
end
endmodule
PART-A: NON-INTERFACING 8 VK
5TH SEM, HDL Lab, 18ECL58 2020-21 DEPT. E&C, CEC, Bengaluru
#10 i_in = 8'b00010000; sel = 3'b100;
#10 i_in = 8'b00100000; sel = 3'b101;
#10 i_in = 8'b01000000; sel = 3'b001;
end
initial #80 $finish;
initial $monitor ($time," %b %b %b %b ",en, i_in, sel, yout);
endmodule
Waveform 4: Mux 8 to 1
0 1 xxxxxxxx xxx z
10 0 xxxxxxxx xxx z
20 0 01000010 001 1
30 0 00000100 010 1
40 0 00001000 011 1
50 0 00010000 100 1
60 0 00100000 101 1
70 0 01000000 001 0
Stopped at time : 80 ns
Transcript4: Multiplexer 8 to 1
PART-A: NON-INTERFACING 9 VK
5TH SEM, HDL Lab, 18ECL58 2020-21 DEPT. E&C, CEC, Bengaluru
5. 4-bit binary to gray converter using 1-bit gray to binary
converter 1-bit adder and subtractor
Binary
inputs 4
to g_op
4
b_in Gray
outputs
Converter
Inputs Outputs
Binary Gray
Decimal
b_in(3) b_in(2) b_in(1) b_in(0) g_op(3) g_op(2) g_op(1) g_op(0)
0 0 0 0 0 0 0 0 0
1 0 0 0 1 0 0 0 1
2 0 0 1 0 0 0 1 1
3 0 0 1 1 0 0 1 0
4 0 1 0 0 0 1 1 0
5 0 1 0 1 0 1 1 1
6 0 1 1 0 0 1 0 1
7 0 1 1 1 0 1 0 0
8 1 0 0 0 1 1 0 0
9 1 0 0 1 1 1 0 1
10 1 0 1 0 1 1 1 1
11 1 0 1 1 1 1 1 0
12 1 1 0 0 1 0 1 0
13 1 1 0 1 1 0 1 1
14 1 1 1 0 1 0 0 1
15 1 1 1 1 1 0 0 0
Truth Table 5: Binary to Gray
Verilog File Name: bin_to_gray_4bit.v
// Binary to Gray 4bit Converter
module bin_to_gray_4bit( b_in, g_op );
input [3:0] b_in;
output [3:0] g_op;
assign g_op[3]= b_in[3];
halfadder ha1(g_op[2],,b_in[3], b_in[2]);
halfsubtractor hs1(g_op[1],,b_in[2], b_in[1]);
PART-A: NON-INTERFACING 10 VK
5TH SEM, HDL Lab, 18ECL58 2020-21 DEPT. E&C, CEC, Bengaluru
xor x1(g_op[0], b_in[1], b_in[0]);
endmodule
module halfadder(sum,carry,ain,bin);
output sum, carry;
input ain, bin;
assign sum=ain ^bin;
assign carry=ain &bin;
endmodule
PART-A: NON-INTERFACING 11 VK
5TH SEM, HDL Lab, 18ECL58 2020-21 DEPT. E&C, CEC, Bengaluru
0 0000 0000
10 0001 0001
20 0010 0011
30 0011 0010
40 0100 0110
50 0101 0111
60 0110 0101
70 0111 0100
80 1000 1100
90 1001 1101
100 1010 1111
110 1011 1110
120 1100 1010
130 1101 1011
140 1110 1001
150 1111 1000
Stopped at time : 160 ns
Transcript5: 4Bit Binary to Gray Converter
PART-A: NON-INTERFACING 12 VK
5TH SEM, HDL Lab, 18ECL58 2020-21 DEPT. E&C, CEC, Bengaluru
6. Full Adder – a. Verilog Module
a_in sum
b_in Full Adder outputs
inputs
c_in carry
a_in S1
b_in x1 sum
x2
a2
S3
carry
o1
a1
S2
c_in
Inputs Outputs
a_in b_in c_in sum carry
0 0 0 0 0
0 0 1 1 0
0 1 0 1 0
0 1 1 0 1
1 0 0 1 0
1 0 1 0 1
1 1 0 0 1
1 1 1 1 1
Truth Table 6a: Full Adder
Logical expression:
Halfadder sum ->S1
𝑆1 = 𝑎 ⊕ 𝑏 ; 𝑠𝑢𝑚 = 𝑆1 ⊕ 𝑐_𝑖𝑛 ;
𝑐𝑎𝑟𝑟𝑦 = 𝑎 ∗ 𝑏 + 𝑆1 ∗ 𝑐_𝑖𝑛;
PART-A: NON-INTERFACING 13 VK
5TH SEM, HDL Lab, 18ECL58 2020-21 DEPT. E&C, CEC, Bengaluru
Inputs Outputs
a b aandb aorb axorb axnorb
0 0 0 0 0 1
0 1 0 1 1 0
1 0 0 1 1 0
1 1 1 1 0 1
Truth Table 6b: Full Adder
Full Adder Data Flow Description
end
endmodule
PART-A: NON-INTERFACING 14 VK
5TH SEM, HDL Lab, 18ECL58 2020-21 DEPT. E&C, CEC, Bengaluru
a_in S1 HA2
b_in x1 sum
x2
HA1 a2
S3
carry
o1
a1
S2
c_in
initial begin
a = 0; b = 0;
#10 a = 0; b = 1;
#10 a = 1; b = 0;
#10 a = 1; b = 1;
#10;
end
endmodule
PART-A: NON-INTERFACING 15 VK
5TH SEM, HDL Lab, 18ECL58 2020-21 DEPT. E&C, CEC, Bengaluru
wire a_in, b_in, c_in;
reg sum, carry;
PART-A: NON-INTERFACING 16 VK
5TH SEM, HDL Lab, 18ECL58 2020-21 DEPT. E&C, CEC, Bengaluru
endmodule
end
endmodule
PART-A: NON-INTERFACING 17 VK
5TH SEM, HDL Lab, 18ECL58 2020-21 DEPT. E&C, CEC, Bengaluru
PART-A: NON-INTERFACING 18 VK
5TH SEM, HDL Lab, 18ECL58 2020-21 DEPT. E&C, CEC, Bengaluru
7. ALU 32 Bits
32 32
ack
3
opcode[2:0] 32
32-bit ALU
zout[31:0]
en
Figure 10: Block diagram of ALU 32 bits
Inputs Outputs
Actions
opc a_in b_in zout ack
XXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXX
XXX ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 0 No Change
XXXXX XXXXX
000 000000000000000000010111 000000000000000000101101 00000000000000000000000001000100 1 a_in + b_in
001 000000000000000000010111 000000000000000000101101 11111111111111111111111111101010 1 a_in - b_in
010 000000000000000000010111 000000000000000000101101 00000000000000000000000000111111 1 a_in or b_in
011 000000000000000000010111 000000000000000000101101 00000000000000000000000000000101 1 a_in and b_in
100 000000000000000000010111 11111111111111111111111111101000 1 not a_in
101 000000000000000000010111 000000000000000000011000 1 a_in + 1
110 000000000000000000010111 000000000000000000010110 1 a_in - 1
111 000000000000000000010111 000000000000000000010111 1 a_in
module alu32bit(a_in,b_in,opcode,zout,ack);
input [23:0] a_in,b_in;
input [2:0] opcode;
output [31:0] zout;
output ack;
reg [31:0] zout;
reg ack;
wire [31:0] a, b;
assign a = {8'b0,a_in};
assign b = {8'b0,b_in};
always@ *
begin
case (opcode)
3'b000 : begin zout = a+b; ack = 1; end
3'b001 : begin zout = a-b;ack = 1; end
3'b010 : begin zout = a | b; ack = 1; end
3'b011 : begin zout = a & b; ack = 1; end
3'b100 : begin zout = ~ a;ack = 1; end
3'b101 : begin zout = a*b;ack = 1; end
3'b110 : begin zout = a + 1;ack = 1; end
PART-A: NON-INTERFACING 19 VK
5TH SEM, HDL Lab, 18ECL58 2020-21 DEPT. E&C, CEC, Bengaluru
3'b111 : begin zout = a;ack = 1; end
default : begin zout = 32'd0; ack = 0; end
endcase
end
endmodule
Verilog Testbench File Name: alu32bit_test.v
module alu32bit_test;
// Inputs
reg [23:0] a_in;
reg [23:0] b_in;
reg [2:0] opcode;
// Outputs
wire [31:0] zout;
initial begin
// Initialize Inputs
a_in = 23; b_in = 45;
opcode = 0;
#1 opcode = 1;
#1 opcode = 2;
#1 opcode = 3;
#1 opcode = 4;
#1 opcode = 5;
#1 opcode = 6;
#1 opcode = 7;
#1 a_in = 53; b_in = 56;
#1 opcode = 0;
#1 opcode = 1;
#1 opcode = 2;
#1 opcode = 3;
#1 opcode = 4;
#1 opcode = 5;
#1 opcode = 6;
#1 opcode = 7;
end
endmodule
PART-A: NON-INTERFACING 20 VK
5TH SEM, HDL Lab, 18ECL58 2020-21 DEPT. E&C, CEC, Bengaluru
PART-A: NON-INTERFACING 21 VK
5TH SEM, HDL Lab, 18ECL58 2020-21 DEPT. E&C, CEC, Bengaluru
8. S R Flip Flop
s
q
r
SR Flip Flop outputs
inputs
qb
rst
clk
Figure 8: Block Diagram of SR Flip Flop
Inputs Outputs
rst clk s r q qb Action
1 ↑ X X q qb No Change
0 ↑ 0 0 q qb No Change
0 ↑ 0 1 0 1 Reset
0 ↑ 1 0 1 0 Set
0 ↑ 1 1 - - Illegal
Truth Table 8: S R Flip Flop
Verilog File Name: sr_ff.v
//Async SR Flip Flop
module sr_ff( sr , clk , reset , q ,qb );
input [1:0] sr;
input clk, reset ;
output q,qb;
reg q,qb;
PART-A: NON-INTERFACING 22 VK
5TH SEM, HDL Lab, 18ECL58 2020-21 DEPT. E&C, CEC, Bengaluru
Verilog Testbench File Name: sr_ff_test.v
`timescale 1ns/1ps
module srflip_tb;
reg clk, rst;
reg [1:0] sr;
wire q, qb;
initial
begin
clk = 0; rst=1; sr=2'b00;
end
always
#5 clk=~clk;
initial
begin
#10 rst=0;
#10 sr = 2'b10;
#10 sr = 2'b00;
#10 sr = 2'b01;
#10 sr = 2'b11;
#20 sr = 2'b10;
#10 sr = 2'b00;
#10;
end
initial #100 $finish;
initial $monitor ($time," %b %b %b ---> %b ",clk , rst , sr, q
,qb);
endmodule
9. J K Flip Flop
j
q
k
JK Flip Flop outputs
inputs
qb
rst
clk
Figure 9: Block Diagram of JK Flip Flop
Inputs Outputs
rst clk j k q qb Action
1 ↑ X X q qb No Change
0 ↑ 0 0 q qb No Change
0 ↑ 0 1 0 1 Reset
0 ↑ 1 0 1 0 Set
0 ↑ 1 1 q' q' Toggle
Truth Table 9: J K Flip Flop
Verilog File Name: jk_ff.v
//Async JK Flip Flop
module jk_ff( jk , clk , reset , q ,qb );
input [1:0] jk;
input clk, reset ;
output q,qb;
reg q,qb;
PART-A: NON-INTERFACING 24 VK
5TH SEM, HDL Lab, 18ECL58 2020-21 DEPT. E&C, CEC, Bengaluru
Verilog Testbench File Name: jk_ff_test.v
`timescale 1ns/1ps
module jkflip_tb;
reg clk, rst;
reg [1:0] jk;
wire q, qb;
d q
clk
Figure 10: Block Diagram of D Flip Flop
Inputs Outputs
rst clk d q qb Action
1 ↑ X q qb No Change
0 ↑ 0 0 1 Reset
0 ↑ 1 1 0 Set
Truth Table 10: D Flip Flop
PART-A: NON-INTERFACING 26 VK
5TH SEM, HDL Lab, 18ECL58 2020-21 DEPT. E&C, CEC, Bengaluru
module dflip_tb;
reg clk, rst, d;
wire q, qb;
d_ff uut ( .clk(clk), .reset(rst), . d(d), .q(q), .qb(qb));
initial
begin
clk = 0; rst=1;
end
always
#5 clk=~clk;
initial
begin
#10; rst=0;
#10 d = 0;
#10 d = 1;
#10
#10 d = 0;
#10 d = 1;
#40;
end
initial #100 $finish;
initial $monitor ($time," %b %b %b ---> %b ",clk , rst , d, q ,qb);
endmodule
t q
clk
Figure 11: Block Diagram of T Flip Flop
Inputs Outputs
rst clk t q qb Action
1 ↑ X q qb No Change
0 ↑ 0 q qb No Change
0 ↑ 1 q' q' Toggle
Truth Table 11: T Flip Flop
Verilog File Name: t_ff.v
//Async T Flip Flop
module t_ff( t, clk, reset, q, qb );
input t, clk, reset ;
output q,qb;
reg q,qb;
PART-A: NON-INTERFACING 28 VK
5TH SEM, HDL Lab, 18ECL58 2020-21 DEPT. E&C, CEC, Bengaluru
module tflip_tb;
reg clk, rst, t;
wire q, qb;
t_ff uut ( .clk(clk), .reset(rst), . t(t), .q(q), .qb(qb));
initial
begin
clk = 0; rst=1;
end
always
#5 clk=~clk;
initial
begin
#10; rst=0;
#10 t = 0;
#10 t = 1;
#20
#10 t = 0;
#10 t = 1;
#40;
end
initial #100 $finish;
initial $monitor ($time," %b %b %b ---> %b ",clk , rst , t, q ,qb);
endmodule
PART-A: NON-INTERFACING 29 VK
5TH SEM, HDL Lab, 18ECL58 2020-21 DEPT. E&C, CEC, Bengaluru
CLOCK DIVIDER CONCEPT
Note:
𝑓
Clock division = = 1 Hz i.e. T=1 sec
222
// initialization and declaration of input and output variables
input clk;
reg [31:0]counter;
wire clk_div;
always@(posedge clk)
begin
counter = counter +1;
end
assign clk_div=counter[21];
// clock pulse of count1[21] to specify the delay of 1 Sec.
always@(posedge clk_div, posedge clr/rst)
// body of the Program
PART-A: NON-INTERFACING 30 VK
5TH SEM, HDL Lab, 18ECL58 2020-21 DEPT. E&C, CEC, Bengaluru
12. BCD Synchronous Reset 4bit Counter
clk
Figure 12: Block Diagram of BCD Synchronous Reset 4bit Counter
module count4bit_tb;
reg rst, clk;
wire [3:0] count;
initial
begin
clk = 0; rst=1;
end
always
#5 clk=~clk;
PART-A: NON-INTERFACING 31 VK
5TH SEM, HDL Lab, 18ECL58 2020-21 DEPT. E&C, CEC, Bengaluru
initial
begin
#5; rst=0;
#105;
#10; rst=1;
#15; rst=0;
#30;
#2; rst=1;
#10;
end
endmodule
PART-A: NON-INTERFACING 32 VK
5TH SEM, HDL Lab, 18ECL58 2020-21 DEPT. E&C, CEC, Bengaluru
rst
Figure 13: Block Diagram of Binary Synchronous Reset 4bit Counter
input clk1,clk2,clk3,clk4,rst;
output reg [3:0]q1=4'd0;
output reg [3:0]q2=4'd0;
output reg [3:0]q3=4'd0;
output reg [3:0]q4=4'd0;
always@(posedge clk1)
begin
if(rst==1)
q1=4'd0;
else
q1=q1+1'b1;
end
always@(posedge clk2)
begin
if(rst==1)
q2=4'd0;
else
q2=q2+1'b1;
end
always@(posedge clk3)
begin
if(rst==1)
q3=4'd0;
else
q3=q3+1'b1;
end
always@(posedge clk4)
begin
if(rst==1)
q4=4'd0;
else
q4=q4+1'b1;
end
endmodule
PART-A: NON-INTERFACING 33 VK
5TH SEM, HDL Lab, 18ECL58 2020-21 DEPT. E&C, CEC, Bengaluru
module bin_tb;
reg clk1,clk2,clk3,clk4;
reg rst;
wire [3:0]q1,q2,q3,q4;
bin_cnt uut (.clk1(clk1), .clk2(clk2), .clk3(clk3), .clk4(clk4),
.rst(rst), .q1(q1), .q2(q2), .q3(q3), .q4(q4));
initial
begin
rst=1; #10;
clk1 = 0;
clk2 = 0;
clk3 = 0;
clk4 = 0;
rst = 0;
end
endmodule
PART-A: NON-INTERFACING 34 VK