Programming for experts
P.
102 of 349
And the entire code:
MaxCycle is the maximum duration
of a processing MinCycleTime the
minimum duration.
Timerstop
Each timer needs its “own” variable
of remaining time
The variable remaining time can be
modified by the program and thus
influenses the course of the timer
In total the calculation of the cycle time as follows:
// Berechnet die minimale und maximale Zyklusdauer
// der Verarbeitung. Dabei ist die Performance-Angabe im EibStudio immer
// als Offset dabei.
Max=1000000000000000u64
Restzeit=0u64
StoppZeit=Max
MaxZyklusZeit=0u64
MinZyklusZeit=Max
// Im EibStudio ggf. geändert, Defaultwert ist 20ms
PerformanceZeit=20u64
// Die erste Zyklus kann etwas länger dauern ...
if afterc(after(systemstart(),10000u64), Max, Restzeit) then {
StoppZeit=0u64;
} endif
MaxZyklusZeit=max(StoppZeit-Restzeit-PerformanceZeit,MaxZyklusZeit);
MinZyklusZeit=min(StoppZeit-Restzeit -PerformanceZeit,MinZyklusZeit);
The timer uses the argument
afterc
remaining time
(s.a.) for storing the elapsed time timer. The user
must therefore ensure that various
afterc
timer use different variables to this store:
// Zähler 1
RestZeit1=0u64
RestZeit2=0u64
if afterc(systemstart(),10000u64, Restzeit1) then {
write('1/2/3'c14,$Timer1$c14)
} endif
if afterc(systemstart(),13000u64, Restzeit2) then {
write('1/2/3'c14,$Timer2$c14)
} endif
The same applies to the function
delayc(
TriggerVariable {Typ b01}, Max{Typ u64}, RemaingTimest {Typ u64}
)
whose timer – just like
delay
– through every change of the
TriggerVariable
(1. argument) from OFF
to ON is triggered again. Again that for the rest of time each with its own variable must be used
otherwise disrupt the timer each other.
When the timer expires the value of 3. arguments (
remaining time
)
to 0u64, upon triggering of the
timer it is set to the value of
Max
. If the
remaining time
is changed during an active phase by the user
so the expiration time of the timer ist changed.
RestZeit1=0u64
if afterc(systemstart(),10000u64, remainingtime1) then {
write('1/2/3'c14,$Timer1$c14)
} endif
if remainingtime1>1000u64 then remainingtime1=500u64 endif
remainingtime2=0u64
if delayc(systemstart(),13000u64, remainingtime2) then {
write('1/2/3'c14,$Timer2$c14)
} endif
In the above example only the
afterc
timer is changed the rest of the time variable
delayc
timer
remains unchanged.
HandbuchEibPC_USA-30.odt, 2017-05-11
Enertex
®
Bayern GmbH - Erlachstraße 13 - 91301 Forchheim - [email protected]