# Counter Hardware

## Visual Basic signed integers

When reading or writing ports that are 16 or more bits wide, be aware of the following issue using signed integers, which is required when using Visual Basic:

On some devices, such as the CIO-CTR10 count register or AUXPORT digital ports, the ports are 16-bits wide or more. When accessing the data at these ports, the digital values are arranged as a single 16-bit word or a 32-bit double word.
When using signed integers, values above 0111 1111 1111 1111 (32,767 decimal) can be confusing. The next increment, 1000 0000 0000 0000 has a decimal value of –32,768. When using signed integers, this is the value that is returned from a 16-bit counter at half of maximum count. The value for full count (just before the counter turns over) is –1. Keep this in mind if you are using Visual Basic, since Visual Basic does not supply unsigned integers (values from 0 to 65,535) or unsigned longs (values from 0 to 4,294,967,295). Refer to 16-bit values using a signed integer data type for information on 16-bit values using unsigned integers.

The Universal Library provides functions for initialization and configuration of counter chips, and can configure a counter for any of the counter operations.

However, counter configuration does not include counter-use, such as event counting and pulse width. Counter-use is accomplished by programs which use the counter functions. The Universal Library provides the cbCFreqIn() function for counter use, while the Universal Library for .NET provides the CFreqIn() method. Other functions and methods may be added for counter use to later revisions.

## Counter chip data sheets

To use a counter for any but the simplest counting function, you must read, understand and employ the information contained in the chip manufacturer's data sheet. Technical support of the Universal Library does not include providing, interpreting or explaining the counter chip data sheet.

To fully understand and maximize the performance of counter/timer hardware and the related function calls, review the following related data sheet(s):

Chip name | Data sheet location
82C54 | 82C54.pdf is installed to the Documents subdirectory where the UL is installed (C:/Program files/Measurement Computing/DAQ by default).
AM9513 | 9513A.pdf is installed to the Documents subdirectory where the UL is installed
Z8536 | Z8536.pdf is included with each product designed with this chip, and is available on our website.
LS7266 | ls7266r1.pdf is installed to the Documents subdirectory where the UL is installed.

## Counter chip variables

Universal Library counter initialization and configuration functions include names for bit patterns, such as ALEGATE, which stands for Active Low Enabled Gate N. In any case where Universal Library has a name for a bit pattern, it is allowed to substitute the bit pattern as a numeric. This will work, but your programs will be harder to read and debug.