Basic Verilog Programs File
Basic Verilog Programs File
EXPERIMENT NO. 1
AIM:
To write a VERILOG code for a master slave D-flip flop & simulate the code using Modelsim simulator.
Module for Master Slave D Flipflop module mslave_dff(d,clk,rst, q,qbar); input d,clk,rst; output q,qbar; wire q1,qbar1; dff dff1(d,clk,rst,q1,qbar1); dff dff2(q1,~clk,rst,q,qbar); endmodule
WAVEFORM:-
AIM:To write a verilog code for 8:1 Multiplexer and simulate the code using Modelsim simulator.
FUNTIONAL DESCRIPTION:A multiplexer (or MUX) is a device that selects one of several analog or digital input signals and forwards the selected input into a single line.A multiplexer of 2 n inputs has n select lines, which are used to select which input line to send to the output.A multiplexer is also called a data selector.
module mux_8(a, sel, y); input [7:0] a; input [2:0] sel; output y; assign y =sel[2]?(sel[1]?(sel[0]?a[7]:a[6]):(sel[0]?a[5]:a[4])):(sel[1]?(sel[0]?a[3]:a[2]):(sel[ 0]?a[1]:a[0])); endmodule
WAVEFORM:-
AIM: To write a VERILOG code for an 8-bit Synchronous Counter with LOAD, RESET & up/down controls & simulate the code using Modelsim Simulator.
VERILOG CODE: Module for synchronous counter module count(out,data,load,reset,clk); output[7:0] out; input[7:0] data; input load,clk,reset; reg[7:0] out; always @(posedge clk) begin if (!reset) out = 8'h00;
8
WAVEFORM:-
AIM:To write a verilog code for 8 bit parity checker & generator and simulate the code using Modelsim simulator.
10
VERILOG CODE: Module for parity checker and generator module parity_checker8(a, y); input [7:0] a; output [8:0] y; reg [8:0]y; reg even=0; reg odd=1; integer i,count; always @(a) begin count<=0;
M.Tech Embedded System Design | NIT KURUKSHETRA 11
12
WAVEFORM:-
13
EXPERIMENT NO. 5
AIM:To write a verilog code for 4 digit decade counter and simulate the code using Modelsim simulator.
14
FUNCTIONAL DESCRIPTION:The decade counter is known as a mod-counter when it counts to ten (0, 1, 2, 3, 4, 5, 6, 7, 8, 9).
VERILOG CODE : Module for Decade Counter module decade_counter(clk,rst, q); input clk,rst; output [3:0]q; reg [3:0]q; always @(posedge clk) begin if ((rst==1'b1) && (q<4'b1001) ) q=q+1; else q=4'b0000; end endmodule
15
WAVEFORM:-
16
EXPERIMENT NO. 6
AIM: To write a VERILOG code for a 4-bit combinational multiplier & simulate the code using Modelsim simulator.
17
FUNCTIONAL DESCRIPTION:A combinational multiplier is a circuit which is used to multiply two 4-bit unsigned numbers and give the result as an 8-bit number. It is possible to construct a 4x4 combinational multiplier from an array of AND gates, half-adders and full-adders.
VERILOG CODE: Module for half_adder module half_adder1(a, b, s, cout); input a,b; output s,cout; assign s= a^b; assign cout =a&b; endmodule
18
Module for full adder module full_adder1(a, b, cin, sum, cout); input a,b,cin; output sum,cout; assign sum= a^b^cin; assign cout= (a&b)|(a&cin)|(b&cin); endmodule
Module for 4 bit combinational multiplier module combmul_4bit(m,a,b); input [3:0]a,b; output [7:0]m; wire w1,w2,w3,w4,w5,w6,w7,w8,w9,w10,w11,w12,w13,w14,w15; wire s1,s2,s3,s4,s5,s6; wire c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11; assign m[0]= a[0]&b[0]; assign w1=a[1]&b[0]; assign w2=a[0]&b[1]; assign w3=a[0]&b[2]; assign w4=a[1]&b[1]; assign w5=a[2]&b[0];
M.Tech Embedded System Design | NIT KURUKSHETRA 19
WAVEFORM:-
21
AIM :To write a verilog code for 4-bit sequential multiplier and simulate the code using Modelsim simulator .
22
module sequential_mul(a,b, clk, prod); input [3:0]a,b; input clk; output [7:0]prod; reg [7:0]prod; reg [7:0]ans; integer i; integer recode; initial begin
23
WAVEFORM:-
25
AIM:To write a verilog code for PIPO and PISO type registers and simulate the code using Modelsim simulator.
(i) PIPO
(ii) PISO
26
VERILOG CODE: Module for PIPO Shift register module pipo(y,a,clk); output [7:0]y; input clk; input [7:0]a; reg [7:0]y; always @(posedge clk) begin y<=a; end endmodule Module for PISO Shift register module piso(clk,rst,load,shift, set_data, data_out,eoc); input clk,rst,load,shift; input [7:0] set_data; output regdata_out,eoc; reg [7:0]sr;
M.Tech Embedded System Design | NIT KURUKSHETRA 27
29
WAVEFORM:-
(i)
PIPO Waveform
30
(ii)
PISO Waveform
M.Tech Embedded System Design | NIT KURUKSHETRA
AIM:To write a verilog code for SISO and SIPO & simulate the code using Modelsim simulator.
(i)
(ii)
FUNCTIONAL DESCRIPTION:Serial-in, serial-out shift registers delay data by one clock time for each stage. They will store a bit of data for each register. A serial-in, serial-out shift register may be one to 64 bits in length, longer if registers or packages are cascaded.
WAVEFORM :-
32
(ii)
SIPO Waveform
33