spec

Software for Diffraction

USB-CTR

Measurement Computing USB-CTR4 and USB-CTR8

DESCRIPTION

The Measurement Computing USB-CTR4 and USB-CTR8 are USB counter/timer modules introduced in 2014 to replace the USB-4300 series that were based on the no longer available am9513 chips. The USB-CTR models feature four or eight 64-bit counter channels along with eight digital I/O (DIO) pins and four programmable frequency generators. Each DIO pin can be configured for input or output. spec supports these devices as both timer/counters and as multichannel scaler (MCS) devices (MCS as of spec release 6.06.07). Some of the commands and description below apply to both configurations. Sections, paragraphs or sentences that apply to only one of the modes will be marked as COUNTERS or MCS.

spec can be configured to use the same module as both a regular timer/counter and as an MCS, although the module can be only be operated in one of the modes at a time. It is not necessary to change the hardware configuration to switch between modes. If active using tcount() or mcount(), for example, a call of mca_par("run") will result in an error. Likewise if the module is active as an MCS, the counting functions will generate an error. It is not possible to use the MCS in "auto_run" mode if the USB-CTR is also configured as a timer/counter or counter device.

COUNTERS: Best performance with timer/counters supported by spec is when the counter channels are hardware gated by the master timer channel. The master timer can count a preset number of seconds or a preset number of pulses from a detector. In spec, that corresponds to counting to time and counting to monitor. A drawback with the USB-CTR models is that it is not possible to change the master preset channel via software while maintaining hardware gating. The USB-CTR can only be used in one mode or the other.

To work around the gating limitation of the USB-CTR hardware, spec supports two special configurations. In the "split-configuration" mode, an eight-channel USB-CTR8 is used with no more than four input signals. One side of the counter is operated in time-preset mode and the other side in monitor-preset mode. In this configuration, each signal to be measured is connected to input pins of two counters. The other mode is "external-gate-select" mode. In this mode a single TTL 74151 1-of-8 data-selector integrated circuit chip is connected to the USB-CTR. This configuration allows any counter channel to be software selected as the master timing channel.

MCS: Although supported as a traditional MCS, the USB-CTR is specifically supported in spec with new standard flyscan macros. These macros do continuous scans with the MCS channel advance driven by pulses from a motor. The motor signal can either connect directly to the channel advance input, or can use an available counter channel as a prescaler. With the motor pulses generating the channel advance, each multi-channel scaler channel can be associated with an accurate motor position. See the flyscan help for details.

Hardware requires that the counter channels read in MCS mode be consecutive on the USB-CTR. Normal configuration would be to have the first channel (0) connected to the 1 MHz timebase signal and the last channel (7) used as a prescaler for the motor pulses, leaving up to six counter channels available for the MCS counting.

The USB-CTR needs to be read continuously to avoid data overflowing its internal FIFO memory. spec creates a dedicated thread to read the USB during acquisition, so that data can be read at full speed even while spec's main thread is busy with other things.

spec allocates memory to store all the channels from all the counters over all the configured passes. When the data is read back with mca_sget() (where counter numbers 0 to 7 are specified with a subaddress), data from all passes is summed for each channel. The special subaddress 8 returns the raw data from all the counters, channels and passes as a single one-dimensional array. The number of channels and maximum number channels associated with device for the MCA commands is automatically readjusted as the product of the number of counters, channels and passes when any of those parameters is changed in order to permit reading back all the raw data.

CONFIGURATION (COUNTERS)

Use spec's configuration editor (edconf, normally invoked by the config macro) to select the timer and to configure the scaler channels. On the Devices screen choose one of the following configurations depending on whether you are using the USB-CTR as master timer or as just as counters:

SCALERS   DEVICE  ADDR  <>MODE  NUM                 <>TYPE U#
    YES  default     0            8  USB-CTR Counter/Timer  0
    YES  default     0            8  USB-CTR Counters Only  1

The DEVICE field is available to enter an optional FPGA image file. If the field contains the string "default", spec will load a copy of the FPGA image that is built into the spec code. Otherwise, the field can contain the path name to an alternate file. The FPGA image is loaded automatically the first time spec accesses the USB-CTR after it has been connected to the USB port.

The ADDR field can contain the serial number of the USB-CTR. If more than one module is being used, the serial number can be used to distinguish between units. If the field contains the value zero, spec will assign the unit numbers in the order in which USB probing discovers the modules.

In counters-only mode, an external gate must be connected to each counter's gate input. By default, the counters use an active-high gate. The "active_low" parameter (see below) can be configured to specify active-low gating. With no external gate, the counters will never increment in the default active-high gating, or will count continuously in active-low gating mode.

On the Scaler screen of the configuration editor, choose USB-CTR for the controller type:

Scaler (Counter) Configuration

Num     Name  Mne <>Device Unit Chan <>Use As Scale Factor
  0  Seconds  sec  USB-CTR    0    0 timebase      1000000
  1  Monitor  mon  USB-CTR    0    1  monitor            1
  2 Detector  det  USB-CTR    0    2  counter            1
  3       c3   c3  USB-CTR    0    3  counter            1
  4       c4   c4  USB-CTR    0    4  counter            1
  5       c5   c5  USB-CTR    0    5  counter            1
  6       c6   c6  USB-CTR    0    6  counter            1
  7       c7   c7  USB-CTR    0    7  counter            1

In general, any channel may be assigned as the timebase and any channel as the monitor. The exception is in external-gate-select mode (see below) when the "dio_gating" parameter is set to other than the default value. If "dio_gating" is 2, only channels 0 and 1 can be timebase or monitor. If "dio_gating" is 4 on an 8-channel card, only channels 0, 1, 2 or 3 can be timebase or monitor.

The timebase scale factor should be set to 1e6 if the recommended connections are used. spec programs timer 0 (TMR0) to output a 1 MHz signal which is expected to be connected to the counter input used as the timebase.

It turns out that even though a 64-bit counter, the USB-CTR only recognizes 31-bit presets. With a 1 MHz input, the time counter can only count for a bit less than 36 minutes. If the config file scale factor is set to the recommended 1e6 value, spec will set the timer 0 frequency to 1e5, 1e4 or 1e3, based on the requested count time, in order to keep the preset to 31 bits. spec will also adjust the scale factor to track the timebase. If the scale factor is set to a different value, spec will assume that an alternate timebase is being used, and will not reprogram timer 0 and will not change the associated scale factor. (As of spec release 6.10.01.)

CONFIGURATION (MCS)

MCS mode is configured on the Acquisition screen in spec's configuration editor:

MCA (1D) and Image (2D) Acquisition Device Configuration

MCA         DEVICE  ADDR  <>MODE                         <>TYPE
 0  YES    default     0           USB-CTR Multi-Channel Scaler

The DEVICE field is available to enter an optional FPGA image file. If the field contains the string "default", spec will load a copy of the FPGA image that is built into the spec code. Otherwise, the field can contain the path name to an alternate file. The FPGA image is loaded automatically the first time spec accesses the USB-CTR after it has been connected to the USB port.

The ADDR field can contain the serial number of the USB-CTR. If more than one module is being used, the serial number can be used to distinguish between units. If the field contains the value zero, spec will assign the MCA numbers in the order in which USB probing discovers the modules.

CONFIGURATION MODES (COUNTERS)

There are several modes of operation for the USB-CTR as counters implemented in spec. The mode is selected based on the contents of the config file and on which board is detected. The modes are as follows:

Counters Only
The mode is selected on the Devices screen of the configuration editor. This mode relies on external hardware to gate the counters. If there is no gate signal the counters will either never count or always count, depending on whether or not they are configured for an active-low gate.
Time Preset Only
Only supports counting to time presets. This mode is selected if one USB-CTR scaler is configured as timebase and no USB_CTR scaler is configured as monitor.
Monitor Preset Only
Only supports counting to monitor presets. This mode is selected if one USB-CTR scaler is configured as monitor and no USB_CTR scaler is configured as timebase. It is not possible to change the monitor-preset channel with counter_par().
Split Configuration
Supports counting to time and counting to monitor. This mode is available with a USB-CTR8 that is configured for only four channels. The mode works by using the first four channels in time-preset mode and the second four channels in monitor-preset mode. The four inputs are each fed into two counters. It is not possible to change the monitor-preset channel with counter_par().
External Gate Selector
This mode uses a single external TTL chip to select which counter output will gate the counters. Both the USB-CTR4 or USB-CTR8 are supported. If both a timebase and a monitor scaler channel are configured, external-gate-select mode is selected. If using a USB-CTR8 card, more than four channels need to be configured to rule out split-configuration mode. The monitor-preset channel can be changed with counter_par(mne, "monitor").

FPGA IMAGE (COUNTERS and MCS)

The USB-CTR requires an FPGA image download when it is powered on, that is, whenever it is plugged into a USB port. spec will automatically download a default FPGA image (currently version 0.29) on startup or reconfig, but only if necessary. The FPGA download requires approximately ten seconds. An alternate FPGA image file can be specified in the hardware config file or loaded using the "FPGA" counter_par()/mca_par() option described below.

spec will check the USB-CTR device status before counting or starting MCS mode. If the status shows that the FPGA is not configured, spec will attempt to reload the FPGA image. The USB-CTR can lose the FPGA configuration when a host computer sleeps if the USB port on the computer powers down on sleep. If spec is unable to reload the FPGA image, use the reconfig command to reinitialize all the hardware.

CONNECTIONS (COUNTERS)

spec programs the USB-CTR to output a 1 MHz signal on the TMR0 (timer 0) pin. That signal should be connected to the counter input selected as timebase, and the scale factor for that channel should be configured to be 1e6. (Another timebase source could be used with the scale factor set appropriately.) The example configuration above uses C0IN as the timebase input.

Other input signals are connected to the associated counter inputs (C1IN, C2IN, etc). If using the split-configuration mode on at USB-CTR8 card, each input signal feeds two counter channels, paired as C0IN:C4IN, C1IN:C5IN, C2IN:C6IN and C3IN:C7IN.

Hardware gating is accomplished by using the output signal of the master counter channel to gate all the counters including the master channel. Note, only one output can be connected to the gate signals at a time. However, all the gate inputs can be tied together. The outputs are labeled C0O, C1O, C2O, etc. Gate inputs are labeled C0GT, C1GT, C2GT, etc.

If configured as time-preset only or monitor-preset only, all the gate signals are connected to the one counter output associated with the timebase or monitor channel, respectively.

If using the split-configuration mode, the four gate signals from counters 0 through 3 are connected to the timebase preset channel output, which must be among counters 0 through 3. The four gate signals from counters 4 through 7 are connected to the monitor preset channel output, which must be among counters 4 through 7.

If the gate input from any channel is not tied to the master counter output pin, that channel will not accumulate counts, including the master counter channel itself.

The external-gate-select connections are a bit more involved and are covered in the next section.

EXTERNAL PRESET DECODER (COUNTERS)

The addition of a single TTL 74151 chip to the USB-CTR configuration allows complete flexibility in assigning master counter channels while maintaining hardware gating.

The chip is a decoder which uses three inputs to select one of eight signals to be presented as an output. The eight signals are the counter outputs from the USB-CTR. The output of the 74151 is connected to all the gate signals of the USB-CTR. USB-CTR DIO pins are used to do the selection. By default, spec will use three DIO pins to allow a one-of-eight selection. However, if DIO pins are needed for another purpose, spec can be configured to use only two pins to allow a one-of-four selection or even just one DIO pin to allow a one-of-two selection.

The 74151 is connected to the USB-CTR terminals as follows. The first two columns are the 74151 pin number and signal name. The remaining columns are the connections to the USB-CTR using three, two or one DIO pins.

74151 74151 One of One of One of
Pin Name Eight Four Two
1 D3 C3O C3O -nc-
2 D2 C2O C2O -nc-
3 D1 C1O C1O C1O
4 D0 C0O C0O C0O
5 Y Gates Gates Gates
6 W -nc- -nc- -nc-
7 STROBE GND GND GND
8 GND GND GND GND
9 C DIO5 GND GND
10 B DIO6 DIO6 GND
11 A DIO7 DIO7 DIO7
12 D7 C7O -nc- -nc-
13 D6 C6O -nc- -nc-
14 D5 C5O -nc- -nc-
15 D4 C4O -nc- -nc-
16 Vcc VO VO VO

Gates are C0G, C1G, C2G, C3G (and C4G, C5G, C6G, C7G)

In the one-of-two and one-of-four configurations, the time-preset and monitor-preset channels must be selected from the first two or four counter channels.

Note, the STROBE pin of the 74151 must be grounded to enable the chip. Unused input select pins must also be grounded. Note that spec uses the upper most DIO pins.

CONNECTIONS (MCS)

Input signals are connected to the associated counter inputs (C0IN, C1IN, C2IN, etc). spec will program the USB-CTR to output a 1 MHz signal on the TMR0 (timer 0) pin, just as in counters mode. Thus, if the input to counter 0 remains connected to TMR0, that channel can be used as time normalization for the other counter channels in the MCS spectrum.

Counters included in the MCS spectrum must be consecutive. The first and last counters to be used are configured with mca_par().

The counter gate signals are ignored in MCS mode.

An external channel advance signal can be connected to the CLKI terminal of the USB-CTR. It is possible to use one of the counter channels as a prescale counter, which is useful in the flyscan macros. In that configuration, the channel advance is connected to the counter input, and the counter output is connected to CLKI. Use mca_par() to select the prescale counter channel.

FUNCTIONS

COUNTERS: The counter_par() function takes an initial argument specifying a counter mnemonic or number. When using counter_par() for commands that apply to the entire module, the module affected will be the one associated with the mne argument.

counter_par(mne, "monitor")
Sets the channel assigned to mnemonic mne to be the monitor preset channel. The monitor channel gets reset when the config file is read on start up or on reconfig. The monitor channel can only be changed if the counter is using external-gate-select mode in one-of-four mode or one-of-eight mode.
counter_par(mne, "active_low" [, how])
Without the optional argument, returns nonzero if the counting card associated with channel mne has been configured for active-low gates. The default mode is active high. If called with how nonzero, turns on the active-low mode for gating. If how is zero, sets active-high gate mode. Setting the mode for one channel affects all channels on the card. The "active_low" parameter can be set as an optional controller parameter from the Devices screen of the hardware configuration editor or as an optional scaler parameter from the Scaler screen. When set as a controller parameter, its value cannot be changed using counter_par(). If the parameter is not set in the config file, rereading the config file resets the mode to active-low off.
counter_par(mne, "dio_gating")
Returns a value of 2, 4 or 8 if "dio_gating" is configured as an optional controller parameter from the Devices screen of the configuration editor. The value reflects whether one, two or three DIO pins will be used in external-gate-select mode. The parameter can only be set from the config file. If not set in the config file, a value equal to the number of counter channels on the board (4 or 8) is used internally. The "dio_gating" parameter is only relevant if external-gate-select mode is detected. See CONFIGURATION MODES (COUNTERS) above.

MCS: The mca_par() function works on the default or currently selected MCA-type device. The mca_sel() command can be used to choose which MCA-type device is the current selection. (See the mca help file.) The mca_spar() function takes an initial argument that specifies the MCA-type device unit number, as set in the hardware config file. When using mca_spar() commands that apply to a particular counter channel, use a subaddress syntax, where the address argument is given as 0.0, 0.1, ..., 0.7. The first digit is the MCA unit number from the config file, and the digit right of the decimal point is the counter channel, which can be from 0 through 7. The syntax "0:0", "0:1", ..., "0:7" is also recognized, where the arguments are strings.

mca_par("run")
Programs and starts the USB-CTR for MCS acquisition.
mca_par("halt")
Halts the USB-CTR MCS acquisition.
mca_par("passes" [, value])
Selects or returns the number of MCS passes. Passes are accumulated continuously or each pass can be externally triggered, as configured with the "trigger" option, below.
mca_par("dwell" [, value])

Selects or returns the channel dwell value. Negative values indicate external dwell. For dwell times less than 0.001 seconds, counts are collected in 16-bit mode. Since the maximum input frequency is 48MHz, the maximum number of counts obtainable in a 0.001 second interval (48000) fits within 16 bits (65536).

The word size (16 bits or 32 bits) when using external dwell is selected based on the absolute value of the value argument using the same rules.

mca_par("channels"|"npts" [, value])
Selects or returns the number of channels per pass.
mca_par("first_counter" [, chan])
Selects or returns the number of the first counter to be read during data acquisition.
mca_par("last_counter" [, chan])
Selects or returns the number of the last counter to be read during data acquisition.
mca_par("prescale_counter" [, chan])
Selects or returns the counter to be programmed to prescale its input. The chan argument is the counter number, which is from 0 to 7. This counter needs to be outside the range of the first and last counters used for MCS acquisition.
mca_par("prescale" [, value])
Selects the prescale value for the designated prescale counter. Hardware limitations require that the value must be two or greater. Every value input counts will generate one count on the output pin of that counter.
mca_par("elapsed_passes")
Returns the current number of elapsed passes based on the number of bytes transmitted. The return value can be non integral reflecting the progress in transmitting data from the current pass.
mca_par("elapsed_channels")
Returns the current number of channels in the current passes based on the number of bytes transmitted.
mca_par("elapsed_time")
Returns the elapsed time of the current acquisition based on the software clock.
mca_par("gate_mode" [, mode])
Selects or returns the gate mode for MCS counters. All counters, including a prescale channel if used, will be gated identically. Allowed string values for mode are "off", "low" and "high". Numerical arguments are also recognized. An argument of zero is the same as off. A value greater than or equal to one will set active high, while a value less than or equal to -1 will set active low.
mca_par("trigger" [, mode])
Selects or returns the trigger mode. An external trigger can be used to start each MCS pass. Valid values for mode are the strings "off", "low", "high", "falling" and "rising", which correspond respectively to no trigger, low level, high level, falling edge and rising edge.
mca_par("report|dump")

Displays the current MCS parameters along the following lines:

MCC USB-CTR08 (sn 195494f, FPGA 0.29)

First MCS counter = 0
 Last MCS counter = 4
 Prescale counter = 7
         Prescale = 29
            Dwell = external (0.05)
     MCS channels = 201
           Passes = 1
          Trigger = off (0)

 Elapsed channels = 201
   Elapsed passes = 1.00
     Elapsed time = 29.67
mca_par("chans"|"max_chans"|"max_channels")
Returns the currently configured number of points for the device. For the USB-CTR, the number is the product of the configured number of counters, channels and passes. The value is recalculated when any of those parameters is changed. This value is the size of the array needed when reading back the raw data. If either the number of counters or number of passes is greater than one, one either needs to specify the roi_beg and roi_end arguments with mca_get() and mca_sget() or pass an array dimensioned to this "chans" value.
mca_get(arr [, roi_beg [, roi_end]])
Gets data from the MCS associated with the first counter configured and transfers it to the array arr. The optional region-of-interest arguments limit the data to the range of channels indicated. The data is placed starting at the beginning of the array. For multiple passes, data from each pass is summed for each channel.
mca_sget(addr[.ch]|"addr:ch", arr [, roi_beg [, roi_end]])
Gets data from the MCA unit number addr. If the subaddress ch is specified, data from that counter number will be returned. If the subaddress is not specified, data from the first counter will be returned. The function will return zero if ch is not an enabled channel. If the optional region-of-interest beginning and ending channels are given, the data is returned from those channels and placed starting at the beginning of the array. For multiple passes, data from each pass is summed for each channel. If the subaddress ch is 8, the raw data from all the counters, channels and passes is returned in a single array. Such data is ordered consecutively by counter, channel, pass.

If more than one pass or more than one counter is configured, the number of MCA channels associated with the device is the product of counters, channels and passes, which is the value returned by mca_par("chans"). Either the array passed to the mca_get() and mca_sget() functions has to be that size, or the region of interest arguments need to be specified.

COUNTERS and MCS:

The following counter_par(), mca_par() and mca_spar() commands are available. The shorthand xxx_par() is used to represent all three for the commands available in both counter and MCS modes. The initial counter mnemonic argument for counter_par() or MCA selection argument for mca_spar() will not be shown.

The USB-CTR models include input debounce circuitry that, according to the device manual, "eliminates switch-induced transients that are typically associated with electro-mechanical devices including relays, proximity switches, and encoders." Such a feature may not be particularly useful with photon counting, but the parameters are accessible with the following two commands.

xxx_par("debounce_time" [, arg])

With no arguments, returns the current debounce time, or zero if the debounce circuitry is bypassed. If present, arg can be either a time or an integer code from 0 through 16 to specify a time. If the value is not an exact match to the allowed times, the next largest value is used. The correspondence between code and time is as follows:

0 no debounce
1 500ns
2 1500ns
3 3500ns
4 7500ns
5 15500ns
6 63500ns
7 31500ns
8 27500ns
9 100us
10 300us
11 700us
12 1500us
13 3100us
14 6300us
15 12700us
16 25500us
xxx_par("debounce_mode" [, arg])
With no arguments, returns the string "before" or "after" which indicates the mode is trigger after stable or trigger before stable, respectively. If arg is present and is nonzero or the string "before" (case insensitive), the mode is set to trigger before stable. If arg is anything else, the mode is set to trigger after stable. The default mode is trigger after stable.

The following commands are associated with the module, not particular counter channels.

xxx_par("blink", count)
Programs the bottom LED on the module to blink the number of times specified by count. May be useful in confirming communication.
xxx_par("snum")
Returns the module serial number, which is a hexadecimal number up to eight digits in length.
xxx_par("timer1"|"timer2"|"timer3" [, freq])
Without an argument returns the currently programmed frequency for the indicated timer. Otherwise sets the timer frequency to the value specified by freq. It is not allowed to change the frequency of timer 0, which spec programs to 1 MHz to be used as the timebase counter input. The valid frequency range is from 0.022 Hz to 48 MHz. The function returns the actual frequency, which may differ a bit from the requested frequency due to the limited precision allowed by the USB-CTR.
xxx_par("FPGA" [, file]) or mca_par("FPGA" [, file])
With no arguments returns the version number of the currently loaded FPGA image. The value should be considered as a 16-bit hexadecimal number with the upper byte holding the major FPGA image version number and the low-order byte the minor version. For example, a value of 0x0102 would be version 1.02. (The argument "firmware" is also recognized, although technically, the "firmware" and FPGA image are different. The "firmware" is non volatile and is updated with a utility provided by Measurement Computing.)
xxx_par("io_config" [, val])

Bits set in val will configure the corresponding DIO pins as outputs. On power up, all pins are configured as inputs. If the optional argument is missing, spec will return the current value. The "io_config" parameter can be set as an optional controller parameter from the Devices screen of the hardware configuration editor or as an optional scaler parameter from the Scaler screen. When set as a controller parameter, its value cannot be changed using counter_par().

When using external-gate-select mode for counters, the highest numbered digital I/O pins are automatically set as outputs. The commands to set and clear bits below can be used to control those bits, but the bits will be reprogrammed to select the external gate when the USB-CTR is started as a master timer, and the commands to set and clear cannot be used while counting is active. If one-of-two mode is selected, DIO7 is reserved. For one-of-four mode, DIO6 and DIO7 are reserved. If one-of-eight mode is configured, DIO5, DIO6 and DIO7 are reserved.

xxx_par("set_bit", val)

Set output pin corresponding to bit number val to high, where bits and pins are numbered from 0 to 7. For example,

counter_par(sec, "set_bit", 4)

would set DIO4 to a high state, if pin 4 has been configured for output. Bits reserved for external-gate-select mode cannot be set while actively counting.

xxx_par("clr_bit", val)
Set output pins corresponding to bit number val to low, where bits and pins are numbered from 0 to 7. Bits reserved for external-gate-select mode cannot be cleared while actively counting.
xxx_par("set_bits"|"put_bits"|"put_byte" [, val])

With no arguments, returns a value indicating the current settings of the output pins. Otherwise, sets output pins corresponding to the bits set in val to high and bits not set in val to low. For example,

counter_par(sec, "set_bits", 0x13)

would set DIO0, DIO1 and DIO4 to a high state, if the pins were configured for output. Bits reserved for external-gate-select mode cannot be set while actively counting with mcount(), tcount() or move_cnt.

xxx_par("get_bit", val)
Returns 0 or 1 based on whether the input pin corresponding to bit number val is high or low, where pins and bits are numbered from 0 to 7.
xxx_par("get_bits"|"get_byte")
Returns an 8-bit value that reflects the setting of the DIO pins configured as inputs.