F165_HighSpeedCounter_Cam

Cam control for FP0R

This instruction performs cam control according to the parameters in the specified DUT with a maximum of 31 target values for the high-speed counter. An interrupt program can be executed whenever the elapsed value matches one of the target values.

Parameters

Input

iHscChannel* (INT)

High-speed counter channel: 0–5

s_dutDataTable (ANY_DUT)

Starting address of area containing the data table

Sample: F165_HighSpeedCounter_Cam_8_Values_DUT

Output

dutBitOutputs (ANY_DUT)

Starting address (WR) of area containing the output word address, e.g. BOOL32_OVERLAPPING_DUT. Select the size (16 or 32 bits) according to the number set with diNumberOfTargetValuesAndOutputRelays.

Remarks

Create your own DUT using the following DUT as a sample: F165_HighSpeedCounter_Cam_8_Values_DUT

The following parameters can be specified in the DUT:

  • Control code

  • Word address for outputs

  • Number of target values

  • Target value1

  • ...

  • Target valuen

  • Maximum target value

y

Elapsed value of high-speed counter

14000

Maximum target value

(1)

Execution condition

10000

Target value4

(2)

High-speed counter control flag

8000

Target value3

(3)

Output0-4

4000

Target value2

2000

Target value1

  • Whenever the elapsed value is in the target value area n to n+1 (incremental counting) or n+1 to n, (decremental counting), the corresponding output n is TRUE.

  • In the example above, maximum target value control has been enabled. When the elapsed value reaches the maximum target value, the elapsed value is reset to 0 and counting restarts.

  • Specify the word address of the outputs in an overlapping DUT, e.g. BOOL32_OVERLAPPING_DUT, and apply this DUT at dutBitOutputs.

  • A maximum of 31 target values can be specified.

  • The target values must be arranged in ascending order. No value may be used twice.

  • When the instruction starts, all outputs are FALSE, except for output 0, which turns to TRUE, provided that the elapsed value is smaller than target value 1. Otherwise, the output corresponding to the target value area turns to TRUE. Example: If the current value is between target value 2 = -4000 and target value 3 = +4000, output 2 is TRUE. In the following example maximum target value control has been disabled. When the elapsed value reaches the last target value, counting continues and the elapsed value is not reset to 0.

y

Elapsed value of high-speed counter

8000

Target value4

(1)

Execution condition

4000

Target value3

(2)

High-speed counter control flag

-4000

Target value2

(3)

Output0-4

-10000

Target value1

INT0

Interrupt program 0

Maximum target value control

  • The instruction can be executed using maximum target value control to reset the elapsed value to 0 when the maximum target value has been reached. Maximum target value control can be enabled in the control code of F165_HighSpeedCounter_Cam_8_Values_DUT. Instead of using maximum target value control, the elapsed value can also be reset using a reset input or a software reset.

  • To perform maximum target value control, positive integer numbers must be specified for all target values.

  • Incremental and decremental counting with maximum target value control:

y

Elapsed value of high-speed counter

14000

Maximum target value

(1)

Execution condition

10000

Target value4

(2)

High-speed counter control flag

8000

Target value3

(3)

Output0-4

4000

Target value2

2000

Target value1

Overview:

Maximum target value control:

enabled

disabled (see note)

Incremental counting:

The pointer of the data table moves from target value 1 to the last target value.

When the elapsed value reaches the maximum target value:

  • the pointer returns to target value 1

  • output 0 turns to TRUE

  • the elapsed value is set to 0

When the elapsed value reaches the last target value:

  • the pointer returns to target value 1

  • output 0 turns to TRUE

  • the elapsed value continues to increment and restarts at the minimum value of the ring counter

Decremental counting:

The pointer of the data table moves from the last target value to target value 1.

When the elapsed value reaches the value -1:

  • the pointer returns to the last target value

  • the output corresponding to the last target value turns to TRUE

  • the elapsed value is set to the maximum target value

When the elapsed value reaches the value -1:

  • the pointer returns to target value n

  • the output corresponding to the last target value turns to TRUE

  • the elapsed value continues to decrement and restarts at the maximum value of the ring counter

NOTE

Provided that neither a reset input nor a software reset is being used.

Hardware reset operation

Channel

Hardware reset input

0

X2

1

2

X5

3

Interrupt operation

The interrupt program will be executed when the elapsed value matches the target value. Any interrupt that has been entered into the Tasks list is automatically enabled.A special interrupt program number is assigned to each channel number.

Channel

0

1

2

3

4

5

Interrupt program

0

1

3

4

6

7

General programming information

  • Select the high-speed counter input for the desired channel in the system registers.

  • When a high-speed counter instruction is executed, the high-speed counter control flag (e.g. sys_bIsHscChannel0ControlActive) for the channel used turns to TRUE. No other high-speed counter instruction using the same channel can be executed as long as the control flag is TRUE.

  • To cancel execution of an instruction, set bit 3 of the data register storing the high-speed counter control code (sys_wHscOrPulseControlCode) to TRUE. The high-speed counter control flag then changes to FALSE. To re-enable execution of the high-speed counter instruction, reset bit 3 to FALSE.

  • Rewriting the elapsed value for the channel used during the execution of the instruction may cause an unexpected operation.

  • Make sure the time span between adjacent target values is greater than 1ms.

  • If the instruction is executed in the main program, make sure the minimum time span between adjacent target values is greater than the scan time.

  • If the instruction is executed in an interrupt program, make sure the minimum time span between adjacent target values is greater than the maximum execution time of the interrupt program.

  • This instruction can be executed simultaneously on a maximum of two channels.

  • When using a reset input or a software reset, make sure target value 1 is an integer and ³1.

  • When maximum target value control is used together with a reset input or software reset, be careful not to use them at the same time.

  • The status of the high-speed counter control flag or pulse output control flag may change while a scan is being carried out. For example, if the number of received bytes is read more than once different statuses may exist within one scan.

Error flags

sys_bIsOperationErrorHold (turns to TRUE and remains TRUE)
  • if channel number or values of the data table are outside the permissible range
  • if high-speed counter has not been set in the system registers
  • if target value > maximum target value.

  • if target value = 0.

  • if target values are not arranged in ascending order

sys_bIsOperationErrorNonHold (turns to TRUE for one scan)
  • if channel number or values of the data table are outside the permissible range
  • if high-speed counter has not been set in the system registers
  • if target value > maximum target value.

  • if target value = 0.

  • if target values are not arranged in ascending order

Example with maximum target value control

DUT

The DUT F165_HighSpeedCounter_Cam_8_Values_DUT is predefined in the FP Library and can be used as a sample.

Global variables

In the global variable list you define variables that can be accessed by all POUs in the project.

POU header

All input and output variables used for programming this function have been declared in the POU header.The same POU header is used for all programming languages.

	VAR
		bStartCam: BOOL:=FALSE;
		dut_F165_CAM_Example1: F165_Cam_Example1_4_Values_DUT;
	END_VAR
	VAR_EXTERNAL
		WR0_bits_F165_CAM_Examples: BOOL16_OVERLAPPING_DUT;
	END_VAR

POU body

When the variable bStartCam turns to TRUE, the function is carried out.

LD body

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
        ACTIVE_NETWORK := 0 ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 5 ;
        NETWORK_BODY
B(B_CONTACT,,sys_bIsFirstScan,5,2,7,4,);
B(B_F,E_MOVE!,Instance,14,1,20,5,,?DEN?D?AENO?C);
B(B_VARIN,,0,12,3,14,5,);
B(B_VAROUT,,sys_diHscChannel0ElapsedValue,20,3,22,5,);
B(B_COMMENT,,Reset the elapsed value,1,0,21,1,);
L(1,3,5,3);
L(7,3,14,3);
L(1,0,1,5);
        END_NETWORK_BODY
    END_NET_WORK
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 6 ;
        NETWORK_BODY
B(B_F,F165_HighSpeedCounter_Cam!,Instance,14,1,28,6,,?DEN?HiHscChannel?Ds_dutDataTable?AENO?CdutBitOutputs);
B(B_VARIN,,0,12,3,14,5,);
B(B_VARIN,,dut_F165_CAM_Example1,12,4,14,6,);
B(B_VAROUT,,WR1_dut_CAM1,28,3,30,5,);
B(B_CONTACT,,bStartCam,5,2,7,4,R);
B(B_COMMENT,,Start the cam control,1,0,21,1,);
L(1,3,5,3);
L(7,3,14,3);
L(1,0,1,6);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

IF (sys_bIsFirstScan) then
    sys_diHscChannel0ElapsedValue:=0;
END_IF;
IF DF(bStartCam) then
    F165_HighSpeedCounter_Cam(iHscChannel := 0, 
      s_dutDataTable := dut_F165_CAM_Example1, 
      dutBitOutputs => WR0_bits_F165_CAM_Examples);
END_IF;

Example without maximum target value control

DUT

The DUT F165_HighSpeedCounter_Cam_8_Values_DUT is predefined in the FP Library and can be used as a sample.

POU header

VAR
		bStartCam: BOOL:=FALSE;
		dut_F165_CAM_Example2: F165_Cam_Example2_4_Values_DUT;
	END_VAR
	VAR_EXTERNAL
		WR0_bits_F165_CAM_Examples: BOOL16_OVERLAPPING_DUT;
	END_VAR

POU body

When the variable bStartCam is set to TRUE, the function is carried out.

LD body

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
        ACTIVE_NETWORK := 0 ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 5 ;
        NETWORK_BODY
B(B_CONTACT,,sys_bIsFirstScan,5,2,7,4,);
B(B_F,E_MOVE!,Instance,14,1,20,5,,?DEN?D?AENO?C);
B(B_VARIN,,0,12,3,14,5,);
B(B_VAROUT,,sys_diHscChannel0ElapsedValue,20,3,22,5,);
B(B_COMMENT,,Reset the elapsed value,1,0,21,1,);
L(1,3,5,3);
L(7,3,14,3);
L(1,0,1,5);
        END_NETWORK_BODY
    END_NET_WORK
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 6 ;
        NETWORK_BODY
B(B_F,F165_HighSpeedCounter_Cam!,Instance,14,1,28,6,,?DEN?HiHscChannel?Ds_dutDataTable?AENO?CdutBitOutputs);
B(B_VARIN,,0,12,3,14,5,);
B(B_VARIN,,dut_F165_CAM_Example2,12,4,14,6,);
B(B_VAROUT,,WR0_bits_F165_CAM_Examples,28,3,30,5,);
B(B_CONTACT,,bStartCam,5,2,7,4,R);
B(B_COMMENT,,Start the cam control,1,0,21,1,);
L(7,3,14,3);
L(1,3,5,3);
L(1,0,1,6);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

IF (sys_bIsFirstScan) then
    sys_diHscChannel0ElapsedValue:=0;
END_IF;
IF DF(bStartCam) then
    F165_HighSpeedCounter_Cam(iHscChannel := 0, 
      s_dutDataTable := dut_F165_CAM_Example2, 
      dutBitOutputs => WR0_bits_F165_CAM_Examples);
END_IF;

Modified on: 2022-06-28Feedback on this pagePanasonic hotline