1 | .. $Id: index.rst 922 2012-06-13 15:58:36Z jemian $ |
---|
2 | |
---|
3 | ======================== |
---|
4 | Debouncer |
---|
5 | ======================== |
---|
6 | |
---|
7 | .. index:: !Debouncer;using time-delay |
---|
8 | .. index:: !Low-pass filter |
---|
9 | |
---|
10 | A signal debouncer, which can be used to remove high-frequency ringing from an |
---|
11 | input signal. The circuit can also be used as a low-pass filter, though the |
---|
12 | criterion on which it discriminates is not precisely a signal's frequency, but |
---|
13 | rather the time interval between rising edges. |
---|
14 | |
---|
15 | Circuit and documentation: Tim Mooney |
---|
16 | |
---|
17 | Circuit |
---|
18 | ------------ |
---|
19 | |
---|
20 | .. image:: debouncer.gif |
---|
21 | :width: 100% |
---|
22 | |
---|
23 | This circuit shows a debouncer, which accepts as input the signal named |
---|
24 | ``input``, and produces the output signal ``output``. As configured here, the |
---|
25 | circuit discriminates against symmetric square waves of frequency higher than |
---|
26 | around 1 kHz, transmitting nothing higher than around 2 kHz. |
---|
27 | |
---|
28 | |
---|
29 | Theory of operation |
---|
30 | ------------------- |
---|
31 | |
---|
32 | ``DivByN-4`` produces narrow (125 :math:`\mu`\ s) positive-going pulses at the |
---|
33 | frequency :math:`f_{threshold} = 8 \times 10^6 / N`, where :math:`N` is the |
---|
34 | ``N`` input. This signal (``filterClock``) initializes the ``accept`` signal |
---|
35 | (``DFF-4``) to 1, and its trailing edge samples the input signal, ``input``, by |
---|
36 | clocking ``DFF-1``. If no additional rising edges of ``input`` are received |
---|
37 | before the leading edge of the next ``filterClock`` pulse, the sampled input |
---|
38 | value is clocked into ``DFF-2``, causing ``output`` to follow ``input``. But if |
---|
39 | an additional rising edge is received during that time, it will clock ``DFF-4``, |
---|
40 | driving ``accept`` to 0, and immediately clearing ``DFF-2``, so that ``output`` |
---|
41 | goes to 0 regardless of the value of ``input``. |
---|
42 | |
---|
43 | .. note:: A somewhat less robust debouncer can be made with only two flip |
---|
44 | flops, by connecting ``input`` directly to the ``D`` input of |
---|
45 | ``DFF-2``, freeing ``DFF-1`` for other uses. The resulting |
---|
46 | circuit has a race condition, and its performance may depend on |
---|
47 | FPGA layout. |
---|
48 | |
---|
49 | Usage |
---|
50 | ----- |
---|
51 | |
---|
52 | To load the circuit into softGlue: |
---|
53 | |
---|
54 | 1) Download this `BURT |
---|
55 | <http://www.aps.anl.gov/epics/extensions/burt/index.php>`_ snapshot file |
---|
56 | :download:`debouncer.snap <debouncer.snap>` |
---|
57 | |
---|
58 | 2) Edit the file to replace all occurrences of the string ``xxx:softGlue:`` |
---|
59 | with whatever value you specified for ``$(P)$(H)`` when you loaded softGlue |
---|
60 | into your IOC. |
---|
61 | |
---|
62 | 3) Load the file with the command ``burtwb -f debouncer.snap`` |
---|
63 | |
---|
64 | To use the circuit: |
---|
65 | |
---|
66 | 1) Set the threshold frequency of the circuit as described above. |
---|
67 | |
---|
68 | 2) Connect ``input`` and ``output`` signals as desired. |
---|
69 | |
---|
70 | Performance |
---|
71 | -------------- |
---|
72 | |
---|
73 | Here's a demonstration circuit with which the debouncer's performance as a |
---|
74 | low-pass filter can be measured: |
---|
75 | |
---|
76 | .. image:: debouncer_demo.gif |
---|
77 | :width: 100% |
---|
78 | |
---|
79 | In this demonstration, ``DivByN-3`` and ``DFF-3`` constitute a :index:`!square |
---|
80 | wave generator` with which to exercise the filter. ``UpCntr-1`` and ``UpCntr-2`` |
---|
81 | count output and input edges, respectively. ``BUF-2`` and ``BUF-3`` fan out |
---|
82 | reset and counter-enable signals, respectively. |
---|
83 | |
---|
84 | ``xxx:softGlue:sseq1`` drives ``demoReset`` and ``demoPause`` to count input and |
---|
85 | output pulses for one second, then processes the up-counter value records, so |
---|
86 | that their values will be available promptly to ``xxx:userCalcOut9``, which |
---|
87 | calculates the filter's pass fraction. ``xxx:scan1`` programs filter and |
---|
88 | input-signal frequencies, using ``xxx:userTran7`` to set the filter frequency |
---|
89 | and to translate frequencies into down-counter load values. The plot shows the |
---|
90 | fraction of the input rising edges that produce output rising edges, as a |
---|
91 | function of input frequency. For this case of a symmetric square wave, the |
---|
92 | circuit passes everything below :math:`f_{threshold}`, and nothing above |
---|
93 | :math:`2 f_{threshold}`. |
---|
94 | |
---|
95 | The BURT file for this demonstration circuit, :download:`debouncer_demo.snap |
---|
96 | <debouncer_demo.snap>`, programs only the records included in a standard |
---|
97 | softGlue installation, not the records ``xxx:scan1``, ``xxx:userCalcOut9``, or |
---|
98 | ``xxx:userTran7``. |
---|