Hello Guest it is December 26, 2024, 09:52:00 AM

Author Topic: Can Mach3 Do a simple loop to increment a variable?  (Read 17920 times)

0 Members and 1 Guest are viewing this topic.

Can Mach3 Do a simple loop to increment a variable?
« on: August 13, 2023, 10:56:15 AM »
I searched but couldn't find an answer.

I am writing a program where I set X at a starting point, Run a subroutine, Then move X .003 and do it again about 35 times. Can Mach3 Loop a variable to increment X?

I have to do this up to 16 times in a single program. If not possible in Mach3 what about Mach4? I have everything I need to upgrade Just too lazy to rewire my panel and switch over. Also many people who may use this code are probably still running Mach3.

Something like this?

start loop
Increment variable .003
X=Variable
if variable < end Number
    Call subroutine
else
    Exit loop
end if
Loop






Offline Graham Waterworth

*
  • *
  •  2,747 2,747
  • Yorkshire Dales, England
Re: Can Mach3 Do a simple loop to increment a variable?
« Reply #1 on: August 13, 2023, 11:00:04 AM »
You can call a sub to do the work.

E.G.

%
O0001 (MAIN)
#100 = 0
G00 X0 Y0
M98 P2 L50 (loop 50 times)
M30

O0002(SUB)
#100 = [#100 + 0.003]
G00 Z-#100
M99
%

Or

%
O0001 (MAIN)
G00 X0 Y0 Z5.
M98 P2 L35 (1ST)
G00 X10. Y5.
M98 P2 L35 (2ND)
G00 G90 Z10.
M30

O0002 (SUB)
G00 G90 Z1.
G01 Z-1.  F25.
G00 Z1.
G91 X-.003
G90
M99
%
« Last Edit: August 13, 2023, 06:35:54 PM by Graham Waterworth »
Without engineers the world stops
Re: Can Mach3 Do a simple loop to increment a variable?
« Reply #2 on: August 13, 2023, 12:35:54 PM »
Yes Sir!  I did not know about the L50 (Loop 50 times) command. Ill have to count my loops and see how many i am making. Thank You!

Im going to figure out how this works!!!
Re: Can Mach3 Do a simple loop to increment a variable?
« Reply #3 on: August 13, 2023, 01:07:37 PM »
Mach3 seems to have an issue with this line.

#100 = #100 - 0.003

Bad character used, block = #100 = #100 - 0.003

I am #100 = -0.460 and im trying to step to -0.463, -0.466 Etc. What am I missing?

BTW everything else is working. Its going to where the variable is set to, Its looping as many times as I tell it. I just need to get the variable to increment. That line is in the sub routine/Loop
« Last Edit: August 13, 2023, 01:22:19 PM by stevehuck »
Re: Can Mach3 Do a simple loop to increment a variable?
« Reply #4 on: August 13, 2023, 01:36:34 PM »
I did some sniffing around on the web and found some example code. Turns out i was missing some brackets.

#100 = #100 - 0.003

#100 = [#100 - 0.003]

Thanks for steering me in the correct direction. You have saved me HOURS of writing code!!

Offline Graham Waterworth

*
  • *
  •  2,747 2,747
  • Yorkshire Dales, England
Re: Can Mach3 Do a simple loop to increment a variable?
« Reply #5 on: August 13, 2023, 06:38:23 PM »
Sorry for the error, I was thinking in Mach4 mode, I had forgotten Mach3 needs the square brackets.  How soon we forget lol
Without engineers the world stops
Re: Can Mach3 Do a simple loop to increment a variable?
« Reply #6 on: August 18, 2023, 05:34:10 PM »
No problem! I usually only need someone to point me in the right direction. Don't have to hold my hand lol. I should switch over to mach4 but I get distracted easily. I have everything I need sitting on top of the computer for over a year now.