Question

Write a Verilog program to describe a sequential circuit that has input X and output Z....

Write a Verilog program to describe a sequential circuit that has input X and output Z. Z goes to 1 whenever the last four X inputs (in four clock cycles) are 1001 or 0110. Use a switch (SW1) on the DE1 board for X and a red LED for Z. Use a push button as the clock input. Use both the Moore and Mealy models to describe the circuit.

0 0
Add a comment Improve this question Transcribed image text
Answer #1


module sequential_mealy (clock, X, Z);

input clock, X;

output reg Z;

parameter [2:0] S0=3'b000, S1=3'b001, S2=3'b010, S3=3'b011, S4=3'b100, S5=3'b101, S6=3'b110;

reg [2:0] current_state, next_state;

always @ (posedge clock)
begin

   current_state   <= next_state;

end

always @ (current_state, X)
begin

   case (current_state)
       S0 :    begin Z   <= 1'b0;
           if (X == 1'b1)
               next_state    <= S1;              
           else
               next_state    <= S2; end

       S1 :    begin Z   <= 1'b0;
           if (X == 1'b1)
               next_state    <= S1;              
           else
               next_state    <= S3; end

       S2 :    begin Z   <= 1'b0;
           if (X == 1'b1)
               next_state    <= S4;              
           else
               next_state    <= S2; end

       S3 :    begin Z   <= 1'b0;
           if (X == 1'b1)
               next_state    <= S4;              
           else
               next_state    <= S5; end

       S4 :    begin Z   <= 1'b0;
           if (X == 1'b1)
               next_state    <= S6;              
           else
               next_state    <= S3; end

       S5 :    if (X == 1'b1) begin
               next_state    <= S4;
               Z       <= 1'b1; end              
           else begin
               next_state    <= S2;
               Z       <= 1'b0; end

       S6 :    if (X == 1'b0) begin
               next_state    <= S3;
               Z       <= 1'b1; end              
           else begin
               next_state    <= S1;
               Z       <= 1'b0; end

   default   :         next_state    <= S0;

   endcase

end

endmodule

  


module sequential_moore (clock, X, Z);

input clock, X;

output reg Z;

parameter [3:0] S0=4'b0000, S1=4'b0001, S2=4'b0010, S3=4'b0011, S4=4'b0100, S5=4'b0101, S6=4'b0110, S7=4'b0111, S8=4'b1000 ;

reg [3:0] current_state, next_state;

always @ (posedge clock)
begin

   current_state   <= next_state;

end

always @ (current_state, X)
begin

   case (current_state)
       S0 :    begin Z   <= 1'b0;
           if (X == 1'b1)
               next_state    <= S1;              
           else
               next_state    <= S2; end

       S1 :    begin Z   <= 1'b0;
           if (X == 1'b1)
               next_state    <= S1;              
           else
               next_state    <= S3; end

       S2 :    begin Z   <= 1'b0;
           if (X == 1'b1)
               next_state    <= S4;              
           else
               next_state    <= S2; end

       S3 :    begin Z   <= 1'b0;
           if (X == 1'b1)
               next_state    <= S4;              
           else
               next_state    <= S5; end

       S4 :    begin Z   <= 1'b0;
           if (X == 1'b1)
               next_state    <= S6;              
           else
               next_state    <= S3; end

       S5 :    begin Z   <= 1'b0;
           if (X == 1'b1)
               next_state    <= S7;              
           else
               next_state    <= S2; end

       S6 :    begin Z   <= 1'b0;
           if (X == 1'b1)
               next_state    <= S1;              
           else
               next_state    <= S8; end

       S7 :    begin Z   <= 1'b1;
           if (X == 1'b1)
               next_state    <= S1;              
           else
               next_state    <= S3; end

       S8 :    begin Z   <= 1'b1;
           if (X == 1'b1)
               next_state    <= S4;              
           else
               next_state    <= S2; end

   default   :         next_state    <= S0;

   endcase

end

endmodule

  

Add a comment
Know the answer?
Add Answer to:
Write a Verilog program to describe a sequential circuit that has input X and output Z....
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