OpenCores
URL https://opencores.org/ocsvn/openmsp430/openmsp430/trunk

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [fpga/] [altera_de0_nano_soc/] [rtl/] [verilog/] [sync_debouncer_10ms.v] - Blame information for rev 221

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 221 olivier.gi
//----------------------------------------------------------------------------
2
// Copyright (C) 2001 Authors
3
//
4
// This source file may be used and distributed without restriction provided
5
// that this copyright statement is not removed from the file and that any
6
// derivative work contains the original copyright notice and the associated
7
// disclaimer.
8
//
9
// This source file is free software; you can redistribute it and/or modify
10
// it under the terms of the GNU Lesser General Public License as published
11
// by the Free Software Foundation; either version 2.1 of the License, or
12
// (at your option) any later version.
13
//
14
// This source is distributed in the hope that it will be useful, but WITHOUT
15
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17
// License for more details.
18
//
19
// You should have received a copy of the GNU Lesser General Public License
20
// along with this source; if not, write to the Free Software Foundation,
21
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22
//
23
//----------------------------------------------------------------------------
24
//
25
// *File Name: sync_debouncer.v
26
//
27
// *Module Description:
28
//                      Super basic 10ms debouncer.
29
//
30
// *Author(s):
31
//              - Olivier Girard,    olgirard@gmail.com
32
//
33
//----------------------------------------------------------------------------
34
// $Rev$
35
// $LastChangedBy$
36
// $LastChangedDate$
37
//----------------------------------------------------------------------------
38
 
39
module sync_debouncer_10ms (
40
 
41
// OUTPUTs
42
    signal_debounced,          // Synchronized and 10ms debounced signal
43
 
44
// INPUTs
45
    clk_50mhz,                 // 50MHz clock
46
    rst,                       // reset
47
    signal_async               // Asynchonous signal
48
);
49
 
50
// OUTPUTs
51
//=========
52
output     signal_debounced;   // Synchronized and 10ms debounced signal
53
 
54
// INPUTs
55
//=========
56
input      clk_50mhz;          // 50MHz clock
57
input      rst;                // reset
58
input      signal_async;       // Asynchonous signal
59
 
60
 
61
// Synchronize signal
62
reg [1:0] sync_stage;
63
always @(posedge clk_50mhz or posedge rst)
64
  if (rst) sync_stage <= 2'b00;
65
  else     sync_stage <= {sync_stage[0], signal_async};
66
 
67
wire signal_sync = sync_stage[1];
68
 
69
 
70
// Debouncer (10.48ms = 0x7ffff x 50MHz clock cycles)
71
reg [18:0] debounce_counter;
72
always @(posedge clk_50mhz or posedge rst)
73
  if (rst)                               debounce_counter <= 19'h00000;
74
  else if(signal_debounced==signal_sync) debounce_counter <= 19'h00000;
75
  else                                   debounce_counter <= debounce_counter+1;
76
 
77
wire debounce_counter_done = (debounce_counter==19'h7ffff);
78
 
79
// Output signal
80
reg signal_debounced;
81
always @(posedge clk_50mhz or posedge rst)
82
  if (rst)                       signal_debounced <= 1'b0;
83
  else if(debounce_counter_done) signal_debounced <= ~signal_debounced;
84
 
85
 
86
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.