Skip to Main Content Skip to Search
Product Documentation

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 and Dialog Box

Sample time

Enter the same value you entered in the Fixed step size box from the Configuration Parameters dialog box, or an integer multiple of that value.

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 all 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 timebase

    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 timebase. 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 timebase. 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 timebase. 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 Demo

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

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS