📄 mealy_beh.v
字号:
/*********************************************************/
// MODULE: Mealy state machine
//
// FILE NAME: mealy_beh.v
// VERSION: 1.0
// DATE: January 1, 1999
// AUTHOR: Bob Zeidman, Zeidman Consulting
//
// CODE TYPE: Behavioral Level
//
// DESCRIPTION: This module shows a state machine
// implementation.
//
// NOTES: This is a Mealy model of a state machine, since
// the outputs are defined by the state transitions.
/*********************************************************/
// DEFINES
`define DEL 1 // Clock-to-output delay. Zero
// time delays can be confusing
// and sometimes cause problems.
// TOP MODULE
module state_machine(
clock,
reset_n,
wr,
rd,
ready,
out_en,
write_en,
ack);
// INPUTS
input clock; // State machine clock
input reset_n; // Active low, synchronous reset
input wr; // Write command from processor
input rd; // Read command from processor
input ready; // Ready signal from memory device
// OUTPUTS
output out_en; // Output enable to memory
output write_en; // Write enable to memory
output ack; // Acknowledge signal to processor
// INOUTS
// SIGNAL DECLARATIONS
wire clock;
wire reset_n;
wire wr;
wire rd;
wire ready;
reg out_en;
reg write_en;
reg ack;
reg [1:0] mem_state; // Memory state machine
// PARAMETERS
parameter[1:0] // State machine states
IDLE = 0,
WRITE = 1,
READ = 2;
// ASSIGN STATEMENTS
// MAIN CODE
// Asynchronous reset
always @(posedge reset_n or negedge reset_n) begin
if (~reset_n) begin
#`DEL;
assign mem_state = IDLE;
assign out_en = 1'b0;
assign write_en = 1'b0;
assign ack = 1'b0;
end
else begin
#`DEL;
deassign mem_state;
deassign out_en;
deassign write_en;
deassign ack;
end
end
// Look at the rising edge of clock for state transitions
always @(posedge clock) begin : fsm
case (mem_state)
IDLE: begin
// Do not do anything if we are
// acknowledging a previous access
if (~ack && (wr == 1'b1)) begin
mem_state <= #`DEL WRITE;
out_en <= #`DEL 1'b0;
write_en <= #`DEL 1'b1;
ack <= #`DEL 1'b1;
end
else if (~ack && (rd == 1'b1)) begin
mem_state <= #`DEL READ;
out_en <= #`DEL 1'b1;
write_en <= #`DEL 1'b0;
ack <= #`DEL 1'b0;
end
else begin
out_en <= #`DEL 1'b0;
write_en <= #`DEL 1'b0;
ack <= #`DEL 1'b0;
end
end
WRITE: begin
mem_state <= #`DEL IDLE;
out_en <= #`DEL 1'b0;
write_en <= #`DEL 1'b0;
ack <= #`DEL 1'b0;
end
READ: begin
if (ready == 1'b1) begin
mem_state <= #`DEL IDLE;
out_en <= #`DEL 1'b1;
write_en <= #`DEL 1'b0;
ack <= #`DEL 1'b1;
end
else begin
out_en <= #`DEL 1'b1;
write_en <= #`DEL 1'b0;
ack <= #`DEL 1'b0;
end
end
endcase
end // fsm
endmodule // state_machine
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -