G
‐
MAS
–
Gold
Maestro
Software
User’s
Manual
Software
User
Manual
XXXXXXXXXXXX(0.01)
3
‐
20
Figure
2:
MachineSequences()
function
Now
we
have
a
program
that
is
“slowly”
looping
in
a
background
–an
almost
idle
loop,
while
a
timer
function,
MachineSequencesTimer()
is
triggered
and
executed
each
TIMER_CYCLE
ms
(20ms
in
our
example),
to
execute
the
States
Machine.
Let’s
investigate
the
MachineSequencesTimer()
function
in
‐
depth.
3.5.3.
The MachineSequencesTimer() function
Figure
3
presents
the
general
structure
of
a
typical
MachineSequencesTimer()
function.
Why
"general"?
Because
it
does
not
present
the
details
of
the
States
Machines.
This
will
be
presented
only
later.
First,
understand
the
general
structure
of
the
MachineSequencesTimer()
function.
Initially,
upon
a
Timer
event
(each
TIMER_CYCLE
ms,
as
initialized
above),
the
MachineSequencesTimer()
function
is
triggered.
Its
first
action
is
to
call
the
ReadAllInputData()
function.
The
ReadAllInputData()
function
is
an
application
dependent
function.
Its
task
is
to
read
all
inputs
that
may
be
necessary
for
the
States
Machines
and
to
copy
them
into
variables
that
are
not
accessible
by
the
"external
world".
This
will
ensure
that
all
the
States
Machines
code,
as
executed
during
this
timer
event,
will
use
the
same
values
of
input
variables.
Why
this
is
needed?
As
the
timer
event
is
not
necessarily
synchronized
with
"external
world"
operations,
a
host,
for
example,
can
access
the
MODBUS
memory
and
modify
one
of
the
registers
that
are
used
by
the
States
Machines
code.
Similarly,
the
G
‐
MAS
core
can
obtain
a
new
reading
of
e.g.
drive's
speed
over
the
device
network.
As
such
"input
data"
can
be
changed
by
the
external
world
during
the
MachineSequencesTimer()
execution,
creating
inconsistent
operation
of
the
code's
flow.
It
is
necessary
first
to
copy
all
necessary
values
into
"mirror
variables"
and
only
then
start
to
use
these
mirror
variables,
which
will
remain
unchanged
until
the
next
timer
event.
This
is
exactly
the
task
of
the
ReadAllInputData()
function.
Depending
on
the
application,
it
should
access
all
necessary
variables
(of
the
MODBUS
memory,
from
the
G
‐
MAS
firmware
core,
etc.)
and
copy
them
into
"mirror
variables".
It
is
extremely
important
to
read
and
create
a
copy
of
all
necessary
"external
world"
variables
at
the
beginning
of
MachineSequencesTimer()
–
using
the
ReadAllInputData()
function
–
and
to
use
only
these
copies,
or
mirrors,
during
the
States
Machines
code.
This
will
avoid
difficulties
in
synchronization
and
inconsistent
code
behavior.