Posted 4 Sep 2021 Hello Everyone, I am writing one logic and need some help regarding that logic. CURRENT LOGIC - -There are two timers TON_1 and TON_2. -TON_1 timer will start as soon as PLC turns on. -After the done bit of TON_1 timer, the TON_2 timer goes on. -After the done bit of TON_2 timer, again the TON_1 timer will start. -This logic cycle will run continuously, both timers will run turn by turn. Code (Codesys/Schneider Eco Structure Machine Expert)- PROGRAM POU_1 VAR TON_1: TON; TON_2: TON; END_VAR TON_1(IN:=(NOT(TON_2.Q)) , PT:= T#100S); TON_2(IN:=(TON_1.Q) AND (NOT(TON_2.Q)) , PT:= T#20S); Actual Requirement - -There is a BOOL tag. -If the BOOL tag gets high during the TON_1 running, the logic should move to the TON_2 immediately. -If the BOOL tag does not get high during the TON_1 running, the logic should move to the TON_2 after completion of TON_1. -after the completion of TON_2, again restart TON_1. -Logic Runs continuously in a cyclic mode. Give me your valuable idea to fulfill the logic requirement. Share this post Link to post Share on other sites
Posted 6 Sep 2021 @Michael Walsh @BobLfoot @panic mode Share this post Link to post Share on other sites
Posted 6 Sep 2021 What happens if BOOL tag remains high? Does TON_2 keep cycling? 1 person likes this Share this post Link to post Share on other sites
Posted 6 Sep 2021 (edited) 49 minutes ago, chelton said: What happens if BOOL tag remains high? Does TON_2 keep cycling? @chelton The BOOL tag will go high only when TON_1 running, and I will reset that BOOL tag as soon as TON_2 Starts. SO the cycle can run continuously. Edited 6 Sep 2021 by SillyBoy 1 person likes this Share this post Link to post Share on other sites
Posted 9 Sep 2021 Do not modify the existing time logic of TON_1 and TON_2. Instead, when BOOL_tag state goes to "1" then move the final value of TON_1 into the active timing register of TON_1. This would be "0" if TON_1 counts from preset value to zero; this might be "100" if TON_1 counts from zero to preset value. You need to verify the operation and final value of TON_1 in order to realize what is the final value of TON_1. 1 person likes this Share this post Link to post Share on other sites
Posted 10 Sep 2021 19 hours ago, pop29684 said: Do not modify the existing time logic of TON_1 and TON_2. Instead, when BOOL_tag state goes to "1" then move the final value of TON_1 into the active timing register of TON_1. This would be "0" if TON_1 counts from preset value to zero; this might be "100" if TON_1 counts from zero to preset value. You need to verify the operation and final value of TON_1 in order to realize what is the final value of TON_1. It's an IEC software, so the TON instruction always counts up. And I am not sure you are allowed to write to the current value. You do not need the AND on the second timer, because the moment TON_2 finishes, TON_1 becomes false and that would reset both timers. Putting it on TON_2 is redundant. As for your extra input, add it as input condition on the second timer. Will it stay on? If not, you need to write a latch to keep it on while the second timer runs and reset it when the second timer ends. The timer needs a true signal for the whole time it is timing. Share this post Link to post Share on other sites
Posted 29 Sep 2021 On 9/10/2021 at 9:47 AM, Crossbow said: You do not need the AND on the second timer, because the moment TON_2 finishes, TON_1 becomes false and that would reset both timers. Putting it on TON_2 is redundant. I think I may have been misunderstood. I was not ANDing the two timers. Allow me to rephrase: Do not modify the existing time logic of either timer (TON_1, TON_2). On 9/10/2021 at 9:47 AM, Crossbow said: It's an IEC software, so the TON instruction always counts up. And I am not sure you are allowed to write to the current value. You may be correct. I was thinking of the Siemens platform where the TON instance DB is accessible. Share this post Link to post Share on other sites
Posted 29 Sep 2021 5 hours ago, pop29684 said: I think I may have been misunderstood. I was not ANDing the two timers. Allow me to rephrase: Do not modify the existing time logic of either timer (TON_1, TON_2). You may be correct. I was thinking of the Siemens platform where the TON instance DB is accessible. You clearly AND the outputs of timer 1 and timer 2 as the trigger for timer 2. This is irrelevant because as soon as timer2 completes, timer 1 will reset itself because its trigger becomes false. Not sure what you mean about accessing the TON instance DB. This is a PLCOpen standard function block, and it should work the same on every controller that follows the PLCOpen rules. 2 people like this Share this post Link to post Share on other sites
Posted 30 Sep 2021 Already sorted this out, mark this thread closed. I have used an Integer Tag to fulfill the required logic. If anyone needs the same logic, revert back to me I will send it. Share this post Link to post Share on other sites
Posted 30 Sep 2021 if one wants to use two timers based on original idea, this should do the job: PROGRAM POU_1 VAR TON_1: TON; TON_2: TON; END_VAR TON_1(IN := NOT TON_2.Q , PT := T#100S); TON_2(IN := TON_1.Q , PT := T#20S); 1 person likes this Share this post Link to post Share on other sites