lauwerstim
Member
I have a rather dificult problem. I have a PLC with 400 inputs (maybe more later on), now I need every input to have an OFF delay (if its on for only 20ms, I need to need to see for a sec or so).
I've been trying to get this done with a function I've written but I'm doing something wrong. This is what I got so far:
A already have every input copied to a DB (for use in the rest of the program) so I use that DB as input to my block and want to copy the pulse output to another DB (also an input on my block)
I have tested it, if I leave out the counter part, it works (it just copies over the inputs), but in the counter there's something wrong. I think I adress the integer for the timer wrong. The timer starts but not in de instance DB of the block, but in de DB with the inputs.
Really hope someone can help.
I've been trying to get this done with a function I've written but I'm doing something wrong. This is what I got so far:
Code:
FUNCTION_BLOCK FB 50
TITLE =
VERSION : 0.1
VAR_INPUT
Puls_100ms : BOOL ;
DB_Inputs : POINTER ;
DB_Inputs_pulse : POINTER ;
Aantal_bits : INT ;
END_VAR
VAR
C_PF_100ms : BOOL ; //Kopie voor flankdetectie 100ms puls
PF_100ms : BOOL ; //Flankdetectie 100ms
I_Bit : DWORD ; //Start adres voor inputs in DB
Q_Bit : DWORD ; //Start adres voor verlengde inputs in DB (waarnaartoe geschreven gaat worden)
C_PF_I_bit : DWORD ; //Adres voor kopiebits nodig voor flankdetectie van de inputs
C_PF_I : ARRAY [1 .. 400 ] OF //Flankdetectie van de inputs
BOOL ;
T_bit : DWORD ; //Adres voor timer
T_pulse : ARRAY [1 .. 400 ] OF //Timer
INT ;
END_VAR
VAR_TEMP
I_DBNR : INT ; //Db nummer voor de inputs
Q_DBNR : INT ; //DB nummer voor de verlengde inputs (waarnaartoe geschreven gaat worden)
TBo : BOOL ;
TBo2 : BOOL ;
TBo3 : BOOL ;
TWo : WORD ;
TInt : INT ;
END_VAR
BEGIN
NETWORK
TITLE =Positieve flank 100ms puls
A #Puls_100ms;
FP #C_PF_100ms;
= #PF_100ms;
NETWORK
TITLE =
LAR1 P##DB_Inputs;
L W [AR1,P#0.0];
T #I_DBNR;
L D [AR1,P#2.0];
T #I_Bit; //Bit locatie van inputs in DB
LAR1 P##DB_Inputs_pulse;
L W [AR1,P#0.0];
T #Q_DBNR;
L D [AR1,P#2.0];
T #Q_Bit; //Bit locatie van de inputs puls in DB
LAR1 P#L 30.0;
T #C_PF_I_bit; //Opslaan van de ingangen zodat ze lokaal gebruikt kunnen worden
LAR1 P#L 84.0;
T #T_bit; //Locatie van timer geheugen
L #Aantal_bits;
NEXT: T MW 20;
OPN DB [#I_DBNR];
L #I_Bit;
LAR1 ;
A [AR1,P#0.0];
= #TBo; //Binnen lezen van input
L #C_PF_I_bit;
LAR1 ;
A #TBo;
FP [AR1,P#0.0];
= #TBo3; //Positieve flank van Input (om timer te starten)
L #T_bit;
LAR1 ;
L W [AR1,P#0.0];
T #TInt;
A #TBo3;
JCN INIT;
L 10;
T #TInt;
INIT: NOP 0; //Wanneer er een positieve flank is van de Input, wordt de teller geĂŻnitiallisseerd
A( ;
L #TInt;
L 0;
>I ;
) ;
O #TBo;
= #TBo2; //Teller groter dan 0 of Inputs is hoog => verlengde puls hoog
A #PF_100ms;
JCN TEL;
L #TInt;
L 1;
-I ;
T #TInt;
TEL: NOP 0; //Wanneer er flank op de 100ms is, wordt er 1 van de teller afgetrokken
L #TInt;
L 0;
<=I ;
JCN SKIP;
L 0;
T #TInt; //Teller kleiner of gelijk aan 0, vast op 0 zetten om geen negatieve getallen te krijgen
SKIP: NOP 0;
L #T_bit;
LAR1 ;
L #TInt;
T W [AR1,P#0.0];
OPN DB [#Q_DBNR];
L #Q_Bit;
LAR1 ;
A #TBo2;
= [AR1,P#0.0];
NETWORK
TITLE =
L #I_Bit;
L W#16#1;
+D ;
T #I_Bit;
L #Q_Bit;
L W#16#1;
+D ;
T #Q_Bit;
L #C_PF_I_bit;
L W#16#1;
+D ;
T #C_PF_I_bit;
L #T_bit;
L W#16#F;
+D ;
// T #T_bit
L MW 20;
LOOP NEXT;
END_FUNCTION_BLOCK
I have tested it, if I leave out the counter part, it works (it just copies over the inputs), but in the counter there's something wrong. I think I adress the integer for the timer wrong. The timer starts but not in de instance DB of the block, but in de DB with the inputs.
Really hope someone can help.