Posts

Showing posts from December, 2021

11011 Sequence Detector

Image
  module dff( input d,clk,rst, output reg q,qbar ); always @(posedge clk ,negedge rst) begin if(rst==0) begin q<=0;qbar<=1;end else begin q<=d; qbar<=~d; end end endmodule module dff_tb(); reg d,clk; wire q,qbar; dff dff_i1(d,clk,q,qbar); initial begin clk=0;d=0; #10d=1; end always #5 clk=~clk; endmodule module seq_detector(     input x,clk,rst,     output z ); wire d0,d1,d2; wire q0,q1,q2; wire q0bar,q1bar,q2bar; wire w1,w2,w3,w4,w5,w6; and and_i1(w1,q2bar,q0bar);//w1=q2'q0' xor xor_i1(w2,x,q1);//w2=x^q1 and and_i2(d0,w1,w2);//d0=w1w2 dff dff_i1(d0,clk,rst,q0,q0bar); and and_i3(w3,q2bar,q1bar,q0,x);//w3=q2'q1'q0x and and_i4(w4,q2,q1bar,q0bar,x);//w4=q2q1'q0'x and and_i5(w5,q2bar,q1,q0bar);//w5=q2'q1q0' or or_i1(d1,w3,w4,w5); dff dff_i2(d1,clk,rst,q1,q1bar); and and_i6(d2,q2bar,q1,q0,x); dff dff_i3(d2,clk,rst,q2,q2bar); and and_i7(z,q2,q1bar,q0bar,x); endmodule module seq_detector_tb(); reg x,clk,rst; wire z; seq_detector seq_detector_i1(x,cl...