2765 views|0 replies

34

Posts

0

Resources
The OP
 

Advanced FPGA Design Skills (I) - FPGA Frame Rate Sampling Calculation [Copy link]

This post was last edited by goodbey155 on 2018-9-6 11:01
For IT-related practitioners, reading other people's code is an indispensable ordeal. During the learning stage, we often need to read other people's code from books to learn valuable experience. This is a very boring process, and we often cannot understand the author's intention. In actual work, it is inevitable that we need to take over half-finished projects or team projects. At this time, we must read the code of previous engineers. If reading the code in the book is painful, then in this case, when the code is not standardized or the design is unreasonable, it is simply unbearable. There are also some god-like players. The designer "has a flash of inspiration" when writing the code, and the result can only be understood by himself and God. These codes can make you feel worse than death, and even start to doubt life: Is the code written in a mess or my level is not good enough? ! Do you think this is the most painful? NO! There is another situation that is enough to make you feel worse than death, and even start to doubt life. That is, when you encounter code that does not run properly, the time and energy spent on troubleshooting the problem is not as good as rewriting it. At this time, your heart is completely broken!
There is one thing that is very helpless. We cannot require other people's code to be very standardized. Therefore, the correct learning method and thinking method are particularly important. What is the correct way to read other people's code? What preparations should be made before reading the code? Use forward thinking or reverse thinking when reading the code? How to judge which parts of the code are worth learning from? Therefore, it is very important to master a general skill to understand other people's code. Let's talk about this aspect below.
We know that there may be many ways to implement a function, so different people write different codes. It is very difficult to know what function it is going to implement by looking at the code. Some beginners will think of taking simulation, looking at circuit diagrams, flow charts, timing diagrams, comments, etc., which are all undesirable. Through these, you still cannot know its function and whether there are any errors.
So what is the correct method? We adopt a method that can be called "reverse deduction" or "reverse method", and this problem will be solved. You know, the purpose of code is to achieve function. No matter what kind of code you use, one thing that is exactly the same is the final result of "achieving function". Knowing this, we can reverse the process (code) through the result (function), and the idea, process, and purpose of the code will be clearly revealed. Okay, let's take an example to illustrate how to use the reverse deduction method to understand other people's code step by step.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[align=cen ter]18
19
20
21
22
23
[align =center]24
25
26
27
28
29
[a lign=center]30
31
32
33
34
35[/alig n]
36
37
38
39
40
41[/ align]
//------------------------------------------------
//Frame rate sampling calculation
reg fps_state;
reg [7:0] fps_data;
always@(posedge iCLK or negedge iRST_N)
begin
if(!iRST_N)
begin
fps_data <= 0;
fps_state <= 0;
CMOS_FPS_DATA <= 0;
end
else if(Frame_valid)
begin
case(fps_state)
0:begin
CMOS_FPS_DATA <= CMOS_FPS_DATA;
if(delay_2s == 0)
begin
fps_state <= 0;
if(CMOS_VSYNC_over == 1'b1) //VS rising edge, 1 frame writing is completed
fps_data <= fps_data + 1' b1;
end
else
fps_state <= 1;
end
1: begin
fps_state <= 0;
fps_data <= 0;
CMOS_FPS_DATA <= fps_data >>1;
end
endcase
end
else
[align =left] begin
fps_data <= 0;
fps_state <= 0;
CMOS_FPS_DATA <= 0;
end
end
endmodule
See attachment for detailed analysis FPGA设计进阶技巧(一)-FPGA帧率采样计算.pdf (105.54 KB, downloads: 16)
This post is from FPGA/CPLD
Personal signatureFPGA学习爱好者,并为之而努力着http://home.eeworld.com.cn/static/image/smiley/default/pleased.gif
 

Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list