![Siemens Simatic SM331 Getting Started Download Page 70](http://html.mh-extra.com/html/siemens/simatic-sm331/simatic-sm331_getting-started_1265387070.webp)
Appendix
A.1 Source of the user program
SM331; AI 8x12 Bit Getting Started part 1: 4 -20mA
A-2
Getting Started, 11/2006, A5E00253410-02
END_DATA_BLOCK
FUNCTION FC 1 : VOID
TITLE =Conversion of a channel’s raw values in mA
VERSION : 1.0
VAR_INPUT
Raw : WORD ;
// Analog value display
END_VAR
VAR_OUTPUT
Current : REAL ;
// Current in mA
END_VAR
VAR_TEMP
TDoubleInt : DINT ;
TInt : INT;
END_VAR
BEGIN
NETWORK
TITLE = Conversion of raw values in mA
L
#Raw;
T
#TInt;
// Only long integers can be converted into REAL format
L
ITD
T
#TInt;
;
#TDoubleInt;
//
HEX value
// Current =
---------------
L
DTR
T
#TDoubleInt;
;
#Current;
//
1728
//
!
/
//
!
/
//
!
/
// -------
+-----
/------
+----
L
/R
T
1.003;
;
#Current;
//
4
20
L
+R
T
4.000;
;
#Current;
// Offset correction
END_FUNCTION
ORGANIZATION_BLOCK OB 1
TITLE = "Main Program Sweep (Cycle)"
VERSION : 1.0
VAR_TEMP
OB1_EV_CLASS : BYTE ;
//Bits 0-3 = 1 (Coming event),
Bits 4-7 = 1 (Event class 1)
OB1_SCAN_1 : BYTE ;
//1 (Cold restart scan 1 of OB 1),
3 (Scan 2-n of OB 1)
OB1_PRIORITY : BYTE ;
//Priority of OB Execution
OB1_OB_NUMBR : BYTE ;
//1 (Organization block 1, OB1)
OB1_RESERVED_1 : BYTE ;
//Reserved for system
OB1_RESERVED_2 : BYTE ;
//Reserved for system
OB1_PREV_CYCLE : INT;
//Cycle time of previous OB1 scan (milliseconds)
OB1_MIN_CYCLE : INT;
//Minimum cycle time of OB1 (milliseconds)
OB1_MAX_CYCLE : INT;
//Minimum cycle time of OB1 (milliseconds)
OB1_DATE_TIME : DATE_AND_TIME ;
//Date and time OB1 started