# cbCConfigScan()

Configures a counter channel. This function only works with counter boards that have counter scan capability.

## Function Prototype

C/C++

int cbCConfigScan(int BoardNum, int CounterNum, int Mode, int DebounceTime, int DebounceMode, int EdgeDetection, int TickSize, int MappedChannel)

Visual Basic

Function cbCConfigScan(ByVal BoardNum&, ByVal CounterNum&, ByVal Mode&, ByVal DebounceTime&, ByVal DebounceMode&, ByVal EdgeDetection&, ByVal TickSize&, ByVal MappedChannel&) As Long

## Arguments

BoardNum

The number associated with the board when it was installed with InstaCal or created with cbCreateDaqDevice(). BoardNum may be 0 to 99. The specified board must have a scan counter.

CounterNum

The counter number to configure. This argument is zero-based, so the first counter number is "0".

Mode

Bit fields that control various options. This field may contain any combination of non-contradictory choices in the "Mode argument values" section below.

DebounceTime

Used to bypass the debounce mode, or to set a channel's comparator output to one of 16 debounce times. Debounce is used to eliminate switch-induced transients typically associated with electromechanical devices including relays, proximity switches, and encoders. The choices are:

CTR_DEBOUNCE500ns | CTR_DEBOUNCE100us
CTR_DEBOUNCE1500ns | CTR_DEBOUNCE300us
CTR_DEBOUNCE3500ns | CTR_DEBOUNCE700us
CTR_DEBOUNCE7500ns | CTR_DEBOUNCE1500us
CTR_DEBOUNCE15500ns | CTR_DEBOUNCE3100us
CTR_DEBOUNCE31500ns | CTR_DEBOUNCE6300us
CTR_DEBOUNCE63500ns | CTR_DEBOUNCE12700us
CTR_DEBOUNCE127500ns | CTR_DEBOUNCE25500us
CTR_DEBOUNCE_NONE (disables the debounce feature) |

DebounceMode

Sets the mode of the debounce module to CTR_TRIGGER_BEFORE_STABLE or CTR_TRIGGER_AFTER_STABLE.

CTR_TRIGGER_BEFORE_STABLE: Use this mode when the input signal has groups of glitches and each group is to be counted as one. The trigger before stable mode will recognize and count the first glitch within a group but reject the subsequent glitches within the group if the debounce time is set accordingly. In this case the debounce time should be set to encompass one entire group of glitches

CTR_TRIGGER_AFTER_STABLE: This mode rejects glitches and only passes state transitions after a specified period of stability (the debounce time). This mode is used with electromechanical devices like encoders and mechanical switches to reject switch bounce and disturbances due to a vibrating encoder that is not otherwise moving. The debounce time should be set short enough to accept the desired input pulse but longer than the period of the undesired disturbance.

EdgeDetection

Selects whether to detect a rising edge or falling edge. Choices are CTR_RISING_EDGE and CTR_FALLING_EDGE.

For counter devices that use channel mapping, if a counter is configured for CTR_FALLING_EDGE, calling cbCIn() or cbCIn32() for that counter will result in a BADCOUNTERMODE error.

TickSize

Sets the tick size, which is the fundamental unit of time for period, pulsewidth, and timing measurements. The choices are:

CTR_TICK20PT83ns | CTR_TICK20ns
CTR_TICK208PT3ns | CTR_TICK200ns
CTR_TICK2083PT3ns | CTR_TICK2000ns
CTR_TICK20833PT3ns | CTR_TICK20000ns

MappedChannel

Used to select the mapped channel. A mapped channel is a counter input channel other than CounterNum that can participate with the input signal of the counter defined by CounterNum by gating the counter or decrementing the counter.

## Returns

- Error code or 0 if no errors

### Mode argument values

- TOTALIZE mode

Sets the specified counter to totalize mode. This mode may contain any combination of non-contradictory choices from the following list of options:

BIT_32 | Selects a 32-bit counter for asynchronous mode. This argument value only affects cbCIn(), cbCIn32() and cbCIn64(). Recommended for use only with cbCIn32(). (Using the BIT_32 option with cbCIn() is not very useful, since the value returned by cbCIn() is only 16 bits. The effect is that the value returned by cbCIn() rolls over 65,535 times before stopping.) Refer to board-specific information for the product you are using for details on how this affects asynchronous reads on a specific device.
BIT_48 | Selects a 48-bit counter for asynchronous mode. This argument value only affects cbCIn(), cbCIn32() and cbCIn64(). Using the BIT_48 option with cbCIn() and cbCIn32() is not very useful, since the value returned by cbCIn() is only 16 bits, and the value returned by cbCIn32() is only 32 bits. The effect is that the value returned by cbCIn() rolls over 4,294,967,295 times before stopping, and the value returned by cbCIn32() rolls over 65,535 times before stopping.) Refer to board-specific information for the product you are using for details on how this affects asynchronous reads on a specific device.
CLEAR_ON_READ | The counter is cleared after every read.
COUNT_DOWN_OFF | The counter counts up.
COUNT_DOWN_ON | The counter counts down.
DECREMENT_ON | Allows the mapped channel to decrement the counter. With this option, the main counter input channel will increment the counter, and the mapped channel can be used to decrement the counter. By default, the counter decrement option is set to "off." This mode is not compatible with cbCIn() or cbCIn32(). If a counter is configured for DECREMENT_ON, calling cbCIn() or cbCIn32() for that counter will result in a BADCOUNTERMODE error.
GATE_CLEARS_CTR | The gate input clears the counter. By default, the counter is cleared when the gate input is high.
GATE_CONTROLS_DIR | The gate input controls the direction of the counter. By default, the counter increments when the gate pin is high, and decrements when the gate pin is low.
GATE_TRIG_SRC | The counter starts counting when the gate input goes active. By default, active is on the rising edge. The gate is re-armed when the counter is loaded and when cbCConfigScan() is called.
GATING_ON | Selects gating "on." When "on", the counter is enabled when the mapped channel or the gate pin that is used to gate the counter is high. When the mapped channel/gate pin is low, the counter is disabled but holds the count value. By default, the counter gating option is set to "off." For counter devices that use channel mapping, this mode is not compatible with cbCIn() or cbCIn32(). If a counter is configured for GATING_ON, calling cbCIn() or cbCIn32() for that counter will result in a BADCOUNTERMODE error.
INVERT_GATE | Inverts the polarity of the gate input.
LATCH_ON_MAP | Causes the count to be latched by the signal on the mapped channel. By default, the count is latched by the internal "start of scan" signal, so the count is updated each time it's read. This mode is not compatible with cbCIn() or cbCIn32(). If a counter is configured for LATCH_ON_MAP, calling cbCIn() or cbCIn32() for that counter will result in a BADCOUNTERMODE error.
MODULO_N_ON | Enables Modulo-N counting mode. In Modulo-N mode, an upper limit is set by loading the max limit register with a maximum count. When counting up, the counter will roll-over to 0 when the maximum count is reached, and then continue counting up. Likewise when counting down, the counter will roll over to the maximum count (in the max limit register) whenever the count reaches 0, and then continue counting down.
NO_RECYCLE_ON | Enables Non-recycle counting mode. In Non-recycle mode, the counter stops counting whenever a count overflow or underflow takes place. Counting restarts when a clear or a load operation is performed on the counter, or the count direction changes.
OUTPUT_INITIAL_STATE_HIGH | Sets the initial state of the counter output pin high.
OUTPUT_INITIAL_STATE_LOW | Sets the initial state of the counter output pin low.
OUTPUT_ON | Enables the counter output. By default, the counter output goes high when the counter reaches the value of output register 0, and low when the counter reaches the value of output register 1. Use cbCLoad(), cbCLoad32(), or cbCLoad64() to set or read the value of the output registers.
RANGE_LIMIT_ON | Enables Range Limit counting mode. In Range Limit mode, an upper and lower limit is set, mimicking limit switches in the mechanical counterpart. Use cbCLoad(), cbCLoad32(), or cbCLoad64() to set the upper and lower limits – set the upper limit by loading the max limit register, and the lower limit by loading the min limit register. Note that on some devices the lower limit is programmable, but on other devices the lower limit is always 0. When counting up, the counter rolls over to min limit when the max limit is reached. When counting down, the counter rolls over to max limit when the min limit is reached. When counting up with NO_RECYCLE_ON enabled, the counter freezes whenever the count reaches the value that was loaded into the max limit register. When counting down with NO_RECYCLE_ON enabled, the counter freezes whenever the count reaches the value that was loaded into the min limit register. Counting resumes if the counter is reset or the direction changes.
STOP_AT_MAX | The counter will stop at the top of its count. For the cbCIn32() function, the top of the count depends on whether the BIT_32 option is used. If it is, the top of the count is FFFFFFFF hex. If not, the top of the count is FFFF hex. By default, the counter counts upward and rolls over on the 32-bit boundary.
UPDOWN_ON | Enables Up/down counting mode.

- ENCODER mode

Sets the specified counter to encoder measurement mode. This mode may contain any combination of non-contradictory choices from the following list of options:

ENCODER_MODE_BIT_16 | Selects a 16-bit counter for asynchronous mode. This argument value only affects cbCIn(), cbCIn32() and cbCIn64(). Recommended for use only with cbCIn().
ENCODER_MODE_BIT_32 | Selects a 32-bit counter for asynchronous mode. This argument value only affects cbCIn(), cbCIn32() and cbCIn64(). Recommended for use only with cbCIn32(). (Using the ENCODER_MODE_BIT_32 option with cbCIn() is not very useful, since the value returned by cbCIn() is only 16 bits. The effect is that the value returned by cbCIn() rolls over 65,535 times before stopping.)
ENCODER_MODE_BIT_48 | Selects a 48-bit counter for asynchronous mode.This argument value only affects cbCIn(), cbCIn32() and cbCIn64(). Recommended for use only with cbCIn64(). (Using the ENCODER_MODE_BIT_48 option with cbCIn() and cbCIn32() is not very useful, since the value returned by cbCIn() is only 16 bits, and the value returned by cbCIn32() is only 32 bits. The effect is that the value returned by cbCIn() rolls over 4,294,967,295 times before stopping, and the value returned by cbCIn32() rolls over 65,535 times before stopping.)
ENCODER_MODE_CLEAR_ON_Z_ON | Selects "clear on Z" on. The counter is cleared when the index (Z input) goes active. By default, the "clear on Z" option is off, and the counter is not cleared.
ENCODER_MODE_LATCH_ON_Z | Selects the Encoder Z mapped signal to latch the counter outputs. This allows the user to know the exact counter value when an edge is present on another counter.
ENCODER_MODE_MODULO_N_ON | Enables Modulo-N counting mode. In Modulo-N mode, an upper limit is set by loading the max limit register with a maximum count. When counting up, the counter will roll-over to 0 when the maximum count is reached, and then continue counting up. Likewise when counting down, the counter will roll over to the maximum count (in the max limit register) whenever the count reaches 0, and then continue counting down.
ENCODER_MODE_NO_RECYCLE_ON | Enables Non-recycle counting mode. In Non-recycle mode, the counter is disabled whenever a count overflow or underflow takes place. The counter is re-enabled when a clear or a load operation is performed on the counter
ENCODER_MODE_RANGE_LIMIT_ON | Enables Range Limit counting mode. In Range Limit mode, an upper and lower limit is set, mimicking limit switches in the mechanical counterpart. The upper limit is set by loading the max limit register with the cbCLoad, cbCLoad32 or cbCLoad64 functions. The lower limit is always 0. When counting up, the counter rolls over to min limit when the max limit is reached. When counting down, the counter rolls over to max limit when the min limit is reached. When counting up with ENCODER_MODE_NO_RECYCLE_ON enabled, the counter freezes whenever the count reaches the value that was loaded into the max limit register. When counting down with ENCODER_MODE_NO_RECYCLE_ON enabled, the counter freezes whenever the count reaches the value that was loaded into the min limit register. Counting resumes if the counter is reset or the direction changes.
ENCODER_MODE_X1 | Sets the encoder measurement mode to X1.
ENCODER_MODE_X2 | Sets the encoder measurement mode to X2.
ENCODER_MODE_X4 | Sets the encoder measurement mode to X4.

- PERIOD mode

Sets the specified counter to period measurement mode. This mode may contain any combination of non-contradictory choices from the following list of options:

PERIOD_MODE_BIT_16 | Selects a 16-bit counter for asynchronous mode. This argument value only affects cbCIn(), cbCIn32() and cbCIn64(). Recommended for use only with cbCIn().
PERIOD_MODE_BIT_32 | Selects a 32-bit counter for asynchronous mode. This argument value only affects cbCIn(), cbCIn32() and cbCIn64(). Recommended for use only with cbCIn32(). (Using the PERIOD_MODE_BIT_32 option with cbCIn() is not very useful, since the value returned by cbCIn() is only 16 bits. The effect is that the value returned by cbCIn() rolls over at 65,535 times before stopping.)
PERIOD_MODE_BIT_48 | Selects a 48-bit counter for asynchronous mode. This argument value only affects cbCIn(), cbCIn32() and cbCIn64(). Recommended for use only with cbCIn64(). (Using the PERIOD_MODE_BIT_48 option with cbCIn() and cbCIn32() is not very useful, since the value returned by cbCIn() is only 16 bits, and the value returned by cbCIn32() is only 32 bits. The effect is that the value returned by cbCIn() rolls over 4,294,967,295 times before stopping, and the value returned by cbCIn32() rolls over 65,535 times before stopping.)
PERIOD_MODE_GATING_ON | Selects gating "on." When "on", the counter is enabled when the mapped channel or the gate pin that is used to gate the counter is high. When the mapped channel/gate pin is low, the counter is disabled but holds the count value. By default, the counter gating option is set to "off." For counter devices that use channel mapping, this mode is not compatible with cbCIn() or cbCIn32(). If a counter is configured for PERIOD_MODE_GATING_ON, calling cbCIn() or cbCIn32() for that counter will result in a BADCOUNTERMODE error.
PERIOD_MODE_INVERT_GATE | Inverts the polarity of the gate input.
PERIOD_MODE_X1 | The measurement is latched each time one complete period is observed.
PERIOD_MODE_X10 | The measurement is latched each time 10 complete periods are observed.
PERIOD_MODE_X100 | The measurement is latched each time 100 complete periods are observed.
PERIOD_MODE_X1000 | The measurement is latched each time 1000 complete periods are observed.

- PULSEWIDTH mode

Sets the specified counter to pulsewidth measurement mode. This mode may contain any combination of non-contradictory choices from the following list of options:

PULSEWIDTH_MODE_BIT_16 | Selects a 16-bit counter for asynchronous mode. This argument value only affects cbCIn(), cbCIn32() and cbCIn64(). Recommended for use only with cbCIn().
PULSEWIDTH_MODE_BIT_32 | Selects a 32-bit counter for asynchronous mode. This argument value only affects cbCIn(), cbCIn32() and cbCIn64(). Recommended for use only with cbCIn32(). (Using the PULSEWIDTH_MODE_BIT_32 option with cbCIn() is not very useful, since the value returned by cbCIn() is only 16 bits. The effect is that the value returned by cbCIn() rolls over 65,535 times before stopping.)
PULSEWIDTH_MODE_BIT_48 | Selects a 48-bit counter for asynchronous mode. This argument value only affects cbCIn(), cbCIn32() and cbCIn64(). Recommended for use only with cbCIn64(). (Using the PULSEWIDTH_MODE_BIT_48 option with cbCIn() and cbCIn32() is not very useful, since the value returned by cbCIn() is only 16 bits, and the value returned by cbCIn32() is only 32 bits. The effect is that the value returned by cbCIn() rolls over 4,294,967,295 times before stopping, and the value returned by cbCIn32() rolls over 65,535 times before stopping.)
PULSEWIDTH_MODE_GATING_ON | Selects gating "on." When "on", the counter is enabled when the mapped channel or the gate pin that is used to gate the counter is high. When the mapped channel/gate pin is low, the counter is disabled but holds the count value. By default, the counter gating option is set to "off." For counter devices that use channel mapping, this mode is not compatible with cbCIn() or cbCIn32(). If a counter is configured for PULSEWIDTH_MODE_GATING_ON, calling cbCIn() or cbCIn32() for that counter will result in a BADCOUNTERMODE error.
PULSEWIDTH_MODE_INVERT_GATE | Inverts the polarity of the gate input.

- TIMING mode

Sets the specified counter to timing mode. This mode supports the following options:

TIMING_MODE_BIT_16 | Selects a 16-bit counter for asynchronous mode. This argument value only affects cbCIn(), cbCIn32() and cbCIn64(). Recommended for use only with cbCIn().
TIMING_MODE_BIT_32 | Selects a 32-bit counter for asynchronous mode. This argument value only affects cbCIn(), cbCIn32() and cbCIn64(). Recommended for use only with cbCIn32(). (Using the TIMING_MODE_BIT_32 option with cbCIn() is not very useful, since the value returned by cbCIn() is only 16 bits. The effect is that the value returned by cbCIn() rolls over 65,535 times before stopping.)
TIMING_MODE_BIT_48 | Selects a 48-bit counter for asynchronous mode.This argument value only affects cbCIn(), cbCIn32() and cbCIn64(). Recommended for use only with cbCIn64(). (Using the TIMING_MODE_BIT_48 option with cbCIn() and cbCIn32() is not very useful, since the value returned by cbCIn() is only 16 bits, and the value returned by cbCIn32() is only 32 bits. The effect is that the value returned by cbCIn() rolls over 4,294,967,295 times before stopping, and the value returned by cbCIn32() rolls over 65,535 times before stopping.)
TIMING_MODE_INVERT_GATE | Inverts the polarity of the gate input.