1.2.7. Solutions¶
Note
Complete and tested solution can be found in the OpenLib Library
Download Exercises solutions TIA Portal 15
Functions written in SCL can be exported and imported.
You can copy the code of the solution to a text file, save it with extension .scl
then import it to TIA.
Otherwise check the project file if you have Tia Portal version greater than 15.
1.2.7.1. Line equation¶
FUNCTION "LineEquation" : Void
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
VAR_INPUT
x : Real;
xA : Real;
yA : Real;
xB : Real;
yB : Real;
END_VAR
VAR_OUTPUT
y : Real;
END_VAR
VAR_TEMP
m : Real;
END_VAR
BEGIN
// Analog input
// x is Analog input (INT)
// y is the physical meausre (REAL) (temperature, pressure,speed,....)
// Analog output
// x is the physical meausre (REAL) (temperature, pressure,speed,....)
// y is Analog output (INT)
#m := (#yA - #yB) / (#xA - #yA);
#y := #m * (#x - #xA) + #yA;
END_FUNCTION
Suppose we have a temperature sensor connected to the analog input of the PLC.
The analog input read an int
, 16-bit signed value between -32768 (-2^15) and 32767 (2^15 - 1).
The s7-1200 AI data sheet show the mapping between tension (voltage) and corresponding numerical value.
The temperature sensor datasheet, will show the mapping between the tension and the temperature. In the PLC program we have to map from AI numerical value to tension, than from tension to temperature.
1.2.7.2. Rising edge¶
1.2.7.3. Falling Edge¶
1.2.7.4. Retentive TON¶
1.2.7.5. Blink¶
FUNCTION_BLOCK "Blink"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
VAR_INPUT
enableDI : Bool;
timeHigh : Time;
timeLow : Time;
END_VAR
VAR_OUTPUT
Q : Bool;
END_VAR
VAR
timer_High {InstructionName := 'TON_TIME'; LibVersion := '1.0'} : TON_TIME;
timer_Low {InstructionName := 'TON_TIME'; LibVersion := '1.0'} : TON_TIME;
bOn {InstructionName := 'TON_TIME'; LibVersion := '1.0'} : TON_TIME;
bOff {InstructionName := 'TON_TIME'; LibVersion := '1.0'} : TON_TIME;
END_VAR
BEGIN
#timer_High(IN := (#enableDI AND NOT #timer_Low.Q),
PT := #timeHigh);
#timer_Low(IN := #timer_High.Q,
PT := #timeLow);
#Q := #timer_High.Q;
END_FUNCTION_BLOCK
1.2.7.6. Bi-stable cylinder¶
A simple and functional solution in ladder is presented. A complete solution can be found in the library, and a state machine implementation can be found in the state machine
chapter.
- Physical IO may be:
- Two digital inputs: proximity sensors
- Two digital outputs: valve solenoid
Interaction with operators may be via physical push buttons, or software buttons (from HMI). The interaction may be with other devices like robots or the PLC itself depending on the plant. But from our point of view they are all the same, and we summarize them as open and close requests.
We can add also a stop request, and other things. But for now, we keep the solution simple.
The cylinder in normal operations, at rest, can be in a single state, or opened or closed.
The cylinder can be opened, if it is not opened and receive a request to open. What if someone send the request to open and close in the same time? So we need to be sure to receive only one request.
The cylinder may not respond to our requests, maybe there is no compressed air. Or the command execution was interrupted, e.g. heavy load, or someone leave some object in middle of the way. The execution time for opening and closing may be different, e.g. the cylinder take more time to open because it push some heavy object, but while closing is free from any load.
When we send the opening request and we didn’t get the opened state for a predefined time, we have an abnormal situation. Keep in mind, the predefined time is greater than the normal operating time, and it differ from application to application. For example, if the cylinder takes normally 5 seconds to open, we set the time to 7 seconds or 8 seconds for the time out.
When we get the time out signal, the commands should be resetted …….