(1) - EDA Playground
Warning! This exercise has been opened in another tab; autosave has been disabled. Close this tab or refresh to reactivate.

 Languages & Libraries

 Tools & Simulators

 Examples

208


133
 
1
2
module tb;
3
reg clk_i;
4
reg rst_i;
5
reg data_i;
6
wire pat_det_o;
7
integer count;
8
9
pattern_det_mealy dut (.clk_i(clk_i),.rst_i(rst_i),.data_i(data_i),.pat_det_o(pat_det_o));
10
11
initial begin
12
 clk_i=0;
13
 forever #5 clk_i=~clk_i;
14
end
15
16
initial begin
17
 rst_i=1;
18
 count=0;
19
 data_i=0; 
20
#10;
21
 rst_i=0;
22
23
  repeat(500)begin
24
  @(posedge clk_i);
25
    data_i=$random;
26
end
27
 // $display("number of times pattern detected=%d",count);
28
#1000;
29
  $display("number of times pattern detected=%d",count);
30
$finish;
31
end
32
covergroup cg ;                         // @(posedge clk) as an event 
33
34
35
        option.per_instance = 1;
36
37
38
                   
39
             coverpoint dut.B            {
40
                                            bins hig_input  = {1};
41
                                         }
42
43
44
             coverpoint dut.pat_det_o    {
45
                                            bins low_output  = {0};
46
                                            bins hig_output  = {1};
47
                                         }
48
49
            
50
51
52
                          
53
             coverpoint dut.state {
54
                                    //when B=1 transition
55
                                    bins trans_S_R_S_B      = (dut.S_R    => dut.S_B);          
56
                                    bins trans_S_B_S_BB     = (dut.S_B    => dut.S_BB);
57
                                    bins trans_S_BB_S_BB    = (dut.S_BB   => dut.S_BB);         
58
                                    bins trans_S_BBC_S_BBCB = (dut.S_BBC  => dut.S_BBCB);   
59
                                    bins trans_S_BBCB_S_BB  = (dut.S_BBCB => dut.S_BB); 
60
61
62
                                  }
63
endgroup
64
65
//cross  dut.B ,dut.state;      
66
           // cross between  i/p and PS
67
68
            
69
             
70
    
71
72
73
    
74
    covergroup cg1 ;                                                // @(posedge clk) as an event 
75
76
        option.per_instance = 1;
77
78
79
        coverpoint dut.B    {
80
                               bins low_input  = {0};
81
                            }
82
83
      
84
                
85
        coverpoint dut.state   { //when B!=0 Transaction
86
                        
87
88
                                     bins trans_S_R_S_R    = (dut.S_R    => dut.S_R);                                                                         bins trans_S_B_S_R    = (dut.S_B    => dut.S_R);
89
                                     bins trans_S_BB_S_BBC = (dut.S_BB   => dut.S_BBC);                                                                       bins trans_S_BBC_S_R  = (dut.S_BBC  => dut.S_R);
90
                                     bins trans_S_BBCB_S_R = (dut.S_BBCB => dut.S_R);                                   
91
                                }
92
93
94
        //cross dut.B,dut.state;                                                // cross between  i/p and PS
95
96
97
                        
98
    endgroup: cg1
99
100
101
102
    cg  cg_h;                                                               // instances of the covergroup
103
    cg1 cg_h1;
104
        
105
    initial begin: B2
106
        
107
        cg_h  = new();
108
        cg_h1 = new();
109
      repeat(100)begin
110
   #5;
111
   cg_h.sample();
112
   cg_h1.sample();
113
  end
114
115
    
116
        
117
        
118
      
119
    end: B2
120
  
121
122
always@(posedge pat_det_o)begin
123
 count=count+1;
124
end
125
  initial begin
126
    $dumpvars();
127
    $dumpfile("1.vcd");
128
end
129
130
endmodule
131
132
133
xxxxxxxxxx
1
91
 
1
// Code your design here
2
// Code your testbench here
3
// or browse Examples
4
module pattern_det_mealy(clk_i,rst_i,data_i,pat_det_o);
5
6
parameter S_R   = 5'b00001;  
7
parameter S_B   = 5'b00010;
8
parameter S_BB  = 5'b00100;
9
parameter S_BBC = 5'b01000;
10
parameter S_BBCB= 5'b10000;
11
12
parameter B = 1'b1;
13
parameter C = 1'b0;
14
15
input clk_i;
16
input rst_i;
17
input data_i;
18
output reg pat_det_o;
19
  reg [4:0] state,nextstate;
20
21
always@(posedge clk_i) begin
22
if(rst_i==1) begin
23
 pat_det_o=0;
24
 state    =S_R;
25
 nextstate=S_R;
26
end
27
else begin
28
 case(state)
29
30
      S_R:begin
31
         if(data_i==B)begin
32
            pat_det_o=0;
33
            nextstate=S_B;
34
         end
35
         else begin
36
            pat_det_o=0;
37
            nextstate=S_R;
38
         end
39
      end
40
41
      S_B:begin
42
         if(data_i==B)begin
43
            pat_det_o=0;
44
            nextstate=S_BB;
45
         end
46
         else begin
47
            pat_det_o=0;
48
            nextstate=S_R;
49
         end
50
      end
51
52
      S_BB:begin
53
         if(data_i==B)begin
54
            pat_det_o=0;
55
            nextstate=S_BB;
56
         end
57
         else begin
58
            pat_det_o=0;
59
            nextstate=S_BBC;
60
         end
61
      end
62
63
      S_BBC:begin
64
         if(data_i==B)begin
65
            pat_det_o=0;
66
            nextstate=S_BBCB;
67
         end
68
         else begin
69
            pat_det_o=0;
70
            nextstate=S_R;
71
         end
72
      end
73
74
      S_BBCB:begin
75
         if(data_i==B)begin
76
            pat_det_o=1;
77
            nextstate=S_BB;
78
         end
79
         else begin
80
            pat_det_o=0;
81
            nextstate=S_R;
82
         end
83
      end
84
  endcase
85
end
86
end
87
  
88
always@(nextstate)begin
89
  state=nextstate;
90
end
91
endmodule
67 views and 0 likes     
A short description will be helpful for you to remember your playground's details
 
100:0