State Diagram
Verilog Code
module mealy (Output, next_state,Input, clock,reset);input Input, clock, reset;
output reg[0:0] Output = 0;
output reg[1:0] next_state =2'b00;
reg[1:0] state = 2'b00;
parameter s0 = 2'b00,
s1 = 2'b01,
s2 = 2'b10,
s3 = 2'b11;
always @ (posedge clock, negedge reset)
if (reset == 0) begin
state<=s0;
next_state =2'b00;
end
else
case (state)
s0:
if(Input)
begin
state <=s1;
Output =0;
next_state =2'b01;
end
else
begin
state <=s0;
Output =0 ;
next_state=2'b00;
end
s1:
if(Input)
begin
state <=s2;
Output =0;
next_state =2'b10;
end
else
begin
state<=s3;
Output =1 ;
next_state=2'b11;
end
s2:
if(Input)
begin
state <=s1;
Output =1;
next_state =2'b01;
end
else
begin
state<=s3;
Output =1 ;
next_state=2'b11;
end
s3:
if(Input)
begin
state <=s2;
Output =1;
next_state =2'b10;
end
else
begin
state<=s0;
Output =0;
next_state=2'b00;
end
endcase
endmodule
Test Bench
module mealy_tb();reg Input, clock, reset;
wire[0:0] Output ;
wire[1:0] next_state ;
mealy test (Output, next_state,Input, clock, reset);
initial
begin
clock = 0;
forever #50 clock =~clock;
end
initial
begin
reset = 0;
#50 reset = 1;
#100 Input = 1;
#100 Input = 0;
#100 Input = 1;
#100 Input = 1;
#100 Input = 0;
#100 Input = 1;
#100 Input = 1;
#100 Input = 1;
#100 Input = 0;
#100 Input = 0;
end
RTL Viewer
RTL Simulation
No comments:
Post a Comment