FUNCTION FC 2 : VOID TITLE = AUTHOR : zc VERSION : 0.1
VAR_INPUT PIW_IN : WORD ; HI_LIMIT : REAL ; LOW_LIMIT : REAL ; DEAD_BAND : REAL ; END_VAR VAR_OUTPUT EN_VALUE : REAL ; END_VAR VAR_TEMP analog_in_INT : INT ; analog_in_DINT : DINT ; analog_in_REAL : REAL ; analog_percent : REAL ; engineering_scale : REAL ; analog_offset : REAL ; analog_temp : REAL ; END_VAR BEGIN NETWORK TITLE =
A( ; A( ; L #PIW_IN; T #analog_in_INT; SET ; SAVE ; CLR ; A BR; ) ; JNB _001; L #analog_in_INT; ITD ; T #analog_in_DINT; SET ; SAVE ; CLR ; _001: A BR; ) ; JNB _002; L #analog_in_DINT; DTR ; T #analog_in_REAL; _002: NOP 0; NETWORK TITLE =
L #analog_in_REAL; L 2.764800e+004; /R ; T #analog_percent; NOP 0; NETWORK TITLE =
L #HI_LIMIT; L #LOW_LIMIT; -R ; T #engineering_scale; NOP 0; NETWORK TITLE =
L #analog_percent; L #engineering_scale; *R ; T #analog_offset; NOP 0; NETWORK TITLE =
L #LOW_LIMIT; L #analog_offset; +R ; T #analog_temp; NOP 0; NETWORK TITLE =
A( ; L #analog_temp; L #DEAD_BAND; <=R ; ) ; JNB _003; L #analog_temp; T #EN_VALUE; _003: NOP 0; NETWORK TITLE =
A( ; L #analog_temp; L #DEAD_BAND; >R ; ) ; JNB _004; L #analog_temp; T #EN_VALUE; _004: NOP 0; END_FUNCTION
FUNCTION FC 1 : VOID TITLE = AUTHOR : zc VERSION : 0.1
VAR_INPUT PIW_START : INT ; //Start address of analog input module PIW_NUM : INT ; //Number of analog channels DB_SCALE : BLOCK_DB ; //DB for analog scale DB_RESULT : BLOCK_DB ; //DB for analog results END_VAR VAR_TEMP PIW_START_Pointer_base : DWORD ; PIW_START_Pointer_offset : DWORD ; PIW_START_Pointer : DWORD ; DB_SCALE_Pointer_offset : DWORD ; DB_RESULT_Pointer_offset : DWORD ; Loop_count : INT ; PIW_IN_TEMP : WORD ; HI_LIMIT_TEMP : REAL ; LOW_LIMIT_TEMP : REAL ; DEAD_BAND_TEMP : REAL ; EN_VALUE_TEMP : REAL ; END_VAR BEGIN NETWORK TITLE =
L #PIW_START; //initialize analog input start address pointer L 8; *D ; T #PIW_START_Pointer_base;
L 0; T #PIW_START_Pointer_offset; //initialize analog input offset address pointer T #DB_SCALE_Pointer_offset; T #DB_RESULT_Pointer_offset; //initialize DB address pointer
NETWORK TITLE =
L 0; T #Loop_count;
LAIC: NOP 0; //Loop for analog input convert
L #Loop_count; L 16; *D ; T #PIW_START_Pointer_offset; //increase one analog channel,the pointer offset increase 1 WORD
L #Loop_count; L 96; *D ; T #DB_SCALE_Pointer_offset; //increase one analog channel,the DB_SCALE_Pointer_offset increase 3 REAL
L #Loop_count; L 32; *D ; T #DB_RESULT_Pointer_offset; //increase one analog channel,the DB_RESULT_Pointer_offset increase 1 REAL
L #PIW_START_Pointer_offset; L #PIW_START_Pointer_base; +D ; T #PIW_START_Pointer; //Get the dynamic pointer of analog input
L PIW [#PIW_START_Pointer]; T #PIW_IN_TEMP; //read analog input to temporary variable
OPN #DB_SCALE;
L #DB_SCALE_Pointer_offset; LAR1 ;
L DBD [AR1,P#0.0]; //read HI_LIMI to temporary variable T #HI_LIMIT_TEMP;
L DBD [AR1,P#4.0]; T #LOW_LIMIT_TEMP; //read LOW_LIMI to temporary variable
L DBD [AR1,P#8.0]; T #DEAD_BAND_TEMP; //read DEAD_BAND to temporary variable
L #EN_VALUE_TEMP; T DBD [#DB_RESULT_Pointer_offset]; //Write the analog result to DB_result
L #Loop_count; //increase the counter for next loop L 1; +I ; T #Loop_count;
L #PIW_NUM; //if the end of analog input reached, convert finished >=I ; JCN LAIC;
END_FUNCTION
ORGANIZATION_BLOCK OB 1 TITLE = "Main Program Sweep (Cycle)" VERSION : 0.1
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 ; //Maximum cycle time of OB1 (milliseconds) OB1_DATE_TIME : DATE_AND_TIME ; //Date and time OB1 started END_VAR BEGIN NETWORK TITLE =
CALL FC 1 ( PIW_START := 256, PIW_NUM := 80, DB_SCALE := DB 1, DB_RESULT := DB 2);