## cbCFreqIn() function

Measures the frequency of a signal. This function is only used with 9513 counters. This function uses internal counters #4 and #5.

## Function Prototype

C/C++

int cbCFreqIn(int BoardNum, int SigSource, int GateInterval, unsigned short *Count, long *Freq)

Visual Basic

Function cbCFreqIn(ByVal BoardNum&, ByVal SigSource&, ByVal GateInterval&, Count%, Freq&) 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 9513 counter.

SigSource

Specifies the source of the signal from which the frequency is calculated.

The signal to be measured is routed internally from the source specified by SigSource to the clock input of counter 5. On boards with more than one 9513 chip, there is more than one counter 5. Which counter 5 is used is also determined by SigSource. Set it to one of the constants in the "SigSource argument values" section below.

The value of SigSource determines which chip will be used. CTRINPUT6 through CTRINPUT10, FREQ6 through FREQ10 and GATE6 through GATE9 indicate chip two will be used. The signal to be measured must be present at the chip two input specified by SigSource. Also, the gating connection from counter 4 output to counter 5 gate must be made between counters 4 and 5 OF THIS CHIP (see below).

Refer to board-specific information in the UL Users Guide to determine valid values for your board.

GateInterval

Gating interval in milliseconds (must be > 0). Specifies the time (in milliseconds) that the counter will be counting. The optimum GateInterval depends on the frequency of the measured signal. The counter can count up to 65,535.

If the gating interval is too low, then the count will be too low and the resolution of the frequency measurement will be poor. For example, if the count changes from 1 to 2 the measured frequency doubles.

If the gating interval is too long the counter will overflow and a FREQOVERRUN error will occur.

The cbCFreqIn function does not return until the GateInterval has expired. There is no background option. Under Windows, this means that window activity will stop for the duration of the call. Adjust the GateInterval so this does not pose a problem to your user interface.

Count

The raw count is returned here.

Freq

The measured frequency in Hz is returned here.

## Returns

- Error code or 0 if no errors
- Count - Count that the frequency calculation is based on is returned here
- Freq - Measured frequency in Hz is returned here

### SigSource argument values

One 9513 chip (Chip 1 used): | CTRINPUT1 through CTRINPUT5
GATE1 through GATE4
FREQ1 through FREQ5
Two 9513 chips (Chip 1 or Chip 2 used): | CTRINPUT1 through CTRINPUT10
GATE 1 through GATE 9 (excluding gate 5)
FREQ1 through FREQ10
Four 9513 chips (Chips 1- 4 may be used): | CTRINPUT1 through CTRINPUT20
GATE1 through GATE19 (excluding gates 5, 10, and 15)
FREQ1 through FREQ20

## Notes

- This function requires an electrical connection between counter 4 output and counter 5 gate. This connection must be made between counters 4 and 5 on the chip determined by SigSource.
- cbC9513Init() must be called for each ChipNum that will be used by this function. The values of FOutDivider, FOutSource, Compare1, Compare2, and TimeOfDay are irrelevant to this function and may be any value shown in the cbC9513Init() function description.
- If you select an external clock source for the counters, the GateInterval, Count, and Freq settings are only valid if the external source is 1 MHz. Otherwise, you need to scale the values according to the frequency of the external clock source.
- For example, for an external clock source of 2 MHz, increase your GateInterval setting by a factor of 2, and also double the Count and Freq values returned when analyzing your results.