News:

  • June 29, 2026, 12:55:17 AM

Login with username, password and session length

Author Topic: for/next loop always runs to completion  (Read 7729 times)

davidbgtx

  • Hero Member
  • *****
  • Posts: 215
  • Host be the Most
for/next loop always runs to completion
« on: December 06, 2014, 09:03:32 AM »
I have a For/Next Loop in a task that always runs to completion. It is config to always yield. I want it to run through loop until for example c601 and c607 is set, then timer in main is enabled and task should not run until timer is done, v600 should be 601 for 5 sec, then task is enabled and loop continues to v607, timer is enabled and v600 should be 607 for 5 sec. What happens is it will always run till completion v600 will be 664, halt for 5 sec then run to completion again. see attachments. I thought if task was set to always yield it would loop once and jump back to main. I think I must be missing something simple.
« Last Edit: December 06, 2014, 09:06:53 AM by davidbgtx »

ATU

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 2126
  • YKPAIHA
    • ATU, Inc.
Re: for/next loop always runs to completion
« Reply #1 on: December 06, 2014, 12:15:07 PM »
I think T2.done resets the timer and shuts off T2.done before it can do anything below the timer.

plcnut

  • Hero Member
  • *****
  • Posts: 814
    • premiersi.com
Re: for/next loop always runs to completion
« Reply #2 on: December 06, 2014, 03:24:55 PM »
You need to get rid of the INIT at the top of your task, the starting index in the FOR should be V600, add a BREAK inside the loop when a C bit is true, and on the rung past the NEXT, add a MATH Result: V600 Formula: IF(V600>=664, 600, V600).
You will probably need to make some changes in MAIN, but this should get you on the right track.
BTW: You could change your comparative contacts to normally open contacts to simplify your rungs for readability.
« Last Edit: December 06, 2014, 03:26:29 PM by plcnut »
Circumstances don't determine who we are, they only reveal it.

~Jason Wolthuis
Premier Systems Integration, LLC
http://premiersi.com

davidbgtx

  • Hero Member
  • *****
  • Posts: 215
  • Host be the Most
Re: for/next loop always runs to completion
« Reply #3 on: December 07, 2014, 07:57:32 AM »
THANKS SO MUCH PLCNUT.
Had to move IF(ELSE) to top of task and add 1 to V600 to get it to "advance to next C that was true after "breaking out",(see final code in attached). The C bits will be my faults, N10 tells HMI which Fault Message to display. So if there are mutiple faults, each fault will display for 5 sec, then "advance" to next fault. No faults, N10=0, will display all ok on HMI. BTW took your advice on comparisons for easier readability too. Now to take some aspirin for the headache I got from beating my head against the wall, should have swallowed pride and asked for help sooner.