Host Engineering Forum

General Category => Do-more CPUs and Do-more Designer Software => Topic started by: Bolt on November 26, 2024, 02:12:46 PM

Title: "Freezing" a FOR/NEXT Loop
Post by: Bolt on November 26, 2024, 02:12:46 PM
Is there a way to "freeze" a FOR/NEXT loop? Say I have a loop monitoring some bits. If a bit becomes TRUE, I'd like to keep the pointer value where it is, end the loop, and let the rest of the PLC's logic proceed as normal. It's not quite a BREAK, as next scan I'd like the loop to continue with it's previous pointer value. Is this even a thing?
Title: Re: "Freezing" a FOR/NEXT Loop
Post by: franji1 on November 26, 2024, 02:23:21 PM
There is no "enable" leg on a FOR/NEXT loop.

What you can do, is emulate a FOR/NEXT using WHILE/WEND where you can conditionally terminate the loop with conditions other than Count < Preset (e.g. EnableLoop AND Count < Preset)
Title: Re: "Freezing" a FOR/NEXT Loop
Post by: Bolt on November 26, 2024, 02:36:40 PM
Ah, I hadn't thought of using WHILE/WEND here. I am considering doing a COPY Pointer to Holding and BREAK, then at the start of the loop IF Holding>0, COPY Holding to Pointer. That should work I think.
Title: Re: "Freezing" a FOR/NEXT Loop
Post by: franji1 on November 26, 2024, 03:50:34 PM
I forgot...
FOR/NEXT behavior is Count <= Preset
;D
Title: Re: "Freezing" a FOR/NEXT Loop
Post by: Bolt on November 26, 2024, 03:59:58 PM
True, but no big deal here. For my application today it worked to COPY Pointer Count to Holding, and BREAK. At the top of the loop I COPY Holding back to Count so it picks up where it left off until I reset the Holding.