Programming for experts
P.
101 of 349
Programming for
experts
Performance
Cycletime
Background
A countdown – counter:
remaining time
is counted down by
Max
Calculating of cycle times
In the following paragraph program code and examples will be explained, which get deeper in the
programming of the Enertex® EibPCs. By the way interesting code fragments from the macro
libraries as well as the background of the procedure are explained.
One of the most asked questions of the user is: How much time does the
Enertex® EibPC in fact
need for the processing? In principal it depends on the size of program respectively the kind of
programming and occurring events. By “validation” (p.
121) of the program, only those parts of the
program are activated per cycle that actually change. Therefore in the normal case the processing is
done in less than 1 ms in more complex programs in a few ms. The time of cycle depending of the
program will fluctuate. Therefore the minimal and maximal processing time is interesting while using
the Enertex® EibPCs.
About the Enertex® EibStudio can after each cycle the operating system of EibPCs a break of up to
250 ms are given, e.g. to send emails to process webserver requests etc. The minimal time slices of
the Linux system are about 1 ms.
To calculate the processing time of the Enertex® EibPCs, the function
afterc
can be used:
afterc(
variable {Typ b01}, max{Typ u64}, remaining time {Typ u64}
)
This function is triggered as the
after
-function with a change of
variable
(1. argument) from OFF to
on: The return value is after the specified time
max
(2. argument in ms) for one processing cycle to
ON. In each cycle from the beginning of the trigger pulse of variable while the remaining time
variable
while the
remaining time
(3. argument) is updated as countdown timer. The initial value of
variable
is
max
. The change of
remaining time
is always at exactly the time at which the processing
is active in one cycle. The chance of
remaining time
is thus the sum of the aforementioned deadtime
plus the processing time of the preceding cycle. This allows the cycle time calculated by using
systemstart
triggers a
afterc
-timer and starts the countdown of
remaining time
e.g.
Max=1000000000000000u64
if afterc(systemstart(), max, remaining time) then { ..... } endif
Max
is here chosen as large as possible to ensure that the end of the countdown is reached not
possible.
With the code
MaxZyklusZeit=max(StoppZeit-Restzeit-PerformanceZeit,MaxZyklusZeit);
MinZyklusZeit=min(StoppZeit-Restzeit -PerformanceZeit,MinZyklusZeit);
can thus be calculated with an accuracy of about ± 1ms (time slice Linux system time) the minimum
and maximum cycle time.
A special case is still taken into account: During the initialisation of the very first program run all parts
of the program must be run through, then the basis of the validation later “only when neccessary” are
evaluated. Therefore the first processing loop may well need serveral hundred ms, when the program
reaches a memory usage of about 30. The start of the countdown counter must therefore be delayed
if you do not want to take into account the initialisation of the program as a special case in the
measurement of cycle times.
Therefore delaying the pulse of
systemstart
at startup with another timer
after
timer by a nesting:
if afterc(after(systemstart(),10000u64), Max, Restzeit) then { ... } endif
HandbuchEibPC_USA-30.odt, 2017-05-11
Enertex
®
Bayern GmbH - Erlachstraße 13 - 91301 Forchheim - [email protected]