当前位置:网站首页>Verilog implementation of key dithering elimination
Verilog implementation of key dithering elimination
2022-07-26 03:54:00 【FPGA silicon agriculture】
Press the key to shake off
When the key is pressed , Due to the limitations of mechanical switches , The corresponding level will not stabilize immediately , Instead, jitter will occur for a period of time . In order to correctly identify the key information , We have to deal with the key shaking .
Code implementation
Beat the input with two registers , When the values of these two registers are different ( shake ), Reset the counter . otherwise , The counter is added every cycle 1, When the value of the counter reaches a given value , If the value of the register is valid , It means that the key has been pressed .
If the key is pressed, the value is 1, The code is as follows :
`timescale 1ns / 1ps
//
// Company:
// Engineer:
//
// Create Date: 2022/07/22 16:43:50
// Design Name:
// Module Name: bit_count
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//
module debounce(
input logic clk,
input logic rst,
input logic key_in,
output logic key_flag);
parameter CNT=1000;
logic key_d1;
logic key_d2;
logic [31:0] cnt;
//key_d2,1
[email protected](posedge clk,posedge rst)
if(rst)
{
key_d2,key_d1}<=2'b00;
else
{
key_d2,key_d1}<={
key_d1,key_in};
//cnt
[email protected](posedge clk,posedge rst)
if(rst)
cnt<=0;
else if(key_d1^key_d2) // Still shaking
cnt<=0;
else if(cnt==CNT)
cnt<=cnt;
else
cnt<=cnt+1;
//key_flag
[email protected](posedge clk,posedge rst)
if(rst)
key_flag<=0;
else if(cnt==CNT-1&&key_d2==1'b1) // It lasts long enough and is pressed
key_flag<=1;
else
key_flag<=0;
endmodule
Test code
`timescale 1ns / 1ps
//
// Company:
// Engineer:
//
// Create Date: 2022/07/23 21:03:12
// Design Name:
// Module Name: key_tb
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//
module key_tb(
);
reg clk;
reg rst;
reg key_in;
wire key_flag;
//clk
initial
begin
clk=0;
forever
#5 clk=~clk;
end
//rst
initial
begin
rst=1;
#100
rst=0;
end
//key_in
initial
begin
key_in=0;
wait(rst==1'b0);
@(posedge clk);
//
key_in<=1;
@(posedge clk);
repeat(100)
begin
key_in<=$random;
@(posedge clk);
end
//
key_in<=1;
repeat(1000)
@(posedge clk);
//
key_in<=0;
repeat(100)
begin
key_in<=$random;
@(posedge clk);
end
@(posedge clk);
key_in<=0;
end
//inst
debounce U(
.*
/* input logic clk, input logic rst, input logic key_in, output logic key_flag */
);
endmodule
Simulation results

边栏推荐
- PHP 对象转换数组
- redux
- [cloud native kubernetes] how to use configmap under kubernetes cluster
- php中可以使用取绝对值函数 abs() 将负数转成正数
- E-commerce operator Xiaobai, how to get started quickly and learn data analysis?
- 【云原生之kubernetes】kubernetes集群下ConfigMap使用方法
- laravel8 实现接口鉴权封装使用JWT
- The convolution kernel is expanded to 51x51, and the new CNN architecture slak counterattacks the transformer
- PHP save array to var file_ export、serialize
- day03_ 1_ Idea tutorial
猜你喜欢

基于JSP实现网上商城系统

Opencv learning notes - remapping
![[programmers must] Tanabata confession strategy:](/img/55/0b43dd18c8682250db13ad94cd2c2c.png)
[programmers must] Tanabata confession strategy: "the moon meets the cloud, the flowers meet the wind, and the night sky is beautiful at night". (with source code Collection)

文件上传报错:Current request is not a multipart request

Opencv learning notes - edge detection and Canny operator, Sobel operator, lapiacian operator, ScHARR filter

第十八章:2位a~b进制中均位奇观探索,指定整数的 3x+1 转化过程,指定区间验证角谷猜想,探求4份黑洞数,验证3位黑洞数
![[unity3d shader] character projection and reflection](/img/00/d0d994d88475ea590dc5cb60a6ad65.png)
[unity3d shader] character projection and reflection

leetcode: 102. 二叉树的层序遍历

CPU and GPU are out of date, and the era of NPU and APU begins

Portable power fast charging scheme 30W automatic pressure rise and fall PD fast charging
随机推荐
5 years, 1.4W times, NFT og's road to immortality Web3 column
[MCU simulation project] external interrupt 0 controls 8 LED flashes
STM32状态机编程实例——全自动洗衣机(下)
Portable power fast charging scheme 30W automatic pressure rise and fall PD fast charging
Worked overtime for a week to develop a reporting system. This low code free it reporting artifact is very easy to use
Find My技术|物联网资产跟踪市场规模达66亿美元,Find My助力市场发展
【程序员必备】七夕表白攻略:”月遇从云,花遇和风,晚上的夜空很美“。(附源码合集)
深度学习之DAT
Save the image with gaussdb (for redis), and the recommended business can easily reduce the cost by 60%
div设置高度不生效
Three ways of redis cluster
Opencv learning notes - remapping
php 保存数组到文件 var_export、serialize
Uncaught TypeError: $(...). Onmousenter is not a function JS error, solution:
JS base64编码和解码
三种解决:在点击用户退出登录时,再按浏览器的后退按钮,仍然能够看到之前登录的页面。
Kbpc1510-asemi large chip 15A rectifier bridge kbpc1510
5年1.4W倍,NFT OG 的封神之路|Web3专栏
【单片机仿真项目】外部中断0控制8个发光二极管闪烁
Div setting height does not take effect