URL
https://opencores.org/ocsvn/forwardcom/forwardcom/trunk
Subversion Repositories forwardcom
[/] [forwardcom/] [trunk/] [debouncer.sv] - Rev 78
Go to most recent revision | Compare with Previous | Blame | View Log
//////////////////////////////////////////////////////////////////////////////////// Engineer: Agner Fog//// Create date: 2020-05-03// Last modified: 2020-12-15// Module name: debounce// Project name: ForwardCom soft core// Tool versions: Vivado 2020.1// License: CERN-OHL-W v. 2 or later// Description: Push button debouncer//// Input from one or more pushbuttons is filtered to remove contact noise.// buttons_out is 1 when buttons_in is stable at 1 over a period.// buttons_out is 0 when buttons_in is stable at 0 over a period.// pulse_out is 1 for one clock cycle when the button is pressed////////////////////////////////////////////////////////////////////////////////////// pushbutton debouncermodule debounce#(parameter num=2) // number of buttons to debounce(input clock, // system clock 50 - 100 MHzinput [num-1:0] buttons_in, // input from pushbuttonoutput reg[num-1:0] buttons_out, // debounced outputoutput reg[num-1:0] pulse_out // a single pulse of 1 clock duration when button is pressed);reg [19:0] count = 0; // clock dividerreg [2:0] shift [num-1:0]; // shift registersgenvar i;generatefor (i=0; i<num; i++) beginalways_ff @(posedge clock) beginpulse_out[i] <= 0;count <= count + 1; // divide clock by 2**20if (count == 0) beginshift[i] <= {shift[i][1:0], buttons_in[i]}; // serial in parallel out shift registerif (shift[i] == 3'b111) begin // accept as stable high after 3 consecutive high samplesif (buttons_out[i] == 0) beginpulse_out[i] <= 1; // set pulse_out high only in the first clock cycle after button press is stableendbuttons_out[i] <= 1; // button is stable highend else if (shift[i] == 3'b000) begin // accept as stable low after 3 consecutive low samplesbuttons_out[i] <= 0; // button is stable lowendendendendendgenerateendmodule
Go to most recent revision | Compare with Previous | Blame | View Log
