1 | .. $Id: index.rst 951 2012-06-20 17:50:50Z mooney $ |
---|
2 | |
---|
3 | ============================ |
---|
4 | Motor accel/decel pulse gate |
---|
5 | ============================ |
---|
6 | |
---|
7 | .. index:: !motor_accel_gate |
---|
8 | |
---|
9 | This circuit shows a way to gate out motor pulses during the acceleration and |
---|
10 | deceleration portions of a motor motion. |
---|
11 | |
---|
12 | Circuit and documentation: Tim Mooney |
---|
13 | |
---|
14 | Context, Description |
---|
15 | --------------------- |
---|
16 | |
---|
17 | One common way to implement a fly scan is to trigger a detector with motor |
---|
18 | pulses. You might want the detector to acquire on every :math:`N^{th}` pulse, |
---|
19 | for example, but to refrain from acquiring during the acceleration and |
---|
20 | deceleration portions of a move. That's what this circuit does. |
---|
21 | |
---|
22 | If you know the number of steps a stepper motor will move during its |
---|
23 | acceleration time, you can easily arrange to deliver motor pulses to some |
---|
24 | external circuit only while the motor is moving at constant speed. For a stepper |
---|
25 | motor controlled by the EPICS motor record, the number of |
---|
26 | acceleration/deceleration steps, :math:`N_a` can be calculated as follows: |
---|
27 | |
---|
28 | .. math:: N_a = ((VBAS + VELO)/2) \times (ACCL / MRES) |
---|
29 | |
---|
30 | where, :math:`VBAS`, :math:`VELO`, :math:`ACCL`, and :math:`MRES` are |
---|
31 | motorRecord fields. |
---|
32 | |
---|
33 | The number of constant-speed steps, :math:`N_c`, is then |
---|
34 | |
---|
35 | .. math:: N_c = ((VAL_{end}-VAL_{start})/MRES) - 2N_a |
---|
36 | |
---|
37 | where :math:`VAL_{end}` and :math:`VAL_{start}` are the final and initial |
---|
38 | values of the motorRecord ``VAL`` field. |
---|
39 | |
---|
40 | |
---|
41 | Circuit |
---|
42 | ------------ |
---|
43 | |
---|
44 | .. image:: motor_accel_gate.gif |
---|
45 | :width: 100% |
---|
46 | |
---|
47 | This circuit accepts negative-going motor pulses at input signal 1, inverts |
---|
48 | them, gates out the first :math:`N_a` (the value of ``DnCntr-1_PRESET``), and |
---|
49 | from 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 |
---|
51 | divide-by-N sends every :math:`N^{th}` rising edge to output pin 17. Thus, the |
---|
52 | detector would see only the :math:`(N_a+N_c)/N` divided pulses that occurred |
---|
53 | while 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 | |
---|
56 | Down counter ``DnCntr-1``, and flipflop ``DFF-1``, together produce a gate |
---|
57 | signal that is 0 after a reset, and that goes to 1 after ``DnCntr-1_PRESET`` |
---|
58 | motor pulses. Down counter ``DnCntr-2``, and flipflop ``DFF-2``, together |
---|
59 | produce 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 |
---|
62 | into ``DnCntr-2_PRESET``. |
---|
63 | |
---|
64 | ``AND-1`` combines the gate signals produced above into a signal that is 1 while |
---|
65 | the motor is moving at constant speed. |
---|
66 | |
---|
67 | ``AND-2`` gates the negative-going motor pulses by inverting the ``motor`` |
---|
68 | signal 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 | |
---|
74 | Note that the down counters are clocked by (rising edges of) ``motor``, to |
---|
75 | produce the signal used to gate ``motor*``. This choice avoids a race condition |
---|
76 | between simultaneous rising edges of ``gateOut`` and ``motor``. (This circuit |
---|
77 | gates negative-going motor pulses, so another way to make this point is to say |
---|
78 | that the trailing edge of a motor pulse is used to produce a gate that will be |
---|
79 | ready in plenty of time for the leading edge of the next motor pulse.) |
---|
80 | |
---|
81 | The circuit includes some diagnostics, and a mechanism for testing: |
---|
82 | |
---|
83 | ``UpCntr-1`` counts all motor pulses; ``UpCntr-2`` counts gated motor pulses. |
---|
84 | Both counters are reset by the same signal that resets the gate circuit. A |
---|
85 | manual 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, |
---|
87 | and thus to its output, the signal named ``reset``. |
---|
88 | |
---|
89 | |
---|
90 | |
---|
91 | EPICS support |
---|
92 | ------------- |
---|
93 | |
---|
94 | Calculations for the circuit are shown in the following screen capture of a |
---|
95 | transform record. |
---|
96 | |
---|
97 | .. figure:: motor_accel_gate_calc.gif |
---|
98 | :width: 100% |
---|
99 | |
---|
100 | |
---|
101 | Usage |
---|
102 | ----- |
---|
103 | |
---|
104 | To load the circuit into softGlue: |
---|
105 | |
---|
106 | 1) 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 | |
---|
109 | 2) 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 | |
---|
113 | 3) Load the file with the command ``burtwb -f motor_accel_gate.snap`` |
---|
114 | |
---|
115 | To load the database :download:`motor_accel_gate_transform.db <motor_accel_gate_transform.db>` |
---|
116 | into 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 | |
---|
122 | To 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. |
---|