边缘检测电路的(SOC)(Verilog)
更新时间:2023-06-09 21:12:01 阅读量: 实用文档 文档下载
边缘检测电路的硬件实现,用的是Verilog语言,采用的是原理图输入,给出了源代码,对于采用FPGA做图像预处理有着很好的参考价值
(筆記) 如何設計邊緣檢測電路? (SOC) (Verilog)
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
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 /*
2 (C) OOMusou 2008
3
4 Filename : posedge_detection.v
5 Compiler : Quartus II 7.2 SP3
6 Description : Demo how to design posedge detection circuit
边缘检测电路的硬件实现,用的是Verilog语言,采用的是原理图输入,给出了源代码,对于采用FPGA做图像预处理有着很好的参考价值
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。
边缘检测电路的硬件实现,用的是Verilog语言,采用的是原理图输入,给出了源代码,对于采用FPGA做图像预处理有着很好的参考价值
Method 2:
使用1個reg posedge_edgedetection2.v / Verilog
1 /*
2 (C) OOMusou 2008
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了。
边缘检测电路的硬件实现,用的是Verilog语言,采用的是原理图输入,给出了源代码,对于采用FPGA做图像预处理有着很好的参考价值
這種寫法經過合成之後,只有一個D-FF與EQUAL,右邊的o_rising_edge的D-FF主要是因為在always block內的reg。
就這個例子而言,Method 1與Method 2目前在Quartus II 7.2 SP3的合成下
resource打成平手,logic element各用兩個D-FF與與一個組合電路,不過Method 2的code可讀性比較高。
边缘检测电路的硬件实现,用的是Verilog语言,采用的是原理图输入,给出了源代码,对于采用FPGA做图像预处理有着很好的参考价值
边缘检测电路的硬件实现,用的是Verilog语言,采用的是原理图输入,给出了源代码,对于采用FPGA做图像预处理有着很好的参考价值
下升沿檢測電路(negedge detection circuit)
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。
边缘检测电路的硬件实现,用的是Verilog语言,采用的是原理图输入,给出了源代码,对于采用FPGA做图像预处理有着很好的参考价值
Method 1:
使用兩個reg nededge_detection.v / Verilog
1 /*
2 (C) OOMusou 2008
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
Method 2:
使用1個reg
nededge_detection2.v
1 /*
边缘检测电路的硬件实现,用的是Verilog语言,采用的是原理图输入,给出了源代码,对于采用FPGA做图像预处理有着很好的参考价值
2 (C) OOMusou 2008
3
4 Filename : nededge_detection2.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_detection2 (
10 input clk,
11 input rst_n,
12 input i_data_in,
13 output reg o_falling_edge
14 );
15
16 reg r_data_in0;
17
18 always@(posedge clk, negedge rst_n) begin
19 if (!rst_n)
20 r_data_in0 <= 0;
21 else begin
22 r_data_in0 <= i_data_in;
23
24 if ({r_data_in0, i_data_in} == 2'b10)
25 o_falling_edge <= 1;
26 else
27 o_falling_edge <= 0;
28 end
29 end
30
31 endmodule
边缘检测电路的硬件实现,用的是Verilog语言,采用的是原理图输入,给出了源代码,对于采用FPGA做图像预处理有着很好的参考价值
边缘检测电路的硬件实现,用的是Verilog语言,采用的是原理图输入,给出了源代码,对于采用FPGA做图像预处理有着很好的参考价值
雙沿檢測電路電路(double edge detection)
r_data_in2與r_data_in1為reg,分別hold住上一個clock與目前clock的
i_data_in,所謂雙沿電路,就是i_data_in由1變0,或者由0變1,也就是r_data_in2為1且r_data_in1為0,或者r_data_in2為0且r_data_in1為1時,故用xor接r_data_in1與r_data_in2。
边缘检测电路的硬件实现,用的是Verilog语言,采用的是原理图输入,给出了源代码,对于采用FPGA做图像预处理有着很好的参考价值
Method 1:
使用2個reg doubleedge_detection.v / Verilog
1 /*
2 (C) OOMusou 2008
3
4 Filename : doubleedge_detection.v
5 Compiler : Quartus II 7.2 SP3
6 Description : Demo how to design double edge detection circuit 7 Release : 07/06/2008 1.0
8 */
9
10 module doubleedge_detection (
11 input clk,
12 input rst_n,
13 input i_data_in,
14 output o_double_edge
15 );
16
17 reg r_data_in0;
18 reg r_data_in1;
19
20 assign o_double_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
Method 2:
使用1個reg
doubleedge_detection2.v / Verilog
边缘检测电路的硬件实现,用的是Verilog语言,采用的是原理图输入,给出了源代码,对于采用FPGA做图像预处理有着很好的参考价值
1 /*
2 (C) OOMusou 2008
3
4 Filename : doubleedge_detection2.v
5 Compiler : Quartus II 7.2 SP3
6 Description : Demo how to design double edge detection circuit 7 Release : 07/06/2008 1.0
8 */
9
10 module doubleedge_detection2 (
11 input clk,
12 input rst_n,
13 input i_data_in,
14 output reg o_double_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'b10)
26 o_double_edge <= 1;
27 else if ({r_data_in0, i_data_in} == 2'b01)
28 o_double_edge <= 1;
29 else
30 o_double_edge <= 0;
31
32 // another method
33 // o_double_edge <= r_data_in0 ^ i_data_in;
34 end
35 end
36
37 endmodule
边缘检测电路的硬件实现,用的是Verilog语言,采用的是原理图输入,给出了源代码,对于采用FPGA做图像预处理有着很好的参考价值
边缘检测电路的硬件实现,用的是Verilog语言,采用的是原理图输入,给出了源代码,对于采用FPGA做图像预处理有着很好的参考价值
完整程式碼下載
posedge_detection.7z
posedge_detection2.7z
negedge_detection.7z
negedge_detection2.7z
doubleedge_detection.7z
doubleedge_detection2.7z
Conclusion
什麼時候會使用這種電路呢?若input是非同步信號,為了要讓input與你同步的FSM一起處理,必須先經過邊緣檢測,使之與clock同步,然後才能跟你的FSM一起運作。
边缘检测电路的硬件实现,用的是Verilog语言,采用的是原理图输入,给出了源代码,对于采用FPGA做图像预处理有着很好的参考价值
See Also
(原創) 如何使用ModelSim-Altera作電路模擬? (SOC) (Quartus II) (ModelSim) (筆記) 如何以絕對時間指定testbench波形? (SOC) (Verilog)
(原創) 深入探討Altera的Checksum Master範例 (SOC) (SOPC Builder) (Nios II) (DE2)
Reference
王钿、卓興旺 2007,基於Verilog HDL的數字應用設計,國防工業出版社
正在阅读:
暖通施工技术中重要问题的分析11-11
2017-2023年空气净化器行业“一带一路”战略研究及投资趋势预测05-22
浦东模范中学2013学年初三年级二次函数单元测试卷06-09
九歌英译张卫(最终稿)06-30
离职交接表02-10
马达加斯加影评08-30
市退役军人事务局最新半年工作总结及2022年工作规划04-04
用按键控制LED灯的亮灭01-02
抓住运动的敏感期 让您的孩子一生受用09-27
- 教学能力大赛决赛获奖-教学实施报告-(完整图文版)
- 互联网+数据中心行业分析报告
- 2017上海杨浦区高三一模数学试题及答案
- 招商部差旅接待管理制度(4-25)
- 学生游玩安全注意事项
- 学生信息管理系统(文档模板供参考)
- 叉车门架有限元分析及系统设计
- 2014帮助残疾人志愿者服务情况记录
- 叶绿体中色素的提取和分离实验
- 中国食物成分表2020年最新权威完整改进版
- 推动国土资源领域生态文明建设
- 给水管道冲洗和消毒记录
- 计算机软件专业自我评价
- 高中数学必修1-5知识点归纳
- 2018-2022年中国第五代移动通信技术(5G)产业深度分析及发展前景研究报告发展趋势(目录)
- 生产车间巡查制度
- 2018版中国光热发电行业深度研究报告目录
- (通用)2019年中考数学总复习 第一章 第四节 数的开方与二次根式课件
- 2017_2018学年高中语文第二单元第4课说数课件粤教版
- 上市新药Lumateperone(卢美哌隆)合成检索总结报告
- 电路
- 边缘
- 检测
- Verilog
- SOC
- 主语从句超全讲解加练习
- 北师大版思品七年级上册1.2结识新朋友学案(幸运mm)
- 人力资源和社会保障一体化信息系统
- 感人的身边小事实践报告
- 实验项目12.5.2 用数据透视表分析销售数据(配套教材实验数据)CHWLing
- 语文:第二单元作文教案(人教新课标七年级下)
- 2014年考研南京大学翻译硕士题目
- 点名软件需求分析报告
- Arcgis教程基本知识
- 如何撰写企业贷款贷前调查报告
- MFC快速入门——数据结构课程设计指导
- 家居照明基础知识培训
- 3年高考离子反应试题(选择题)
- 雅思作文考官范文分布详解
- 脑胃综合征胃潴留预防误吸的治疗护理体会
- 江苏省扬州市江都区2015-2016学年八年级语文上学期七校联谊月考试题 苏教版
- 北京交通大学翻译硕士就业如何
- 二年级下册数学单元同步测验
- 现在我才明白:原来最早发明纸的不是我国
- 02 第二章 现代市场营销观念