I
itaybz
Guest
can someone please explain me the differnce between Mealy machine an
Moore machine?
I understand that Mealy nachine is a function of current state and
Moore machine is a function of current state only.
What I have is this problem: I need to design a Mealy finite machine
with one input,X, and one input Y. with this machine I get an output
of Y=1 everytime the input sequence has exactly four 1's in a row. Y=0
otherwise.
The machine does this:
Input:0110111011110111110
Output:0001000000001000000
I can't tell if I get ecaxtly 2 or 4 1's untill I see the next input.
Anyway the machine must be a mealy machine, meaning that no i can
change the inputs between clocks...
I wrote a code that is syncronized but clearly not a Mealy machine.
I'm not quiet sure what is Mealy machine is.
Here is the code:
module Mealy(x,y,clk,reset);
input x,clk,reset;
output y;
reg y;
reg [2:0] prestate,nxtstate;
parameter idle=3'b000,A=3'b001,B=3'b010,C=3'b011,D=3'b100;
always @ (posedge clk or posedge reset)
if (reset) prestate=idle;
else prestate=nxtstate;
always @ (posedge clk)
begin
case (prestate)
idle:begin
if (x==0) begin
nxtstate=idle;
y=0;
end
if (x) begin
nxtstate=A;
y=0;
end
end
A:begin
if (x==0) begin
nxtstate=idle;
y=0;
end
if (x) begin
nxtstate=B;
y=0;
end
end
B:begin
if (x==0) begin
nxtstate=idle;
y=1;
end
if (x) begin
nxtstate=C;
y=0;
end
end
C:begin
if (x==0) begin
nxtstate=idle;
y=0;
end
if (x) begin
nxtstate=D;
y=0;
end
end
D:begin
if (x==0) begin
nxtstate=idle;
y=1;
end
if (x) begin
nxtstate=idle;
y=0;
end
end
default: nxtstate=idle;
endcase
end
always @ ( posedge clk)
$display ("%d x=%b y=%b ps=%b ns=%b",$time,x,y,prestate,nxtstate);
endmodule
module test_Mealy2;
reg x,reset;
wire y,clk;
integer i;
parameter temp=23'b01111101111011101100000;
Mealy M(x,y,clk,reset);
clock c(clk);
initial
begin
x=0;
i=0;
repeat(23)
begin
#100 x=temp>>i;
i=i+1;
end
end
initial
#30000 $finish;
endmodule
module clock(clk);
output clk;
reg clk;
initial
begin
clk=0;
#1 clk=1;
end
always
#50 clk=~clk;
endmodule
the machine works for test bench which has changes of x every 100 ns.
If I change the sequence, say, every 30 ns, the machine won't work.
can someone explain me the meaning of Mealy & Moore machines and how
to make this program work...
Itaybz@hotmail.com
Itay.
Moore machine?
I understand that Mealy nachine is a function of current state and
Moore machine is a function of current state only.
What I have is this problem: I need to design a Mealy finite machine
with one input,X, and one input Y. with this machine I get an output
of Y=1 everytime the input sequence has exactly four 1's in a row. Y=0
otherwise.
The machine does this:
Input:0110111011110111110
Output:0001000000001000000
I can't tell if I get ecaxtly 2 or 4 1's untill I see the next input.
Anyway the machine must be a mealy machine, meaning that no i can
change the inputs between clocks...
I wrote a code that is syncronized but clearly not a Mealy machine.
I'm not quiet sure what is Mealy machine is.
Here is the code:
module Mealy(x,y,clk,reset);
input x,clk,reset;
output y;
reg y;
reg [2:0] prestate,nxtstate;
parameter idle=3'b000,A=3'b001,B=3'b010,C=3'b011,D=3'b100;
always @ (posedge clk or posedge reset)
if (reset) prestate=idle;
else prestate=nxtstate;
always @ (posedge clk)
begin
case (prestate)
idle:begin
if (x==0) begin
nxtstate=idle;
y=0;
end
if (x) begin
nxtstate=A;
y=0;
end
end
A:begin
if (x==0) begin
nxtstate=idle;
y=0;
end
if (x) begin
nxtstate=B;
y=0;
end
end
B:begin
if (x==0) begin
nxtstate=idle;
y=1;
end
if (x) begin
nxtstate=C;
y=0;
end
end
C:begin
if (x==0) begin
nxtstate=idle;
y=0;
end
if (x) begin
nxtstate=D;
y=0;
end
end
D:begin
if (x==0) begin
nxtstate=idle;
y=1;
end
if (x) begin
nxtstate=idle;
y=0;
end
end
default: nxtstate=idle;
endcase
end
always @ ( posedge clk)
$display ("%d x=%b y=%b ps=%b ns=%b",$time,x,y,prestate,nxtstate);
endmodule
module test_Mealy2;
reg x,reset;
wire y,clk;
integer i;
parameter temp=23'b01111101111011101100000;
Mealy M(x,y,clk,reset);
clock c(clk);
initial
begin
x=0;
i=0;
repeat(23)
begin
#100 x=temp>>i;
i=i+1;
end
end
initial
#30000 $finish;
endmodule
module clock(clk);
output clk;
reg clk;
initial
begin
clk=0;
#1 clk=1;
end
always
#50 clk=~clk;
endmodule
the machine works for test bench which has changes of x every 100 ns.
If I change the sequence, say, every 30 ns, the machine won't work.
can someone explain me the meaning of Mealy & Moore machines and how
to make this program work...
Itaybz@hotmail.com
Itay.