source: specdomain/trunk/src/specdomain/doc/bpm.mac @ 1011

Last change on this file since 1011 was 1011, checked in by jemian, 10 years ago

various things while discussing with Christian

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision URL Header
File size: 5.5 KB
Line 
1# $Id: bpm.mac 1011 2012-07-13 19:03:45Z jemian $
2
3"""
4Macro support for a beam position monitor.
5
6Purpose
7        Macro support for a beam position monitor.
8        The BPM has a serial interface.
9        This support uses the EPICS generic serial record as a communications channel.
10
11Dependencies
12        These macros require:
13                EPICS
14                    Experimental Physics and Industrial Control System, http://www.aps.anl.gov/epics
15                EPICS support for XBPM
16                    The EPICS support for the X-ray Beam Position Monitor (XBPM) is needed to
17                    interface between the RS-232 connection on the XBPM and the EPICS IOC
18                    using an octal232 IP card. The software support consists of an EPICS
19                    generic serial record, an EPICS database, and a
20                    state notation language sequence program.
21                EPICS PV support prefix
22                        The support prefix is ``ioc:xbpm`` (configurable in :spec:constant:`XBPM_PREFIX`)
23
24
25Usage::
26
27        qdo /epics/clients/spec/macros/bpm.mac
28"""
29
30constant GX_FACTOR "5.93"               ;#: X-axis calibration, mm/unit
31constant GY_FACTOR "4.56"               ;#: Y-axis calibration, mm/unit
32constant XBPM_PREFIX "ioc:xbpm"  ;#: EPICS support prefix
33
34def BPM_read_diode(chan) '{
35  """
36  read current value from the named BPM channel
37 
38  :param character chan: channel letter (a, b, c, or d)
39 
40  example::
41 
42        value = BPM_read_diode("b")
43  """
44 
45  return(epics_get(sprintf("%s:current:%s:raw", XBPM_PREFIX, chan)))
46}'
47
48def BPM_set_defaults '{
49  """
50  Set (or reset) proper default values on the XBPM.
51 
52  Also, measure the dark signals at each amplifier gain scale (*range*)
53  for each photodiode by calling :spec:def:`BPM_setAllDarkSignals`.
54  This process takes about one minute.
55  The software does not check to make sure that the beam is **off**
56  so you should be sure that the shutter is closed during the time
57  you run this macro.
58  When finished, set the amplifier gain back to the value
59  it had as this macro was started.
60  """
61  local range factors
62
63  comment "setting BPM software to default values ..."
64  epics_put(sprintf("%s:enable", XBPM_PREFIX), "1")
65  # scaling factor to mm
66  epics_put(sprintf("%s:GY", XBPM_PREFIX), GX_FACTOR)
67  epics_put(sprintf("%s:GX", XBPM_PREFIX), GY_FACTOR)
68
69  if (epics_get(sprintf("%s:current:low:raw", XBPM_PREFIX)) == 0) {
70    epics_put(sprintf("%s:mode", XBPM_PREFIX),   "AVERAGE")
71    epics_put(sprintf("%s:buflen", XBPM_PREFIX), "20")
72    epics_put(sprintf("%s:current:low:raw", XBPM_PREFIX), "5000")
73  }
74
75  # diode gain factors
76  factors[0] =  3.33786010742e-13    ;# 350 nA / 10 VDC / 10 kHz
77  factors[1] =  6.67572021484e-13    ;# 700 nA / 10 VDC / 10 kHz
78  factors[2] =  1.33514404297e-12    ;# 1400 nA / 10 VDC / 10 kHz
79  factors[3] =  6.67572021484e-12    ;# 7 uA / 10 VDC / 10 kHz
80  factors[4] =  6.67572021484e-11    ;# 70 uA / 10 VDC / 10 kHz
81  factors[5] =  6.67572021484e-10    ;# 700 uA / 10 VDC / 10 kHz
82  for (range=0; range<6; range+=1) {
83    epics_put(sprintf("%s:r%d:A1", XBPM_PREFIX, range+1), factors[range])
84    epics_put(sprintf("%s:r%d:B1", XBPM_PREFIX, range+1), factors[range])
85    epics_put(sprintf("%s:r%d:C1", XBPM_PREFIX, range+1), factors[range])
86    epics_put(sprintf("%s:r%d:D1", XBPM_PREFIX, range+1), factors[range])
87  }
88
89  comment "setting BPM dark signals (takes about 1 minute) ..."
90  BPM_setAllDarkSignals
91  comment "BPM_set_defaults is complete"
92}'
93
94def BPM_setDarkSignal(range) '{
95  """
96  measure and set the dark signal on each channel
97  for the given amplifier range
98 
99  :param int range: :math:`0 <= range <= 5`
100 
101  Measure and set the dark signal for each photodiode amplifier
102  at the selected amplifier gain scale (*range*).
103  Report the findings as a spec comment.
104 
105  =====  ===========
106  range  gain
107  =====  ===========
108  0      350 nA
109  1      700 nA
110  2      1400 nA
111  3      7 uA
112  4      70 uA
113  5      700 uA
114  =====  ===========
115  """
116  local chan_A chan_B chan_C chan_D numObservations str txt
117  if (range <0 || range>5) return
118  #
119  # choose the range
120  epics_put(sprintf("%s:gain", XBPM_PREFIX), range)
121  sleep(5)    ;# diode and amplifier signal settling time
122  if (range == 0) txt = epics_get(sprintf("%s:gain.ZRST", XBPM_PREFIX))
123  if (range == 1) txt = epics_get(sprintf("%s:gain.ONST", XBPM_PREFIX))
124  if (range == 2) txt = epics_get(sprintf("%s:gain.TWST", XBPM_PREFIX))
125  if (range == 3) txt = epics_get(sprintf("%s:gain.THST", XBPM_PREFIX))
126  if (range == 4) txt = epics_get(sprintf("%s:gain.FRST", XBPM_PREFIX))
127  if (range == 5) txt = epics_get(sprintf("%s:gain.FVST", XBPM_PREFIX))
128 
129  #comment "BPM: setting dark signal for range: %d" range
130  #
131  # measure the dark signals
132  numObservations = 10
133  chan_A = chan_B = chan_C = chan_D = 0
134  for (loop=0; loop<numObservations; loop+=1) {
135    chan_A += BPM_read_diode("a")
136    chan_B += BPM_read_diode("b")
137    chan_C += BPM_read_diode("c")
138    chan_D += BPM_read_diode("d")
139    sleep(1)
140  }
141  chan_A /= numObservations
142  chan_B /= numObservations
143  chan_C /= numObservations
144  chan_D /= numObservations
145  epics_put(sprintf("%s:r%d:A2", XBPM_PREFIX, range+1), chan_A)
146  epics_put(sprintf("%s:r%d:B2", XBPM_PREFIX, range+1), chan_B)
147  epics_put(sprintf("%s:r%d:C2", XBPM_PREFIX, range+1), chan_C)
148  epics_put(sprintf("%s:r%d:D2", XBPM_PREFIX, range+1), chan_D)
149  str = sprintf("(%s) [dark] A=%d  B=%d  C=%d  D=%d", txt, chan_A, chan_B, chan_C, chan_D)
150  comment "BPM: %s" str
151}'
152
153def BPM_setAllDarkSignals '{
154  """measure and set the dark current for all amplifier ranges"""
155  local range old_range
156  old_range = epics_get(sprintf("%s:gain", XBPM_PREFIX), "short")
157  for (range=0; range<6; range+=1) {
158    BPM_setDarkSignal(range)
159  }
160  epics_put(sprintf("%s:gain", XBPM_PREFIX), old_range)
161}'
Note: See TracBrowser for help on using the repository browser.