source: softGlue_examples/source/motor_accel_gate/index.rst @ 952

Last change on this file since 952 was 951, checked in by mooney, 10 years ago

Added div-by-N

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.1 KB
Line 
1.. $Id: index.rst 951 2012-06-20 17:50:50Z mooney $
2
3============================
4Motor accel/decel pulse gate
5============================
6
7.. index:: !motor_accel_gate
8
9This circuit shows a way to gate out motor pulses during the acceleration and
10deceleration portions of a motor motion.
11
12Circuit and documentation: Tim Mooney
13
14Context, Description
15---------------------
16
17One common way to implement a fly scan is to trigger a detector with motor
18pulses.  You might want the detector to acquire on every :math:`N^{th}` pulse,
19for example, but to refrain from acquiring during the acceleration and
20deceleration portions of a move.  That's what this circuit does.
21
22If you know the number of steps a stepper motor will move during its
23acceleration time, you can easily arrange to deliver motor pulses to some
24external circuit only while the motor is moving at constant speed. For a stepper
25motor controlled by the EPICS motor record, the number of
26acceleration/deceleration steps, :math:`N_a` can be calculated as follows:
27
28.. math:: N_a = ((VBAS + VELO)/2) \times (ACCL / MRES)
29
30where, :math:`VBAS`, :math:`VELO`, :math:`ACCL`, and :math:`MRES` are
31motorRecord fields.
32
33The number of constant-speed steps, :math:`N_c`, is then
34
35.. math:: N_c = ((VAL_{end}-VAL_{start})/MRES) - 2N_a
36
37where :math:`VAL_{end}` and :math:`VAL_{start}` are the final and initial
38values of the motorRecord ``VAL`` field.
39
40
41Circuit
42------------
43
44.. image:: motor_accel_gate.gif
45        :width: 100%
46
47This circuit accepts negative-going motor pulses at input signal 1, inverts
48them, gates out the first :math:`N_a` (the value of ``DnCntr-1_PRESET``), and
49from then on sends pulses to a divide-by-N circuit, until a total of
50:math:`N_a+N_c` (the value of ``DnCntr-2_PRESET``) have been sent. The
51divide-by-N sends every :math:`N^{th}` rising edge to output pin 17.  Thus, the
52detector would see only the :math:`(N_a+N_c)/N` divided pulses that occurred
53while the motor was moving at constant speed.  The circuit is reset by writing
54``1!`` (positive-going pulse) to the input of ``BUF-1``.
55
56Down counter ``DnCntr-1``, and flipflop ``DFF-1``, together produce a gate
57signal that is 0 after a reset, and that goes to 1 after ``DnCntr-1_PRESET``
58motor pulses. Down counter ``DnCntr-2``, and flipflop ``DFF-2``, together
59produce a gate signal that is 1 after a reset, and that goes to 0 after
60``DnCntr-2_PRESET`` motor pulses. We load the number of acceleration steps into
61``DnCntr-1_PRESET``, and the number of acceleration steps plus constant-speed steps
62into ``DnCntr-2_PRESET``.
63
64``AND-1`` combines the gate signals produced above into a signal that is 1 while
65the motor is moving at constant speed.
66
67``AND-2`` gates the negative-going motor pulses by inverting the ``motor``
68signal before applying it to the gate.
69
70        .. note::  Positive-going pulses can be gated with an AND gate, by applying the signal to one input of the AND gate, and setting the other input to 0(1) to deny(allow) passage through the gate.
71
72                   Negative-going pulses can be gated with an OR gate, by applying the signal to one input of the OR gate, and setting the other input to 0(1) to allow(deny) passage through the gate.
73
74Note that the down counters are clocked by (rising edges of) ``motor``, to
75produce the signal used to gate ``motor*``. This choice avoids a race condition
76between simultaneous rising edges of ``gateOut`` and ``motor``. (This circuit
77gates negative-going motor pulses, so another way to make this point is to say
78that the trailing edge of a motor pulse is used to produce a gate that will be
79ready in plenty of time for the leading edge of the next motor pulse.)
80
81The circuit includes some diagnostics, and a mechanism for testing:
82
83``UpCntr-1`` counts all motor pulses; ``UpCntr-2`` counts gated motor pulses.
84Both counters are reset by the same signal that resets the gate circuit. A
85manual reset is implemented using ``BUF-1``. Writing ``1!`` to the input of
86``BUF-1``, as shown, causes a short positive-going pulse to be applied to it,
87and thus to its output, the signal named ``reset``.
88
89
90
91EPICS support
92-------------
93
94Calculations for the circuit are shown in the following screen capture of a
95transform record.
96
97.. figure:: motor_accel_gate_calc.gif
98        :width: 100%
99
100
101Usage
102-----
103
104To load the circuit into softGlue:
105
1061)      Download this `BURT <http://www.aps.anl.gov/epics/extensions/burt/index.php>`_ snapshot file :download:`motor_accel_gate.snap
107        <motor_accel_gate.snap>`
108
1092)      Edit the file to replace all occurrences of the string ``xxx:softGlue:`` with
110        whatever value you specified for ``$(P)$(H)`` when you loaded softGlue into
111        your IOC.
112
1133)      Load the file with the command ``burtwb -f motor_accel_gate.snap``
114
115To load the database :download:`motor_accel_gate_transform.db <motor_accel_gate_transform.db>`
116into the IOC, add something like the following command to the IOC's st.cmd:
117
118``dbLoadRecords("$(TOP)/xxxApp/Db/motor_accel_gate_transform.db","P=xxx:,H=softGlue:,M=m9")``
119
120
121
122To use the circuit:
123
124#) Connect negative-going motor step pulses to input 1.
125
126#) Write the data-start and data-end motor positions to the transform record
127   fields ``G`` and ``H``, respectively.
128
129#) Move the motor to the data-start position.
130
131#) Reset the circuit by writing ``1!`` to ``BUF-1``.
132
133#) Move the motor to the data-end position.
Note: See TracBrowser for help on using the repository browser.