ADVANCED: PCT (Functionblock) |
Top Previous Next |
PCT is a high-speed pulse counter. This function block will increment the "cv" value with one on each rising edge on the "pinput" input. If a high signal is present on the "ld" input, the counter will be set to the value present on the "ncv". Unlike the normal CTU (Up counter), the PCT counter is realized at a lower level - thereby making it possible to count high-speed pulses. By using the PCT function block, the pulse counting will occur in the background without being dependent on the actual execution speed of the VPL program.
On NX32 devices a frequency of 400 Hz can be counted on 1 channel, 200 Hz on 2 channels, 133 Hz on 3 channels, and 100 Hz on 4 channels. The frequency on NX32L devices is up to 13 kHz on all simultaneous channels. Please refer to the technical manual for the specific device in question. On the RTCU LX4, inputs 6-8 have support for up to 400 Hz on 1 to 3 channels. NX32L devices can use the mode parameter to debounce the pulses to avoid counting a noisy signal as multiple pulses.
For other high-speed IO functions on NX32L, see the High-Speed IO functions.
Input: pinput : PTR Address of a digital input signal (please see the example below). On the leading edge of this input, the "cv" will be incremented with 1.
Note: The address can only be a simple variable and will therefore not work with an ARRAY variable.
ld : BOOL (true/false) Load input. When this input is high, the counter value will be set to the value in "ncv".
ncv : DINT New counter value. It will be written to "cv" when "ld" is high.
mode: SINT (default _PCT_T_NONE) (requires firmware R2.00.00 or newer) Debounce mode. Only supported on NX32L devices. When enabled, the signal must be active for at least the specified time to be counted. The signal must also be inactive for at least the specified time before the next pulse can be counted. Note that the mode must be set when the PCT function block is called for the first time, it can not be changed once it is running.
Approximate minimum pulse width for the different modes:
Output: cv : DINT The current value of the counter.
Declaration: FUNCTION_BLOCK PCT;
Example: INCLUDE rtcu.inc |