David83
Advanced Member level 1
Hello all,
I was trying to write a synthesizable RTL code for a 3 1-bit full adder using Verilog, where the inputs are A, B, and C_in. In a full adder there are 2 1-bit outputs: the sum S and the carry out C_out, where S=A^B^C_in, and C_out=AB+BC+AC, where ^ the XOR logic operation and + is the logic OR operation. I wrote the following design (structural description) and stimulus blocks:
The simulation runs fine. The schematic diagram is attached and generated suing Vivado. I have a couple of questions:
1- Can I enhance my code? I guess I can learn some tricks to make more efficient.
2- what is `timescale 1ns/1ns? I understand that each time unit is 1ns, but what is the other 1ns in 1ns/1ns? I saw this in a tutorial, and I've kept using it.
3- Why Vivado didn't generate 1 3-input XOR gate, but instead generated 2 2-input XOR gate? isn't it practical?
Thanks
I was trying to write a synthesizable RTL code for a 3 1-bit full adder using Verilog, where the inputs are A, B, and C_in. In a full adder there are 2 1-bit outputs: the sum S and the carry out C_out, where S=A^B^C_in, and C_out=AB+BC+AC, where ^ the XOR logic operation and + is the logic OR operation. I wrote the following design (structural description) and stimulus blocks:
Code:
\\ Design Block
module full_adder(A,B,C_in,S,C_out);
input A,B,C_in;
output S,C_out;
wire f1,f2,f3;
xor(S,A,B,C_in);
and(f1,A,B);
and(f2,B,C_in);
and(f3,A,C_in);
or(C_out,f1,f2,f3);
endmodule
\\Stimulus Block
`timescale 1ns/1ns
module full_adder_tb;
reg clk;
reg [2:0] count;
wire S,C;
initial
begin
clk=1;
count=3'b111;
end
always #5 clk=~clk;
always @(posedge clk)
count=count+1;
full_adder MUT(count[2],count[1],count[0],S,C);
endmodule
The simulation runs fine. The schematic diagram is attached and generated suing Vivado. I have a couple of questions:
1- Can I enhance my code? I guess I can learn some tricks to make more efficient.
2- what is `timescale 1ns/1ns? I understand that each time unit is 1ns, but what is the other 1ns in 1ns/1ns? I saw this in a tutorial, and I've kept using it.
3- Why Vivado didn't generate 1 3-input XOR gate, but instead generated 2 2-input XOR gate? isn't it practical?
Thanks
Attachments
Last edited: