flyscan
Continuous Scans with Multichannel Scalers
DESCRIPTION
The fly-scan macros are similar to the cscan (continuous scan) macros in that counts are accumulated while a motor is in motion. With the continuous scans, the motor position is read on the fly, but is not strictly correlated with the counter reading. With the fly scans, counts are accumulated in an MCS (multi-channel scaler) device with the MCS channel advance controlled by pulses from the motor being swept. It is thus possible to associate the counts collected from each MCS channel with an accurate motor position.
There are macros for single-pass fly scans, mesh scans with one sweep motor and one motor that is stepped through a range, and 3D mesh scans where two motors are stepped through a mesh with the fly motor swept at each position:
flyscan mot start end intervals time flymesh m0 s0 f0 intervals time m1 s1 f1 ints1 flymesh3d m0 s0 f0 intervals time m1 s1 f1 ints1 m2 s2 f2 ints2 flydscan mot relative_start relative_end intervals time flydmesh m0 s0 f0 intervals time m1 s1 f1 ints1 flydmesh3d m0 s0 f0 intervals time m1 s1 f1 ints1 m2 s2 f2 ints2
The first three are absolute position scans. The second three are delta scans. The position arguments for delta scans are relative positions, and the motors are returned to their starting positions at the end of the scan or if the scan is interrupted.
The first argument in each case is the fast motor followed by start and end positions, either absolute or relative. The intervals argument determines the number of channels allocated in the MCS. The intervals argument can be either the number of intervals or the distance (or pitch) of each interval, depending on a configuration option. The time argument is either the time per channel or the elapsed time for the entire sweep, also depending on a configuration option. The time is used to set the speed of the fly motor during the sweep.
The mesh and mesh3D scans step one or two other motors. The fly motor is swept at each step. By default, the fly motor will alternate sweep directions at each step, but a configuration option is available to make the sweeps all in the same direction.
Normally, a counter is used to prescale the motor pulses so that a set number of motor pulses generates one MCS channel advance. The prescale value is calculated as:
prescale = int(range * M / intervals)
where M is the number of pulses generated by the motor (or encoder) per unit (mm or degree, usually), while range and intervals are take from the scan arguments. To ensure the prescale counter receives a full complement of pulses to generate a channel advance for the last MCS channel, the macro adjusts the number of intervals to fit the range. The range endpoint is fine tuned, if necessary, to be a multiple of the step width and number of intervals. Finally, a width equivalent to two additional motor pulses is added to the endpoint, as a bit of fudge to account for any loss of a pulse due to rounding.
If there is no prescaling, the number of intervals will be adjusted to fit the width of the scan given the number of motor pulses per unit distance.
The motor speed will be adjusted to accommodate the time argument, but no higher than the steady-state rate in the config file. If the sweep speed is higher than the base rate, the base rate will be set to half the sweep speed. Backlash is set to zero for the sweep motor during the scans. The speed and backlash settings are restored at the end of the scan or if the scan is interrupted. However, there is no backlash correction done on the fly motor after the final sweep for absolute position scans. For delta scans, the usual backlash correction will be performed when motors are returned to starting positions.
The macros adjust the start and end positions of the swept motor to extend one half the distance of a single channel in order to center each motor position in the center of the MCS count bins.
A motorless loopscan-like flyscan can be invoked using:
flyscan points time
where the points argument is the number of readings, and the time argument is either the time per channel or the elapsed time for the entire sweep, depending on the configuration option. This version of the scan uses the internal time base of the MCS to generate the calculated dwell time and simply accumulates counts over the specified time period. There is a configuration option to use the MCS external channel advance signal with a source not necessarily associated with a motor, in which case, the time argument is ignored.
The fly_setup macro configures the motors available for fly scans and acquisition parameters for all the scans. Some of the options reflect the particular capabilities and limitations of the particular MCS device.
The fly scan macros invoke the standard scan_head and scan_loop macros, which default to the standard _head and _loop definitions. The standard _head and _loop macros now include special code to write to the data file for fly scans. After each sweep, the MCS data is read directly into the SCAN_D data array, which has been allocated to accommodate the motors and counters involved in the scan. Unlike the rest of the standard scans, the fly scans do not include the value of EPOCH in the data rows of the data file.
The fly scans redefine scan_count to put average values of the MCS counters into the S[] scaler array for the screen display.
Additional counters in a list FLY_other_counters will be included in the data file and screen display. These counters are read after a complete sweep is made. Each row of the data file will contain the same value for such counters for a particular sweep. One might define a macro hardware counter to be included that contains the number of intervals in the sweep as read from the MCS at the end of the sweep.
The macros disable all counters not included in the fly scan or the "other counters" list for the duration of the scan.
The fly_setup macro includes an option to normalize the data. Normally the timebase channel is selected as the normalization channel. Normalization can correct for uneven count times due to motor acceleration and deceleration at the start and end of the sweeps. Normalized data will be plotted, but the raw, unnormalized data is saved to the data file. The macros fly_norm and fly_unnorm perform reciprocal operations on the current SCAN_D data whether or not the automatic normalization for plotting is configured. When the data has been normalized, the plot title (T_L) will contain the words "normalized".
The current macros will work with two devices supported by spec: The Measurement Computing USB-CTR4/USB-CTR8 counter/timer modules and the Struck SIS3820 VME Scaler. The same module can be used as a counter/timer and as an MCS in the same spec session, but only in one mode at a time. There is no need to change the hardware configuration when switching between regular counting and fly scans.
USB-CTR
For the USB-CTR, data can be collected from multiple counters, but the counter channels must be consecutive. Conventionally, the first channel (channel 0) will be connected to the output of timer 0, which is programmed by spec to generate a 1 MHz signal. That channel can be used for normalization of the counts in the other channels.
Also with the USB-CTR, the last channel (channel 7 on the 8-channel device) is conveniently used as the prescale counter and is not included in the data collection. The motor pulses connect to the counter input (C7IN) and the counter output (C7O) is connected to the CLKI pin, which is the MCS mode external channel advance. Hardware limitations require a minimum prescale value of two. If the scan range and configured motor pulse value results in too small a needed prescale, the macros either adjust the number of intervals to accommodate that minimum or abort the scan altogether, depending on a configuration option.
There are also configuration options to select DIO bits to be used as a trigger and as a gate. When using two USB-CTR modules in MCS mode, it is important that both be triggered and gated simultaneously. In addition, one of the 74151 inputs (is used with the USB-CTR in timer/counter mode) can be designated as the gate enabler in MCS mode.
When using the USB-CTR, the macros support a fly_chk_beam macro, which can be used along the lines of the standard chk_beam macro to pause the scan if the source is down. The provided macro tests the state of a DIO bit on the USB-CTR to see if the source is down. The check is performed after an MCS sweep. If the DIO bit is set at the end of the sweep, the scan pauses until the bit is clear, at which point the sweep is repeated.
SIS3820
With the SIS3820 any or all of the 32 counter channels can be active during an MCS acquisition. Any channel can be used as the channel advance input, and that channel will be prescaled as needed to fit the parameters of the scan.
The SIS3820 also has a configurable word size. Data can be configured as one-, two- or four-byte words. The SIS3820 has a start-mode configuration option where acquisition either begins on the start of the scan or with the first channel advance pulse.
INTERNAL MACROS
fly_setup prompts user for various configurable parameters using spec_menu().
The macro automatically detects the unit number for the MCS device and finds the matching counters assigned to the device using the "controller" ID string along with serial number for the USB-CTR or VME address for the SIS3820.
_fly_prep parses and expands arguments for all the fly scans. By using a regular macro rather than a macro function, local variables used in the arguments will retain their values. All arguments are evaluated with eval().
Local variables in _fly_prep have a prepended underscore in at attempt to avoid conflict with more naturally named variables in the calling code.
Once arguments are expanded and global variables set, the _flyscan() macro function does the work.
fly_normalize() is called if FLY_normalize_chan is set. It is assumed it is a channel of the MCS device connected to a clock. To deal with divide-by-zero possibilities, if a normalization channel has a value of zero, corresponding channels in other counters have their values preserved.
If using one- or two-byte word sizes, be careful that the channel used for normalization doesn't overflow due to a high input clock frequency.
user_flysetup can be a cdef() or ordinary macro called within flysetup to create addition spec_menu() items for configuration.
user_flysetup_fini can be a cdef() or ordinary macro called within flysetup to handle any post-spec_menu() assignments based on user selections.
user_flyscan_pre_run is a cdef() defined macro called immediately before the MCS is started with mca_par("run"). It is an empty macro by default.
user_flyscan_trigger is a cdef() defined macro called immediately after the MCS is started with mca_par("run"). It is an empty macro by default.
user_flyscan_post_run is a cdef() defined macro called immediately after a wait() call indicates the MCS run is complete. It is an empty macro by default.
user_flyscan_post_sweep is a cdef() defined macro called just before channels are written to the data file and screen. This would be a good place to add to SCAN_D data that depends on channel number, but is not from the MCS. It is an empty macro by default.
_fly_scan_loop() and _fly_scan_on() are macro functions that contain the scan_loop and _scan_on macros in in order for the updated definitions of those macro to be parsed. (Macro functions are parsed when invoked.)
The standard _loop doesn't do flyscan printing to the screen. That is done here in order to be able to compress the output based on FLY_screen_mode:
0 - just print the last line of the sweep
1 - print the entire sweep
2 - print a block of the first and last lines
3 - print blocks of the first, middle and last lines
- 4 - print the entire sweep if less than FLY_screen_max,
- otherwise print as mode 3.
The block size is currently set to 6 in the macro.
The _loop_line() macro is called to actually output the line and uses NPTS, VPRNT and the counter S[] array to create a line of output.
_fly_count assigns values to scalers in S[]. Currently using the average value normalized by the elapsed channels in the MCS. The scan_count macro gets redefined to _fly_count for the fly scans.
_fly_set_cleanup() installs cleanup macro. The argument is 1 on the first call when the scan initializes. The argument is 0 if called during a resume to restart an aborted macro.
_fly_start_position() moves motors to start position. It is a separate macro so that it can be called on resume to restart scans.
_flyscan() does the scanning.
flyscan_cleanup() clears the external gate bit (if used), re-enables any counters disabled for the scan, and restores the motor parameters. A separate dscan_cleanup() will move motors to starting positions if it was a delta scan. If not a dscan, a message reminds the user that the fly motor hasn't had a backlash correction.
GLOBALS
FLY_adjust_bins - If set, adjust number of bins if required prescale is impossible
FLY_chan_list[] - Enabled channels, indexed by MCS channel, value is counter mnemonic
FLY_check_bit - Optional DIO bit for checkbeam signal (-1 to disable)
FLY_counter_list - String list of counter mnemonics on the MCS device
FLY_dwell
FLY_mcstype - MCS counter type (USB-CTR or SIS3820)
FLY_first_chan - First USB-CTR channel (0-7)
FLY_last_chan - Last USB-CTR channel (0-7)
FLY_normalize_chan - MCS channel for normalizing (-1 to disable)
FLY_other_counters - String list of non-MCS counters to enable
FLY_start_mode - Start mode for SIS3820
FLY_gate_mode - Enable gating (0 to disable)
FLY_trigger_mode - Use external trigger (0 to disable)
FLY_unidirectional - If nonzero, sweep in same direction during mesh
FLY_unit - MCA unit number
FLY_use_intervals - If set, use intervals, otherwise use pitch
FLY_use_scan_time - If set, time argument is for whole sweep
FLY_word_size - 1, 2 or 4 bytes for SIS3820
FLY_ext_dwell - Set if using external dwell when no motors
FLY_screen_mode - What to display on the screen after each sweep
FLY_screen_max - Max to display with FLY_screen_mode 4
FLY_extgate_bit - Optional USB-CTR DIO bit for external gate (-1 to disable)
FLY_74151_gate_chan
FLY_trigger_bit - Optional USB-CTR DIO bit for trigger (-1 to disable)
FLY_chan_list2[] - Enabled channels, indexed by MCS channel, value is counter mnemonic
FLY_unit2 - Secondary USB-CTR
FLY_first_chan2 - First USB-CTR channel (0-7)
FLY_last_chan2 - Last USB-CTR channel (0-7)
FLY_prescale_chan[] - Prescaler channel (for motor input or -1 to disable)
FLY_motor_choices[] - For SIS3820, array of channels by motor
FLY_use_step_size[] - Use motor steps/degree from config file
FLY_mot_steps_per[] - Motor steps per degree of fly motor
_fly_SCAN_D_cols[] - Column numbers in SCAN_D indexed by MCS channel number
_fly_backlash_save - Fly motor backlash to restore on cleanup
_fly_base_save - Fly motor base rate to restore on cleanup
_fly_base_use - Fly motor base rate to use during sweep
_fly_cleanup_save - Saved definition of cleanup macro
_fly_disable_save[] - Saved enabled motor list to restore on cleanup
_fly_intervals - Number of intervals in sweep
_fly_is_dscan - Flag set if a delta scan
_fly_pitch - Size of each sweep interval
_fly_scan_count_save - Saved definition of scan_count to restore on cleanup
_fly_speed_save - Fly motor speed to restore on cleanup
_fly_speed_use - Fly motor speed to use during sweep
_fly_ticker - Ticker for bidirectional mesh scans (even/odd sets direction)
_fly_mot_index - Current index into FLY arrays associated with motor
_fly_SCAN_D_cols2[] - Column numbers in SCAN_D indexed by MCS channel number
MACROS
_fly_init()
flysetup
fly_setup
fly_chan_config(mne, type, unit, module, chan)
fly_chan_cmd(mne, key, p1, p2)
flyscan
flydscan
flymesh
flydmesh
flymesh3d
flydmesh3d
_fly_prep
fly_normalize(undo)
fly_norm 'fly_normalize()
fly_unnorm 'fly_normalize(1)
fly_chk_beam
_fly_scan_loop()
_fly_scan_on()
_fly_count
_fly_setup_cleanup(how)
_fly_start_position()
_flyscan()
flyscan_cleanup()