|
我剛好有寫了一個計算FPS程式給你參考看看..
/*
2009 Intellignet Control Laborator of Tamkang University. All rights reserved
Filename : ShowFPS.v
Compiler : Quartus II 9.0
Description : Show CMOS and LTM FPS
Author : Shih-An Li
Release : 04/29/2009 1.0
*/
module ShowFPS ( iCLK_50,
iCMOS_V,
iLTM_V,
oShowCMOSfps,
oShowLTMfps );
//===========================================================================
// PARAMETER declarations
//===========================================================================
parameter SystemClk = 50000000; // 50Mhz
//===========================================================================
// PORT declarations
//===========================================================================
input iCLK_50;
input iCMOS_V; // CMOS V sync
input iLTM_V; // LTM V Sync
output [7:0] oShowCMOSfps;
output [7:0] oShowLTMfps;
//=============================================================================
// REG/WIRE declarations
//=============================================================================
reg pre_CMOS_V,pre_LTM_V;
reg [31:0] CMOS_V_cnt, LTM_V_cnt, Count,pre_CMOS_Frame_Cont,pre_LTM_Frame_Cont;
reg [31:0] CMOS_FPS, LTM_FPS;
reg [7:0] CMOS_FPS0,CMOS_FPS1;
reg [7:0] LTM_FPS0,LTM_FPS1;
//=============================================================================
// Structural coding
//=============================================================================
always@(posedge iCLK_50) begin
// Calculate the CMOS Frame
pre_CMOS_V <= iCMOS_V;
if({pre_CMOS_V,iCMOS_V}==2'b10) begin
CMOS_V_cnt <= CMOS_V_cnt + 1;
end
// Calculate the LTM Frame
pre_LTM_V <= iLTM_V;
if({pre_LTM_V,iLTM_V}==2'b10) begin
LTM_V_cnt <= LTM_V_cnt + 1;
end
end
always@(posedge iCLK_50) begin
if (Count >=SystemClk) begin
Count <= 0;
pre_CMOS_Frame_Cont <= CMOS_V_cnt;
CMOS_FPS <= CMOS_V_cnt - pre_CMOS_Frame_Cont;
pre_LTM_Frame_Cont <= LTM_V_cnt;
LTM_FPS <= LTM_V_cnt - pre_LTM_Frame_Cont;
end
else begin
Count <= Count +1;
end
end
assign oShowCMOSfps = CMOS_FPS;
assign oShowLTMfps= LTM_FPS ;
endmodule
/////////////////////////////////////end////////////////////////////////////
CMOS_FPS, LTM_FPS 就是你要的. |
|