Question

Design a synchronous state machine which detects the serial bit sequence of 0 1 10 on the 1-bit input signal A (tested one bi
0 0
Add a comment Improve this question Transcribed image text
Answer #1

(a)

The ASM chart

olo o/o 0 input/output rst Secondヽ 1/0 thndv ASM chart (state diagram)

(b)

//+++++++++++++Verilog code ++++++++++++++++//

`timescale 1ns / 1ps

module sequence_d(in,clk,rst,out
);
input clk,rst,in;
output reg out;
parameter reset=2'd0,first0=2'd1,second1=2'd2,third1=2'd3;
reg [1:0] p_state,n_state;

always @(posedge clk or posedge rst) begin
if(rst)
   p_state<=reset;
else
   p_state<=n_state;
end

always @(*) begin
case(p_state)
reset:begin
out=1'b0;
if(in)
   n_state=reset;
else
   n_state=first0;
end

first0:begin
out=1'b0;
if(in)
   n_state=second1;
else
   n_state=first0;
end

second1:begin
out=1'b0;
if(in)
   n_state=third1;
else
   n_state=first0;
end

third1:begin
if(in) begin
   n_state=reset;
   out=1'b0;
   end
else begin
   n_state=first0;
   out=1'b1;
   end
end

endcase
end

endmodule
//++++++++++++++END++++++++++++++++//

(c)

//+++++++++test bench+++++++++++++++//

`timescale 1ns / 1ps

module tb;

   // Inputs
   reg in;
   reg clk;
   reg rst;

   // Outputs
   wire out;

   // Instantiate the Unit Under Test (UUT)
   sequence_d uut (
       .in(in),
       .clk(clk),
       .rst(rst),
       .out(out)
   );

   initial begin
       // Initialize Inputs
       in = 0;clk = 0;rst = 1; #4
       in = 0;rst = 0; #4
       in = 0;rst = 0; #4
       in = 1;rst = 0; #4
       in = 1;rst = 0; #4
       in = 0;rst = 0; #40 $finish;
       end
always #1 clk=~clk;
  
endmodule

//++++++++++++++++++END+++++++++++++++++++//

Add a comment
Know the answer?
Add Answer to:
Design a synchronous state machine which detects the serial bit sequence of 0 1 10 on the 1-bit i...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT