ISE_Codes (exp-1,2,3,4,5,6,7,8) All Done
ISE_Codes (exp-1,2,3,4,5,6,7,8) All Done
Given a 4-variable logic expression, simplify it using appropriate technique and simulate the same using basic gates.
module ise_exp_1(
input A,B,C,D,
output F
);
assign F = (~A) | (B & C & D) | (A & ~B & ~C) | (A & C & ~D);
endmodule
module ise_exp_1_tb;
// Inputs
reg A;
reg B;
reg C;
reg D;
// Outputs
wire F;
ise_exp_1 uut (
.A(A),
.B(B),
.C(C),
.D(D),
.F(F)
);
initial begin
// Initialize Inputs
D = 0; C = 0; B = 0; A = 0; #100;
D = 0; C = 0; B = 0; A = 1; #100;
D = 0; C = 0; B = 1; A = 0; #100;
D = 0; C = 0; B = 1; A = 1; #100;
D = 0; C = 1; B = 0; A = 0; #100;
D = 0; C = 1; B = 0; A = 1; #100;
D = 0; C = 1; B = 1; A = 0; #100;
D = 0; C = 1; B = 1; A = 1; #100;
D = 1; C = 0; B = 0; A = 0; #100;
D = 1; C = 0; B = 0; A = 1; #100;
D = 1; C = 0; B = 1; A = 0; #100;
D = 1; C = 0; B = 1; A = 1; #100;
D = 1; C = 1; B = 0; A = 0; #100;
D = 1; C = 1; B = 0; A = 1; #100;
D = 1; C = 1; B = 1; A = 0; #100;
D = 1; C = 1; B = 1; A = 1; #100;
#100;
// Add stimulus here
end
endmodule
Experiments-2A
Design a 4 bit full adder and subtractor and simulate the same using basic gates. (For 4-Bit Full Adder)
//2A: VERILOG CODE FOR 4-BIT FULL ADDER (THIS IS MAIN MODULE)
module FA_4bit_main(
input a,b,cin,
output s,cout
);
assign s = a ^ b ^ cin;
endmodule
//VERILOG CODE OF 4-BIT FULL ADDER (THIS IS SUB MODULE UNDER MAIN MODULE)
module FA_4bit(
output cout
);
wire c1,c2,c3,c4;
endmodule
module fourbit_tb;
// Inputs
reg [3:0] a;
reg [3:0] b;
// Outputs
wire cout;
FA_4bit uut (
.a(a),
.b(b),
.sum(sum),
.cout(cout)
);
initial begin
// Initialize Inputs
#100;
end
endmodule
OUTPUT WAVEFORM OF 4-BIT FULL ADDER (as per the test cases values)
Experiments-2B
Design a 4 bit full adder and subtractor and simulate the same using basic gates. (For 4-Bit Full Subtractor)
//2B: VERILOG CODE FOR 4-BIT FULL SUBTRACTOR (THIS IS MAIN MODULE)
module FS_4bit_main(
input a,b,bin,
output d,bout
);
assign d = a ^ b ^ bin;
endmodule
//VERILOG CODE OF 4-BIT FULL SUBTRACTOR (THIS IS SUB MODULE UNDER MAIN MODULE)
module FS_4bit(
output bout
);
wire c1,c2,c3,c4;
endmodule
Experiments-3A
Design Verilog HDL to implement simple circuits using structural, Data flow and Behavioural model. (Half Adder)
1: Dataflow Style of Modelling
//VHDL code for Half Adder using DATAFLOW MODELLING
library ieee;
use ieee.std_logic_1164.all;
entity ha_dataflow is
port (a, b: in std_logic; sum, carry_out: out std_logic);
end ha_dataflow;
Experiments-3B
Design Verilog HDL to implement simple circuits using structural, Data flow and Behavioural model. (Half Adder)
2: Behavioral Style of Modelling
//VHDL code for Half Adder using BEHAVIORAL
library ieee;
use ieee.std_logic_1164.all;
entity ha_behavioral is
port (a, b: in std_logic; sum, carry_out: out std_logic);
end ha_behavioral;
library ieee;
use ieee.std_logic_1164.all;
entity ha_structural is
-- Entity declaration for half adder
port (a, b: in std_logic; sum, carry_out: out std_logic);
end ha_structural;
component xor_gate
-- xor component declaration
port (i1, i2: in std_logic; o1: out std_logic);
end component;
component and_gate
--and component declaration
port (i1, i2: in std_logic; o1: out std_logic);
end component;
begin
u1: xor_gate port map (i1 => a, i2 => b, o1 => sum);
u2: and_gate port map (i1 => a, i2 => b, o1 => carry_out);
//VHDL code for xor_gate as an component //VHDL code for and_gate as an component
library IEEE;
use IEEE.STD_LOGIC_1164.ALL; library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity xor_gate is
Port ( i1,i2 : in STD_LOGIC; entity and_gate is
o1 : out STD_LOGIC); Port ( i1,i2 : in STD_LOGIC;
end xor_gate; o1 : out STD_LOGIC);
end and_gate;
architecture Behavioral of xor_gate is
begin architecture Behavioral of and_gate is
o1 <= i1 xor i2; begin
end Behavioral; o1 <= i1 and i2;
end Behavioral;
Experiments-4
Design Verilog HDL to implement Binary Adder-Subtractor – Half and Full Adder, Half and Full Subtractor.
4A: Half Adder 4B: Full Adder 4C: Half Subtractor 4D: Full Subtractor
module HA_ISE(
input A,B,
);
assign SUM = A ^ B;
endmodule
module HA_ISE_TB;
// Inputs
reg A;
reg B;
// Outputs
wire SUM;
wire CARRY;
HA_ISE uut (
.A(A),
.B(B),
.SUM(SUM),
.CARRY(CARRY)
);
initial begin
// Initialize Inputs
B = 0; A = 0; #100;
B = 0; A = 1; #100;
B = 1; A = 0; #100;
B = 1; A = 1; #100;
#100;
end
endmodule
input a,b,cin,
output sum,carry
);
endmodule
module FA_ISE_TB;
// Inputs
reg a;
reg b;
reg cin;
// Outputs
wire sum;
wire carry;
FA_ISE uut (
.a(a),
.b(b),
.cin(cin),
.sum(sum),
.carry(carry)
);
initial begin
// Initialize Inputs
cin = 0; b = 0; a = 0; #100;
cin = 0; b = 0; a = 1; #100;
cin = 0; b = 1; a = 0; #100;
cin = 0; b = 1; a = 1; #100;
cin = 1; b = 0; a = 0; #100;
cin = 1; b = 0; a = 1; #100;
cin = 1; b = 1; a = 0; #100;
cin = 1; b = 1; a = 1; #100;
#100;
end
endmodule
module HS_ISE(
input a, b,
output D, B
);
assign D = a ^ b;
assign B = ~a & b;
endmodule
module HS_ISE_TB;
// Inputs
reg a;
reg b;
// Outputs
wire D;
wire B;
HS_ISE uut (
.a(a),
.b(b),
.D(D),
.B(B)
);
initial begin
// Initialize Inputs
b = 0; a = 0; #100;
b = 0; a = 1; #100;
b = 1; a = 0; #100;
b = 1; a = 1; #100;
#100;
end
endmodule
module FS_ISE(
input a, b, Bin,
output D, Bout
);
assign D = a ^ b ^ Bin;
endmodule
module FS_ISE_TB;
// Inputs
reg a;
reg b;
reg Bin;
// Outputs
wire D;
wire Bout;
FS_ISE uut (
.a(a),
.b(b),
.Bin(Bin),
.D(D),
.Bout(Bout)
);
initial begin
// Initialize Inputs
Bin = 0; b = 0; a = 0; #100;
Bin = 0; b = 0; a = 1; #100;
Bin = 0; b = 1; a = 0; #100;
Bin = 0; b = 1; a = 1; #100;
Bin = 1; b = 0; a = 0; #100;
Bin = 1; b = 0; a = 1; #100;
Bin = 1; b = 1; a = 0; #100;
Bin = 1; b = 1; a = 1; #100;
#100;
// Add stimulus here
end
endmodule
Experiments-5
Design Verilog HDL to implement Decimal adder.
module ise_DA(
input [3:0] A,
input [3:0] B,
);
assign Sum = A + B;
endmodule
module DA_tb;
// Inputs
reg [3:0] A;
reg [3:0] B;
// Outputs
ise_DA uut (
.A(A),
.B(B),
.Sum(Sum)
);
initial begin
// Initialize Inputs
A = 4; B = 7; #600;
A = 9; B = 8; #600;
A = 3; B = 3; #600;
#100;
// Add stimulus here
end
endmodule
module ise_mux_2to1(
output Y
);
endmodule
// Inputs
reg D0;
reg D1;
reg S;
// Outputs
wire Y;
ise_mux_2to1 uut (
.D0(D0),
.D1(D1),
.S(S),
.Y(Y)
);
initial begin
// Initialize Inputs
D0 = 1'b0;
D1 = 1'b0;
S = 1'b0;
#100;
// Add stimulus here
end
always #10 S = ~ S;
always@(D0 or D1 or S)
endmodule
module ise_mux_4to1(
input a,b,c,d,
input s0,s1,
output out
);
endmodule
module mux_4to1_tb;
// Inputs
reg a;
reg b;
reg c;
reg d;
reg s0;
reg s1;
// Outputs
wire out;
ise_mux_4to1 uut (
.a(a),
.b(b),
.c(c),
.d(d),
.s0(s0),
.s1(s1),
.out(out)
);
initial begin
// Initialize Inputs
a = 1'b0;
b = 1'b0;
c = 1'b0;
d = 1'b0;
s0 = 1'b0;
s1 = 1'b0;
#100;
end
always #5 d = ~d;
always@(a or b or c or d or s0 or s1)
$monitor("At time = %t, Output = %d", $time, out);
endmodule
module mux8_1(
output out
);
assign S1bar=~S1;
assign S0bar=~S0;
assign S2bar=~S2;
assign out =
endmodule
module mux8_1_tb;
// Inputs
reg D0;
reg D1;
reg D2;
reg D3;
reg D4;
reg D5;
reg D6;
reg D7;
reg S0;
reg S1;
reg S2;
// Outputs
wire out;
.D0(D0),
.D1(D1),
.D2(D2),
.D3(D3),
.D4(D4),
.D5(D5),
.D6(D6),
.D7(D7),
.S0(S0),
.S1(S1),
.S2(S2),
.out(out)
);
initial begin
// Initialize Inputs
D0 = 1'b0;
D1 = 1'b0;
D2 = 1'b0;
D3 = 1'b0;
D4 = 1'b0;
D5 = 1'b0;
D6 = 1'b0;
D7 = 1'b0;
S0 = 1'b0;
S1 = 1'b0;
S2 = 1'b0;
// Wait 100 ns for global reset to finish
#100;
end
always@(D0 or D1 or D2 or D3 or D4 or D5 or D6 or D7 or S0 or S1 or S2)
endmodule
module DEMUX__1to2(
input sel,
input i,
output y0, y1
);
endmodule
module demux_tb;
// Inputs
reg sel;
reg i;
// Outputs
wire y0;
wire y1;
DEMUX__1to2 uut (
.sel(sel),
.i(i),
.y0(y0),
.y1(y1)
);
initial begin
// Initialize Inputs
#100;
endmodule
module DEMUX__1to4(
input sel,
input i,
);
case(sel)
end
endmodule
module demux_tb;
// Inputs
reg sel;
reg i;
// Outputs
wire y0;
wire y1;
wire y2;
wire y3;
DEMUX__1to4 uut (
.sel(sel),
.i(i),
.y0(y0),
.y1(y1),
.y2(y2),
.y3(y3)
);
initial begin
// Initialize Inputs
$monitor("sel = %b, i = %b -> y0 = %0b, y1 = %0b ,y2 = %0b, y3 = %0b", sel,i, y0,y1,y2,y3);
#100;
end
endmodule
module dff_ise(
output reg q
);
q < = d;
endmodule
module dff_tb;
// Inputs
reg d;
reg clk;
// Outputs
wire q;
dff_ise uut (
.d(d),
.clk(clk),
.q(q)
);
// Clock generation
//always #((clk_PERIOD/2))
always #((clk))
clk = ~ clk;
// Stimulus
initial begin
// Initialize Inputs
d = 0;
clk = 1;
// Apply inputs
#500 d = 1;
#500 d = 0;
#500 d = 1;
#500 d = 0;
// Finish simulation
#100;
end
endmodule
Experiments-8B
Design Verilog program for implementing various types of Flip-Flops such as SR, JK and D.
module ise_SRFF(
input wire s,
input wire r,
output reg q,
output q_bar
);
begin
if (r)
q = 0;
else if (s)
q = 1;
end
assign q_bar = ~ q;
endmodule
module ise_tb;
// Inputs
reg s;
reg r;
reg clk;
// Outputs
wire q;
wire q_bar;
.s(s),
.r(r),
.clk(clk),
.q(q),
.q_bar(q_bar)
);
// Clock generation
//always #((clk_PERIOD/2))
always #(clk)
clk = ~clk;
// Stimulus
initial begin
// Initialize Inputs
s = 0;
r = 0;
clk = 0;
// Apply inputs
#500 s = 1;
#500 s = 0;
#500 r = 1;
#500 r = 0;
#100;
// Add stimulus here
end
endmodule
Experiments-8C
Design Verilog program for implementing various types of Flip-Flops such as SR, JK and D.
module ise_JKFF(
input wire j,
input wire k,
output reg q,
output q_bar
);
if (j && k)
q <= q;
else if (j)
q <= 1;
else if (k)
q <= 0;
end
endmodule
module jkff_tb;
// Inputs
reg j;
reg k;
reg clk;
// Outputs
wire q;
wire q_bar;
ise_JKFF uut (
.j(j),
.k(k),
.clk(clk),
.q(q),
.q_bar(q_bar)
);
// Clock generation
//always #((clk_PERIOD/2))
always #(clk)
clk = ~clk;
// Stimulus
initial begin
// Initialize Inputs
j = 0;
k = 0;
clk = 0;
#500 j = 1;
#500 k = 1;
#500 j = 0;
#500 k = 0;
end
endmodule