Professional Documents
Culture Documents
Tip No. 4
SIMATIC
S7-200 Tips
Group
2
Topic
How to use High Speed Counters of the S7-200 CPU 214
Overview
This Application Tip explains the function of one configuration for a high speed counter (HSC)
on the SIMATIC S7-200. High speed counters can be used in many different configurations for
processing the input signals of certain sensors (such as encoders).
This example uses a pulse output to generate high speed signals for the HSC to count. It is
possible to generate pulse strings along with pulse width modulations to control, for example, a
servo-motor. Since a pulse output is used, a CPU 214 DC/DC/DC is required.
The following application shows how a program should be structured to use a high speed
counter, and a simple feedback loop demonstrates the pulse output function.
Figure 4.1
page 1 / 8
S72_04e.doc
Version 3.2
SIMATIC S7-200 customers have free use of the application tips. These tips are only a general approach to using the S7-200 with various applications.
Your specific application may be different. It is your responsibility to use the SIMATIC S7-200 properly in your applications.
S7-200 Tip
Tip No. 4
Program Structure
Main Program
SBR1:
Start of HSC 0
SBR0: Initialization
and start of Pules
Program stops at the
end of the Pulse string
INT 0:
First Preset
INT 1:
Second Preset
INT 2:
Third Preset
1,500
INT 1
1,000
1,000
INT 0
INT 2
Program Description
This example demonstrates the usage of a high speed counter on the S7-200 CPU 214
DC/DC/DC. The counter used is a 2kHz software counter (also integrated in the CPU 212) and
counts more rapidly than the PLC scan time. In addition to a 2 kHz counter, the CPU 214 has
two 7 kHz hardware counters. Overall, the counters need 10 bytes of data memory for
controlling, counting, storing values, and reading the current state.
The size of the program is 96 words.
Chapter 6.1, High-speed Counter Instructions, of the S7-200 Programming Reference Manual
provides more information about high speed counters. Chapter 6.3 High-speed Output
Instructions gives additional information about pulse strings.
page 2 / 8
S72_04e.doc
Version 3.2
SIMATIC S7-200 customers have free use of the application tips. These tips are only a general approach to using the S7-200 with various applications.
Your specific application may be different. It is your responsibility to use the SIMATIC S7-200 properly in your applications.
S7-200 Tip
Tip No. 4
LAD (S7-MicroDOS)
STL (IEC)
Main Program
// The main program resets the output Q0.0 because it is needed for the
// pulse functions. In addition, it initializes the high speed counter HSC0
// and calls the subroutines 0 and 1 . HSC0 is thus enabled with
// the following features: updating of values possible and counting up.
// The program ends after the number of pulses (specified in the SBR 0 (SMD72)) is reached.
),567
6&$1%,7
604.
5
029B%
(1
.+),128760%
029B':
(1
.,128760'
029B':
(1
.,128760'
+'()
(1
+6&
02'
&$//
&$//
0(1'
page 3 / 8
LD
R
MOVB
MOVD
MOVD
1000, SMD42
// First Stop Value of
// HSC0 (PV)
HDEF
0, 0
CALL
// Calling Subroutine 0
CALL
// Calling Subroutine 1
MEND
S72_04e.doc
Version 3.2
SIMATIC S7-200 customers have free use of the application tips. These tips are only a general approach to using the S7-200 with various applications.
Your specific application may be different. It is your responsibility to use the SIMATIC S7-200 properly in your applications.
S7-200 Tip
Tip No. 4
Subroutines
// Subroutine 0 initializes and enables the pulse output.
// The output is defined in special memory byte SMB67: pulse strings, time base,
// updateability of values and enable. The word SMW68 contains the
// pulse time as a multiplier of the time base. Finally, the number of pulses
// to be generated will be specified in the special memory-double word.
6%5
$/:$<6
21%,7
60029B%
(1
.+',128760%
029B:
(1
.,128760:
029B':
(1
.,128760'
3/6
(1
4;
5(7
SBR
LD
MOVB
MOVW
1,SMW68
// Length of a pulse in ms
MOVD
30000, SMD72
// Number of pulses to be
// generated
PLS
RET
// Subroutine 0
// End of Subroutine 0
// Subroutine 1 starts the high speed counter HSC0 and assigns the Interrupt
// Routine 0 to Interrupt Event 12 (HSC0 current value = preset value). This event occurs
// as soon as the number of pulses counted (current value) reach the stop value (Preset).
// Finally, the interrupts are enabled.
6%5
$/:$<6
21%,7
60$7&+
(1
.,17
.(97
(1,
Copyright 1996 by SIEMENS
Status: 10/96
page 4 / 8
SBR
LD
ATCH
ENI
// Subroutine 1
S72_04e.doc
Version 3.2
SIMATIC S7-200 customers have free use of the application tips. These tips are only a general approach to using the S7-200 with various applications.
Your specific application may be different. It is your responsibility to use the SIMATIC S7-200 properly in your applications.
S7-200 Tip
+6&
(1
1
5(7
Tip No. 4
HSC
RET
// End of Subroutine 1
Interrupt routines
// Interrupt Routine 0 is called when the first Preset value (1000)
// of high speed counter 0 is reached. Output Q0.1 is set, and a
// new Preset value (1500) is loaded for the high speed counter.
// Interrupt Routine 1 is now assigned to Interrupt Event 12 instead of INT 0.
,17
$/:$<6
21%,7
604.
6
029B%
(1
.+$,128760%
029B':
(1
.,128760'
$7&+
(1
.,17
.(97
+6&
(1
1
5(7,
INT
// Interrupt Routine 0
LD
S
MOVB
16#A0, SMB37
// Set control bits to only
// load a new preset value
// (PV)
MOVD
1500, SMD42
// Next Preset value of
// HSC0
ATCH
1, 12
// Assign Interrupt Event 12
// to INT 1 instead of INT 0
HSC
RETI
page 5 / 8
S72_04e.doc
Version 3.2
SIMATIC S7-200 customers have free use of the application tips. These tips are only a general approach to using the S7-200 with various applications.
Your specific application may be different. It is your responsibility to use the SIMATIC S7-200 properly in your applications.
S7-200 Tip
,17
$/:$<6
21%,7
604.
6
029B%
(1
.+%,128760%
029B':
(1
.,128760'
$7&+
(1
.,17
.(97
+6&
(1
1
5(7,
Tip No. 4
INT
LD
S
MOVB
// Interrupt Routine 1
MOVD
1000, SMD42
// Next Preset Value (PV)
ATCH
2, 12
HSC
RETI
// End of Interrupt
// Routine 1
,17
$/:$<6
21%,7
604.
5
029B%
(1
.+',128760%
page 6 / 8
INT
LD
R
MOVB
// Interrupt Routine 2
S72_04e.doc
Version 3.2
SIMATIC S7-200 customers have free use of the application tips. These tips are only a general approach to using the S7-200 with various applications.
Your specific application may be different. It is your responsibility to use the SIMATIC S7-200 properly in your applications.
S7-200 Tip
029B':
(1
.,128760'
$7&+
(1
.,17
.(97
+6&
(1
1
5(7,
MOVD
Tip No. 4
0, SMD38
// Reset the current value of
// HSC0
ATCH
0, 12
// Reassign INT 0 to
// Interrupt Event 12
HSC
RETI
// End of Interrupt
// Routine 2
Conversion Notes
To Convert from IEC STL to S7-Micro/DOS STL:
z
z
z
z
z
page 7 / 8
S72_04e.doc
Version 3.2
SIMATIC S7-200 customers have free use of the application tips. These tips are only a general approach to using the S7-200 with various applications.
Your specific application may be different. It is your responsibility to use the SIMATIC S7-200 properly in your applications.
S7-200 Tip
Tip No. 4
General Notes
The SIMATIC S7-200 Application Tips are provided to give users of the S7-200 some indication
as to how, from the view of programming technique, certain tasks can be solved with this
controller. These instructions do not purport to cover all details or variations in equipment, nor do
they provide for every possible contingency. Use of the S7-200 Application Tips is free.
Siemens reserves the right to make changes in specifications shown herein or make
improvements at any time without notice or obligation. It does not relieve the user of
responsibility to use sound practices in application, installation, operation, and maintenance of
the equipment purchased. Should a conflict arise between the general information contained in
this publication, the contents of drawings or supplementary material, or both, the latter shall take
precedence.
Siemens is not liable, for whatever legal reason, for damages or personal injury resulting from
the use of the application tips.
All rights reserved. Any form of duplication or distribution, including excerpts, is only permitted
with express authorization by SIEMENS.
page 8 / 8
S72_04e.doc
Version 3.2
SIMATIC S7-200 customers have free use of the application tips. These tips are only a general approach to using the S7-200 with various applications.
Your specific application may be different. It is your responsibility to use the SIMATIC S7-200 properly in your applications.