Sei sulla pagina 1di 3

How to calculate frequency from counting pulses measurement?

Denilson Pegaia A&D

Motivation/Benefit:
Many times is necessary to measure frequency in industrial automation. Normally it is done from a pulses
generator signal. The S7-200 CPUs have high speed counters incorporated to do this task. The conversion
counting pulses to frequency, however, must be done by user software. Despites it is a not complicated
evaluation, many users of S7-200 have difficult to implement it. Think in this case, I program an easy subroutine
to do this calculation.

FAQ Text
Many times is necessary to measure frequency in industrial automation. Normally it is done from a
pulses generator signal. The S7-200 CPUs have high speed counters incorporated to do this task.
The conversion of the measured pulses to frequency must be done by the user software. The follow
article explain the principle of this conversion and gives a subroutine that does this task.
Principles
Frequency is calculated by the formula:
Frequency = number of events / time interval.
Normally the number of events is done by a counter. If the counter is runs continuously, the number
of the events is done by the difference of the counter values at begin and at end of the time interval.
Frequently, the number of events is given by a pulse generator. In this case it is common that the
pulse generator gives many pulses per rotation. If the desired event to be measure is the rotation
itself, it is necessary to divide the counter value per the ratio pulses per turn of the pulse generator.
The frequency unit depends also of the time interval. The most used frequency unit is Hertz, witch
correspondent time interval is one second.
Frequently it is not possible to wait one second to obtain a frequency measurement. In this case, it is
possible to have others samples intervals adapting and respecting the original formula. The
calculation error, however, is also dependent of the sample interval (smalls sample interval leaves to
bigger errors).
Error % = 100 / number of events in the sample interval
Other unit, normally used with motors, is rpm. In this case, it is measured rotations per minutes.
Frequency gave in Hertz und RPM can be related by the formula:
RPM = Frequency Hertz / 60

Sample program
The follow sample program [project1.mwp] brings a subroutine that calculates a frequency from a
counting value.
In the first network a high speed counter is configured:

[hsc.bmp]
In the second network a sub routine is called to convert the counted pulses to frequency:

[sub.bmp]
Parameter description:
Parameter

Type

Format

Description

Counter
MinTimeInterval

Input
Input

DINT
FLOAT

PulsePerRotation

Input

FLOAT

Reset
ElapsedTime

Input
Input Output

BOOL
FLOAT

ElapsedCountValue

Input Output

DINT

Hz
rpm

Output
Output

FLOAT
FLOAT

Input for high speed counter value.


Minimal sample time for measure (unit:
seconds).
Pulses per rotation factor (from encoder to axis,
for example). The counter value is divided by
this number to obtain the number of effective
events. If the counter value should be
evaluated integrally, this variable must be set to
1.0.
Reset
Auxiliary variable that measure how many of
the minimal time interval was elapsed. It was
used internally for the conversion evaluation, so
it must not be overwrite by the user program.
Auxiliary variable that measure how many
events was occurred in the correspondent time
interval. It was used internally for the
conversion evaluation, so it must not be
overwrite by the user program.
Frequency in Hertz.
Frequency in rpm.

Important:

The sample program is freeware. Any user can use copy and forward this program FREE OF
CHARGE. The authors and owners of this program take no responsibility whatsoever for the
functionality and compatibility of this software. Use of the software is entirely at the user's own risk.
Since this software is free of charge, there is no warranty, nor claim for error correction and hotline
support.

Potrebbero piacerti anche