Program instructions   
7.6 Counters 
  S7-200 SMART 
280  System Manual, V2.3, 07/2017, A5E03822230-AF 
Initialization of modes 9 and 10 
The following steps describe how to initialize HSC0 as an AB quadrature phase counter 
(modes 9 and 10): 
1.  Use the first scan memory bit to call a subroutine in which the initialization operations are 
performed. Since you use a subroutine call, subsequent scans do not make the call to the 
subroutine, which reduces scan time execution and provides a more structured program. 
2.  In the initialization subroutine, load SMB37 according to the desired control operation. 
Example (1x counting mode): SMB37 = 16#FC produces the following results: 
–  Enables the counter 
–  Writes a new current value 
–  Writes a new preset value 
–  Sets the initial direction of the HSC to count up 
–  Sets the reset input to be active high 
Example (4x counting mode): SMB37 = 16#F8 produces the following results: 
–  Enables the counter 
–  Writes a new current value 
–  Writes a new preset value 
–  Sets the initial direction of the HSC to count up 
–  Sets the reset input to be active high 
3.  Execute the HDEF instruction with the HSC input set to 0 and the MODE input set to one 
of the following: 
–  Mode 9 for no external reset 
–  Mode 10 for external reset 
4.  Load SMD38 (double-word-sized value) with the desired current value (load with 0 to 
clear it). 
5.  Load SMD42 (double-word-sized value) with the desired preset value. 
6.  In order to capture the current-value-equal-to-preset event, program an interrupt by 
attaching the CV = PV interrupt event (event 12) to an interrupt routine. See the section 
on enabling interrupts (ENI) for complete details on interrupt processing. 
7.  In order to capture direction changes, program an interrupt by attaching the direction 
changed interrupt event (event 27) to an interrupt routine. 
8.  In order to capture an external reset event, program an interrupt by attaching the external 
reset interrupt event (event 28) to an interrupt routine. 
9.  Execute the global interrupt enable instruction (ENI) to enable interrupts. 
10.Execute the HSC instruction to cause the CPU to program HSC0. 
11.Exit the subroutine.