G Code Cycle repeat

Moderators: TomKerekes, dynomotion

Post Reply
aaperezd
Posts: 11
Joined: Wed Feb 26, 2020 3:07 pm

G Code Cycle repeat

Post by aaperezd » Sat Mar 28, 2020 9:25 pm

Hi Tom, is there a way to do the following:
I need to execute a code g a selectable number of times, when starting the sequence I must put the number (example N = 10), press start (Execute code G) and when finished (example R = 1 (R = executions code G) it must to deduct once from the total number of executions that I put at the beginning (NR = 9 times remaining), that until the number of executions ends (N = 0) and when I get there I warn with an alarm (activates an output in high state, to activate a horn)

I imagine the system like this:

N = Target executions of g code
R = Executions carried out g code

N = 10
Start / cycle start /
Run G code
At the end G code
N-R = 9
Start / cycle start /
Run G Code
At the end G Code
N-R = 8
.
.
.
N-R = 0

If N = R then Activate output (turn on Horn)

Please can you tell me where to read information regarding this?
Thank you

Moray
Posts: 282
Joined: Thu Apr 26, 2018 10:16 pm

Re: G Code Cycle repeat

Post by Moray » Sat Mar 28, 2020 10:02 pm

Use a sub-routine, and then configure one of the custom M-codes (I just used M110, but anything from M100-119) to activate an output bit.
If you only want to have the horn sound for a set amount of time, configure another custom M-code to deactivate the output bit, and put a dwell (G4) command in between the two on and off M-codes.

for example -

Code: Select all

(loop test)
#1=2 (number of loops)
G20 G90
G0 X0 Y0
F40
m100
M98 P100 L[#1]
M110 (custom M-Code to activate horn)
G4 5 (dwell for 5 seconds)
M111 (custom M-code to deactivate horn)
M2



O100
G1 X0 Y0
X1 Y0
X1 Y1
X0 Y1
X0 Y0
M99


aaperezd
Posts: 11
Joined: Wed Feb 26, 2020 3:07 pm

Re: G Code Cycle repeat

Post by aaperezd » Sun Mar 29, 2020 7:45 pm

Thanks friend, I had not remembered the use of subroutines in G code, I will test and I will tell you, thank you very much!

aaperezd
Posts: 11
Joined: Wed Feb 26, 2020 3:07 pm

Re: G Code Cycle repeat

Post by aaperezd » Sun Mar 29, 2020 8:01 pm

If I have a doubt, I was remembering, the times that I used the subroutine it did not stop, it was only towards the number of cycles that I determined without stopping, I need it to be able to stop, because material must be changed, that is, if I do a circle in table one and the cycle is ten I must change the table every time a cycle is made.

in any case I am reviewing manuals to see if I determine it by myself

thank you

User avatar
TomKerekes
Posts: 2527
Joined: Mon Dec 04, 2017 1:49 am

Re: G Code Cycle repeat

Post by TomKerekes » Sun Mar 29, 2020 9:49 pm

Hi aaperezd,

I'm not sure I understand. But you can halt the GCode with an M0. Or you can pause and display a message with (MSG,Change the Table).

If you need to pause based on a formula, such as every 10 times, then a conditional call to a pause subroutine can be coded. See the example: SubroutineWithConditionals.ngc also shown below:

Code: Select all

G20
#100 = 5

(examples of logical operations)
(result is 1 if condition is true)
(result is 0 if condition is false)

#101 = [#100 >  5]
#102 = [#100 >= 5]
#103 = [#100 <  5]
#104 = [#100 <= 5]
#105 = [#100 =  5]
#106 = [#100 <> 5]

(subroutine call can be looped a number of times)
(the L or Q word may be used to specify the count)
(if neither L or Q is specified a count of 1 is used)
(if the count is 0 the subroutine will not be called at all)

M98 P1 L3  (example using L to specify the loop count)
M98 P1 Q3  (example using Q to specify the loop count)

M98 P1 L#100  (example using a variable loop count)

M98 P1 L[5 > 4]  (example using a conditional as a loop count)
M2

O1
#200 = [#200+1]
M99
Regards,

Tom Kerekes
Dynomotion, Inc.

aaperezd
Posts: 11
Joined: Wed Feb 26, 2020 3:07 pm

Re: G Code Cycle repeat

Post by aaperezd » Mon Mar 30, 2020 12:59 am

Thanks to both,

I will use the Mach 3 plugin for now because we have the screens programmed and designed for the retrofitt, but in the future I want to create a totally own screen through Visual Studio.

but I'm already understanding the reference you gave me Tom, thank you very much.

Post Reply