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

Last change on this file since 974 was 974, 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
28
29Theory of operation
30-------------------
31
32``DivByN-4`` produces narrow (125 :math:`\mu`\ s) positive-going pulses at the
33frequency :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
36clocking ``DFF-1``.  If no additional rising edges of ``input`` are received
37before the leading edge of the next ``filterClock`` pulse, the sampled input
38value is clocked into ``DFF-2``, causing ``output`` to follow ``input``.  But if
39an additional rising edge is received during that time, it will clock ``DFF-4``,
40driving ``accept`` to 0, and immediately clearing ``DFF-2``, so that ``output``
41goes 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
49Usage
50-----
51
52To load the circuit into softGlue:
53
541)      Download this `BURT
55        <http://www.aps.anl.gov/epics/extensions/burt/index.php>`_ snapshot file
56        :download:`debouncer.snap <debouncer.snap>`
57
582)      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
623)      Load the file with the command ``burtwb -f debouncer.snap``
63
64To use the circuit:
65
661) Set the threshold frequency of the circuit as described above.
67
682) Connect ``input`` and ``output`` signals as desired.
69
70Performance
71--------------
72
73Here's a demonstration circuit with which the debouncer's performance as a
74low-pass filter can be measured:
75
76.. image:: debouncer_demo.gif
77        :width: 100%
78
79In this demonstration, ``DivByN-3`` and ``DFF-3`` constitute a :index:`!square
80wave generator` with which to exercise the filter.  ``UpCntr-1`` and ``UpCntr-2``
81count output and input edges, respectively.  ``BUF-2`` and ``BUF-3`` fan out
82reset and counter-enable signals, respectively.
83
84``xxx:softGlue:sseq1`` drives ``demoReset`` and ``demoPause`` to count input and
85output pulses for one second, then processes the up-counter value records, so
86that their values will be available promptly to ``xxx:userCalcOut9``, which
87calculates the filter's pass fraction.  ``xxx:scan1`` programs filter and
88input-signal frequencies, using ``xxx:userTran7`` to set the filter frequency
89and to translate frequencies into down-counter load values.  The plot shows the
90fraction of the input rising edges that produce output rising edges, as a
91function of input frequency.  For this case of a symmetric square wave, the
92circuit passes everything below :math:`f_{threshold}`, and nothing above
93:math:`2 f_{threshold}`.
94
95The BURT file for this demonstration circuit, :download:`debouncer_demo.snap
96<debouncer_demo.snap>`, programs only the records included in a standard
97softGlue installation, not the records ``xxx:scan1``, ``xxx:userCalcOut9``, or
98``xxx:userTran7``.
Note: See TracBrowser for help on using the repository browser.