Question

In: Computer Science

1. Write Verilog code and test bench for Moore FSM having a single input line ‘X’...

1. Write Verilog code and test bench for Moore FSM having a single input line ‘X’ and a single output-line ’Z’. An output of 1 is to be produced coincident with the pattern 1101 and an output of ‘ 0’ is to be produced for all the other sequences and simulate it.

Solutions

Expert Solution

The verilog code:

module moore_fsm_1101_seq(reset,clk,X,Z);
input reset,X,clk; //inputs to the state machine
output reg Z; //output
reg [2:0] present_state,next_state; //resent and next state of state machine
parameter s1=3'b001,s2=3'b010,s3=3'b011,s4=3'b100,s5=3'b101; //encoding each state with 001,010,011,100,101
initial
begin //out=1 when success else out=0 in error
present_state=0;
next_state=0;
end
always@(posedge clk)
begin
if(reset==1)
present_state<=s1;
else
present_state<=next_state;
end
always@(present_state or X)
begin
case(present_state)
s1:begin
if(X==1)
next_state<=s2;
else
next_state<=s1;
Z=1'b0;
end
s2:begin
if(X==1)
next_state<=s3;
else
next_state<=s1;
Z=1'b0;
end
s3:begin if(X==1)
next_state<=s3;
else
next_state<=s4;
Z=1'b0;
end
s4:begin if(X==1)
next_state<=s5;
else
next_state<=s1;
Z=1'b0;
end
s5:begin if(X==1)
next_state<=s3;
else
next_state<=s1;
Z=1'b1;
end
endcase
end
endmodule

Code snippet:

Test bench code:

module moore_fsm_tb;
reg reset,X,clk; //INPUTS are declared as reg
wire Z; //outputs are declared as wire
//module instantiation
moore_fsm_1101_seq m1(reset,clk,X,Z);
initial
//input assigning
begin
reset=1;clk=0;X=0;
#10 reset=0;
#10 X=0;
#10 X=1;
#10 X=1;
#10 X=0;
#10 X=1;
#10 X=1;
#10 X=0;
#10 X=1;
#10 X=0;
#10 X=0;
#10 X=1;
#10 X=1;
#10 X=1;
#10 X=0;
#10 X=1;
#10 X=0;
#10 X=1;
#10 X=1;
end
always
#5 clk=~clk; //clock declaration
initial
#200 $finish ;
endmodule

code snippet:

Simulation Results:

Please see the code snippet for the indentation.

I write the code in vivado tool. The code is with overlap sequence i have written here,

Please upvote this.


Related Solutions

Using the conditional assignment statements, write the verilog code for 16:1 Mux. Write the test bench...
Using the conditional assignment statements, write the verilog code for 16:1 Mux. Write the test bench for this module.
Write the VERILOG code for an arithmetic/logic unit (ALU) with a test bench that does the...
Write the VERILOG code for an arithmetic/logic unit (ALU) with a test bench that does the following with 4 bit inputs , and can be tested in on nexys 4 board This is to be implement on : ISE Design Suite - Xilinx /* ALU Arithmetic and Logic Operations ---------------------------------------------------------------------- |ALU_Sel| ALU Operation ---------------------------------------------------------------------- | 0000 | ALU_Out = A + B; ---------------------------------------------------------------------- | 0001 | ALU_Out = A - B; ---------------------------------------------------------------------- | 0010 | ALU_Out = A * B;...
Can anyone write a Verilog code and a test bench for a universal shift register with...
Can anyone write a Verilog code and a test bench for a universal shift register with 4 bits using D flip flop? Thanks
Write the Verilog code and test bench for the following circuits: - Mealy State machine design...
Write the Verilog code and test bench for the following circuits: - Mealy State machine design for a Serial Adder Circuit - Moore State Machine design for a Serial Adder Circuit
Derive a state diagram and table for a single-input and single-output Moore-type FSM that produces an...
Derive a state diagram and table for a single-input and single-output Moore-type FSM that produces an output of 1 if an input sequence of 101 is detected
imulate/ code in verilog: Develop an electronic key system using the FSM (moore) methology. Use from...
imulate/ code in verilog: Develop an electronic key system using the FSM (moore) methology. Use from student ID and use the last 4 digits:(0864) if the number is <5 then = 1 if the number is >=5 then = 0 example: 8012345. Take last 4 digits (2345) which makes it 0001. In my case, the last 4 digits are 0864, which makes it 0110 features of FSM (moore FSM): input 4 bits serially, if the sequence is correct, then you...
code an 8 bit LFSR random number generator in system verilog. Write a test bench, load...
code an 8 bit LFSR random number generator in system verilog. Write a test bench, load the seed 11111111, and generate the first 10 random numbers.
Implement a 4x4 multiplier using gate level (verilog code and test bench)
Implement a 4x4 multiplier using gate level (verilog code and test bench)
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.
verilog code of a 64 x64 array with 128 parameters please include test bench
verilog code of a 64 x64 array with 128 parameters please include test bench
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT