Host Engineering Forum
General Category => Do-more CPUs and Do-more Designer Software => Topic started by: davidbgtx 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.
-
I think T2.done resets the timer and shuts off T2.done before it can do anything below the timer.
-
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.
-
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.