Documentation

National Instruments PCI/PXI-6602 Event Counter

PCI-6602 Event Counter block

Library

Simulink® Real-Time™ Library for National Instruments®

Description

The Event Counter is used for such tasks as measuring the frequency of a pulse train and counting binary events, such as switch closures and photocell interruptions (see Examples).

Block Parameters

Channel

From the list, choose one of the following:

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

These parameters specify the counter to be used with this driver block (channels 0 to 7). In each case, one block is required for each counter.

Counting Mode

Select one of:

  • Cumulative counter

    Accumulates count of edges of the source signal. Counter is reset according to Reset Mode. Block returns the current count without latching.

  • HW gated cumulative counter

    Accumulates count of edges of the source signal when the gate condition is true. Counter is reset according to Reset Mode (the gate end does not reset the count). Block returns the current count without latching.

    Use Gate Trigger Mode values Level Active High or Level Active Low in this mode. Edge gating produces a simple cumulative counter that starts with the first edge after arming the counter.

  • HW gated latched counter

    Accumulates count of edges of the source signal when the gate condition is true. Gate end latches the count and resets the count to the reset value for the next gate interval. Reset Mode is ignored.

Arm Control Input

Select this box to add arm input A to the block. If the arm input is high (> 0.5), the counter is turned on. If the input is low (≤ 0.5), the counter is turned off. The arm state is changed at the end of block execution and continues until the next time step.

The arm input serves as a software control for the counter, but does not latch the counter when it goes low. The block will output the most recently latched value if HW gated latched counter mode is also selected.

Source

Select the counter input pin. Default Source Pin selects the pin documented in the 6601/6602 User Manual. The PFI values select the input pin for other counters. The Timebase values select one of three different standard frequencies.

  • Default Source Pin

  • PFI 39 ( Pin 2 )

  • PFI 35 ( Pin 7 )

  • PFI 31 ( Pin 34 )

  • PFI 27 ( Pin 31 )

  • PFI 23 ( Pin 28 )

  • PFI 19 ( Pin 25 )

  • PFI 15 ( Pin 22 )

  • PFI 11 ( Pin 52 )

  • Timebase 1 (20.0 MHz)

  • Timebase 2 (100 kHz)

  • Timebase 3 (80 MHz)

Source Polarity

Choose the signal edge that will increment the counter. Using the fastest edge will give the most accurate count. Select one of:

  • Rising Edge

  • Falling Edge

Filter

Choose a filter to remove signal pulses shorter than a specified duration. High-frequency noise and slow signal edges can cause false counting. Select one of:

  • None

  • Synchronize input to Timebase 1 (20MHz)

  • Minimum pulse width 5 microsec

  • Minimum pulse width 1 microsec

  • Minimum pulse width 500 nanosec

  • Minimum pulse width 100 nanosec

  • Minimum pulse width 25 nanosec

HW Gate Input

Select the PFI input pin to be used as gate when Counting Mode is set to a gated mode. Default Gate Pin selects the pin shown in the 6601/6602 user manual. To gate two or more counters from the same signal, select the same input for each counter. Select one of:

  • Default Source Pin

  • Default Gate Pin

  • PFI 38 ( Pin 3 )

  • PFI 34 ( Pin 8 )

  • PFI 30 ( Pin 67 )

  • PFI 26 ( Pin 64 )

  • PFI 22 ( Pin 61 )

  • PFI 18 ( Pin 58 )

  • PFI 14 ( Pin 21 )

  • PFI 10 ( Pin 51 )

Gate Trigger Mode

Select the trigger mode to be used when Counting Mode is set to a HW gated cumulative counter or HW gated latched counter. The choice of trigger edge depends on the rise time or fall time of the gate signal. Using the fastest edge will give the most accurate count. Select one of:

  • Level Active High

    Count source edges when the gate input is high. Latch the current count when the gate input goes from high to low and reload the counter with the reset value. The block outputs the most recently latched value.

  • Level Active Low

    Count source edges when the gate input is low. Latch the current count when the gate input goes from low to high and reload the counter with the reset value. The block outputs the most recently latched value.

  • Rising Edge

    Latch the current count on a rising edge, reload the counter with the reset value, and resume counting. The block outputs the most recently latched value.

  • Falling Edge

    Latch the current count on a falling edge, reload the counter with the reset value, and resume counting. The block outputs the most recently latched value.

Reset Mode

Select the reset mode to be used when Counting Mode is set to Cumulative counter or HW gated cumulative counter.

  • No Reset

    Accumulate source input edges without resetting the counter to the reset value. Sample and return the accumulated value in the counter.

  • Reset after read

    Return the accumulated value in the counter and load the counter with the reset value.

  • SW Reset

    Select this value to add reset input R. During block execution, the block returns the accumulated value and checks input R. If R is nonzero, the block loads the counter with the reset value.

Reset Mode is ignored if Counting Mode is HW gated latched counter.

The counter value may become very large in No Reset mode. The value rolls over to 0 when it exceeds 0xFFFFFFFF (4294967295).

If R remains nonzero, SW Reset behaves like Reset after read mode.

Initial Load and Reset Value

Load the counter with this value on initial model load and again when the reset condition is met. When Counting Mode is HW gated latched counter, load the counter with this value when the gate turns off and latch the latest counter value for reading.

Sample time

Enter the base sample time or a multiple of the base sample time (-1 means sample time is inherited).

PCI slot (-1:autosearch)

If only one board of this type is in the target computer, enter -1 to locate the board.

If two or more boards of this type are in the target computer, enter the bus number and the PCI slot number of the board associated with this driver block. Use the format [BusNumber,SlotNumber].

To determine the bus number and the PCI slot number, type:

tg = slrt;
getPCIInfo(tg, 'installed')

Examples

You can configure this block in many different ways, including:

Frequency Counter

Measures the frequency of a signal. Configure a second counter as a pulse generator and feed the pulse output to the gate input for this channel. Set the pulse generator H and L inputs to set your chosen measurement interval. Set the event counter block as follows:

Block ParameterValue

Counting Mode

HW gated latched counter

Arm Control Input

Not checked

Source

Default Source Pin

Source Polarity

Rising Edge or Falling Edge (choose the cleaner edge)

Filter

None, or a choice faster than the signal being measured

HW Gate Input

Default Gate Pin, or some other if sharing a gate with another channel

Gate Trigger Mode

Rising Edge or Falling Edge. Because the pulse generator produces fast edges, rising and falling give the same result.

Reset Mode

Ignored

If you use a Gate Trigger Mode of Level Active High or Level Active Low for a frequency counter, the gate must be both on and off for longer than the period of the signal being measured. If it is not on for long enough, it may not latch an edge. If it is not off for long enough, a source edge may not occur while the gate is off, the gate end condition will be missed, and the counter will add the next interval.

Events Since Last Execution

Counts the number of external binary events, such as switch closures and photocell interruptions, since the last sample time. Set the event counter block as follows:

Block ParameterValue

Counting Mode

Cumulative counter

Arm Control Input

Checked or unchecked.

If checked, use arm input A in the model to control when to accept events.

Source

Default Source Pin, or some other source pin

Source Polarity

Rising Edge or Falling Edge (choose the cleaner edge)

Filter

None, or a pulse width required to eliminate switch bounce and similar artifacts

HW Gate Input

Ignored

Gate Trigger Mode

Ignored

Reset Mode

Reset after read

Use No Reset to create a running total of external events.

Use SW Reset and reset input R to reset the count according to some condition in your model.

Was this topic helpful?