How to write 8 to 3 priority encoder and T-flip flop using verilog task coding????

Status
Not open for further replies.

slayunk23

Newbie level 1
Joined
Nov 1, 2013
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
12

Code Verilog - [expand]
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
module priencoder1_8to3 ( binary_out , encoder_in ,enable );
output [2:0] binary_out ;
input  enable ; 
input [7:0] encoder_in ; 
reg [2:0] binary_out ;
      
always @ (enable or  encoder_in)
 
if (enable == 0) 
 
begin
    
    if (encoder_in[7] == 0) binary_out = 0; 
    else if (encoder_in[6] == 0) binary_out = 1; 
    else if (encoder_in[5] == 0) binary_out = 2; 
    else if (encoder_in[4] == 0) binary_out = 3; 
    else if (encoder_in[3] == 0) binary_out = 4; 
    else if (encoder_in[2] == 0) binary_out = 5; 
    else if (encoder_in[1] == 0) binary_out = 6; 
    else if (encoder_in[0] == 0) binary_out = 7; 
    
   
end
endmodule
 
 
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 
 
module tflipflop(
    input CLR, PRE, T, C, 
    output reg Q);
 
always @(negedge C or negedge CLR or negedge PRE)
     if(!CLR)
       Q <= 0;
     else if(!PRE)
       Q <= 1;
     else if (T == 1)
       Q <= ~Q;
     else if (T == 0)
       Q = Q;
endmodule

 
Last edited by a moderator:

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…