DSDV Lab Manual
DSDV Lab Manual
EXPERIMENT:01:
To Simplify the given Boolean expressions and realize using Verilog program
Aim: To Simplify the given Boolean expressions and realize using Verilog program
Program:
module ckt1(a,b,c,d,f);
input a,b,c,d;
output f;
wirex,y,z;
assign x=a&b;
assign y=c&d;
assign z=x|y;
assign f=~z;
endmodule
Output:
EXPERIMENT:02
Aim:- To realize Adder/Subtractor(Full) Half circuits using Verilog data flow description
module fulladder(
input a,
input b,
input c,
output sum,output carry, inout x, inout y, inout z);
assign sum=a^b^c;
assign carry=(a&b)|(b&c)|(c&a);
endmodule
Output:
module halfsubtractor(
input a,
input b,
output difference,
output borrow
);
assign difference=a^b;
assign borrow=(~ a)&b;
endmodule
Output:
module fullsubtractor(A,B,C,diff,borrow );
input A,B,C;
output diff, borrow;
wire p,q,r;
assign diff=A^B^C;
assign p=(!A)&C;
assign q=(!A)&B;
assign r=B&C;
assign borrow=p|q|r;
endmodule
Output:
EXPERIMENT:03:
To realize 4 bit ALU using verilog Program
Aim:- To realize Adder/Subtractor(Full) Half circuits using Verilog data flow description
Output:
EXPERIMENT:04
To realise the following code converters using Verilog behavioural description
AIM: To realise the following code converters using Verilog behavioural description
module b_g(b,g);
input [3:0] b;
outputreg [3:0]g;
always@(b,g)
begin
g[3]=b[3];
g[2]=b[3]^b[2];
g[1]=b[2]^b[1];
g[0]=b[1]^b[0];
end
endmodule
Output:
Program:
module b_g(g,b);
input [3:0] g;
output [3:0]b;
assign b[3]=g[3];
assign b[2]=g[3]^g[2];
assign b[1]=g[3]^g[2]^g[1];
assign b[0]=g[3]^g[2]^g[1]^g[0];
endmodule
Output:
EXPERIMENT:05
To realize using Verilog Behavioural description 8:1 Multiplexer, 8:3 priority Encoder.
AIM: To realize using Verilog Behavioural description 8:1 Multiplexer, 8:3 priority Encoder.
module mux8_1(en,s,d,y);
input en;
input [2:0]s;
input [7:0]d;
outputreg y;
always@(en,s,d)
begin
if(en==1)
case(s)
3'd0:y=d[0];
3'd1:y=d[1];
3'd2:y=d[2];
3'd3:y=d[3];
3'd4:y=d[4];
3'd5:y=d[5];
3'd6:y=d[6];
3'd7:y=d[7];
default:y=1'bx;
endcase
else
y=1'bz;
end
endmodule
Output:
module encoder83wp(en,din,dout);
input en;
input [7:0]din;
outputreg [2:0]dout;
always@(en,din)
begin
if(en==1)
case(din)
8'b10000000:dout=3'b111;
8'b01000000:dout=3'b110;
8'b00100000:dout=3'b101;
8'b00010000:dout=3'b100;
8'b00001000:dout=3'b011;
8'b00000100:dout=3'b010;
8'b00000010:dout=3'b001;
8'b00000001:dout=3'b000;
default:dout=3'bxxx;
endcase
else
dout=3'bzzz;
end
endmodule
Output:
Program:
module encoder83p(en,din,dout);
input en;
input [7:0]din;
outputreg [2:0]dout;
always@(en,din)
begin
if(en==1)
casex(din)
8'b1xxxxxxx:dout=3'b111;
8'b01xxxxxx:dout=3'b110;
8'b001xxxxx:dout=3'b101;
8'b0001xxxx:dout=3'b100;
8'b00001xxx:dout=3'b011;
8'b000001xx:dout=3'b010;
8'b0000001x:dout=3'b001;
8'b00000001:dout=3'b000;
default:dout=3'bxxx;
endcase
else
dout=3'bzzz;
end
endmodule
Output:
EXPERIMENT:06
To realize using Verilog behavioural description 1:8 Demux, 3:8 Decoder, 2 bit Comparator
AIM: To realize using Verilog behavioural description 1:8 Demux, 3:8 Decoder, 2 bit Comparator
module demux(in,s0,s1,s2,d0,d1,d2,d3,d4,d5,d6,d7);
input in,s0,s1,s2;
output d0,d1,d2,d3,d4,d5,d6,d7;
assign d0=(in & ~s2&~s1&~s0);
assign d1=(in & ~s2&~s1&s0);
assign d2=(in & ~s2&s1&~s0);
assign d3=(in & ~s2&s1&s0);
assign d4=(in & s2&~s1&~s0);
assign d5=(in & s2&~s1&s0);
assign d6=(in & s2&s1&~s0);
assign d7=(in & s2&s1&s0);
endmodule
Output:
Program:
Program:
module comp(x,y,xlty,xgty,xeqy);
input [1:0] x,y;
output reg xlty,xgty,xeqy;
always@(x,y)
begin
xlty=1'b0;
xgty=1'b0;
xeqy=1'b0;
if(x==y)
xeqy=1;
else if(x>y)
xgty=1;
else
xlty=1;
end
endmodule
Output:
AIM: To realize using Verilog behavioural description 1:8 Demux, 3:8 Decoder, 2 bit Comparator
Program:
module sr_ff1(s,r,clk,q,qb);
input s,r,clk;
output reg q,qb;
initial
begin
q=1;
end
always@(posedgeclk)
begin
case({s,r})
2'b00:q=q;
2'b01:q=0;
2'b10:q=1;
2'b11:q=1'bx;
endcase
qb=~q;
end
endmodule
Output:
Program:
module d_ff1(d,clk,q,qb);
inputd,clk;
outputregq,qb;
always@(posedgeclk)
begin
case(d)
1'b0:q=0;
1'b1:q=1;
endcase
qb=~q;
Dept. of ECE,KLS VDIT,Haliyal Page 14
Digital System Design Using Verilog (21EC32)
end
endmodule
Output:
Program:
odule t_ff(t,clk,q,qb);
input t,clk;
output reg q,qb;
initial
begin
q=1;
end
always@(posedgeclk)
begin
case(t)
1'b0:q=q;
1'b1:q=~q;
endcase
qb=~q;
end
endmodule
Output:
EXPERIMENT:08
To realize counter up/down(BCD and Binary) using Verilog Behavioural description
AIM: To realize counter up/down(BCD and Binary) using Verilog behavioural description
Program:
Module downbin_count(clk,reset,load,data,q);
parameter n=4;
input clk,reset,load;
input [n-1:0] data;
output reg [n-1:0]q;
always@(posedgeclk)
begin
if(reset)
Dept. of ECE,KLS VDIT,Haliyal Page 16
Digital System Design Using Verilog (21EC32)
q=4'b1111;
else if(load)
q=data;
else
q=q-1;
end
endmodule
Output:
Program:
module bcdup(clk,reset,q);
parameter n=4;
input clk,reset;
output reg [n-1:0]q;
always@(posedgeclk)
begin
if(reset)
q=0;
else if(q<9)
q=q+1;
else
q=0;
end
endmodule
Output:
Program:
module bcddown(clk,reset,q);
parameter n=4;
input clk,reset;
output reg [n-1:0]q;
always@(posedge clk)
begin
if(reset)
q=4'b1001;
else if(q>0)
q=q-1;
else
q=4'b1001;
end
endmodule
Output:
EXPERIMENT:09
To interface a stepper motor the FPGA/CPLD and rotate the motor in the specified direction by
N steps
AIM: To interface a stepper motor the FPGA/CPLD and rotate the motor in the specified direction by N steps
4'b0111:out=4'b1110;
4'b1110:out=4'b1101;
4'b1101:out=4'b1011;
endcase
end
end
endmodule
NETLIST:
OUTPUT:
EXPERIMENT:10
To interface a Relay or ADC to the FPGA/CPLD and demonstrate
NETLIST:
NET “en” LOC=P2;
NET “d[0]” LOC=P35;
NET ”d[1]” LOC=P29;
NET ”d[2]” LOC=P27;
NET ”d[3]” LOC=P21;
NET “fnd[7]” LOC=P19;
NET “fnd[6]” LOC=P18;
NET “fnd[5]” LOC=P16;
NET “fnd[4]” LOC=P15;
NET “fnd[3]” LOC=P13;
NET “fnd[2]” LOC=P12;
Output:
EXPERIMENT:11EXPERIMENT:07
To interface DAC to the FPGA/CPLD for waveform generationTo realize using Verilog
behavioural description Flip Flop a) JK Type b) SR Type c) T Type d) D Type
a[0] = 8'h80;
a[1] = 8'h90;
a[2] = 8'hA1;
a[3] = 8'hB1;
a[4] = 8'hC0;
a[5] = 8'hCD;
a[6] = 8'hDA;
a[7] = 8'hE5;
a[8] = 8'hEE;
a[9] = 8'hF6;
a[10] = 8'hFB;
a[11] = 8'hFE;
a[12] = 8'hFF;
a[13] = 8'hFE;
a[14] = 8'hFB;
a[15] = 8'hF6;
a[16] = 8'hEE;
a[17] = 8'hE5;
a[18] = 8'hDA;
Dept. of ECE,KLS VDIT,Haliyal Page 23
Digital System Design Using Verilog (21EC32)
a[19] = 8'hCD;
a[20] = 8'hC0;
a[21] = 8'hB1;
a[22] = 8'hA1;
a[23] = 8'h90;
a[24] = 8'h80;
a[25] = 8'h70;
a[26] = 8'h5F;
a[27] = 8'h4F;
a[28] = 8'h40;
a[29] = 8'h33;
a[30] = 8'h26;
a[31] = 8'h1B;
a[32] = 8'h12;
a[33] = 8'h0A;
a[34] = 8'h05;
a[35] = 8'h02;
a[36] = 8'h00;
a[37] = 8'h02;
a[38] = 8'h05;
a[39] = 8'h0A;
a[40] = 8'h12;
a[41] = 8'h1B;
a[42] = 8'h26;
a[43] = 8'h33;
a[43] = 8'h40;
a[44] = 8'h4F;
a[45] = 8'h5F;
a[46] = 8'h70;
a[47] = 8'h80;
if(clk1 == 1)
begin
if(i == 47)
i = 0;
else
i = i + 1;
temp = a[i];
dout = temp;
end
end
endmodule
Dept. of ECE,KLS VDIT,Haliyal Page 24
Digital System Design Using Verilog (21EC32)
reg clkout;
reg [4:0] cnt = 5'b00000;
reg check=1'b0;
reg t=1'b0;
always @(posedge clkin)
begin
cnt = cnt + 1;
if(cnt == 5'b11110)
begin
check = !check;
cnt = 5'b00000;
end
end
always @(posedge check)
begin
t = !t;
clkout = t;
end
endmodule
NETLIST:
NET "dout[7]" LOC = P138;
NET "dout[6]" LOC = P139;
NET "dout[5]" LOC = P134;
NET "dout[4]" LOC = P137;
NET "dout[3]" LOC = P132;
NET "dout[2]" LOC = P133;
NET "dout[1]" LOC = P127;
NET "dout[0]" LOC = P131;
NET "clk" LOC = P51;
OUTPUT:
EXPERIMENT:12
To interface switches and LEDs to the FPGA/CPLD and demonstrate its working
AIM: To interface switches and LEDs to the FPGA/CPLD and demonstrate its working
module fulladder(
input a,
input b,
input c,
output sum,
output carry,
inout x,
inout y,
inout z
);
assign sum=a^b^c;
assign carry=(a&b)|(b&c)|(c&a);
endmodule
NETLIST:
NET "a" LOC = P22;
NET "b" LOC = P24;
NET "c" LOC = P27;
NET "sum" LOC = P21;
NET "carry" LOC = P23;