ADVANCED: PCT (Functionblock)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

ALL

Firmware version:

1.00 / 1.00.00


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:

_PCT_T_NONE

Debounce disabled.

_PCT_T_500US

0.5 ms.

_PCT_T_1MS

1 ms

_PCT_T_2MS

2 ms

_PCT_T_5MS

5 ms

_PCT_T_10MS

10 ms

_PCT_T_20MS

20 ms

_PCT_T_50MS

50 ms

_PCT_T_100MS

100 ms

_PCT_T_200MS

200 ms

_PCT_T_500MS

500 ms

_PCT_T_1000MS

1000 ms

 

Output:

cv : DINT

The current value of the counter.

 

Declaration:

FUNCTION_BLOCK PCT;
VAR_INPUT
  pinput : PTR; | Address of input variable (by using the ADDR() function)
  ld     : BOOL; | Load new counter value
  mode   : SINT; | Debounce mode
  ncv   : DINT; | New counter value
END_VAR;
VAR_OUTPUT
  cv     : DINT; | Current counter value
END_VAR;

 

Example:

INCLUDE rtcu.inc
 
VAR_INPUT
  input1 : BOOL; | Input that will increment the counter
END_VAR;
 
VAR
  hscounter : PCT; // Declare an instance of the PCT functionblock
END_VAR;
 
PROGRAM test;
 
hscounter.pinput:=ADDR(input1); // Assign address of input to use as pulse input
 
BEGIN
  hscounter(); //
  DebugFmt(message:="Counter=\4",v4:=hscounter.cv));
  Sleep(delay:=1000);
END;
END_PROGRAM;