EDA Playground lets you type in and run HDL code (using a selection of free and commercial simulators and synthesizers).
It's great for learning HDLs, it's great for testing out unfamiliar things and it's great for sharing code.
You can start typing straight away. But to run your code, you'll need to sign or log in. Logging in with a Google account gives you access to all non-commercial simulators and some commercial simulators:
To run commercial simulators, you need to register and log in with a username and password. Registration is free, and only pre-approved email's will have access to the commercial simulators.
208
module tb;
reg clk_i;
reg rst_i;
reg data_i;
wire pat_det_o;
integer count;
pattern_det_mealy dut (.clk_i(clk_i),.rst_i(rst_i),.data_i(data_i),.pat_det_o(pat_det_o));
initial begin
clk_i=0;
forever #5 clk_i=~clk_i;
end
initial begin
rst_i=1;
count=0;
data_i=0;
#10;
rst_i=0;
repeat(500)begin
@(posedge clk_i);
data_i=$random;
end
// $display("number of times pattern detected=%d",count);
#1000;
$display("number of times pattern detected=%d",count);
$finish;
end
covergroup cg ; // @(posedge clk) as an event
option.per_instance = 1;
coverpoint dut.B {
bins hig_input = {1};
}
coverpoint dut.pat_det_o {
bins low_output = {0};
bins hig_output = {1};
}
coverpoint dut.state {
//when B=1 transition
bins trans_S_R_S_B = (dut.S_R => dut.S_B);
bins trans_S_B_S_BB = (dut.S_B => dut.S_BB);
bins trans_S_BB_S_BB = (dut.S_BB => dut.S_BB);
bins trans_S_BBC_S_BBCB = (dut.S_BBC => dut.S_BBCB);
bins trans_S_BBCB_S_BB = (dut.S_BBCB => dut.S_BB);
}
endgroup
//cross dut.B ,dut.state;
// cross between i/p and PS
covergroup cg1 ; // @(posedge clk) as an event
option.per_instance = 1;
coverpoint dut.B {
bins low_input = {0};
}
coverpoint dut.state { //when B!=0 Transaction
bins trans_S_R_S_R = (dut.S_R => dut.S_R); bins trans_S_B_S_R = (dut.S_B => dut.S_R);
bins trans_S_BB_S_BBC = (dut.S_BB => dut.S_BBC); bins trans_S_BBC_S_R = (dut.S_BBC => dut.S_R);
bins trans_S_BBCB_S_R = (dut.S_BBCB => dut.S_R);
}
//cross dut.B,dut.state; // cross between i/p and PS
endgroup: cg1
cg cg_h; // instances of the covergroup
cg1 cg_h1;
initial begin: B2
cg_h = new();
cg_h1 = new();
repeat(100)begin
#5;
cg_h.sample();
cg_h1.sample();
end
end: B2
always@(posedge pat_det_o)begin
count=count+1;
end
initial begin
$dumpvars();
$dumpfile("1.vcd");
end
endmodule
xxxxxxxxxx
vsim +access+r;
run -all;
acdb save;
acdb report -db fcover.acdb -txt -o cov.txt -verbose
exec cat cov.txt;
exit
xxxxxxxxxx
// Code your design here
// Code your testbench here
// or browse Examples
module pattern_det_mealy(clk_i,rst_i,data_i,pat_det_o);
parameter S_R = 5'b00001;
parameter S_B = 5'b00010;
parameter S_BB = 5'b00100;
parameter S_BBC = 5'b01000;
parameter S_BBCB= 5'b10000;
parameter B = 1'b1;
parameter C = 1'b0;
input clk_i;
input rst_i;
input data_i;
output reg pat_det_o;
reg [4:0] state,nextstate;
always@(posedge clk_i) begin
if(rst_i==1) begin
pat_det_o=0;
state =S_R;
nextstate=S_R;
end
else begin
case(state)
S_R:begin
if(data_i==B)begin
pat_det_o=0;
nextstate=S_B;
end
else begin
pat_det_o=0;
nextstate=S_R;
end
end
S_B:begin
if(data_i==B)begin
pat_det_o=0;
nextstate=S_BB;
end
else begin
pat_det_o=0;
nextstate=S_R;
end
end
S_BB:begin
if(data_i==B)begin
pat_det_o=0;
nextstate=S_BB;
end
else begin
pat_det_o=0;
nextstate=S_BBC;
end
end
S_BBC:begin
if(data_i==B)begin
pat_det_o=0;
nextstate=S_BBCB;
end
else begin
pat_det_o=0;
nextstate=S_R;
end
end
S_BBCB:begin
if(data_i==B)begin
pat_det_o=1;
nextstate=S_BB;
end
else begin
pat_det_o=0;
nextstate=S_R;
end
end
endcase
end
end
always@(nextstate)begin
state=nextstate;
end
endmodule
Your account is not validated. If you wish to use commercial simulators, you need a validated account.
If you have already registered (or have recently changed your email address), but have not clicked on the link in the email we sent you, please do so. If you cannot find the email, please check your spam/junk folder. Or click here to resend the email.
If you have not already registered for a full account, you can do so by clicking below. You will then need to provide us with some identification information. You may wish to save your code first.
Creating, deleting, and renaming files is not supported during Collaboration. To encourage development of these features for Collaboration, tweet to @EDAPlayground
This playground may have been modified. Please save or copy before starting collaboration.
Your exercise has been submitted.