2. Processing analog values

advertisement
SCRIPT – PROGRAMMABLE LOGIC
CONTROLS (PLC)
VOLUME III
©HÄGELE
Tutorial
© Hg
Programmable logic controls
MODULO III
Hg\Script_PLC_ModulIII.doc
CONTENTS
1. Parameterizable program blocks ................................................................................ 2
2. Processing analog values............................................................................................ 7
2.1. Introduction, technical terms .................................................................................. 7
2.2. Analog signals ....................................................................................................... 8
2.3. Read analog signals .............................................................................................. 9
2.4. Scale (normalize) analog values .......................................................................... 11
Pagina 1
Tutorial
© Hg
Programmable logic controls
MODULO III
Hg\Script_PLC_ModulIII.doc
1. Parameterizable program blocks
You wonder why a variable suddenly changes its value, although no error is found within the
program module? The cause may be that there were so-called "side effects".
Example:
You’ve not set flag M100.0. –
Nethertheless the output Q0.0
is activated!
OB 1
FC 1
A I 1.0
= M 100.0
A I 2.0
S M 100.0
Call FC1
A M100.0
= Q 0.0
Causes of these ,unwanted effects': _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_____________________________________________________
_____________________________________________________
Solution: Use of variables which can be only used within a program module. These are known as
local variables!
By doing this the program module is fully protected ("encapsulated") and cannot be influenced by
other parts of the program. However, the values must still be (here M 100.0) passed to the program
module (in this example FC1). This is done by means of a parameter interface:
Integrated parameter
interface
Global variable
FC 1
M100.0
Bool_Var
Internal variable
Note:
The fact that a program module uses only internal variables, it is fully protected (i.e.
"encapsulated"). You can use this module for different programs without causing unwanted effects.
Pagina 2
© Hg
Tutorial
Programmable logic controls
MODULO III
Hg\Script_PLC_ModulIII.doc
How can this software-interface be installed in S7?
Here you click on if you
want to define an input
variable.
Here you define the type
of variable
Fig.: Parameter list, also called ‘declaration’ part of the local variables within a
Configurable program block
Input
data
IN
.............
.............
.............
IN_OUT
............
............
............
TEMP
.............
.............
.............
STAT (nur FB)
............
............
............
Fig.: Illustration of a software interface
Pagina 3
OUT
............
............
............
Output
data
Tutorial
© Hg
Programmable logic controls
MODULO III
Hg\Script_PLC_ModulIII.doc
You can create the following variables in this software interface:
Variable type Function of this variable
IN
Input variable
In the graphic representation of the program the interface of these input
variables is situated on the left side of the block. Only variables with the
declared data type can be handed over.
OUT
Output variable
By using these variables, the program module returns information. In the graphic
representation of the program the interface of these input variables is situated on
the right side of the block
IN_OUT
Input and output variable
The value of these variables can be changed within a program module.
TEMP
Variables with temporary value
These variables can be considered as 'flags' locations.
FC 3
Generally the information of the TEMP variable is no longer
available after a program cycle.
STAT
Variables that can keep their value (can only be used within function
blocks FB`s)
In addition to the temporary variables (TEMP) function blocks
DB 3
also allow static variables (STAT). These are managed in an
instance data block (DB) so that the block has a “memory”. The
value of the static variables are kept - even after the end of cycle
- until it is renewed by new values
.
Pagina 4
FC 3
Tutorial
© Hg
Programmable logic controls
MODULO III
Hg\Script_PLC_ModulIII.doc
Exercise 1: Calculator for basic arithmetic
Program the function FC1 function with the parameter
list as seen on the side! Call FC1 in OB1.
Exercise 2: select the operation mode
Most machines have the same or at least similar control box as shown below. You have the task to
program the operating modes within a configurable function block. The advantage is that you can
(possibly with minor changes) to apply this function block to other machines.
CONTROL
ON
OFF
Reset
Start
Auto Manual
Stop
Jog
Pagina 5
Tutorial
© Hg
Programmable logic controls
MODULO III
Solution exercise 1: Calculator
Pagina 6
Hg\Script_PLC_ModulIII.doc
© Hg
Tutorial
Programmable logic controls
MODULO III
Hg\Script_PLC_ModulIII.doc
2. Processing analog values
2.1. Introduction, technical terms
In a production process exists a variety of physical quantities (pressure, temperature, velocity,
rotational speed, viscosity, etc.). They all need to be processed by the PLC.
Process
Physical
quantity
Analog input module
Converted
analog signal
Memory
(cache)
ADC
Sensor
• Pressure
•Temperature
• Flow rate
• Velocity
• Valor de pH
• Viscosity
• etc.





Physical
quantity
Analog
actuator
± 500 mV
± 10 V
± 20 mA
0 ... 20 mA
etc.
PIW ...
PIW ...
...
PIW ...
Módulo de Saída Analógica
DAC
PQW ...
PQW ...
...
PQW ...
CPU
:
:
:
L PIW 256
:
:
:
:
:
:
:
:
:
:
:
:
T PQW 256
:
Fig.: Use of Analog Modules
Sensor
Sensor elements are also called ‘converters’ because they convert a physical quantity
(in most cases a mechanical quantity) into an electrical signal, such as current, voltage
or electrical resistance.
ADC
Before the analog values can be processed from the CPU, they must be converted in a
digital form. This is done by the ADC (Analog-Digital Converter) within the analog input
module.
Input /
output
cache
The result of the conversion is stored in a cache and stays there until it is overwritten by
a new value. The converted analog value can be read with the instruction load "L PIW
...”
Analog
output
The transfer instruction "T PQW ..." is used to write the analog value calculated by the
user program in the analog output, where a DAC (Analog-Digital Converter) module
converts the values for standard analog signals.
Pagina 7
© Hg
Tutorial
Programmable logic controls
MODULO III
Hg\Script_PLC_ModulIII.doc
2.2. Analog signals
In automation technology, there are a variety of analog signals to be processed. Examples therefor
are: thickness of a workpiece, temperature, flow, speed, etc.. These non-electrical quantities are
converted by a sensor in electrical quantities (current or voltage) to be read from a PLC via its
analog input.
Example: The thickness of the workpiece is measured
by a measuring potentiometer.
+ 10 V
0 ... 10 V
R
Entrada
analógi
ca PLC
0V
0 cm
Here the thickness of 0 to 4 cm is converted into a
voltage range of 0 to 10 V by a potentiometer. A
measure of 1 cm thickness, the potentiometer gives a
voltage of 2.5 V voltage on its center tap.
Pagina 8
4 cm
1 cm
2,5 V
0V
10 V
© Hg
Tutorial
Programmable logic controls
MODULO III
Hg\Script_PLC_ModulIII.doc
2.3. Read analog signals
Analog signals need to be converted to digital information before being processed by the PLC. The
module, which performs the analog to digital conversion is named as ADC converter (AnalogDigital-Converter).
This means that, for example, the voltage of 10V is stored in a series of bits as binary information.
The more binary digits are available the better the resolution.
If so, for example, for the voltage range of 0 ... 10 V only one bit is available, it can be distinguished
only a voltage range of 0 ... +5 V and +5 V ... 10 Volt.
With 2 bits, the range can be already divided into four separate areas: 0 ... 2.5 / 2.5 ... 5/5 ... 7.5 /
7.5 ... 10V.
11
The resolution can be determined with the following equation:
Resolution = Range of measurement
n = Number off bits
2n
10
01
00
Fig.:
7,5V …10V
5V … 7,5 V
2,5V … 5V
0V … 2,5V
Ilustração da resolução de
um conversor 2-bit-AD
An usual A / D converter commonly used in the industry have between 8 or 11 bits. With 8 bits you
get 256 individual areas, by 11-bit already 2048 individual areas.
The analog values are read in and send out from the PLC as information in format "WORD". The
instructions to get access to this data are the following:
L PIW
xxx
//
load process-input WORD
T PQW xxx
//
transfer process-output WORD
Each analog value ("channel") can be read or sent as an integer. Addressing Analog inputs and
outputs depends on the address of the first module and can be viewed within the hardware
configuration.
Pagina 9
Tutorial
© Hg
Programmable logic controls
MODULO III
Hg\Script_PLC_ModulIII.doc
The scanned range of 0-10V voltage or 0-20 mA current for analog modules from Siemens (SM
334) values are illustrated in the following. Also can be seen, that 10 V / 20 mA digitalized has the
valor of 2764810.
Voltage
range
Upper limit
Max
Decimal
11,7589 V
10,00 V
Maximum range
27648
Faixa nominal
0V
Min
Lower limit
Above range
- 10,00 V
- 27648
Mimimum range
11,7589 V
Below range
Pagina 10
© Hg
Tutorial
Programmable logic controls
MODULO III
Hg\Script_PLC_ModulIII.doc
2.4. Scale (normalize) analog values
These digitized values can be more easily processed in the PLC when they are normalized / scaled.
Normalizing (scaling) means converting the integer value (from the analog input 'PIW' or formed by
the same program), into a real number, which refers to the voltage on the analog input or analog
output. For example, measuring a voltage of 0-10 V should correspond to the actual number from
0.0 to 10.0.
10 V
27 648
27 648
27648
* 10.0
13 824
13 824
27648
* 10.0
10.0
5.0
5V
0V
Analog
signal
0
__0__
27648
* 10.0
Digitalized
signal
0.0
Scaled value
Work order:
1. In this task, you need to program function FC 10, which reads a value from 0 to 10V (PIW256)
to normalize this. The PIW256 is presented as an integer (16 bits) and is scaled to 0.0 ... 10.0 in
floating point format and stored in memory as double word MD10.
2. Program an interface for transferring parameter? The input parameters are (as shown below):
Word of input PIW 256 process, the upper and lower limits of the normalized value (HI_LIM,
LO_LIM), and an enable signal. The result of standardization must be available at the output
OUT.
3. Upgrade the interface parameter by an input "offset" for the zero calibration.
FC 10
I 125.0
PEW 256
O
EN
IN
1.000000+e001
HI_LIM
0.000000+e000
LO_LIM
MD 10
OUT
Pagina 11
Tutorial
© Hg
Programmable logic controls
MODULO III
Hg\Script_PLC_ModulIII.doc
Solution in IL:
To program the scaling you use arithmetical instructions. To get the best possible accuracy as
possible, the values must be converted into the data type REAL, that the rounding errors are
minimal. Also you avoid by doing so a data conflict.
L PQW 256
// Read analog signal 0 to 10 V corresponding 0 to 27648 integer (16 Bit)
ITD
// Convert integer (16 Bit) to integer (32 Bit)
DTR
// Converter integer (32 Bit) to floating point number
L 2.7648e+4
//
/R
// Divide with 27648.0 – format real
L 1.000e+1
//
*R
// multiply valor with 10.0
T MD10
// Transfer the result to an double WORD
Using program modules from the "Standard Library“
To convert analog values to real numbers you can use a ready function provided from Siemens available in the standard library inside the folder 'TI-S7 converting blocks ' FC 105 `SCALE`. (Note:
The interface parameters of this function is very similar to your own written function.)
HI_LIM and LO_LIM stands for upper and lower limit.
The BIPOLAR input determines whether negative values should also be converted. In the example
here, the input has I124.1 signal "0" and this indicates that the input value is unipolar – the voltage
is between 0V and 10V.
The result of scaling is transferred to the output
OUT in the format as a real number.
For more information refer to the Siemens manual
or online-help.
Pagina 12
Tutorial
© Hg
Programmable logic controls
MODULO III
Hg\Script_PLC_ModulIII.doc
Exercise 2:
The measurement of the thickness of the workpiece is effected by means of a potentiometer. Your
task is to write a library function that can make a decision “Value within the limits or apart." Below
you can see a the call of the functions and its interfaces.
Fig.: Software-interface and its parameters
Pagina 13
Download