Documentation Center

  • Trial Software
  • Product Updates

Counter Input

Select and connect counter input channels

Library

Real-Time Windows Target™

Description

The Counter Input block allows you to select and connect specific counter input channels to your Simulink® model. After you have added a Counter Input block to your model, you can enter the parameters for its I/O driver. The following procedure uses the HUMUSOFT® MF604 I/O board as an example.

Parameters

Sample time

Enter a value representing how frequently you want the block to execute and interact with the I/O hardware. The block will also synchronize your model with the real-time clock at this sample rate.

    Tip   If you are using a fixed-step solver, you must enter the value you entered in the Fixed step size box from the Configuration Parameters dialog box, or an integer multiple of that value.

Maximum missed ticks

Enter the number of timer ticks that your model can lag behind the real-time kernel. When the model lags by more than this number, the block reports an error and simulation stops. Otherwise, simulation continues even if some ticks are missed.

Show "Missed Ticks" port

Select this check box to display the current number of missed ticks as a block output.

Yield CPU when waiting

Select this check box to grant other programs more CPU time while the kernel waits for a response from the hardware.

Input channels

Enter a channel vector that selects the counter input channels you are using on this board. The vector can be any valid MATLAB® vector form. For example, to select the four counter input channels on the MF604 board, enter

[1,2,3,4] or [1:4]
Reset after read

Determines if the counter should be reset to zero after its value has been read. From the list, choose one of the following options:

  • never — Do not reset after reading.

  • always — Always reset after reading.

  • level — Reset after reading if block input is nonzero. This will add an input to the Counter Input block.

  • rising edge — Reset after reading if block input changes from zero to nonzero between the last two successive readings. This will add an input to the Counter Input block.

  • falling edge — Reset after reading if the block input changes from nonzero to zero between last two successive readings. This will add an input to the Counter Input block.

  • either edge — Reset after reading if the block input changes either from zero to nonzero or from nonzero to zero between the last two successive readings. This will add an input to the Counter Input block.

Clock input source

Determines the clock input source to increment the counter. From the list, select

  • input pin rising edge — Clock edge low to high transitions

  • input pin falling edge — Clock edge high to low transitions

  • internal clock — Internal time base

    If you set the Gate input functionality parameter to enable when high, latch & reset on edge or enable when low, latch & reset on edge, you can measure positive or negative pulse lengths in units of the internal time base. You can use this combination with the National Instruments® PCI/PXI-60xx and National Instruments PCI/PCIe/PXI/PXIe-62xx drivers for pulse width measurement.

Not all counter chips support selecting the input edge. In this case, only supported options appear in the pull-down menu.

Gate input functionality

Defines the action of the counter's gate pin. From the list, select

  • none — Gate is disabled.

  • enable when high — Counting is disabled when the gate is low and enabled when the gate is high.

  • enable when low — Counting is disabled when the gate is high and enabled when the gate is low.

  • start on rising edge — Counting is disabled until low to high transition of the gate occurs.

  • start on falling edge — Counting is disabled until high to low transition of the gate occurs.

  • reset on rising edge — Counter is reset when low to high transition of the gate occurs.

  • reset on falling edge — Counter is reset when high to low transition of the gate occurs.

  • latch on rising edge — The count of the counter is remembered when low to high transition of the gate occurs.

  • latch on falling edge — The count of the counter is remembered when high to low transition of the gate occurs.

  • latch & reset on rising edge — The count of the counter is remembered and then the counter is reset when low to high transition of the gate occurs.

  • latch & reset on falling edge — The count of the counter is remembered and then the counter is reset when high to low transition of the gate occurs.

  • enable when high, latch & reset on edge — Enables pulse counting when the gate input goes high, counts the clock while it is high, and remembers (latches) the pulse count. Then resets the counter to prepare it for the next pulse in the gate input.

    If you set the Clock input source parameter to internal clock, you can measure positive pulse lengths in units of the internal time base. You can use this combination with the National Instruments PCI/PXI-60xx and National Instruments PCI/PXI-62xx drivers for pulse width measurement.

  • enable when low, latch & reset on edge — Enables pulse counting when the gate input goes high, counts the clock while it is low, and remembers (latches) the pulse count. Then resets the counter to prepare it for the next pulse in the gate input.

    If you set the Clock input source parameter to internal clock, you can measure negative pulse lengths in units of the internal time base. You can use this combination with the National Instruments PCI/PXI-60xx and National Instruments PCI/PXI-62xx drivers for pulse width measurement.

Not all counter chips support all gate modes. Only supported gate modes appear in the pull-down menu.

Output data type

From the list, select the type of data that the block will output to the model.

Counter Input Block Example

The Real-Time Windows Target software includes an example that shows the operation of the Counter Input block. To see this example, type rtcounter in the MATLAB Command Window, or start MATLAB Help and choose Real-Time Windows Target > Demos > Frequency Measurement.

    Tip   You can run examples in both Simulink Normal Mode (initial setting) and in Simulink External Mode.

Was this topic helpful?