Automatismos - Universidad de Sevillafabio/TranspAuto2005.pdf · Automatismos. 5º Ing. Telecom....
Transcript of Automatismos - Universidad de Sevillafabio/TranspAuto2005.pdf · Automatismos. 5º Ing. Telecom....
1
Automatismos Automatic Systems
5º Ingeniero de Telecomunicación
Transparencias de la asignatura
Fabio Gómez- Estern. ES Ingenieros. 2005
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 2
Lesson 1 Index
� Introduction
� Evaluation of modelling tools
� Tables and phase diagrams
� Reduced state graph
� Petri Networks
� Introduction
� Description
� Modelling examples
� Advantages and comparison with other tools
2
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 3
Introduction
Systemsdescription
� A system description consists of the development
of a model of the system itself. Two types of
models can be distinguished:
� Structural models: defining the parts of the system
� Functional models: defining how the system works
� Petri Networks (PN) are intended for studying logic
sequential systems from a functional point of view
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 4
IntroductionSeparation between Operating and Control Parts
� Most Logic Sequential Systems can be represented
and divided into two Subsystems
� Operating part (OP): makes the process run by transforming the input variables into output variables,
and issuing reports. It comprises the elements inside process (Sensors, motors, actuators, valves, etc.)
� Control part (CP): From the established set points, and
the reports, it provides adequate orders for commanding the behavior
3
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 5
IntroductionSeparation between Operating and Control Parts
OperativePart
Reports
CommandsControl
Part
Inputs
Outputs
Set p oints, references
External outputs, if required
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 6
IntroductionFinite Automata: mathematical definition� Definition of Automaton : “Device capable of emulating or following
certain movements”.
� Formally, a finite automaton is a Discrete System defined by the quintuplet <E,S,Q,d,l>
� Finite set of input symbols: E={E i}
� Finite set of output symbols: S={Sj}
� Finite set of internal states: Q={Qk}
� Transition function between states in terms of inputs and previous states: dddd:Q x E → Q
� Output function, in terms of inputs and states
l:Q x E → S
4
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 7
IntroductionTable representation of finite Automata
� Consider a finite Automaton with E={a,b} and S={x,y}.The prescribed behavior is: the output at an instant “k”
should be S(k)=xif and only if the last three inputs follow the sequence “a-b-a” and S(k)=yotherwise.
� Q={Qa,Qab,Qbb} are the significant
states of the problem
� Qa: last input was “a”
� Qab: last 2 inputs were “a-b”
� Qbb: last 2 inputs were “b-b”
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 8
Evaluation of ToolsPhase diagrams and tables
� The procedure is: Build a table associating the states with the inputs
in order to indicate the corresponding outputs and the new states.
� Graphical representation in phase diagrams.
Phase table Phase diagram
5
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 9
Evaluation of ToolsPhase diagrams and tables – Example: Cart System
� When button M is pressed, the cart
moves right (d), until B is rechaed.
Once there, it starts moving left (i) until A is reached, and then stops.
� E={M,A,B}
� S={i,d}
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 10
Evaluation of ToolsTable and phase diagrams - criticism
� They are exhaustive descriptions, as they gather all data of all possible combinations of inputs and states.
� Industrial systems are characterized by
� Large number of inputs and outputs.
� Largely unspecified. Many I/O pairs (E x Q) have no physical meaning.
� These methods have little practical use. They are difficult
to implement when the number of inputs increases.
6
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 11
Evaluation of ToolsReduced state graph
� It introduces the concept of Receptivity.
� When the system is in a specific state, it is only receptive (or sensitive) to a small subset of external events capable
of inducing a state transition.
� Hence, there is no need to analyze all possible
combinations of inputs for every single state.
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 12
Evaluation of ToolsReduced state graph - Examples
� The RG (Reduced State Graph) is a graph where the logical condition that triggers a transition between 2 states is described as any logical function of the inputs.
� Moving Cart Example
� The resulting description is simpler, direct, and more intuitive.
7
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 13
Evaluation of ToolsReduced state graph – Examples continued� Two carts come and go. They are synchronized at the right ends. Both carts must have reached (B,D) in order to start moving backwards.
A small specification change (e.g. add a new cart) may affect the description significantly.
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 14
Evaluation of ToolsReduced state graph – Examples continued
� Three carts come and go, synchronized at the right ends.
� The number of states grow at a rate of 2N+1-1, where N is the number of carts.
� All combinations of events are evaluated taking into account the order of occurrence, though it might be irrelevant.
8
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 15
Evaluation of ToolsReduced state graph – Examples continued
end(A)
end(B)
end(B)
end(A)
� Two simultaneous actions A and B, followed by C, are composed of subtasks.
DRAWBACK: All possible finishing order of subtasks Should be considered
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 16
Evaluation of ToolsReduced state graph – Criticism
� Advantages� When introducing the concept of receptivity, the system
description is significantly simplified.
� The information used for modelling is minimum and necessary.
� Drawbacks� When there are concurrent evolutions, this method requires
the evaluation of all possible chronological orderings of external events.
� Local changes may result in total redefinitions of the description.
� It is not suitable for a descending description (“top- down”).
9
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 17
Petri NetsIntroduction http://www.daimi.au.dk/PetriNets/
� Created by German Prof. C.A. Petri in the 60’s.� Structure
� A Petri Network or (Petri Net) is a mathematical tool (with it associated graphical representation) that allows to model the behavior of a large variety of systems, being of special interest in the logical sequential and concurrent systems.
� It consists of an oriented graph, with two types of nodes: Places and Transitions, joined together arternatively by Arcs. The Places are represented by circles, and the Arcs by segments.
� The Arcs are oriented and they connect Places with Transitions and vice- versa, but never 2 Places or 2 Transitions at a time.
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 18
Petri Nets (PN)Introduction (continued)
� Petri Nets permit to model and analyze the Control Subsystem (CP) of discrete systems with concurrent evolutions.
� In order to use them in application modelling, they must be endowed with an interpretation, by assigning physical meaning to the evolution conditions of the network and to the actions triggered by that evolution.� Petri Net → Structure
� Interpretation → Physical Significance
� The evolution of a PN without interpretation is said to be autonomous.
10
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 19
Petri Nets Introduction (continued)
� Behavior:� A Place may contain a nonnegative number of Marks. Each mark is represented by a dot in the Place.
� The set of Marks associated, at a given time, to the places, is denoted the Network Marking.
� For the functional description of a PN, the following associations are made,� Places → actions or outputs� Transitions → events (as functions of inputs and actions)
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 20
Petri Nets Introduction (continued)
� Behavior:� The dynamics of the PN is represented by the evolution of its marking.
� The basic rules conducting the evolution of the marking are,� A Place Li is an input Place of the Transition Tj, if there exists an Arc
oriented from Li to Tj.� A Place Li is an output Place of the Transition Tj, if there exists an Arc
oriented from Tj to Li.� A Transition is enabledif all its input places are marked.� An enabled Transition is fired if the event associated with it is verified.
A Firing of a transition consists of removing marks from each of its input Places, and adding marks to each of its output Places.
11
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 21
Petri Nets Description model. Structure
� Autonomous PN:� When analyzing autonomous PN we must observe its structure and behavior.
� Structural model of a PN� Generalized PN: a quadruplet R=<P,T,a,ba,ba,ba,b> such that
� P: Finite nonempty set of Places.� T: Finite nonempty set of Transitions.� aaaa: P x T → N Pre-incidence function� bbbb: T x P→ N Post-incidence function
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 22
Petri Nets Description model. Graphical Representation
� Oriented Graph with 2 types of nodes:� Places (circles), to which “long-lasting” actions are associated.
� Transitions (line segments), to which “instantaneous” actions are associated.
� The Arcs join places with transitions and vice-versa.
� The marks reside in places and they represent their active state.
12
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 23
Petri Nets Description model. Graphical Representation
� Each Arc is labelled with a nonnegaive integer aaaa(p,t) or bbbb(p,t) called weight of the Arc.
� There exists and Arc oriented from Place Pi to Transition Tj � aaaa(pi,tj) >0.
� There exists and Arc oriented from Transition Tk to Place Pl � bbbb(tk,pl) >0
� As a general rule, a non-labelled Arc has weight 1 and if weight>1, it must be labelledwith the corresponding weight.
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 24
Petri Nets Description.
� For a generalized Petri Net, R=<P,T,a,ba,ba,ba,b>, tXXXXT, pXXXXP; the following sets are defined:� Set of input places ot t:
�t={ pXXXXP / aaaa(p,t)>0 };� Set of output places of t:
t� ={ pXXXXP / bbbb(t,p)>0 };� Set of input transitions of p:
�p={ tXXXXT / aaaa(p,t)>0 };� Set of output transitions of p:
p� ={ tXXXXT / bbbb(t,p)>0 };
13
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 25
Petri Nets Description.
� Example:�t1={pa,pb};
t1�={pc,pd};�ph={t4,t8};
ph�={t6,t7};
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 26
Petri Nets Description. Behavior� Marking: the Marking M is a mapping P→N that links an integer number (of Marks) to each Place.
� Marked Petri Net: A pair <R,M0>, where M0 is theinitial Marking.
� Enabled Transition: Transition t is enabled for the Marking M ����each input Place has, at least, aaaa(p,t) marks.
p XXXX�t , M(p)≥aaaa(p,t)� Evolution of Markings: the firing of an enabled Transition implies the removal of aaaa(p,t) Marks from each Place p XXXX�t and the addition of bbbb(t,p) Marks to each place p XXXXt�.
14
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 27
Petri Nets Description. Markings evolution. Examples
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 28
Petri Nets Description. Properties (Deadlocks)� Live Transition: (for a given initial Marking M0). If, for all marking M reachable from M0, there is a marking, successor of M, from which the Transition can be fired.
� Live Petri Net: (for a given initial Marking M0), if all its transitions are live for that Marking.
� Bounded Petri Net: (for a given initial Marking M0). There is a constant k>0 such that any marking reachable from M0 is such that no place has more than k Marks.
� Binary Petri Net: (for a given initial Marking M0). If any Marking reachable from M0 is such that no place has more than 1 Mark.
15
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 29
Petri Nets Description. Properties. Example
� Is this a Live Petri net?� Is this a Binary Petri Net?
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 30
Petri Nets Description. Properties.
� Live is too hard a property.
� “Liveness” levels. L(M0)=set of possible firing sequences from M0.
16
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 31
Petri Nets Description. Properties.
� Marking Related Properties� Conformed Petri Net: If it is Live and Binary� Conflicting Transitions: some simultaneously enabled transitions are in conflict if they are descendants from the same Place and this does not have enough number of Marks to fire them simultaneously.
� A conflict is made effective if the events associated to the transitions are verified simultaneously. An effective conflict corresponds to ambivalences in the description.
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 32
Petri Nets Description. Properties. Example.
Not LiveNot BinaryConformed
•Are there conflicting transitions?•And in the previous PN? Where?
17
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 33
Petri Nets Description. Matrix representation.
A PN may be represented by means of two matrices. Assuming |P|=n and |T|=m, then we define� Pre-incidence matrix C-=[Cij
-]n*m with Cij-=aaaa(pi,tj)
� Post-incidence matrix C+=[Cij+]n*m with Cij
+=bbbb(tj,pi)
� Ordinary PN: The one whose incidence functions values are 0 or 1.
aaaa(pi,tj) XXXX{0,1}, bbbb(tj,pi) XXXX{0,1}, tXXXXT, pXXXXP
� Pure PN: the one where no place is simultaneoulsy input and output place of the same transition.
aaaa(pi,tj) bbbb(tj,pi)=0 for all (i,j)
The matrix representation of a PN may be simplified by using a unique incidence matrix
C=C+- C-
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 34
Petri Nets Description. Matrix representation.
� Matrix representation of an ordinary pure PN
18
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 35
Petri Nets Matrix representation. Marking & Evolution
� The marking vector of an ordinary and pure PN is a column vector of |P|=n elements in the form M(pi), where each element represents the number of existing marks in each place. Therefore, in the last example
M0T=(1 0 0 0 0 0 0 0 1)
� Marking evolution rule: if transition t is enabled by the Marking Mi and t is fired, the new parking Mj for each place, p is evaluated as
Mj(p)=Mi(p)+b(t,p)-a(p,t)
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 36
Petri Nets Matrix representation. Firing sequences
� A firing sequence (ssss) from a marking M0 is represented by the sequence of transitions such that the firing of each of them leads to a marking that guarantees the enablement of the next transition in the sequence
M0 – t1 –→ M0 –t2 –→ M0 –t3 –→… – tr –→ Mq���� M0 – ssss –→ Mq
� In the last example, the sequence of firings s=s=s=s=t8t6t1t3t2t4t6 is applicable
M0T=(1 0 0 0 0 0 0 0 1) – ssss1 –→M7
T=(0 1 0 0 0 0 1 0 0)
19
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 37
Petri Nets Matrix representation. Firing sequences
� Characteristic vector associated to a sequence of firings: the vector ssssXXXXNm whose i-th element is the number of times that transition t has been fired in the sequence.
� For instance, the characteristic vector associated to the sequence s=s=s=s=t8t6t1t3t2t4t6 would be
ssss8T====(1 1 1 1 0 2 0 1)
� A Marking M is reachable from an initial marking M0
���� there exists a sequence of firings applicable from M0 that transforms M0 into M. llllssss/ M0 -ssss- →M
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 38
Petri Nets Matrix representation. State equation
� Let be C the pre-incidence matrix of a pure and marked Petri Net. From the definition of C and the marking evolution rule the following Petri net state equation is derived.
Mk = Mk-1 +C*Uk=M0 +C*s, if M0 -s-→M
� Where� Mk marking after the k- th firing
� Mk-1 marking after the (k- 1)- th firing
� Uk=vector with all zero elements except the i- th, if ti fires at instant k
20
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 39
Petri Nets Interpretation
� We have previously seen a Petri Net (generalized) as a mathematical structure, a marking and some evolution rules (dynamical properties). Un order for a PN to represent a real-world system, it is necessary to associate it with an interpretation which is defined as� Physical meaning of firing conditions� Actions generated by the evolution of the marking
� The internal state of a PN will be always given by the marking.
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 40
Petri Nets Interpretation
� Interpreted Petri Nets:� In order to give interpretation to a Petri Net it is necessary to define the following elements
� Set of inputs: X={x1,x2,…xe}
� Set of outputs: Y={y1,y2,…ys}
� Set of impulse outputs: Z={z1,z2,…zq}
� Some other useful definitions� External Condition (Ci): a combinational logic function of the input (and output) variables of the system.
� Event (Ei): a change in the logic state of an external condition.
21
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 41
Petri Nets Interpretation
� Interpreted Petri Nets:� Two types of interpretation
� Actions generated associated to places.
� Actions generated associated to transitions.
� As a general rule� Transitions: Events, external conditions, impulse outputs
� Places: Level outputs
� If the activation of an output is linked to external conditions, it is said to be a conditioned output.
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 42
Petri Nets Interpretation
� An interpreted PN:� A marked PN
� An application T->E (events)
� An application T->C (external conditions)
� An aplication T->Z (impulse outputs)
� An application P*C->Y (level outputs)
� Three rules of marking evolution in interpreted Petri Nets1. Firing of enabled transition ti: iff Ci&Ei.
2. When a transition is fired, all its associated impulse outputs are generated.
3. If a place p is marked and the associated external conditions are satisfied, all level outputs are activated.
22
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 43
Lesson 2 Functional modelling of concurrent systems
� Table of contents:� Concurrency.
� Shared resources and mutual exclusion
� Task Synchronization
� Classical modelling examples
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 44
Petri NetsTypical configurations
� Places:� A place with several input/output arcs
is called “OR-node”. There are two particular cases of OR-nodes:� Selection: 1 input arc and several output
arcs� Attribution: several input arcs and 1 output
arcs
� Transitions:� A transition with several input/output
arcs is called “AND-node”. There are two particular cases of AND-nodes:� Distribution: 1 input arc and several output
arcs� Junction: several input arcs and 1 output
arcs
General OR-node Selection Attribution
General AND-node Distribution Junction
23
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 45
Petri NetsTypical configurations
� OR-node: when one of the 3 transitions is fired (either 1st, or 2st or 3rd) the corresponding output place is selected.
� OR-node: when one of the 3 transitions is fired (either 1st, or 2st or 3rd) the output place is granted (attributed) the right to execute.
� AND-node: when the transition is fired, the execution (mark) is distributed between one place AND another AND another…
� AND-node: when the transition is fired, the execution threads join together in a unique output place.
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 46
Petri NetsTypical scenarios: Timing in Petri Nets
� Assume the system must stay in a specific place for a fixed time interval. An external Timer will be used. The timer starts when the place is activated (when its input transition is fired)
� The same timer may be associated to several transitions (if they are not conflicting)
24
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 47
Petri NetsTypical scenarios: Counting in Petri Nets
� Assume that the system must stay in a specific state until a certain number of events of one type have occurred.
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 48
Petri NetsModelling examples: moving carts
Two carts Three carts
25
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 49
Petri NetsModelling examples: simultaneous actions
2 simultaneousactions
2 simultaneousactions withsubactions
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 50
Petri NetsAdvantages and comparison of tools
� Clear advantages in concurrent systems
� Descriptions are less complex. In the moving carts example, the number of places is 4N vs. 2N+1-1 states for the reduced state graphs (for N=10, 40 places vs. 2047 states). This is due to the fact that the state is determined by the marking.
� It is much simpler to introduce local variations.
26
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 51
Petri NetsModelling of complex systems - Concurrency
� Concurrency refers to the simultaneous execution of processes, making it harder to visualize the concept of state.
� In Petri Nets, concurrency is modelled by means of transitions with more output places than input places (distribution), thus increasing the total number of marked places.
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 52
Petri NetsModelling of complex systems – Mutual exclusion
� Mutual exclusion refers to resources that can only be used by a single process or a limited number of them.
� In Petri Nets, mutual exclusion is modelledby means of places with more output transitions than input transitions(selection).
27
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 53
Petri NetsModelling of complex systems – Synchronization
� Synchronization refers to the need for coordinating the endings of a set of processes.
� In Petri Nets, synchronization is modelledby means of transitions with several input places (distribution). They may represent task endings (junction) or synchronization points (wait points before a start).
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 54
Petri NetsModelling of complex systems – Alternating tasks
� Two processes (each modelled as Petri subnet) could alternate without any need for a common resource, and it can occur between more than two processes. For example, an alternating behavior is desired between Process A, B and C. Sequence: A- >B- >C- >A- >B- >C
28
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 55
Petri NetsModelling of complex systems – Modularity
� A set of sequences represented by a Petri subnet may be reused at several points of a network, by simply considering that the return point of the sequence must be remembered.
� Moreover, the function call will not be executed while the module is running.
� With this tool, modularity is gained, and smaller size designs are achieved
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 56
Petri NetsModelling of complex systems – Modularity
Rep
eate
d se
quen
ce
29
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 57
Petri NetsModelling of complex systems – Modularity
Rep
eate
d se
quen
ce
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 58
Petri NetsModelling of complex systems – Examples
� Shared resource between two carts� A: Must wait in Ea until common tregion is
free. Wait time in D Ta: 100s� Same as A but with priority and Tb=50s
30
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 59
Petri NetsModelling of complex systems – Examples
� Shared resource between two cartsCOMMENTS1) Initial condition: two carts at rest in Ca and Cb.
2) The central place models the access to the shared resource and it represents its idle state.
3) The output transitions of the resource are in conflict if they request it simultaneously. In order to solve the ambiguity, priority is given to cart B.
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 60
Petri NetsModelling of complex systems – Examples� Producer-consumer problem
Producer Consumer
31
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 61
Petri NetsModelling of complex systems – Examples� Alternating sequences
� Surface treatment via immersion
� 2 treatment tanks (double time)
� 2 subcicles with operator acknowledgement
Load Ungrease Treatment Vashing Unload
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 62
Petri NetsModelling of complex systems – Examples� Alternating sequences
32
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 63
Petri NetsModelling of complex systems – Examples� Readers and writers
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 64
Petri NetsModelling of complex systems – Examples� Philosophers dinner
33
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 65
AWL Programming in S7-300TIMERS AND COUNTERS
� Timers:� Elements capable of adopting a sequence of states in
time.
� They are fired through the evaluation of a condition(raising edge)
� Each CPU model has a determined quantity of timers
� There exist hardware timer modules
� Timers programming: initial setup� Fixed Setup: L S5T#4S200MS
� H:HOURS, M:MINUTES, S:SECONDS, MS:MILLISECONSDS
� Variable setup (e.g. 4.2s): L MW 120� At address 120: 0001 0000 0100 0010� Base time: 00:0.01s; 01:0.1s; 11:10s
BCD value
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 66
AWL Programming in S7-300TIMERS AND COUNTERS
� Timer types:� SI: Impulse
U E0.1L S5T#42S500MSSI T1
� Usage: on raising edge of E0.1. T1 takes value “1” for 42,5 seconds as long as E0.1 remains at “1”
� SV: Extended ImpulseU E3.0L S5T#125SSV T3
� Usage: on raising edge of E3.0. T3 takes value “1” for 125s, independent of E0.3. Moreover, it can be fired agai n (raising edge of E3.0 restarts countdown)
34
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 67
AWL Programming in S7-300TIMERS AND COUNTERS
� Timer types:� SE: Connection delay
U E3.5L S5T#700MSSE T2
� Usage: on raising edge of E3.5, T2 takes value “1” AFTER 0.7 seconds, as long as E3.5 remains at “1”, and it wil l remain there until E3.5 goes back to “0”
� SA: Disconnection delayU E3.4L S5T#8SSA T3
� Usage: on raising edge of E3.4, T2 takes value “1”. When E3.4 returns to “0”, T2 will be zero AFTER 8s. May be re fired.
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 68
AWL Programming in S7-300TIMERS AND COUNTERS
� Counters:� Elements capable of storing, increasing a decreasing an integer
value.
� Its initial setup, increase or decrease are fired through the evaluation of a logical condition (raising edge)
� Each CPU model has a determined quantity of counters
� There exist hardware counter modules
� Initialization:� Fixed Setup: L C#37� Variable setup (e.g. 153) L MW 160
� At address 160: 0000 0001 0101 0011 BCD value
35
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 69
AWL Programming in S7-300TIMERS AND COUNTERS� Counter operations:
� S: Initialize
� ZR: Decrease
� ZV: increase
� =: Query
� Usage:� On raising edge of 3.0, Z1
takes value “1”,. A raising edge of E3.1 increases by 1 the value of Z1. On falling edge of E3.2, it is decreased by 1. A4.0 is “1” if Z1 is nonzero
U E 3.0
L C#21
S Z 1
U E 3.1
ZV Z 1
UN E 3.2
ZR Z 1
…
U Z 1
= A 4.0
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 70
AWL Programming in S7-300TRANSFER OPERATIONS
� Accumulators� ACU1 (32 bits). Stores results� ACU2 (32 bits)� Overflow bit: OV
� L: Loads the contents of a byte, word or double word into ACU1. Old contents of ACU1 move to ACU2.� L EB 7 PAE byte 7 to lower byte of ACU1� L EW 7 PAE bytes 7-8 to lower w. ACU1� L -312 Bipolar constant 16bits� L 2#1010100101100001 16bits binary constant� L W#16#FFFF 16bits HEX constant� L -1.3e+3 Floating point
36
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 71
AWL Programming in S7-300TRANSFER & LOGICAL OPERATIONS
� T: Transfers the contents of ACU1 to a byte, word or double word of memory. ACU2 remains unchanged.� T AB 8� T AW 8� T MW 5� T MD 10
� Logical operations(the result is soterd in ACU1)� UW logical AND between ACU1 and ACU2 (16 lower bits)� OW logical OR between ACU1 and ACU2 (16 lower bits)� XOW logical XOR between ACU1 and ACU2 (16 lower bits )� Example
� L EW 90 (0000011 0110 1100)� L W#16#F0A9� UW
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 72
AWL Programming in S7-300ARITHMETIC OPERATIONS
� +I ACU1=ACU1+ACU2 (16bits)
� -I ACU1=ACU2-ACU1 (16bits)
� *I ACU1=ACU1*ACU2 (16bits)
� /I ACU1=ACU1*ACU2 (16bits)� (In case of overflow, OV is activated)
� ==I
� <>I
� >I ACU2>ACU1?
� >=I ACU2>=ACU1?
� <=I ACU2<=ACU1?� L EW 90 0000 0011 0110 1100 ACU2-L� L Z 3 0000 0010 1001 1100 ACU1-L� <I� =A 1.2 (A1.2=0)
37
Automatismos. 5º Ing. Telecom. Fabio Gómez-Estern Slide 73
AWL Programming in S7-300FLANK EVALUATION
� POSITIVE (FP) OR NEGATIVE (FN)
� REQUIRES A MEMORY MARK
� Positive flank (Raising edge)� U E1.0 � U E1.3� FP M1.0� =A4.0
� Negative flank (falling edge)� U E2.1� O M2.0� FN M1.1� =A4.1