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

Subversion Repositories socgen

[/] [socgen/] [trunk/] [common/] [opencores.org/] [cde/] [ip/] [sync/] [rtl/] [verilog/] [sync_with_hysteresis] - Blame information for rev 134

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 134 jt_eaton
reg [WIDTH - 1:0]         hysteresis_data;
2
reg [WIDTH - 1:0]         clean_data;
3
reg [DEBOUNCE_SIZE-1:0]        debounce_counter;
4
 
5
always@(posedge clk )
6
  if(reset)
7
     begin
8
     data_out  <= data_in;
9
     data_rise <= {WIDTH{1'b0}};
10
     data_fall <= {WIDTH{1'b0}};
11
     end
12
  else
13
     begin
14
     data_out  <= clean_data;
15
     data_rise <= clean_data &( data_out  ^ clean_data);
16
     data_fall <= data_out   &( data_out  ^ clean_data);
17
     end
18
 
19
 
20
 
21
 
22
 
23
 
24
 
25
 
26
always@(posedge clk )
27
       if(reset)
28
         begin
29
            clean_data             <= data_in;
30
            hysteresis_data        <= data_in;
31
            debounce_counter       <= {DEBOUNCE_SIZE{1'b0}};
32
         end
33
       else
34
         begin
35
         // if the current input data differs from hysteresis
36
         // then reset counter and update hysteresie
37
 
38
         if(data_in != hysteresis_data )
39
              begin
40
              clean_data           <= clean_data;
41
              hysteresis_data      <= data_in;
42
              debounce_counter     <= {DEBOUNCE_SIZE{1'b0}};
43
              end
44
        // if counter reaches DEBOUNCE_DELAY then the signal is clean
45
         else
46
         if(debounce_counter == DEBOUNCE_DELAY)
47
              begin
48
              clean_data           <= hysteresis_data;
49
              hysteresis_data      <= hysteresis_data;
50
              debounce_counter     <= debounce_counter;
51
              end
52
           // data_in did not change but counter did not reach limit. Increment counter
53
         else
54
              begin
55
              clean_data           <= clean_data;
56
              hysteresis_data      <= hysteresis_data;
57
              debounce_counter     <= debounce_counter+1;
58
              end
59
         end
60
 
61
 

powered by: WebSVN 2.1.0

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