1).I have lot of timers and I have to reset them when repeating the sequence.
2).for loop is too fast it is finishing the count in no time,for 1 sequence.
3).There is no jump statement ST Language,so I went for case statement.
Below is my Code:
IF g_TIU[i_TiuNo].HeaterTest.bTest THEN
tofdelay(in:=NOT tofdelay.Q AND g_TIU[i_TiuNo].HeaterTest.bTest AND i=0 ,pt:=t#1s);
btofdelay:=tofdelay.Q;
IF NOT bdelay THEN
g_TIU[i_TiuNo].STICScriptNo:=eTempset;
END_IF
IF btofdelay OR bdelay THEN
p_TIU[i_TiuNo].bSTICRunScriptHeater:=TRUE;
ELSE
p_TIU[i_TiuNo].bSTICRunScriptHeater:=FALSE;
END_IF
IF (g_TIU[i_TiuNo].STICScriptNo=31 AND i=0) THEN
(RsScript(SET:=p_TIU[i_TiuNo].bSTICRunScriptHeater,RESET1:=g_TIU[i_TiuNo].STICRunScript);
g_TIU[i_TiuNo].STICRunScript:=RsScript.Q1;)
i:=i+1;
END_IF
IF i=1 THEN
tondelay(in:=NOT tondelay.Q AND NOT bdelay AND TRUE,pt:=r_TCUConfig[i_TiuNo].TIUHeaterTimer);
bdelay:=tondelay.Q;
END_IF
currenttime:=tondelay.ET;
IF bdelay THEN
g_TIU[i_TiuNo].STICScriptNo:=eTempget;i:=i+1;
END_IF
IF btofdelay OR bdelay THEN
p_TIU[i_TiuNo].bSTICRunScriptHeater:=TRUE;
ELSE
p_TIU[i_TiuNo].bSTICRunScriptHeater:=FALSE;
END_IF
How about adding a counter that you increment by one every time you've done the sequence and and IF-case to see if you have performed the sequence enough times?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
gooday sarathbabu
Your code will not work, probably as the timers are every loop starting.
Case statement can be used here, however for or do while is better here probably.
please give us a flowdiagram what you want. because the code used by you is very garbled.
if you have to test on a timer use this timers output. timeron.q and timeroff.q
you can not use timers inside a array, however you can use RTC in an array.
something like it takes 5000 msec for step 1 use array[1]:=5000
if starttime > arraytime + RTC do something.
this way you keep the times correct, with timers it is not very precise (takes about 10 msec)
flowchart still not correct.
yes within a for loop it is possible, just check if timer is expired and then move on.
use wait for this, but the program stops now.
if you haVE MORE AS ONE PROG RUNNING THIS IS BAD PRACTICE.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
your sequence is still not correct.
now it is 1 second on
20 seconds off
2 seconds on because the third timer is followed by the first timer.
probably you want to wait for 20 seconds again, but this you can do by jumping one step lower.
A PLC is always looping its programs, and checks if values are true, this is to avoid a standstill somewhere in a POU and rest of machine is not controlled anymore.
you can achieve your goal with
WHILE NOT timer.Q DO
nothing:=true;
END_WHILE
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
late reply, but here's an implementation in ST with a case based state machine, only one timer is needed as its used for both on and off states.
PROGRAMPOUVAR_INPUT
  //Startthesequence
  Start: BOOL;
  //Numberofrepeats
  Repeats: INT :=10;END_VARVAR_OUTPUT
  //Outputsignal
  A: BOOL;END_VARVAR
  State: WORD;
  Counter: INT;
 Â
  Timer: TON;END_VARVARCONSTANT
  STATE_START : WORD :=0;
  STATE_ON  : WORD :=1;
  STATE_OFF  : WORD :=2;
  STATE_STOP : WORD :=3;END_VARCASEStateOFSTATE_START:
  IFStartTHEN
    Timer(IN:=FALSE); Â
   Â
    Counter:=0;
    State :=STATE_ON;
  END_IF//Putsthesignalonfor1secSTATE_ON:
  A:=TRUE;
 Â
  Timer(IN:=TRUE, PT:=T#1S);
  IFTimer.Q  THEN
    //Resettimer
    Timer(IN:=FALSE); Â
   Â
    State :=STATE_OFF;
  END_IF//Putthesignalofffor20secSTATE_OFF:
  A:=FALSE;
 Â
  Timer(IN:=TRUE, PT:=T#20S);
  IFTimer.Q  THEN
    //Resettimer
    Timer(IN:=FALSE); Â
    Counter:=Counter+1;
   Â
    IFCounter<RepeatsTHEN
      State:=STATE_ON;
    ELSE
      State:=STATE_STOP;
    END_IF;
     Â
  END_IF//Done Â
STATE_STOP:
  //Waitforstartsignaltoberemoved, elsethesequencewillberestarted
  IFNOTStartTHEN
    State:=STATE_START;
  END_IF Â
 Â
END_CASE
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
yes the number can be a variable, but
when you need it variable use
While counter<endnumber do
end_while
in a CASE it is not possible to use a VAR for the cases.
constants are possible
CASE INT1 OF
INT1 is a normal Variable of the INT type (byte etc possible.
1, 5: BOOL1 := TRUE;
above 1 and 5 must be a constant
BOOL3 := FALSE;
2: BOOL2 := FALSE;
BOOL3 := TRUE;
10..20: BOOL1 := TRUE;
BOOL3:= TRUE;
ELSE
BOOL1 := NOT BOOL1;
BOOL2 := BOOL1 OR BOOL2;
END_CASE;
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In Case statement
case integer of
1..n:
end_case
where n is an integer
It is showing error,when am building it
I need to execute the sequence 10 times if n=10,but n is a configurable value by the user it can be an integer.
Can any one help me on this?
Hello,
If it's the same sequence that you would like to do N times I would instead recommend a FOR-case. Something like:
The above code will fill the array aThings up to index MaxCount when the BOOL xDoIt is set to TRUE.
I hope this helps.
Best regards,
Kristian Berlin
Hi Berlin
Thanks for the reply
1).I have lot of timers and I have to reset them when repeating the sequence.
2).for loop is too fast it is finishing the count in no time,for 1 sequence.
3).There is no jump statement ST Language,so I went for case statement.
Below is my Code:
IF g_TIU[i_TiuNo].HeaterTest.bTest THEN
tofdelay(in:=NOT tofdelay.Q AND g_TIU[i_TiuNo].HeaterTest.bTest AND i=0 ,pt:=t#1s);
btofdelay:=tofdelay.Q;
IF NOT bdelay THEN
g_TIU[i_TiuNo].STICScriptNo:=eTempset;
END_IF
IF btofdelay OR bdelay THEN
p_TIU[i_TiuNo].bSTICRunScriptHeater:=TRUE;
ELSE
p_TIU[i_TiuNo].bSTICRunScriptHeater:=FALSE;
END_IF
IF (g_TIU[i_TiuNo].STICScriptNo=31 AND i=0) THEN
(RsScript(SET:=p_TIU[i_TiuNo].bSTICRunScriptHeater,RESET1:=g_TIU[i_TiuNo].STICRunScript);
g_TIU[i_TiuNo].STICRunScript:=RsScript.Q1;)
i:=i+1;
END_IF
IF i=1 THEN
tondelay(in:=NOT tondelay.Q AND NOT bdelay AND TRUE,pt:=r_TCUConfig[i_TiuNo].TIUHeaterTimer);
bdelay:=tondelay.Q;
END_IF
currenttime:=tondelay.ET;
IF bdelay THEN
END_IF
IF btofdelay OR bdelay THEN
p_TIU[i_TiuNo].bSTICRunScriptHeater:=TRUE;
ELSE
p_TIU[i_TiuNo].bSTICRunScriptHeater:=FALSE;
END_IF
(RsScript(SET:=p_TIU[i_TiuNo].bSTICRunScriptHeater ,RESET1:=g_TIU[i_TiuNo].STICRunScript);
g_TIU[i_TiuNo].STICRunScript:=RsScript.Q1;)
IF i=15 THEN
(RsScript(SET:=p_TIU[i_TiuNo].bSTICRunScriptHeater ,RESET1:=g_TIU[i_TiuNo].STICRunScript);)
p_tiu[i_tiuno].bHeaterTestCompleted:=TRUE;
END_IF
END_IF
I have to repeat the above sequence by 'n' times based on users input
How about adding a counter that you increment by one every time you've done the sequence and and IF-case to see if you have performed the sequence enough times?
gooday sarathbabu
Your code will not work, probably as the timers are every loop starting.
Case statement can be used here, however for or do while is better here probably.
please give us a flowdiagram what you want. because the code used by you is very garbled.
if you have to test on a timer use this timers output. timeron.q and timeroff.q
you can not use timers inside a array, however you can use RTC in an array.
something like it takes 5000 msec for step 1 use array[1]:=5000
if starttime > arraytime + RTC do something.
this way you keep the times correct, with timers it is not very precise (takes about 10 msec)
Related
Talk.ru: 1
Hi Berlin
1).If I keep counter with in FOR loop it is executing the sequence once and the counter is updated with in that time,before the sequence go to start.
2).I need to reset the timers also before it goes to start.
Hi Shooter
1).Please find the attached image for the flow.It is too simple but timers reset and 'n' times repetition of the sequence are the critical part.
your bit A is still on after 20 seconds
but i made a program exactly as yours is.
i made it in SFC to follow your flow.
20120505.pro [26.51 KiB]
Hi,
1).SFC is solving the problem.
2).Any reason why cannot we use FOR loop for this kind of sequence?
For is also possible, but when you draw a simple flowchart it is easier to make an SFC
with FOR you can do
FOR a = 1 to variable
ton1
ton2
next a
i made an SFC but it is not correct, as your flowdiagram is not correct.
Hi
1).I have corrected my flow chart.
2).With out SFC is it possible in for loop using a counter
Thanks
flowchart still not correct.
yes within a for loop it is possible, just check if timer is expired and then move on.
use wait for this, but the program stops now.
if you haVE MORE AS ONE PROG RUNNING THIS IS BAD PRACTICE.
Shooter,
In the sequence k:k+1; is supposed to increment once,in the flow but it is incremented in no time with in the FOR loop.
Attached is the flow chart
your sequence is still not correct.
now it is 1 second on
20 seconds off
2 seconds on because the third timer is followed by the first timer.
probably you want to wait for 20 seconds again, but this you can do by jumping one step lower.
A PLC is always looping its programs, and checks if values are true, this is to avoid a standstill somewhere in a POU and rest of machine is not controlled anymore.
you can achieve your goal with
WHILE NOT timer.Q DO
nothing:=true;
END_WHILE
Thanks for the idea.
Hope fully this flow chart should be correct to some extent
late reply, but here's an implementation in ST with a case based state machine, only one timer is needed as its used for both on and off states.
Hi
repeat:=n;
where n can be any integer
Thanks
yes the number can be a variable, but
when you need it variable use
While counter<endnumber do
end_while
in a CASE it is not possible to use a VAR for the cases.
constants are possible
CASE INT1 OF
INT1 is a normal Variable of the INT type (byte etc possible.
1, 5: BOOL1 := TRUE;
above 1 and 5 must be a constant
BOOL3 := FALSE;
2: BOOL2 := FALSE;
BOOL3 := TRUE;
10..20: BOOL1 := TRUE;
BOOL3:= TRUE;
ELSE
BOOL1 := NOT BOOL1;
BOOL2 := BOOL1 OR BOOL2;
END_CASE;