Writing the high-speed counter control code

The special data register where the high-speed counter and pulse output control code are stored can be accessed with the system variable sys_wHscOrPulseControlCode. (The system variable sys_wHscOrPulseControlCode corresponds to special data register DT90052.)

Operations performed by the high-speed counter control code

The control code settings for each channel can be monitored using the system variables sys_wHscChannelxControlCode or sys_wPulseChannelxControlCode (where x=channel number).The settings of this system variable remain unchanged until another setting operation is executed.

Cancelling high-speed counter instructions (bit 3)

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.

Enabling/disabling the reset input (hardware reset) of the high-speed counter (bit 2)

X0 High-speed counter input

  1.  (1) Elapsed value
  2.  (2) Bit 2 of high-speed counter control code (enable/disable reset input)
  3.  (3) Elapsed value is reset to 0
  4.  (4) Reset not possible

When bit 2 of the control code is set to TRUE, a hardware reset using the reset input specified in the system registers is not possible. Counting will continue even if the reset input has turned to TRUE. The hardware reset is disabled until bit 2 is reset to 0.

Enabling/disabling counting operations (bit 1)

Count input control operation

X0 High-speed counter input

  1.  (1) Elapsed value
  2.  (2) Bit 1 of high-speed counter control code (count)

When bit 1 of the control code is set to TRUE, counting is prohibited and the elapsed value keeps its current value. Counting is continued when bit 1 is reset to FALSE.

Resetting the elapsed value (software reset) of the high-speed counter to 0 (bit 0)

X0 High-speed counter input

  1.  (1) Elapsed value
  2.  (2) Bit 0 of high-speed counter control code (software reset)

When bit 0 of the control code is set to TRUE, a software reset is performed and the elapsed value is set to 0. The elapsed value keeps the value 0 until bit 0 is reset to FALSE.

Description for FP-Sigma, FP-X, FP0R

Bits 0–15 of the control code are allocated in groups of four. The bit setting in each group is represented by a hex number (e.g. 00020000 0000 1001 = 16#2009).

  1.  (1) Channel number (channel n: 16#n)
  2.  (2) Cancel high-speed counter instruction (bit 3)

    0: continue/1: cancel

  3.  (3) Reset input (bit 2) (see note)

    0: enabled/1: disabled

  4.  (4) Count (bit 1)

    0: permit/1: prohibit

  5.  (5) Reset elapsed value to 0 (bit 0)

    0: no/1: yes

Example: 16#2009

Group

Value

Description

IV

2

Channel number: 2

III

0

(fixed)

II

0

(fixed)

I

9

Hex 9 corresponds to binary 1001

Cancel high-speed counter instruction: cancel (bit 3)

1

Reset input: enabled (bit 2)

0

Count: permit (bit 1)

0

Reset elapsed value to 0: yes (bit 0)

1

Description for FP0, FP-e

Bits 0–15 of the control code are allocated in groups of four, each group containing the settings for one channel. The bit setting in each group is represented by a hex number (e.g. 0000 0000 1001 0000 = 16#90).

  1.  (1) Cancel high-speed counter instruction (bit 3)

    0: continue/1: cancel

  2.  (2) Reset input (bit 2) (see note)

    0: enabled/1: disabled

  3.  (3) Count (bit 1)

    0: permit/1: prohibit

  4.  (4) Reset elapsed value to 0 (bit 0)

    0: no/1: yes

Group

IV

III

II

I

Channel

3

2

1

0

Example: 16#90

Group

Value

Description

IV

0

III

0

II

9

Channel number: 1

Hex 9 corresponds to binary 1001

Cancel high-speed counter instruction: cancel (bit 3)

1

Reset input: enabled (bit 2)

0

Count: permit (bit 1)

0

Reset elapsed value to 0: yes (bit 0)

1

I

0

NOTE

Turning the reset input to TRUE, sets the elapsed value to 0. Use the reset input setting (bit 2) to disable the reset input allocated in the system registers.

Example: software reset for channel 0

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
		bSoftwareReset: BOOL:=FALSE;
			(*Activates the function*)
	END_VAR
	VAR CONSTANT 
		HSC_CH0_RESET_ELAPSED_VALUE: WORD:=16#0001;
			(*Resets elapsed value of channel 0*)
		HSC_CH0_CONTINUE: WORD:=16#0000;
			(*Continues counting in channel 0*)
	END_VAR
	VAR 
	END_VAR

POU body

The reset is performed in step 1, and 0 is entered just after that in step 2 to start counting. A reset alone does not start counting.

LD body

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
        ACTIVE_NETWORK := 0 ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 8 ;
        NETWORK_BODY
B(B_VARIN,,HSC_CH0_RESET_ELAPSED_VALUE,22,2,24,4,);
B(B_CONTACT,,bSoftwareReset,5,1,7,3,R);
B(B_VARIN,,HSC_CH0_CONTINUE,22,6,24,8,);
B(B_F,E_MOVE!,Instance,24,0,30,4,,?DEN?D?AENO?C);
B(B_VAROUT,,sys_wHscOrPulseControlCode,30,2,32,4,);
B(B_F,E_MOVE!,Instance,24,4,30,8,,?DEN?D?AENO?C);
B(B_VAROUT,,sys_wHscOrPulseControlCode,30,6,32,8,);
L(1,2,5,2);
L(7,2,8,2);
L(8,2,24,2);
L(8,6,24,6);
L(8,2,8,6);
L(1,0,1,8);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

if DF(bSoftwareReset) then
    sys_wHscOrPulseControlCode:=HSC_CH0_RESET_ELAPSED_VALUE;
    sys_wHscOrPulseControlCode:=HSC_CH0_CONTINUE;
end_if;

Example: software reset for channel 1 (FP-SIGMA, FP-X, FP0R)

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
		bSoftwareReset: BOOL:=FALSE;
			(*Activates the function*)
	END_VAR
	VAR CONSTANT 
		HSC_CH1_RESET_ELAPSED_VALUE: WORD:=16#1001;
			(*Resets elapsed value of channel 1*)
		HSC_CH1_CONTINUE: WORD:=16#1000;
			(*Continues counting in channel 1*)
	END_VAR
	VAR 
	END_VAR

POU body

The reset is performed in step 1, and 0 is entered just after that in step 2 to start counting. A reset alone does not start counting.

LD body

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
        ACTIVE_NETWORK := 0 ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 8 ;
        NETWORK_BODY
B(B_VARIN,,HSC_CH1_RESET_ELAPSED_VALUE,24,2,26,4,);
B(B_CONTACT,,bSoftwareReset,5,1,7,3,R);
B(B_VARIN,,HSC_CH1_CONTINUE,24,6,26,8,);
B(B_F,E_MOVE!,Instance,26,0,32,4,,?DEN?D?AENO?C);
B(B_VAROUT,,sys_wHscOrPulseControlCode,32,2,34,4,);
B(B_F,E_MOVE!,Instance,26,4,32,8,,?DEN?D?AENO?C);
B(B_VAROUT,,sys_wHscOrPulseControlCode,32,6,34,8,);
L(1,2,5,2);
L(7,2,8,2);
L(8,2,26,2);
L(1,0,1,8);
L(8,6,26,6);
L(8,2,8,6);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

if DF(bSoftwareReset) then
    sys_wHscOrPulseControlCode:=HSC_CH1_RESET_ELAPSED_VALUE;
    sys_wHscOrPulseControlCode:=HSC_CH1_CONTINUE;
end_if;

Modified on: 2019-01-25Feedback on this pagePanasonic hotline