首先来看时序图。
接着按照时序图来编写:
`timescale 1ns/1ns
module touch_ctrl_led
(
input wire sys_clk , //系统时钟,频率50MHz
input wire sys_rst_n , //复位信号,低电平有效
input wire touch_key , //触摸按键信号
output reg led //led输出信号
);
wire touch_en ; //触摸使能信号
reg touch_key_dly1 ; //touch_key延迟一个时钟信号
reg touch_key_dly2 ; //touch_key延迟两个时钟信号
assign touch_en = touch_key_dly2 & (~touch_key_dly1);
//对touch_key信号延迟两个时钟周期用来产生触摸按键信号
always@(posedge sys_clk or negedge sys_rst_n)
if(sys_rst_n == 1'b0)
begin