source: softGlue_examples/source/debouncer/index.rst @ 949

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