Advanced Digital System Design Laboratory
Advanced Digital System Design Laboratory
ENGINEERING COLLEGE
THIRUVANNAMALAI
Regulation – 2021
NAME : ……………………………………………
YEAR : ……………………………………………
SEMESTER: ……………………………………………
REG NO:…………………………………………….
BONAFIDE CERTIFICATE
NAME……………………………………………………………..YEAR……………
SEM ………. … BRANCH……….…………………………………… REGISTER
NO…………………………………….… certified that this bonafide record of work
done by the above Student of the…….………………………… …….laboratory
during the year 2021-2022.
1.
Design of Universal Shift Register
2.
Design of Finite State Machine
3.
4 Bit synchronous counter using flip flops
AIM:
To develop the source code for the design of universal shift register using VERILOG and
obtainthe simulation, synthesis, place and route and implement into FPGA.
APPARATUS REQUIRED:
● Xilinx.
● Modelsim
PROCEDURE:
Step2: Declare the name of the entity and architecture by using Verilog source code.
Step4: Check the syntax and debug the errors if found, obtain the synthesis report.
Step6: Write all possible combinations of input using the test bench.
PROGRAM :
Verilog Code:
module usr(clk, clear, sel, p1, p2, p3, p4, seri, sele, q1, q2, q3, q4);
input clk, clear, p1, p2, p3, p4, seri, sele;
input [1:0]sel;
output q1, q2, q3, q4;
mux u1(p4, q3, seri, q4, sel, y4);
mux u2(p3, q2, q4, q3, sel, y3);
mux u3(p2, q1, q3, q2, sel, y2);
mux u4(p1, sele, q2, q1, sel, y1);
dff u5(y4, clk, clear, q4);
dff u6(y3, clk, clear, q3);
dff u7(y2, clk, clear, q2);
dff u8(y1, clk, clear, q1);
endmodule
Test Bench:
module usr_tb; reg clk, clear, p1, p2, p3, p4, seri, sele;
reg [1:0] sel;
wire q1, q2, q3, q4;
usr uut(clk, clear, sel, p1, p2, p3, p4, seri, sele, q1, q2, q3, q4);
initial begin clk = 0;
forever #10 clk = ~clk;
p1 = 0;
p2 = 0;
3 = 0;
p4 = 0;
seri = 0;
sele = 0;
#10
clear = 0;
p3 = 1;
p4 = 0;
#20
#20 seri = 1;
#20 seri = 0;
end
endmodule
output:
AIM:
To develop the source code for Finite State Machine by using VERILOG and obtain the
simulation, synthesis, place and route and implement into FPGA.
SOFTWARE REQUIRED:
● Xilinx
● Modelsim
PROCEDURE:
Test Bench:
module seq_det_tb;
reg sin,clk,reset;
wire y;
seq_det d1(sin,clk,reset,y);
initial
begin
clk = 1'b0;
repeat (41) #5 clk = ~clk;
end
initial
begin
$monitor($time,"sin=%b,clk=%b,reset=%b,y=%b", sin, clk, reset, y);
reset = 1;
sin=0;
#10 reset =0;
#10 sin = 1;
#10 sin = 0;
#10 sin = 1;
#10 sin = 1;
#10 sin = 0;
#10 sin = 0;
#10 sin = 1;
#10 sin = 1;
S.K.P.ENGINEERING COLLEGE Page 10
#10 sin = 0;
#10 sin = 1;
end
endmodule
Test Bench:
module seq_det_moore_tb;
reg sequence_in;
reg clock; reg reset;
wire detector_out;
seq_det_moore uut(sequence_in,clock,reset,detector_out );
initial begin clock = 0;
forever #5 clock = ~clock;
end
initial
begin
sequence_in = 0;
reset = 1;
#30;
reset = 0;
#20;
sequence_in = 1;
#20; sequence_in = 1;
#10; sequence_in = 0;
#10; sequence_in = 1;
#20; sequence_in = 0;
#20; sequence_in = 1;
#20; sequence_in = 0;
End endmodule
RESULT:
Thus the outputs of finite state machine are verified by synthesizing and simulating the
Verilog code.
AIM:
To develop the layout design for 4 bit synchronous counter using D flip flop by Microwind
andobtain the simulation results.
SOFTWARE REQUIRED:
● Xilinx
● Modelsim
AIM:
To implement a combinational circuits using FPGA.
SOFTWARES REQUIRED:
Xilinx.Modelsim.
TOOLS REQUIRED: FPGA kit.
ALGORITHM:
HALF ADDER:
Step 1: Start the program.
Step 2: Declare the input ports a, b.
Step 3: Declare output ports s, c.
Step 4: Begin the process using behavioral architecture.
Step 5:.Assign s=a b.
Step 6: Assign c=a.b.
Step 7: End the process.
FULL ADDER:
Step 1: Start the program.
Step 2: Declare the input ports a, b, cin.
Step 3: Declare the output ports s, cy.
Step 4: Begin the process using behavioral architecture.
Step 5: Assign s= a b cin. Assign cy= (a.b) + (b.cin) + (cin.a).
Step 6: End the process.
HALF ADDER:
The half adder operation needs two binary inputs, augends and addend bits and two binary
outputs are sum and carry. Sum= a b. Carry=ab. In multi-digit addition, we have to add two bytes
along with the carry of the previous digit addition. Effectively such addition requires addition of
three bits. This is not possible with the half adder.
FULL ADDER:
Full adder is a combinational circuit that forms the arithmetic sum of three input bits. It
consists of three inputs and two outputs. Two of the input variables denoted by A and B, represent
the two significant bits to be added. The third input Cin represents the carry from the previous
lower significant position.
__ _ _ _ _ _
Sum= A.B. Cin+ A.B. Cin+ A.B. Cin+ A.B. Cin.
Cin= Cin (A B)
Cout=A.B+A.Cin+B.Cin
FULL ADDER:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity full is Port ( a,b,cin : in STD_LOGIC;
s,cy : out STD_LOGIC);
end full;
architecture Behavioral of full is
begin s<=a xor b xor cin;
cy<=(a and b)or(b and cin)or(cin and a);
end Behavioral;
HALF ADDER
FULL ADDER
RESULT:
Thus the combinational circuit was designed and implemented using FPGA and its
truth table was verified.
AIM:
SOFTWARE REQUIRED:
Xilinx
TOOLS REQUIRED:
FPGA kit
ALGORITHM:
THEORY:
In the majority of digital signal processing (DSP) applications the critical operations
usually involve many multiplications and/or accumulations. For real-time signal processing, a
high speed and high throughput Multiplier Accumulator (MAC) is always a key to achieve a
high performance digital signal processing system. In the last few years, the main consideration
of MAC design is to enhance its speed. This is because; speed and throughput rate is always the
concern of digital signal processing system.
But for the epoch of personal communication, low power design also becomes another
main design consideration. This is because; battery energy available for these portable products
limits the power consumption of the system. Therefore, the main motivation of this work is to
PROGRAM:
module MAC(clk,rst,a,b,z);
input clk,rst;
input[2:0] a,b;
output z;
wire[5:0] w;
multiplier U1(.a(a),.b(b),.p(w));
pipo U2(.RIN(w),.clk(clk),.rst(rst),.ROUT(z));
endmodule
module multiplier(a,b,p);
input[2:0] a,b;
output[5:0] p;
wire[7:0] u;
wire[1:0] su;
wire[8:0] i;
and(p[0],a[0],b[0]);
and(u[0],a[1],b[0]);
and(u[1],a[2],b[0]);
and(u[2],a[0],b[1]);
and(u[3],a[1],b[1]);
and(u[4],a[2],b[1]);
and(u[5],a[0],b[2]);
and(u[6],a[1],b[2]);
and(u[7],a[2],b[2]);
hadd h1(.l(u[0]),.m(u[2]),.sum(p[1]),.cry(i[0]));
hadd h2(.l(i[0]),.m(u[1]),.sum(su[0]),.cry(i[1]));
hadd h3(.l(u[3]),.m(u[5]),.sum(su[1]),.cry(i[2]));
hadd h4(.l(su[0]),.m(su[1]),.sum(p[2]),.cry(i[6]));
hadd h5(.l(i[1]),.m(i[2]),.sum(i[5]),.cry(i[6]));
or(i[7],i[5],i[4]);
fadd f3(.d(i[7]),.e(u[4]),.cin(u[6]),.s(p[3]),.cout(i[8]));
fadd f4(.d(i[8]),.e(i[6]),.cin(u[7]),.s(p[4]),.cout(p[5]));
endmodule
module pipo(RIN,clk,rst,ROUT);
input[5:0] RIN;
input clk,rst; output[5:0]
ROUT; reg[5:0] ROUT;
always @(posedge clk or negedge rst) begin
if(!rst)
begin
ROUT<=6'b000000;
RESULT:
AIM:
SOFTWARE REQUIRED:
Verilog/VHDL
PROGRAM:
// define stateGCD
result = 0;
end
`LOAD: begin
$display("state: LOAD");
$display("load A = %d, B = %d", A, B);
nsGCD = `CHANGE;
nextDividend = (A > B) ? A : B;
nextDivisor = (A < B) ? A : B;
if (nextDivisor == 0) begin
$display("state: JUDGE");
// check if divisor == 1 or 0
$display("JUDGE, divisor = %d", divisor);
nsGCD = `DIVIDE0;
$display("state: DIVIDE1");
startDiv = 1'b0;
nsGCD = (doneDiv) ? `CHANGE : `DIVIDE1;
if (doneDiv) begin
nextDividend = divisor;
nextDivisor = remainder;
$display("quotient = %d, remainder = %d", quotient, remainder);
end
end
`CHANGE: begin
$display("state: CHANGE");
dividend = nextDividend;
divisor = nextDivisor;
nsGCD = `JUDGE;
$display("state: RESULT");
result = (divisor == 1) ? 1 : dividend;
nsGCD = `DONE;
end
S.K.P.ENGINEERING COLLEGE Page 30
`ERROR: begin
$display("state: ERROR");
$display("ERROR");
ERROR = 1'b1;
nsGCD = `DONE;
end
`DONE: begin
$display("state: DONE");
doneGCD = 1'b1;
nsGCD = `WAIT;
end
`DELAY0: begin
$display("state: DELAY1");
delay = delay - 1;
nsGCD = `DELAY0;
end
default: begin
nsGCD = `WAIT;
end
endcase
end
endmodule
end
end
default : begin
startGCD = 1'b0;
done = 1'b0;
ns = gcd;
if (doneGCD) begin
ns = idle;
done = 1'b1;
end
S.K.P.ENGINEERING COLLEGE Page 32
end
endcase
end
endmodule
inner_start = 1;
end
else if (clk) begin
state = state + 1;
end
// Datapath
remainder = 0;
end
long_divisor = long_divisor >> 1;
quotient = quotient << 1;
done = 0;
if (long_dividend >= long_divisor) begin
long_dividend = long_dividend - long_divisor;
quotient = quotient + 1;
end
if (state == 31) begin
remainder = long_dividend[31:0];
if (inner_start) begin
inner_start = 0;
done = 1;
end
end
end
endmodule
RESULT:
AIM:
SOFTWARE REQUIRED:
Verilog/VHDL
PROGRAM:
module testbench;
reg clk, reset;
initial
begin
clk = 1'b0;
reset = 1'b1;
reset = #161 1'b0;
end
always clk = #5 ~clk;
processor_top proc_top1(clk, reset);
endmodule
module processor_top (clk, reset);
input clk, reset;
input clk;
input [9:0] prog_ctr;
input [7:0] data_rd_addr, datamem_wr_data;
input [7:0] data_wr_addr;
input store_to_mem;
output [15:0] instr_mem_out;
output [7:0] datamem_rd_data;
reg [15:0] instr_mem_out;
reg [7:0] datamem_rd_data;
// instruction memory operations
$readmemh("C:/Users/ekstep1/Desktop/verlog/run/data2.txt",data_mem);
end
reg en_op2_complement_reg,jump_true_reg;
reg invalidate_fetch_instr_r2;
reg invalidate_decode_instr,reg_wr_en_ex;
reg invalidate_fetch_instr_r1;
reg invalidate_execute_instr,carry_flag_ex;
reg gt_flag_ex_reg, gt_flag;
reg lt_flag_ex_reg, lt_flag, unconditional_jump;
if (reset == 1'b1)
begin
prog_ctr <= 10'b0;
instruction <= 16'b0;
end
//****************************************
// INSTRUCTION FETCH PIPELINE REGISTERS
//****************************************
if (reset == 1'b1)
begin
else
begin
instruction <= #1 instr_mem_out;
if (branch_taken_reg == 1'b1)
end
//***************************
// INSTRUCTION DECODE LOGIC
//****************************
always@(instruction)
begin
opcode<= instruction[15:11];
op1_addr <= instruction[2:0];
op2_addr <= instruction[6:4];
res_addr <= instruction[10:8];
ld_mem_addr <= instruction[7:0];
st_mem_addr <= instruction [10:3];
branch_addr <= instruction[9:0];
end
// OP_ADD: begin
5'h01: begin
write_to_regfile <= 1'b1;
end
// OP_AND: begin
5'h03: begin
and_op_true <= 1'b1;
lgcl_or_bitwse_T <= 1'b1;
// OP_OR: begin
5'h04: begin
or_op_true <= 1'b1;
lgcl_or_bitwse_T <= 1'b1;
// OP_SHL begin
5'h06: begin
shift_left_true <= 1'b1;
// OP_JMP: begin
5'h07: begin
nxt_prog_ctr <= branch_addr;
jump_true <= 1'b1;
// OP_LOAD: begin
5'h08: begin
load_true <= 1'b1;
write_to_regfile <= 1'b1;
end
// OP_STORE: store_true <= 1'b1;
// OP_ANDBIT: begin
5'h0a: begin
end
// OP_ORBIT: begin
5'h0b: begin
end
// OP_JMPLT: begin
5'h0f: begin
end
// OP_JMPEQ: begin
5'h10: begin
end
// OP_JMPC: begin
5'h11: begin
nxt_prog_ctr <= branch_addr;
jump_true <= 1'b1;
end
default: ; //= NOP
endcase
end
//BYPASS logic
//check store pipeline stage signals and address to determine
// if one of the operands have to be bypassed
else
bypass_op1_dcd_stage <= 1'b0;
end
begin
begin
//BYPASS logic
begin
else if (en_op2_complement_reg == 1)
data_in2 <= ~operand2;
else
data_in2 <= operand2;
end
//Instruction execution
//ALU and store instructionss
always @(data_in1 or data_in2 or carry_in_reg)
{alu_carry_out, alu_data_out} <= data_in1 + data_in2
+ carry_in_reg;
// Compare instruction
assign gt_flag_ex = (alu_carry_out == 1'b1) && (alu_data_out != 8'b0) && (compare_true_reg ==
1'b1);
always @(data_in1)
begin
shift_carry_out <= data_in1[7];
shift_data_out <= {data_in1[6:0], 1'b0};
end
if (and_op_true_reg == 1'b1)
// BRANCH LOGIC
// add for conditional jumps
assign gt_flag_true =
(((compare_true_r2 && !invalidate_instr) == 1'b1) &&
gt_flag_ex_reg) || gt_flag;
assign lt_flag_true =
(((compare_true_r2 && !invalidate_instr) == 1'b1) &&
lt_flag_ex_reg) || lt_flag;
assign eq_flag_true =
(((compare_true_r2 && !invalidate_instr) == 1'b1) &&
eq_flag_ex_reg) || eq_flag;
assign carry_flag_true =
(((save_carry_flag_reg && !invalidate_instr) == 1'b1)
S.K.P.ENGINEERING COLLEGE Page 54
&& carry_flag_ex) || carry_flag ;
assign branch_taken = unconditional_jump_reg || (gt_flag_true && jump_gt_reg) ||
//****************************************
// EXECUTION STAGE PIPELINE REGISTERS
//****************************************
begin
if (save_carry_flag == 1'b1)
if (reset == 1'b1)
begin
store_to_mem_ex <= #1 1'b0;
reg_wr_en_ex <= #1 1'b0;
destination_reg_addr <= 3'b0;
branch_taken_reg <= 1'b0;
begin
store_to_mem_ex <= #1 store_true_reg;
reg_wr_en_ex <= #1 write_to_regfile_reg;
destination_reg_addr <= #1 res_addr_reg;
if (branch_taken_reg == 1'b1)
invalidate_execute_instr <= #1 1'b1;
else
invalidate_execute_instr <= #1 1'b0;
end
//****************************************
// STORE RESULTS STAGE LOGIC
//****************************************
//****************************************
// STORE RESULT STAGE PIPELINE REGISTERS
//****************************************
always @(posedge clk)
begin
if (reset == 1'b1)
begin
//****************************************
// PROGRAM COUNTER
//****************************************
always @(posedge clk)
if (reset == 1'b1)
prog_ctr <= #1 10'b1;
else
begin
if (branch_taken_reg == 1) //update in store res stage
begin
end
end
endmodule
module register_file (clk, reset, wr_data, rd_data1, rd_data2, rd_addr1, rd_addr2, wr_addr, wr_en);
input clk, reset;
S.K.P.ENGINEERING COLLEGE Page 58
input [7:0] wr_data;
input [2:0] rd_addr1, rd_addr2, wr_addr;
input wr_en;
endmodule
AIM
To simulate the NAND and NOR circuit using PSPICE circuit simulator and to verify the
waveform
SOFTWARE REQUIRED
PSPICE students‘ version 9.1
PROCEDURE
1. Draw the schematic diagram in pspice schematic editor
2. Go choose the icon ―set up -> analysis‖, for choosing proper analysis options.
3. Now select the option ―transient‖.
4. Choose appropriate print step (eg:10 ns) and final time.
5. Now choose the icon ―set up -> Examine netlist‖, and if the netlist has no errors, choose
the ―simulate‖ option which is under ―set up‖.
6. The waveform window will pop up after the simulation.
PROGRAM:
NAND
* Schematics Netlist *
NOR
* Schematics Netlist *
RESULT:
Thus the NAND circuit is simulated and the required waveforms are obtained.