News:

  • June 28, 2026, 02:15:53 PM

Login with username, password and session length

Author Topic: Loops vs Program/stage  (Read 84836 times)

CReese

  • Hero Member
  • *****
  • Posts: 184
Re: Loops vs Program/stage
« Reply #45 on: September 23, 2013, 02:28:47 PM »
Question : The LogEvent actions can be in a task since it will be executed before the next Log Event, correct?
I would NOT stick it in a separate code-block, but do all the logic from within S2.  That way, if you DO have anything that takes more than 1 scan, you will stay in S2 until it finishes, then once the work inside S2 is done, JMP back to S1.  Hence, your JMP S1 from within your S2 should have a contact driving it.  You could make it unconditional ONLY IF there are no multi-scan instructions inside S2 (no edge triggers, no async/device instructions, no tmr, no cnt, only "combinatorial" logic that runs to completion within its execution).


Or I could make the jump back into the WHILE conditional upon a completion bit set by the LogEvent Task.

CReese

  • Hero Member
  • *****
  • Posts: 184
Re: Loops vs Program/stage
« Reply #46 on: September 23, 2013, 02:48:31 PM »
This would maximize speed, correct? (Skipping the remainder of the stage). Please take a look below and let me know what you think. It seems from what you have said that if I put an EXIT below the RST in the DAlarmIndex >= DAlarmCount block that I could skip the remainder of that stage's logic, which could be a minimal improvement.

What I currently have is the following. It is currently running at ~900ms for the whole alarm stack. This is quite fast.

SG0:
MATH DAlarmReadTime=TICKms()
DATAINFO DAlarmCount=Length(DAlarmNames)
SETNUMR DAlarmIndex=0
SET RunAlarmLoop
JMP SG1

SG1:
WHILE RunAlarmLoop
   IF DAlarmIndex >= DAlarmCount:
      DAlarmReadTimer=TICKms()-DAlarmReadTime
      RST RunAlarmLoop
      JMP S0

   << Alarm Processing Code >>

   MATH DAlarmIndex= DAlarmIndex+1

   IF LogEvent:
      RST RunAlarmLoop
      JMP S2

WEND

S2:

<< Alarm logging preprocessing >>

ENTASK CopyElementToLog
IF LogDone:
   SET RunAlarmLoop
   JMP S1

« Last Edit: September 23, 2013, 03:10:06 PM by CReese »

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3827
    • Host Engineering
Re: Loops vs Program/stage
« Reply #47 on: September 23, 2013, 03:52:51 PM »
Do NOT use EXIT.  Monitoring Alarms is a continuously running program that never ends.

I only mentioned that anomaly to show how EXIT does what you THOUGHT JMP did.

CReese

  • Hero Member
  • *****
  • Posts: 184
Re: Loops vs Program/stage
« Reply #48 on: September 23, 2013, 04:59:46 PM »
Do NOT use EXIT.  Monitoring Alarms is a continuously running program that never ends.

I only mentioned that anomaly to show how EXIT does what you THOUGHT JMP did.

Yes I since tested it. Break does what I want.

CReese

  • Hero Member
  • *****
  • Posts: 184
Re: Loops vs Program/stage
« Reply #49 on: September 23, 2013, 05:00:21 PM »
although I suppose BREAK should start another scan, which is what I was trying to avoid in the first place.

CReese

  • Hero Member
  • *****
  • Posts: 184
Re: Loops vs Program/stage
« Reply #50 on: September 23, 2013, 05:01:53 PM »
CONTINUE is what I want!