Question

In: Computer Science

In Verilog Design a state machine, using the D flip-flop, that implements a 00 and 11...

In Verilog

Design a state machine, using the D flip-flop, that implements a 00 and 11 sequence detector. Your machine should output a 1 as soon as it detects two 0s or two 1s on its input, otherwise it outputs 0s.
Write a module that implements the machine and a test bench to test it.

Solutions

Expert Solution

Answer 1)

Verilog code in behavioral style is mentioned below. the code is written with the help of the state diagram.

module moore_00_11 (clk, rst, x, z);
input clk;
input rst;
input x;
output reg z;

parameter S0 = 2'b00,
S1 = 2'b01,
S2 = 2'b10,
S3 = 2'b11;

//Internal reg and wires decalarations
reg [2:0] cur_state, next_state;

// current state logic
always @(posedge clk)
begin
if(rst)
cur_state <= S0;
else
cur_state <= next_state;
end

// Logic for next state and output
always @(*)
begin
case(cur_state)
S0 : begin
z = 1'b0;
next_state = x ? S1 : S2;
end

S1 : begin
z = 1'b0;
next_state = x ? S3 : S0;
end

S2 : begin
z = 1'b1;
next_state = x ? S1 : S2;
end

S3 : begin
z = 1'b1;
next_state = x ? S3 : S0;
end
default : begin
z = 1'b0;
next_state = S0;
end
endcase
end

endmodule

Testbench for the verilog code

module testbench;
reg clk;
reg rst;
reg x;
wire z;

moore_00_11 u_fsm_moore (.clk(clk), .rst(rst), .x(x), .z(z));

always
#5 clk = !clk;

initial
begin
   clk = 1'b0;
   rst = 1'b1;
x = 1'b0;
repeat(2)
   @(negedge clk);
   rst = 1'b0;
x = 1'b1;
   @(negedge clk);
   x = 1'b0;
   @(negedge clk);
   x = 1'b1;
   @(negedge clk);
x = 1'b0;
repeat(3)
   @(negedge clk);
x = 1'b1;
   @(negedge clk);
x = 1'b0;
   @(negedge clk);
x = 1'b1;
   @(negedge clk);
x = 1'b0;
   @(negedge clk);
x = 1'b1;
repeat(5)
   @(negedge clk);

   $finish;
end

initial
begin
$recordfile("file1.trn");
$recordvars();
end

endmodule

Waveform:-


Related Solutions

Design a synchronously settable flip-flop using a regular D flip-flop and additional gates.
Design a synchronously settable flip-flop using a regular D flip-flop and additional gates.
Create a state meachine that encrypts an incoming digital bitstream using a D-flip-flop and a Mealy...
Create a state meachine that encrypts an incoming digital bitstream using a D-flip-flop and a Mealy Meachine. The device have to meet these requirments: A. The output of the encryption device matches the input bitstream until a certain set of bits is detected (such as 110). After this detection, the output is the complemented version of the input. B. When a second bitstream 010 is detected, the output reverts to simply matching the input stream again. Please make both bitstreams...
Design a 5-bit binary counter using JK flip flops. Draw the flip-flop circuit diagram, the state...
Design a 5-bit binary counter using JK flip flops. Draw the flip-flop circuit diagram, the state graph, the timing diagram, the truth table (with clk pulse) and the state table (with present and next states).
9. Why is the D flip flop the more common flip flop? 10. What is the...
9. Why is the D flip flop the more common flip flop? 10. What is the purpose of a clock in a digital system?
You are to implement the following in VHDL: D flip-flop D flip-flop       with enable and reset J-K...
You are to implement the following in VHDL: D flip-flop D flip-flop       with enable and reset J-K flip flop with asynchronous set T Flip flop with asynchronous clear
A T flip-flop is a 1-bit synchronous storage component alternative to the D flip-flop, with a...
A T flip-flop is a 1-bit synchronous storage component alternative to the D flip-flop, with a slightly different interface. The T flip-flop has one input t to synchronously control the state of the flip-flop, as follows: When t is 0, the flip-flop does not change its state value. When t is 1, the flip-flop inverts its current state value (0 becomes 1, and 1 becomes 0). Write a Verilog module for the T flip-flop using a behavioral model. The flip-flop...
Design a synchronous counter of four-bit using D flip‐flops and gates (AND, OR etc.) *use verilog...
Design a synchronous counter of four-bit using D flip‐flops and gates (AND, OR etc.) *use verilog language modules and test and explain briefly
Implement a JK Flip flop using behavioral modeling in verilog, also write its test bench code.
Implement a JK Flip flop using behavioral modeling in verilog, also write its test bench code.
Create a VHDL code of a 4 bit Counter using D flip flop and a Frequency...
Create a VHDL code of a 4 bit Counter using D flip flop and a Frequency Divider that provides the clock signal input for counter
Verify the operation of a D flip-flop by providing appropriate inputs to the D, Preset, and...
Verify the operation of a D flip-flop by providing appropriate inputs to the D, Preset, and Clear pins. Use CLOCK input to the flip-flop to function properly ( can be found under wiring in Logisim) //If you present a diagram designed in the "Logisim app" it would be very much appreciated. Thank you
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT