verilog coding

9
VERILOG CODING Mealy and Moore Machines -PREM RANJAN 14ESP003 1

Upload: prem-ranjan

Post on 16-Jul-2015

87 views

Category:

Engineering


1 download

TRANSCRIPT

Page 1: Verilog coding

VERILOG CODINGMealy and Moore Machines

-PREM RANJAN

14ESP003

1

Page 2: Verilog coding

MEALY MACHINE

2

Page 3: Verilog coding

module state(x, clk, state, z); // Mealy FSM

input x, clk;

output z;

output [1:0] state;

reg z;

reg [1:0] state;

parameter S0=2’b00,

S1=2’b01;

initial

begin

state=S0;

z=0;

end 3

Page 4: Verilog coding

always @(negedge clk) // Next-State

case(state)

S0: if (x==0) state=S1;

else if (x==1) state=S0;

S1: if (x==0) state=S1;

else if (x==1) state=S0;

endcase

always@(state or x) // Output

case(state)

S0: if (x==0) z=0;

else if (x==1) z=0;

S1: if (x==0) z=0;

else if (x==1) z=1;

endcase

endmodule

4

Page 5: Verilog coding

MOORE MACHINE

5

Page 6: Verilog coding

module state(x, clk, state, z); // Moore FSM

input x, clk;

output z;

output [1:0] state;

reg z;

reg [1:0] state;

parameter S0=2’b00,

S1=2’b01,

S2=2’b10;

initial

begin

state=S0;

z=0;

end6

Page 7: Verilog coding

always@(negedge clk) // Next-State

case(state)

S0: if (x==0) state=S1;

else if (x==1) state=S0;

S1: if (x==0) state=S1;

else if (x==1) state=S2;

S2: if (x==0) state=S1;

else if (x==1) state=S0;

endcase

always@(state) // Output

case(state)

S0: z=0;

S1: z=0;

S2: z=1;

endcase

endmodule

7

Page 8: Verilog coding

8

Page 9: Verilog coding

9