📄 moore_beh.v
字号:
/*********************************************************/
// MODULE: Moore state machine
//
// FILE NAME: moore_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 Moore model of a state machine, since
// the outputs are defined by the current state.
/*********************************************************/
// 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,
READ1 = 2,
READ2 = 3;
// ASSIGN STATEMENTS
// MAIN CODE
// Asynchronous reset
always @(posedge reset_n or negedge reset_n) begin
if (~reset_n)
#`DEL assign mem_state = IDLE;
else
#`DEL deassign mem_state;
end
// Look at the rising edge of clock for state transitions
always @(posedge clock) begin : fsm
case (mem_state)
IDLE: begin
if (wr == 1'b1)
mem_state <= #`DEL WRITE;
else if (rd == 1'b1)
mem_state <= #`DEL READ1;
end
WRITE: begin
mem_state <= #`DEL IDLE;
end
READ1: begin
if (ready == 1'b1)
mem_state <= #`DEL READ2;
end
READ2: begin
mem_state <= #`DEL IDLE;
end
endcase
end // fsm
// Look at changes in the state to determine outputs
always @(mem_state) begin : outputs
// Default output values
out_en = 1'b0;
write_en = 1'b0;
ack = 1'b0;
case (mem_state)
WRITE: begin
write_en = 1'b1;
ack = 1'b1;
end
READ1: begin
out_en = 1'b1;
end
READ2: begin
out_en = 1'b1;
ack = 1'b1;
end
endcase
end // outputs
endmodule // state_machine
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -