For and While in Studio 5000 Ladder?

ASF's code with the minor adjustment to the location of the JMP works perfectly and it's pretty fast. Not quite as fast as the ST but close enough. I combined it with the rest of the logic needed, made an AOI and it works great.

I just wish I could pull the description field from a Logix PLC tag from within PLC logic. That would be the cherry on top - but alas that can't yet be done.

Thanks to all for the assist.
 
A 16-bit signed integer can handle -32768 up to 32767.
Yes, and subtracting 1 from -32768 would cause and overflow, and any 16-bit signed integer with a value of 1 in alarm bit 15 will eventually result in subtracting 1 from -32768.

Update: Actually, these appear to be DINTs, but they still have the same problem if any bit 31 values are 1.
 
Last edited:
ASF's code with the minor adjustment to the location of the JMP works perfectly and it's pretty fast. Not quite as fast as the ST but close enough. I combined it with the rest of the logic needed, made an AOI and it works great.

I just wish I could pull the description field from a Logix PLC tag from within PLC logic. That would be the cherry on top - but alas that can't yet be done.

Thanks to all for the assist.

This should run slightly, but perhaps not measurably, faster.

Untitled.png
 
Is the juice here worth the squeeze?
Like you I like to get the code as tight as I can if for no other reason than my own OCD and I think that's true here.
Having said that... now that you pointed it out... Damn it!.
 
Here are the results for a MicroLogix 1100; I don't know if they will be similar in a Logix/Studio 5000 environment.

speed_vs_byte_value.png

The timing was used the S:4/S:35 10kHz timer for 1000 iterations of four 32-bit signed integers (MicroLogix Longs). Each of the four Longs were filled with for consecutive bytes of the same value (0x00_00_00_00, 0x01_01_01_01, ..., 0xFF_FF_FF_FF).

The following 1-valued bit counting algorithms were coded and measured:
  • CONTRL - no bit counting (control group; measures mean scan time)
  • SUBAND - Kernighan's way; SUBtract and AND result to count right-most bit; what @waterboy used; cf. here.
  • PARALLEL - fancy parallel counting; cf. here.
  • XIC_ - check each bit using /[INDEX[ notation
  • LOOKUP - precalculate bits for all possible values (0-255) of a byte; count 8 bits at a time.
 
Yes e.g.

Code:
FOR N := 1 TO 3 DO
  Y[I] := N * N;
END_FOR;

is equivalent to this "unrolled" version

Code:
N = 0
Y[N] := N * N; N := N + 1;
Y[N] := N * N; N := N + 1;
Y[N] := N * N; N := N + 1;

Optimizing compilers can unroll FOR loops when the number of iterations is known, and even sometimes when the number of iterations is not known. It provides a performance enhancement because the loop index comparison with its implicit GOTO (JMP equivalent) are eliminated.

In our case, the NEQ element 0 was the comparison, so only some JMPs saved, but it does save a few µs per Long.
 

Similar Topics

After migrating a SLC to a 1769-L36ERM, the Studio 5000 interface was almost unusable. I started with v24, and then changed to v30 with no...
Replies
8
Views
6,419
Hi guys, To make a short story of my problem, We had studio view 6.000 here installed on our laptop and alot of the automation have been done...
Replies
1
Views
2,536
Hello The plant is running and there is no shutdown nowadays therefore I can add 1734- AENTR and its card while PLC is in Run? I do not wanna...
Replies
8
Views
349
I have an issue with Power Flex 525 during running processing, the VFD stopped suddenly while the PLC and VFD connection ok, VFD does not have any...
Replies
1
Views
127
Hello! When trying to load the hardware configuration I get error 0050-133 2 2458, check the diagnostic buffer. When checking the buffer, it says...
Replies
4
Views
186
Back
Top Bottom