Hello Guest it is May 01, 2025, 09:44:25 AM

Author Topic: Mach 3 Loop (L) parameter limit  (Read 4434 times)

0 Members and 1 Guest are viewing this topic.

Offline rcaffin

*
  •  1,066 1,066
Mach 3 Loop (L) parameter limit
« on: December 02, 2024, 01:35:43 AM »
The L parameter lets one call a subroutine many times - but no more that about 997  times.
Why the limit? (g-code is not recursive)
Has anyone found a way to change this - up to, say, 64,000?
(As far as I can see, this should not add anything to the internal SW stack.)

Cheers
Roger

Offline Graham Waterworth

*
  • *
  •  2,779 2,779
  • Yorkshire Dales, England
Re: Mach 3 Loop (L) parameter limit
« Reply #1 on: December 02, 2024, 05:24:22 PM »
But the return pointer has to be stored for every iteration.

Just put a sub in a sub

%
M98 P1 L100
M30

O0001 (Sub 1)
M98 P2 L100
M99

O0002(Sub 2)
G01 Z-1. F25.
M99
%
Without engineers the world stops

Offline rcaffin

*
  •  1,066 1,066
Re: Mach 3 Loop (L) parameter limit
« Reply #2 on: December 02, 2024, 06:34:45 PM »
Hi Graham

But the return pointer has to be stored for every iteration.
Yes, true, BUT ...
If I think in terms of Assembler, a return address does have to be stored on the stack, but it gets overwritten with each call. After all, once the program returns from the called sub, the pointer on the stack can be wiped out (ie, overwritten). So calling a sub 10 times or 10,000 times makes no changes in stack size per se. OK, I don't know how Mach3 is written, but would think the same would apply for (most) any language.

Nested subroutines? Yes, already done of course.
That even has some advantages: where I don't need the extra resolution, I can just put the 2nd loop parameter equal to 1 rather than, say, 20. Not that it matters very much with a gigahertz processor driving a metal-working CNC!

But still, I ask why?

Cheers
Roger

Offline Graham Waterworth

*
  • *
  •  2,779 2,779
  • Yorkshire Dales, England
Re: Mach 3 Loop (L) parameter limit
« Reply #3 on: December 02, 2024, 07:14:25 PM »
I bow to your greater knowledge, what I will say is, after many years of testing Mach3/4 the more loops the greater the memory used to the point things get corrupted.

Think yourself lucky most systems only allow 99 loops (L99).

Without engineers the world stops

Offline rcaffin

*
  •  1,066 1,066
Re: Mach 3 Loop (L) parameter limit
« Reply #4 on: December 02, 2024, 08:59:28 PM »
Strange programming in that case. Oh well, it happens.

Only L99 on some systems? Good lord - primitive! But indeed, on pre-PC systems, they would be.

Thank you.
But I still wish someone knew the location for the 997 figure, so I could try changing it.

Cheers
Roger