(筆記) 如何設計邊緣檢測電路? (SOC) (Verilog)
来源:互联网 发布:linux进入root模式 编辑:程序博客网 时间:2024/05/29 04:21
转自http://www.cnblogs.com/oomusou/archive/2008/08/11/verilog_edge_detection_circuit.html
Abstract
邊緣檢測電路(edge detection circuit)是個常見的基本電路。
Introduction
使用環境:Quartus II 7.2 SP3
所謂的邊緣檢測,簡單的說就是判斷前一個clock的狀態和目前clock狀態的比較,若由0變1,就是上升沿檢測電路(posedge edge detection circuit)(又稱上緣微分電路),若是由1變0,就是下升沿檢測電路(negedge edge detection circuit)(又稱下緣微分電路),若上升沿與下升沿都要檢測,就是雙沿檢測電路電路(double edge detection)。
上升沿檢測電路(posedge detection circuit)
Method 1:
使用兩個reg
posedge_detection_00
r_data_in0與r_data_in1為D-FF,分別hold住上一個clock與目前clock的i_data_in,所謂上升沿電路,就是i_data_in由0變1,也就是r_data_in0為0且r_data_in1為1,故用not接r_data_in0,之後再用and連接r_data_in1。
posedge_detection.v / Verilog
复制代码
1 /*
3
4 Filename : posedge_detection.v
5 Compiler : Quartus II 7.2 SP3
6 Description : Demo how to design posedge detection circuit
7 Release : 07/06/2008 1.0
8 */
9
10 module posedge_detection (
11 input clk,
12 input rst_n,
13 input i_data_in,
14 output o_rising_edge
15 );
16
17 reg r_data_in0;
18 reg r_data_in1;
19
20 assign o_rising_edge = ~r_data_in0 & r_data_in1;
21
22 always@(posedge clk, negedge rst_n) begin
23 if (!rst_n) begin
24 r_data_in0 <= 0;
25 r_data_in1 <= 0;
26 end
27 else begin
28 r_data_in0 <= r_data_in1;
29 r_data_in1 <= i_data_in;
30 end
31 end
32
33 endmodule
复制代码
這種寫法經過合成後,會很聰明的只用一個2 bit的D-FF,與一個AND。
edge01
Method 2:
使用1個reg
posedge_edgedetection2.v / Verilog
复制代码
1 /*
3
4 Filename : posedge_detection2.v
5 Compiler : Quartus II 7.2 SP3
6 Description : Demo how to design posedge detection circuit
7 Release : 08/11/2008 1.0
8 */
9
10 module posedge_detection2 (
11 input clk,
12 input rst_n,
13 input i_data_in,
14 output reg o_rising_edge
15 );
16
17 reg r_data_in0;
18
19 always@(posedge clk, negedge rst_n) begin
20 if (!rst_n)
21 r_data_in0 <= 0;
22 else begin
23 r_data_in0 <= i_data_in;
24
25 if ({r_data_in0, i_data_in} == 2’b01)
26 o_rising_edge <= 1;
27 else
28 o_rising_edge <= 0;
29 end
30 end
31
32 endmodule
复制代码
若你覺得Method 1比較不好理解,那Method 2就非常的behavior,只使用一個reg記住前一個clock的狀態,並在這個clock判斷前一個狀態是否為0且目前狀態是否為1,這樣就是posedge了。
這種寫法經過合成之後,只有一個D-FF與EQUAL,右邊的o_rising_edge的D-FF主要是因為在always block內的reg。
edge00
就這個例子而言,Method 1與Method 2目前在Quartus II 7.2 SP3的合成下resource打成平手,logic element各用兩個D-FF與與一個組合電路,不過Method 2的code可讀性比較高。
edge03
edge02
下升沿檢測電路(negedge detection circuit)
negedge_detection_00
r_data_in2與r_data_in1為reg,分別hold住上一個clock與目前clock的i_data_in,所謂下升沿電路,就是i_data_in由1變0,也就是r_data_in2為1且r_data_in1為0,故用not接r_data_in1,之後再用and連接r_data_in2。
Method 1:
使用兩個reg
nededge_detection.v / Verilog
复制代码
1 /*
3
4 Filename : nededge_detection.v
5 Compiler : Quartus II 7.2 SP3
6 Description : Demo how to design nededge detection circuit
7 Release : 07/06/2008 1.0
8 */
9 module negedge_detection (
10 input clk,
11 input rst_n,
12 input i_data_in,
13 output o_falling_edge
14 );
15
16 reg r_data_in0;
17 reg r_data_in1;
18
19 assign o_falling_edge = r_data_in0 & ~r_data_in1;
20
21 always@(posedge clk, negedge rst_n) begin
22 if (!rst_n) begin
23 r_data_in0 <= 0;
24 r_data_in1 <= 0;
25 end
26 else begin
27 r_data_in0 <= r_data_in1;
28 r_data_in1 <= i_data_in;
29 end
30 end
31
32 endmodule
- (筆記) 如何設計邊緣檢測電路? (SOC) (Verilog)
- 如何設計乘加電路? (SOC) (Verilog) (MegaCore)
- (筆記) 如何使用blocking與nonblocking assignment? (SOC) (Verilog)
- 如何將值delay n個clock? (SOC) (Verilog)
- 如何避免Quartus II自動將未宣告的信號視為wire? (SOC) (Verilog) (Quartus II)
- 如何使用SignalTap II觀察reg與wire值? (SOC) (Verilog) (Quartus II) (SignalTap II)
- 如何計算浮點數? (SOC) (Verilog) http://www.cnblogs.com/oomusou/archive/2008/10/11/verilog_floating.html
- 如何使用SignalTap II觀察reg與wire值? (SOC) (Verilog) (Quartus II) (SignalTap II)
- 如何處理signed integer的加法運算與overflow? (SOC) (Verilog)
- (筆記) $dispaly()、$strobe()、$monitor() 、$fwrite()與blocking / nonblocking的關係 (SOC) (Verilog) (Debussy)
- 如何實現Real Time的Sobel Edge Detector? (SOC) (Verilog) (Image Processing) (DE2-70) (TRDB-D5M) (TRDB-LTM)
- Verilog testbench 与module建議的coding style(SOC) (Verilog)
- soc
- SoC
- SoC
- 如何学习verilog
- -如何在 Zynq SoC 上使用中断
- 如何搭建SoC项目的基本Testbench
- 炒股的那些事
- 第一次开通博客
- 【Android开发】范例2-实现幻灯片式图片浏览器
- 全排列 NOJ 1103
- ORA-01031 权限不足-过程中DBA 角色用户无法执行DDL
- (筆記) 如何設計邊緣檢測電路? (SOC) (Verilog)
- android新手学习:SQLite数据库
- 第五周 课后实践:项目四——用多文件组织多个类的程序
- Redis on spark java.io.NotSerializableException
- 文件比较函数
- 通信系统中进行编码和解码的原因及常见的编码方法
- 【Android开发】消息提示框与对话框-使用Toast显示消息提示框
- ecshop二次开发 结构分析和代码研究
- vsftp安装配置,以及问题解决