Professional Documents
Culture Documents
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58 endmodule
You could download file encoder_using_if.v here
Encoder - Using case Statement
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Priority Encoders
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
You
// Coder
: Deepak Kumar Tala
//----------------------------------------------------module pri_encoder_using_if (
binary_out , // 4 bit binary output
encoder_in , // 16-bit input
enable
// Enable for the encoder
);
output [3:0] binary_out ;
input enable ;
input [15:0] encoder_in ;
reg [3:0] binary_out ;
always @ (enable or encoder_in)
begin
binary_out = 0;
if (enable) begin
if (encoder_in[0] == 1) begin
binary_out = 1;
end else if (encoder_in[1] == 1) begin
binary_out = 2;
end else if (encoder_in[2] == 1) begin
binary_out = 3;
end else if (encoder_in[3] == 1) begin
binary_out = 4;
end else if (encoder_in[4] == 1) begin
binary_out = 5;
end else if (encoder_in[5] == 1) begin
binary_out = 6;
end else if (encoder_in[6] == 1) begin
binary_out = 7;
end else if (encoder_in[7] == 1) begin
binary_out = 8;
end else if (encoder_in[8] == 1) begin
binary_out = 9;
end else if (encoder_in[9] == 1) begin
binary_out = 10;
end else if (encoder_in[10] == 1) begin
binary_out = 11;
end else if (encoder_in[11] == 1) begin
binary_out = 12;
end else if (encoder_in[12] == 1) begin
binary_out = 13;
end else if (encoder_in[13] == 1) begin
binary_out = 14;
end else if (encoder_in[14] == 1) begin
binary_out = 15;
end
end
end
endmodule
could download file pri_encoder_using_if.v here
Encoder - Using assign Statement
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Function
: Pri Encoder using assign
// Coder
: Deepak Kumar Tala
//----------------------------------------------------module pri_encoder_using_assign (
binary_out , // 4 bit binary output
encoder_in , // 16-bit input
enable
// Enable for the encoder
);
output [3:0] binary_out ;
input enable ;
input [15:0] encoder_in ;
wire [3:0] binary_out ;
assign binary_out = ( !
(encoder_in[0]) ? 0 :
(encoder_in[1]) ? 1 :
(encoder_in[2]) ? 2 :
(encoder_in[3]) ? 3 :
(encoder_in[4]) ? 4 :
(encoder_in[5]) ? 5 :
(encoder_in[6]) ? 6 :
(encoder_in[7]) ? 7 :
(encoder_in[8]) ? 8 :
(encoder_in[9]) ? 9 :
(encoder_in[10]) ? 10
(encoder_in[11]) ? 11
(encoder_in[12]) ? 12
(encoder_in[13]) ? 13
(encoder_in[14]) ? 14
enable) ? 0 : (
:
:
:
:
: 15);
endmodule
23
4'h0 : decoder_out = 16'h0001;
24
4'h1 : decoder_out = 16'h0002;
25
4'h2 : decoder_out = 16'h0004;
26
4'h3 : decoder_out = 16'h0008;
27
4'h4 : decoder_out = 16'h0010;
28
4'h5 : decoder_out = 16'h0020;
29
4'h6 : decoder_out = 16'h0040;
30
4'h7 : decoder_out = 16'h0080;
31
4'h8 : decoder_out = 16'h0100;
32
4'h9 : decoder_out = 16'h0200;
33
4'hA : decoder_out = 16'h0400;
34
4'hB : decoder_out = 16'h0800;
35
4'hC : decoder_out = 16'h1000;
36
4'hD : decoder_out = 16'h2000;
37
4'hE : decoder_out = 16'h4000;
38
4'hF : decoder_out = 16'h8000;
39
endcase
40 end
41 end
42
43 endmodule
You could download file decoder_using_case.v here
Decoder - Using assign Statement
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
11
12
13
14
15
16
17
18
19
20
21
22
You
mux_out
// Mux output
);
//-----------Input Ports--------------input din_0, din_1, sel ;
//-----------Output Ports--------------output mux_out;
//------------Internal Variables-------wire mux_out;
//-------------Code Start----------------assign mux_out = (sel) ? din_1 : din_0;
endmodule //End Of Module mux
could download file mux_using_assign.v here
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
din_0
, // Mux first input
din_1
, // Mux Second input
sel
, // Select input
mux_out // Mux output
);
//-----------Input Ports--------------input din_0, din_1, sel ;
//-----------Output Ports--------------output mux_out;
//------------Internal Variables-------reg mux_out;
//-------------Code Starts Here--------always @ (sel or din_0 or din_1)
begin : MUX
case(sel )
1'b0 : mux_out = din_0;
1'b1 : mux_out = din_1;
endcase
end
endmodule //End Of Module mux
Asynchronous reset D- FF
1 //----------------------------------------------------2 // Design Name : dff_async_reset
3 // File Name : dff_async_reset.v
4 // Function
: D flip-flop async reset
5 // Coder
: Deepak Kumar Tala
6 //----------------------------------------------------7 module dff_async_reset (
8 data , // Data Input
9 clk
, // Clock Input
10 reset , // Reset input
11 q
// Q output
12 );
13 //-----------Input Ports--------------14 input data, clk, reset ;
15
16 //-----------Output Ports--------------17 output q;
18
19 //------------Internal Variables-------20 reg q;
21
22 //-------------Code Starts Here--------23 always @ ( posedge clk or negedge reset)
24 if (~reset) begin
25 q <= 1'b0;
26 end else begin
27 q <= data;
28 end
29
30 endmodule //End Of Module dff_async_reset
Synchronous reset D- FF
1 //----------------------------------------------------2 // Design Name : dff_sync_reset
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Asynchronous reset T - FF
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
-
Synchronous reset T - FF
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Regular D Latch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 q <= data;
28 end
29
30 endmodule //End Of Module dlatch_reset
8-Bit Simple Up Counter
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
21
22
23
24
25
26
27
28
29
30
31
32