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

📄 statemachine.v

📁 FPGA 学习 .再学习 .谢谢!啥得啊,还不够呢!
💻 V
字号:
`timescale 1ns / 1ps
////////////////////////////////////////////////////////////////////////////////
// Company: 
// Engineer:
//
// Create Date:    16:48:06 09/13/06
// Design Name:    
// Module Name:    StateMachine
// Project Name:   
// Target Device:  
// Tool versions:  
// Description:
//
// Dependencies:
// 
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
// 
////////////////////////////////////////////////////////////////////////////////
module StateMachine(CLK ,V_Line ,StateChangePulse ,MuxSel_A ,MuxSel_B);

parameter   MixPatterm 	= 1 ;
parameter 	ColorBar		= 2 ;
parameter 	NormalWhite = 3 ;
parameter 	Gray			= 4 ;
parameter 	ColorSpace	= 5 ;


parameter	State_1_HoldTime = 240 ; 
parameter	State_2_HoldTime = 180 ;
parameter	State_3_HoldTime = 180 ;
parameter	State_4_HoldTime = 180 ;
parameter 	State_5_HoldTime = 180 ;  


	input CLK;

	input [9:0] V_Line ;
	output StateChangePulse ;
	output [1:0] MuxSel_A ,MuxSel_B ;
				

	reg StateChangePulse = 0 ;	
	wire [1:0] MuxSel_A ,MuxSel_B ;			
	reg [1:0] MuxSel ,MuxSel2 ,SelectChanger  ;
	

	reg [2:0]   State = 0;
	reg [7:0]	HoldCount = 0;
	reg [7:0]	ResetCountValue = 0;

	assign MuxSel_A = (SelectChanger[0])? (V_Line >> 6) :MuxSel   ;
	assign MuxSel_B = (SelectChanger[1])? (V_Line >> 6) :MuxSel2  ;

	always @ (posedge CLK) 
	begin
		if (HoldCount )
			begin
			HoldCount = HoldCount - 1 ;
			StateChangePulse = 0 ;
			end
		else
			begin
			HoldCount = ResetCountValue ;
			StateChangePulse = 1 ;
			end
	end

	always @ (posedge StateChangePulse ) //CLK_H)
	begin 
		case (State)

			MixPatterm:
			begin
						MuxSel 	<= V_Line >> 6;						
						MuxSel2	<= MuxSel ;	
						SelectChanger = 2'b01;				

						ResetCountValue = State_2_HoldTime ;
						State = ColorBar ;	
			end

			ColorBar:
			begin
						MuxSel	<= 2'b00 ;
						MuxSel2	<= MuxSel ;					
						SelectChanger = 2'b10;

						ResetCountValue = State_3_HoldTime ;
						State = NormalWhite ;	
			end

			NormalWhite:					 
			begin
						MuxSel	<= 2'b01 ;
						MuxSel2	<= MuxSel ;	
						SelectChanger = 2'b00;				

						ResetCountValue = State_4_HoldTime ;
						State = Gray ;	
			end

			Gray:					 
			begin
						MuxSel	<= 2'b10 ;
						MuxSel2	<= MuxSel ;	
						SelectChanger = 2'b00;				

						ResetCountValue = State_5_HoldTime ;
						State = ColorSpace ;	
			end

			ColorSpace:					 
			begin
						MuxSel	<= 2'b11 ;
						MuxSel2	<= MuxSel ;	
						SelectChanger = 2'b00;				

						ResetCountValue = State_1_HoldTime ;
						State = MixPatterm ;	
			end

			default:					 
			begin
						MuxSel	<= 0 ;
						MuxSel2	<= 0 ;
						SelectChanger = 2'b00;					

						ResetCountValue = State_1_HoldTime ;
						State = NormalWhite ;	
			end


		endcase


	end

endmodule


//R,G,B Enable , Brightness Control //

module MuxControl(MuxSel , R1,G1,B1,R2,G2,B2 ,R3,G3,B3 ,R4,G4,B4 ,R_Out,G_Out,B_Out);

	input [1:0] MuxSel ;
	input [7:0] R1,G1,B1,R2,G2,B2,R3,G3,B3,R4,G4,B4 ;
	output [7:0] R_Out,G_Out,B_Out ;

	reg [7:0] R_Out,G_Out,B_Out ;

	always @ (MuxSel)
		begin
			case (MuxSel)
			0:
				begin
				R_Out <= R1;	G_Out <= G1;	B_Out <= B1;
				end
			1:
				begin
				R_Out <= R2;	G_Out <= G2;	B_Out <= B2;
				end
			2:
				begin
				R_Out <= R3;	G_Out <= G3;	B_Out <= B3;
				end
			3:
				begin
				R_Out <= R4;	G_Out <= G4;	B_Out <= B4;
				end
			endcase
		end


endmodule

⌨️ 快捷键说明

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