⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 read_sm_rev0.1.v

📁 Verilog jpec coder encoder source code
💻 V
字号:
////////////////////////////////////////////////////
//
//  Module Name: 	read_sm
// 	Descr: 			State Machine to Read from 
// 					FIFO with Two Clock Domains
// 	Author: 		James Rosenthal
// 	Date: 			11/15/04
//
//
// 	Version	Date		Modifications
// 	---------------------------------
// 	0.0		11/15/04	- Initial
//	0.1		11/27/04	- Reduce to 1 Wait State
//						- Add Transition from Wait to Read
//						- Remove extclk from module
//						- Remove rd_en, add are, and nce
//
////////////////////////////////////////////////////

`timescale 1ns / 10ps

module read_sm(
	sysclk,		// System Clock
	rst,		// Active Low Reset
	empty,		// FIFO Empty
	are,		// Asynchronous Read Enable
	nce,		// Active Low Chip Enable
	rd_fifo,	// Read FIFO Enable
	din,		// Data input
	dout,		// Data output
	error		// Invalid Write
	);
	
	// 
	// Inputs & Outputs
	//

	input [12:0] din;	// Data Input	
	input sysclk;		// System Clock
	input rst;			// Asynchronous Actie Low Reset
	input are;			// Asynchronous Read Enable
	input nce;			// Active Low Chip Enable
	input empty;		// FIFO Empty
	
	output [12:0] dout;	// Data Output
	output [1:0] error;	// Invalid Read
	output rd_fifo;		// Read FIFO


	//
	// Parameters
	//
	
	parameter IDLE	= 4'h1;			// Start Read FIFO if Empty
	parameter READFIFO1 = 4'h2;		// Read Enable to FIFO
	parameter READFIFO2	= 4'h4;		// Read Data from FIFO, Wait rd_en
	parameter WAIT = 4'h8;			// Wait for read cycle to end
	
	//
	// Wires & Registers
	//
	
	reg [12:0] sdata;	// Data Latched on sysclk
	
	reg rd_fifo;		// FIFO Read Enable
	reg [1:0] error;	// Error Output {Read_Empty,Read_in_Progress}
	reg [12:0] dout;	// 13-bit Output
	
	reg [3:0] state;	// State Register
	reg [3:0] nstate;	// Next State Register
	
	//
	// Behavioral Description
	// 
	
	// Read Enable
	assign rd_en = !are & !nce;

	// State Transitions
	always @ (posedge sysclk or negedge rst)
	begin
		if(!rst)
			state <= IDLE;
		else state <= nstate;
	end
	
	// State Behaviors
	always @ (negedge sysclk or negedge rst)
	begin
		if(!rst)
		begin
			rd_fifo <= 1'b0;
			sdata <= 13'h0;
			nstate <= IDLE;
		end
		else
		begin
			case(state)
				
				IDLE:
				begin
					rd_fifo <= !empty;
					nstate <= !empty ? READFIFO1 : IDLE;
				end
				
				READFIFO1:
				begin
					rd_fifo <= 1'b0;
					nstate <= READFIFO2;
				end
				
				READFIFO2: 
				begin
					rd_fifo <= 1'b0;
					sdata <= din;
					nstate <= rd_en ? WAIT : READFIFO2;
				end
				
				WAIT:
				begin
					rd_fifo <= !rd_en & !empty;
					nstate <= rd_en ? WAIT : 
						(rd_en && !empty) ? READFIFO1 : IDLE;
				end
				
			endcase
		end
	end

	// Error Flag
	always @ (posedge sysclk or negedge rst)
	begin
		if(!rst)
			error <= 2'b0;
		else
		begin
			error[1] <= rd_en && state == IDLE; // Read on Empty
			error[0] <= rd_en && state == READFIFO1; // Read In Progress
		end
	end

endmodule

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -