Полный сумматор с использованием Verilog HDL
Опубликовано: 25 Сентября, 2022
В этой статье мы обсудим обзорную часть Full Adder с использованием Verilog HDL. И цель понять концепцию и реализовать с помощью кода Verilog HDL для Full Adder. Давайте обсудим это один за другим.
Предварительное условие — полный сумматор в цифровой логике
Постановка задачи :
Напишите Verilog HDL для разработки полного сумматора. Давайте обсудим это шаг за шагом следующим образом.
Шаг 1 :
Концепция -
Полный сумматор — это цифровая комбинационная схема, имеющая три входа a, b и cin и два выхода sum и cout. Ниже приведена таблица истинности, показывающая функциональность полного сумматора.
Шаг 2 :
Таблица истинности –
| а | б | син | сумма | cout |
|---|---|---|---|---|
| 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 |
Шаг 3 :
Код Verilog HDL для Full Adder (часть дизайна) -
// Code your design : Full Adder module full_add(a,b,cin,sum,cout); input a,b,cin; output sum,cout; wire x,y,z; // instantiate building blocks of full adder half_add h1(.a(a),.b(b),.s(x),.c(y)); half_add h2(.a(x),.b(cin),.s(sum),.c(z)); or o1(cout,y,z); endmodule : full_add // code your half adder design module half_add(a,b,s,c); input a,b; output s,c; // gate level design of half adder xor x1(s,a,b); and a1(c,a,b); endmodule :half_add
Шаг-4:
Испытательный стенд -
// Code your testbench here
module full_add_tb;
reg a,b,cin;
wire sum,cout;
// instantiate the DUT block
full_add f1(.a(a),.b(b),.cin(cin),.sum(sum),.cout(cout));
// this particular line is added to dump the file on online simulator
initial begin $dumpfile("full_tb.vcd");$dumpvars(); end
// insert all the inputs
initial begin a=1"b1; #4; a=1"b0;#10 $stop();end
initial begin b=1"b1; forever #2 b=~b;end
initial begin cin=1"b1;forever #1 cin=~cin; #10 $stop();end
// monitor all the input and output ports at times
// when any of the input changes its state
initial begin $monitor(" time=%0d A=%b B=%b
Cin=%b Sum=%b Cout=%b",$time,a,b,cin,sum,cout);end
endmodule : full_add_tbШаг-5:
Ожидаемый результат –
time=0 A=1 B=1 Cin=1 Sum=1 Cout=1 time=1 A=1 B=1 Cin=0 Sum=0 Cout=1 time=2 A=1 B=0 Cin=1 Sum=0 Cout=1 time=3 A=1 B=0 Cin=0 Sum=1 Cout=0 time=4 A=0 B=1 Cin=1 Sum=0 Cout=1 time=5 A=0 B=1 Cin=0 Sum=1 Cout=0 time=6 A=0 B=0 Cin=1 Sum=1 Cout=0 time=7 A=0 B=0 Cin=0 Sum=0 Cout=0 time=8 A=0 B=1 Cin=1 Sum=0 Cout=1 time=9 A=0 B=1 Cin=0 Sum=1 Cout=0 time=10 A=0 B=0 Cin=1 Sum=1 Cout=0 time=11 A=0 B=0 Cin=0 Sum=0 Cout=0 time=12 A=0 B=1 Cin=1 Sum=0 Cout=1 time=13 A=0 B=1 Cin=0 Sum=1 Cout=0