1 | .. $Id: index.rst 922 2012-06-13 15:58:36Z jemian $ |
---|
2 | |
---|
3 | ======================== |
---|
4 | Gated scaler |
---|
5 | ======================== |
---|
6 | |
---|
7 | |
---|
8 | This circuit shows one way to build a four channel :index:`!gated scaler`. |
---|
9 | |
---|
10 | Circuit and documentation: Tim Mooney |
---|
11 | |
---|
12 | Circuit |
---|
13 | ------------ |
---|
14 | |
---|
15 | .. image:: gatedScaler.gif |
---|
16 | :width: 100% |
---|
17 | |
---|
18 | This circuit implements four counter channels, a time base to control counting |
---|
19 | time, an overall gate, and additional circuitry to control starting, stopping, |
---|
20 | and processing of the count-value records. Note that the :index:`interrupt |
---|
21 | <interrupt; in gated scaler>` configuration for I/O bit 17, and the sseq record |
---|
22 | that causes counter values to be read, are not shown. |
---|
23 | |
---|
24 | Requirements |
---|
25 | ------------ |
---|
26 | |
---|
27 | This circuit uses a :index:`busy record <busy record; in gated scaler>` (from |
---|
28 | the busy module) and a :index:`sseq record <sseq record; in gated scaler>` (from |
---|
29 | the std module, but moved to the calc module for synApps 5.7), which are loaded |
---|
30 | by ``softGlue_convenience.db``. If these records are not available, the circuit |
---|
31 | will still function, but the counters will not be read immediately after the |
---|
32 | count time has elapsed, and it will not be useful to drive the counter with a |
---|
33 | ``ca_put_callback()``, because the callback will come immediately, instead of |
---|
34 | coming after counting has finished. |
---|
35 | |
---|
36 | Usage |
---|
37 | ----- |
---|
38 | |
---|
39 | To load the circuit into softGlue: |
---|
40 | |
---|
41 | 1) Download this `BURT <http://www.aps.anl.gov/epics/extensions/burt/index.php>`_ snapshot file :download:`gatedScaler.snap |
---|
42 | <gatedScaler.snap>` |
---|
43 | |
---|
44 | 2) Edit the file to replace all occurrences of the string ``xxx:softGlue:`` with |
---|
45 | whatever value you specified for ``$(P)$(H)`` when you loaded softGlue into |
---|
46 | your IOC. |
---|
47 | |
---|
48 | 3) Load the file with the command ``burtwb -f gatedScaler.snap`` |
---|
49 | |
---|
50 | To use the circuit: |
---|
51 | |
---|
52 | 1) Connect field inputs to the counters by giving names to four field input |
---|
53 | bits, and writing those names also to the clock inputs for up counters 1-4. |
---|
54 | (As delivered, all counters count the signal named ``Clock_8MHz``, which is |
---|
55 | the name this circuit gives to the 8 MHz clock.) |
---|
56 | |
---|
57 | 2) Set the count time by writing a number, to the ``N`` input of ``DivByN-1``. |
---|
58 | The timebase clock is 8 MHz, so the actual count time will be N/8 |
---|
59 | microseconds. |
---|
60 | |
---|
61 | 3) Start the counter by writing ``1`` to ``$(P)$(H)busy1`` (one of the busy |
---|
62 | records in the EPICS database ``softGlue_convenience.db``, which is loaded by |
---|
63 | the standard ``softGlue.cmd`` file). |
---|
64 | |
---|
65 | 4) Either wait for the count time to elapse, or abort the count by writing |
---|
66 | ``0`` to ``$(P)$(H)busy1``. |
---|
67 | |
---|
68 | .. note:: A better way to abort would be to write ``0`` to the input of |
---|
69 | ``BUF-1``. This is better because it results in the counters |
---|
70 | being read before the busy record is cleared. |
---|
71 | |
---|
72 | 5) Read the accumulated counts from ``UpCntr-<n>_COUNTS``, where ``<n>`` is in |
---|
73 | [1-4]. |
---|
74 | |
---|
75 | 6) Gating can be done either by EPICS, or by a field input. |
---|
76 | |
---|
77 | To gate with EPICS, write ``1`` to the second input of ``AND-1`` to enable |
---|
78 | counting, or ``0`` to disable counting. |
---|
79 | |
---|
80 | To gate from a field input, give the field input a signal name, and write |
---|
81 | that same name to the second input of ``AND-1``. |
---|
82 | |
---|
83 | The time-base counter also is gated, though you can have only the counter |
---|
84 | channels gated by changing the ``EN`` input of ``DivByN-1`` from |
---|
85 | ``gatedStart`` to ``start``. |
---|
86 | |
---|
87 | Theory of operation |
---|
88 | ------------------- |
---|
89 | |
---|
90 | Execution begins when a client writes ``1`` to ``$(P)$(H)busy1``. This record declares |
---|
91 | itself to be busy (for the purpose of ``ca_put_callback()``), and starts the counter |
---|
92 | circuit by writing the value ``1`` to the input of ``BUF-1``. ``BUF-1`` fans the signal |
---|
93 | out, as the signal named ``count``, to the clock inputs of flip flops ``DFF-2`` and |
---|
94 | ``DFF-4``. ``count`` will stay at ``1`` until the counters are finished counting. |
---|
95 | |
---|
96 | * ``DFF-4`` makes an extremely short pulse (named ``clear``) from the rising edge of |
---|
97 | ``count``. |
---|
98 | |
---|
99 | * ``DFF-2`` makes an extremely short pulse (named ``abort``) from the falling edge |
---|
100 | of ``count``. |
---|
101 | |
---|
102 | ``clear`` zeroes the counters (``UpCntr-<n>``), and loads the count time (i.e., |
---|
103 | the number of clock pulses) into the time base ``DivByN-1``. ``clear*`` sets |
---|
104 | the output of ``DFF-3`` to ``1``, producing the signal ``counting``, which stays |
---|
105 | at ``1`` until it's time for the counters to stop counting. |
---|
106 | |
---|
107 | ``counting`` is sent to field output bit 17, which must actually be configured |
---|
108 | as an output, and which will generate an interrupt on the falling edge of |
---|
109 | ``counting`` (when pulse counting has finished). The interrupt configuration |
---|
110 | (which is not shown in the figure) is set so that the falling edge of |
---|
111 | ``counting`` causes the record ``$(P)$(H)sseq1`` to process, which causes EPICS |
---|
112 | records for all four counters to process, reading their values so that a client |
---|
113 | can acquire them, and then clears the busy record ``$(P)$(H)busy1``. If the |
---|
114 | client that started the scaler did so with a ``ca_put_callback()``, clearing the |
---|
115 | busy record results in a "done" callback to that client. |
---|
116 | |
---|
117 | * You can, of course, use any field output bit for this purpose, as long as |
---|
118 | you configure it correctly. |
---|
119 | |
---|
120 | * The only reason for using an output bit is to generate an interrupt when the |
---|
121 | counting is finished. |
---|
122 | |
---|
123 | * The counter doesn't actually rely on the interrupt. It's only needed to get |
---|
124 | the counter values read from hardware promptly - before the busy record is |
---|
125 | cleared, indicating that counting is done. The counters will eventually be |
---|
126 | read in any case, by the periodic update ``$(P)$(H)ReadRate``. But a fast |
---|
127 | client (such as the sscan record) will not want to wait for this periodic |
---|
128 | read, nor will it know when the read has occurred. |
---|
129 | |
---|
130 | ``counting`` is sent to ``AND-1`` to be ANDed with the user's gate signal (the |
---|
131 | second input of ``AND-1``), producing the signal ``gatedCounting``. As |
---|
132 | delivered, the gate signal is simply ``1``. The user can gate counting off by |
---|
133 | writing ``0`` to the gate signal, or the user can implement a hardware gate as |
---|
134 | described above in "Usage". |
---|
135 | |
---|
136 | ``gatedCounting`` enables the counters and the time base, ``DivByN-1``. When the |
---|
137 | specified number of clock pulses have been received by ``DivByN-1``, its output, |
---|
138 | ``stopTime``, goes to ``1`` for one clock pulse. |
---|
139 | |
---|
140 | ``stopTime`` is delivered to ``OR-1``, to be ORed with the ``abort`` signal mentioned |
---|
141 | earlier. When either ``stopTime`` or ``abort`` goes to ``1``, ``DFF-3`` is cleared, |
---|
142 | rescinding ``counting``, which causes all counters and the time base to cease |
---|
143 | counting. |
---|
144 | |
---|
145 | When ``counting`` goes to ``0``, an interrupt is generated. The interrupt |
---|
146 | causes the sseq record to process the counter-value records |
---|
147 | (``$(P)$(H)UpCntr-<n>_COUNTS``, where ``<n>`` is in [1-4]) so their values will be |
---|
148 | available to be read by an EPICS client. The string-sequence record also sets |
---|
149 | ``$(P)$(H)busy1`` to ``0``, signalling completion to EPICS. |
---|