 |
plc.myforum.ro PLCs users www.plc.myforum.ro!
|
| View previous topic :: View next topic |
| Author |
Message |
mascalzone Junior

Joined: 20 Nov 2016 Posts: 11
|
Posted: 14/01/2017 19:02 Post subject: Siemens FB3:Derive calc-Derive calculation |
|
|
FB3 - <offline>
"FB3:Derive calc" Derive calculation
This function calculate the 1st derive of [Input_value]
The derive is calculate on 20 samples of [Input_value] the samples are take each time [CLK] is TRUE
The output value is the sum of 1st 10 samples with 2nd 10 samples.
| Code: | Parameters:
.[Input_value]: Value to derive
.[Reset]: This command reset the act derive value. The calculation restart when
all the items of samples array are refreshed
.[Derive_spl_CMD]: Timing step. The samples are taken when [Derive_spl_CMD] = TRUE
.[Derive_value]: Derivated output value
.[Enable]: This output is energized when the calculation of act value is finished
.[Samples]: Samples container.
.[Nr_samples]: # of samples to take for calculation
.[Derive_calc_ON]: System variable
.[Nr_of_shf]: System variable
.[Loop]: System variable
.[Index]: System variable
.[Prev_sum]: System variable
.[Next_sum]: System variable
.[Dummy_bit_1]: System variable
.[Calc_ON]: System variable
.[Init_end]: System variable
Segmento: 1 Reset
This network manages the reset command
U #Reset // Reset command
R #Derive_calc_ON
Segmento: 2 Timing
This network manage the timing of function
U #Derive_spl_CMD
BLD 100
FP #Dummy_bit_1
= #Calc_ON // One-shot clock
UN #Calc_ON // Timng calculation
R #Enable
BEB // End block
Segmento: 3 1st derive calculation
This network manages the calculation of [Input_value] 1st derive
// *************************************** Derive calculation *****************************************//
U #Derive_calc_ON // **** Reset derive value ****
SPB Calc
L 0
T #Derive_value
SPA Shf // Jump derive calculation
Calc: L 0
T #Index // Init array index
T #Prev_sum // Init 1st 10 samples sum
T #Next_sum // Init 2nd 10 samples sum
L 5
Lab: T #Loop // Load loop index
L #Funct_pointer // Load derive function pointer
LAR1 // Load pointment register
L P##Samples // Load array pointer
+AR1 // ADD to pointment register
L #Index // Load pointer of array index
SLD 3
+AR1 // Sum the array pointer to inex pointer
L DID [AR1,P#0.0] // Load pointed sample
L #Prev_sum
+R
T #Prev_sum // Add the act sample to prev sum
L DID [AR1,P#20.0] // Load pointed sample plus 5
L #Next_sum
+R
T #Next_sum // Add the act sample plus 5 to next sum
L 4
L #Index
+I // Array index increment
T #Index
L #Loop
LOOP Lab // Loop end
L #Prev_sum // 1st derive calculation
L #Next_sum
-R
//L 5.000000e+000
///R // ([Prev_sum]-[Next-sum])/25
T #Derive_value
//
// ********************************* 1 item to right array shifting ***********************************//
Shf: L 32
T #Index // Load array index whit address of 9th item
L 9
Lab1: T #Loop // Load loop index
L #Funct_pointer // Load the pointer to derive function
LAR1 // Load pointement register
L P##Samples // Load the pointer of array samples
+AR1 // ADD to pointement register
L #Index // Load the pointer of act sample
SLD 3
+AR1 // Sum the pointer of array with the pointer of 19th sample
L DID [AR1,P#0.0]
T DID [AR1,P#4.0] // Shift the samples of 1 item to right
L #Index
L 4
-I // Array index decrement
T #Index
L #Loop
SIMATIC Simone_gen\Derivate calc\...\FB3 - <offline> 07/20/2000 18:57:35
Pagina 3
LOOP Lab1 // Loop end
Segmento: 4 Add new sample to array
This network add a new sample to array
L #Funct_pointer
LAR1
L P##Samples
+AR1
L #Input_value
T DID [AR1,P#0.0] // Insert new sample to 1ft array field
SET
SAVE
S #Enable
L #Nr_of_shf // # of shifted samples calculation
L 1
+I
T #Nr_of_shf
Segmento: 5 Array init end calculation start
This network manages the activation of derive calculation start (when array
initialization is finish)
L #Nr_of_shf // # of shifted samples
L 9
>=I // Array init end
= #Init_end
U #Init_end
S #Derive_calc_ON // Set derive calculation start
U(
O #Init_end // Reset coomand
O #Reset
)
SPBNB Jmp
L 0 // Reset # of shifted samples
T #Nr_of_shf
Jmp: NOP 0 |
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group Fa-ti si tu propriul forum GRATUIT, pe www.myforum.ro
|