Professional Documents
Culture Documents
1-State Diagram Problems With Solutions
1-State Diagram Problems With Solutions
PROBLEM 1
Represent as a state diagram model the process described here, explaining the actions performed in
each state
Whenever the “START” button is pressed, a conveyor belt is activated, and starts carrying cups.
When the sensor “S1” detects a cup, the conveyor belt is stopped, and two valves (V1, V2) are
opened simultaneously. “V1” has to remain open for 5 seconds, “V2” will remain open until the cup
is full. This is detected by the sensor “S2”. Once the cup is full, the conveyor belt starts moving
again in order to bring a new cup. The process continues until 4 cups have been filled, and then the
systems goes back to the idle state. After filling the last cup, the conveyor belt has to remain active
for 10 seconds in order to move the cup to the pick-up area.
SOLUTION:
NOTE: It is possible to merge “FILL V1 & V2” and “FILL V2” states into a single state, named
“FILL_CUP”. In this case, inside the “FILL_CUP” state, both valves have to be opened, a timer is
required for deactivating V1 (without leaving the state) , by using the timer’s output Q to deactivate
V1. The system leaves the state when S2 detects that the cup is full.
PROBLEM 2
Loading valve
V1
Program the process controller using LD, based on the state diagram model
SOLUTION:
Inputs: P, SM (maintenance area sensor), SC (loading area sensor), SD (unloading area sensor)
Output: MDer, MIzq, MotDesc, V1, Luz
Programming:
Before using LD to program the system, we need to asign the inputs, outputs and states to different
memory slots in the PLC.
In order to assign memory variables, we need to take into account how the PLC manages the
memory. For states, we will use boolean variables with the name %M0, %M1, %M2, etc… For
inputs and outputs of the system, we need to know how the inputs and outputs of the PLC are
configured. In the PLCs that we have in our labs, binary inputs (only two possible states: 0 or 1) are
located in the first module, and they will be labeled %I0.1.0, %I0.1.1, %I0.1.2, etc… Ouptuts are
located in the second module, so they will be labeled %Q0.2.0, %Q0.2.1, %Q0.2.2, etc…
States:
Next, we proceed to program this system using LD. We can identify three different parts:
Initializing the system: Program must be initialized in the %M0 state, this is, the IDLE state.
When we run the program, all variables start with a value of zero. So, if no state variable is True (if
the program is not in any state), then we activate the %M0 state.
Programming the state sequence: Next, we need to program the sequence that the state diagram
follows. Whenever a state is active and the condition for activating a transition is met, the active
state is reseted to 0 and the next state is set to 1. This is done by using set and reset operations. In
this problem, if we are in the %M0 state and the activation button is pressed (input P), then %M0
state is reseted and %M1 state is activated.
Moving from %M1 to %M2 is similar, %M2 is set to 1 when %M1 is active and S_LA (loading
area position sensor) is active. In order to move from %M2 to %M3, we need to check a timer that
indicates that the state has been active for 10 seconds (the time that takes to load the trolley).
The transition between %M3 and %M4, and the one between %M4 and %M5 follows the same
logic that the ones presented before. The only changes would be the input that we have to check and
how long we have to remain in the state %M4.
In %M5 we have to increase the value stored in a counter, that has to be programmed as well.
Once %M5 is active, there are two possible routes. If the counter is equal to 5, then the counter’s
output %FB1_2.Q is set to 1. So, if we are in %M5, the counter’s value is 5 and the trolley is in the
maintenance area (S_MA is active), then we transition from %M5 to %M6. On the other hand, if the
count is lower than 5 (this is detected by using a comparer that checks the counter’s value by
reading the output %FB1_2.CV), we are in %M%, and the trolley is in the loading area (S_LA is
active), then we transition from %M5 to %M2.
Now, we have programmed all the required transitions between states.
Output activation: Once we have programmed all the state transitions, we need to program the
activation of the different outputs required:
• We place all the outputs that have to be activated in the actions area (right). Next, we check
in which state each output has to be active, and we place those states in the conditions area
(left), using an OR logical operation.
• Outputs SHOULD NOT appear more than once, because they could receive contradictory
instructions.
• States have to be placed in parallel, so the action can be active in any of those states
PROBLEM 3
We want to mix two products with water. The tank is filled with water by opening the valve V1. The
dosage of both products is done by pouring them into a hopper. First add the product A, until the
weight SP1 is reached, and then we add product B, until the final weight (SP2) is reached. Once
both products are in the hopper, then the valve V2 is opened for 10 seconds, and the contents of the
hopper are dropped in the tank. The mixer (M) is activated in order to start the mixing process,
which goes on for 30 seconds. Finally, the tank is emptied, and the system is ready to start a new
cycle. The process starts when the button P is pressed
Program the process controller using LD, based on the state diagram model
SOLUTION:
First of all, we need toassign memory addresses to the inputs, outputs, and states:
1. Initialization:
2. Transitions:
3. Output activation:
There is another possible solution for this problem:
In this case, we simlify the state diagram, but when programming the activation of the outputs, we
need to take into account all the possibilities that can happen inside each state. When assigning the
memory addresses, the input and output assignation is the same in both solutions, the only thing that
changes is the memory adresses for the states:
In this case, output activation depends on which state is active, and also the activation and
deactivation of the input variables in each state.
PROBLEM 4
We want to automate a system that packs soda bottles in packs of two bottles. The following figure
depicts a top view of the whole process:
START BUTTON
PISTONS
BOTTLE PACKING
MACHINE PICK-UP
AREA
BELT 1
BELT 3
BELT 2
BOTTLE BOTTLE
PACK
The process starts whenever the worker presses the start button P. Two independent conveyor belts
(MC1 and MC2) bring bottles from the previous stage of the manufacturing process, where they
have been filled and tagged. We need to pack them in sets of two bottles each. The PLC has to
control each belt independently, so they can be stopped when a bottle is in place (SP1 or SP2
sensors activate) It is important to notice that bottles can arrive at different times. When both
sensors have detected a bottle (both conveyor belts are stopped), then two lateral pistons (EMB) are
activated. The pistons place the bottles in the third conveyor belt (MC3). This operation takes 2
seconds. Next, MC3 is activated, and moves the bottles to the packing machine (EMP). This is
detected by the sensor SP3. The packaging process takes 10 seconds. Then, the bottle pack is sent to
the pick-up area, until the sensor SP4 detects the pack, stops the MC3, and the system goes back to
the idle state.
a) Model the system using a state diagram model, and program it using LADDER logic
MC1 is active while SP1
MC1 is not active, MC2 is
MC2 active while SP2 is not
active
%M 4
EMB
%M 5
MC3
%M 6
EMP
%M 7
MC3
We want to automate a level crossing system. The desired system’s behavior is the following:
While the system is in the idle state, the barrier has to be open, and the green traffic light (LV) has
to be on.
Whenever the system detects a train coming (this is detected either by the sensors S1 or S2), then
the following actions have to be performed:
• Change the light to orange (LA) for 30 seconds, while at the same time we activate an
acoustic signal (SA)
• Then, the light changes to red (LR) and, 20 seconds later, the barrier goes down, by
activating the barrier’s lowering motor (MBaj), until sensor SD detects that the barrier is at
the lower position
• When the train passes by the other sensor over the rail (either S1 if S2 was activated before
or S2 if S1 was activated before), the barrier is raised by activating the motor (MSub) until
the barrier is at the higher position (detected by the SU sensor).
• Once the barrier is open, the light changes back to green and the acoustic signal is
deactivated
reset(SA)
reset(LR)
LV
LA
set(SA)
set(LR)
MBaj
MSub