CNCzone.com-The Largest Machinist Community on the net!



Home Page Mark Forums Read Today's Posts My Replies Classifieds Reviews Photo Gallery Web Links Share Files Advertise With Us Ad List
Go Back   CNCzone.com-The Largest Machinist Community on the net! > Machine Controllers Software and Solutions > G-Code Programing


G-Code Programing Discuss G-code programing and problems here!


This forum is sponsored by:

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Ban this user!
Old 03-23-2007, 02:21 AM
 
Join Date: Feb 2006
Location: india
Posts: 1,187
sinha_nsit is on a distinguished road
custom macro question

Can we call subprograms (using M98) from a macro and
vice-versa (using G65/66)?

If the answer is "yes", can we have a total of 8
levels of mixed nesting (4 for macro and 4 for
subprograms)?

If the answer to the previous question is "yes", I
believe, all the nested macros will have different
"levels" of the local variables (#1 to #33), but the
local variables of the nested subprograms will have
the level of the calling program (which can be a macro
or another subprogram). Am I right?
Thanks.
Reply With Quote

  #2   Ban this user!
Old 03-25-2007, 08:47 PM
gar gar is offline
 
Join Date: Mar 2005
Location: USA
Posts: 1,498
gar is on a distinguished road

070325-2009 EST USA

sinha_nsit:

On a HAAS machine, similar to Fanuc, a G65 subroutine call allows parameter passing on the G65 line thru alphabetic addresses on the G65 line that map to local addresses in the called routine. The local addresses in a G65 subroutine (which is a separate O-numbered program) are independent of any other local addresses in any other G65 subrountine. My guess is that these local variables are stored on the computer stack. This means they are volatile, and may be unique.

Note: there is no way to pass values back to the calling program level other than thru common variables. Also, the local variables of a given level are not destroyed by calling a subprogram. But when you go up a level those on the level you go up from are destroyed.

Other subroutines than G65 do not allow parameter passing thru addresses on the calling line. Thus, common variables are used for parameter passing and these must be preset before calling the subroutine.

G65 subroutines at each level have a new set of local variables created.

I suspect that since M98 is an external subroutine call that its local variables are different than those in the calling program, but I have never tested this.

My guess is that a local subroutine call, M97, may share the local variables of the calling program. I might think to test this later or someone else can maybe check these.

You run tests like this by using a common variable to store the value of a local variable in the common variable for inspection later, or use DPRNT to output your test values.

.
Reply With Quote

  #3   Ban this user!
Old 03-26-2007, 02:03 AM
 
Join Date: Feb 2006
Location: india
Posts: 1,187
sinha_nsit is on a distinguished road

Thanks for your reply. You have understood what confusion I have. Incidently, Fanuc 0i series uses M98 for internal subprograms and M198 for the external ones.
In case you do get some additional information regarding combined nesting of subprograms and macros (I use the term subprogram for a program called by M98, and macro for a program called by G65), and how the local variables are treated by them, please let me know.
We may discuss it with an example to pinpoint the confusion:
The main program 1000 calls a subprogram 1001 by M98,
1001 calls a macro 1002 by G65,
1002 calls a subprogram 1003 by M98,
1003 calls a macro 1004 by G65,
1004 calls a subprogram 1005 by M98,
1005 calls a macro 1006 by G65,
1006 calls a subprogram 1007 by M98 and
1007 calls a macro 1008 by G65.
Here we have used 8 level nesting - 4 for subprograms and 4 for macros. My question is that can we have a combined nesting of 8 levels in this manner? Actually, 4 levels of nesting each for subprograms and macros are allowed.
Assuming such a nesting is permissible with Fanuc 0i series, let us assume that a local variable #1 is being used in the main program as well as in all the nested subprograms/macros. I believe (please correct me if I am wrong!), a subprogram called by M98 does not change the level of the local variables of the calling program, whereas a macro called by G65 does change the level. This means that #1 will have different meanings in the main program 1000 and the 4 macros (1002, 1004, 1006 and 1008), but #1 of the main program 1000 and that of subprogram 1001 will have the same meaning (i.e., they refer to the same memory location). Similarly, #1 of 1002 and that of 1003 will have the same meaning, and so on. Am I correct?
I do have the original 0i series TC and MB manuals, but these things are not clear. Kindly help! Thanks.
Reply With Quote

  #4   Ban this user!
Old 03-26-2007, 06:13 AM
gar gar is offline
 
Join Date: Mar 2005
Location: USA
Posts: 1,498
gar is on a distinguished road

070326-0543 EST USA

sinha_nsit:

See page 83 under MACROS in the HAAS on-line mill manual. This is 96-8000.pdf . A statement there says
"Local Variables
..G65...the local variables are saved and a new set is available for use...
...Calling a subroutine via an M97 or M98 does not nest the local variables.
....
"

In this HAAS discussion they provide a very clear explanation.



Do the following to verify what happens in your system:

O1000
#1 = 101
#500 = #1
M98 P1001
#501 = #1
#506 = #2

M30




N 1001
#502 = #1
G65 P1002 A5.0
#504 = #1
#505 = #2
M99


O1002
#503 = #1
#1 = 1002
#503 = #1
#2 = 11002
M99

.
Reply With Quote

  #5   Ban this user!
Old 03-09-2009, 12:45 AM
 
Join Date: Feb 2006
Location: india
Posts: 1,187
sinha_nsit is on a distinguished road

I have verified on 0i TC.
Yes, a maximum of 8 level of mixed nesting is allowed, with max 4 macros and max 4 subprograms. But, you cannot have, say, 5 macros or 5 subprograms.

Nested subprograms always use the local variables of the calling program (which can be the main program, or a macro or another subprogram). So, even in a mixed nesting of 8 levels, there will only be 4 levels of local variables (plus one level for the main program).
Reply With Quote

Sponsored Links
  #6   Ban this user!
Old 03-09-2009, 07:45 AM
 
Join Date: Jun 2008
Location: United States
Posts: 1,507
stevo1 is on a distinguished road

Wow sinha nsit you have been busy on this for quite some time. Anyhow I am glad that you have becasue this raises a question of mine that I have not bothered to try and see if it works or not. It has just been more of a personal wanting to know not that I have needed to use it.

You are mixing the macro calls and sub calls to be able to nest up to 8 levels. I am going to use an example. When calling G65P8000A10 program 8000 is called and #1=10. Now in the 8000 program we do another macro call say G65P8001A50 now program 8001 is called and #1=50 now when returning from 8001 to 8000 via M99 #1 is restored to 10. My question is does this hold true when using a M98 call then returning to the previous macro? Or do you not rerun your previous macro?

I do this quite often with macro calls but I have never dropped a M98 in the program to see if the values restore.

Stevo
Reply With Quote

  #7   Ban this user!
Old 03-10-2009, 12:44 AM
 
Join Date: Feb 2006
Location: india
Posts: 1,187
sinha_nsit is on a distinguished road

No.
A subprogram is only an "extended part" of the calling program, and M98/M99 just do copy-and-paste operation. So, a subprogram uses the local variables of the calling program with the same meaning, ie, using the same memory location. So, if a subprogram assigns to a new value to a local variable of the calling program, the original values defined in the calling program is lost for ever. After M99, the new values, as defined in the subprogram, become available in the calling program.

Incidently, you can call a subprogram with G65 also, ie, without passing values for the local variables:
M98 P1000 or G65 P1000
These two are NOT equivalent.
O1000, called by M98, will use the local variables of the calling program.
But, O1000 called by G65, will use a new set of local variables which will all be NULL, initially.
Reply With Quote

  #8   Ban this user!
Old 03-10-2009, 12:45 AM
 
Join Date: Feb 2006
Location: india
Posts: 1,187
sinha_nsit is on a distinguished road

No.
A subprogram is only an "extended part" of the calling program, and M98/M99 just do copy-and-paste operation. So, a subprogram uses the local variables of the calling program with the same meaning, ie, using the same memory location. So, if a subprogram assigns to a new value to a local variable of the calling program, the original values defined in the calling program is lost for ever. After M99, the new values, as defined in the subprogram, become available in the calling program.

Incidently, you can call a subprogram with G65 also, ie, without passing values for the local variables:
M98 P1000 or G65 P1000
These two are NOT equivalent.
O1000, called by M98, will use the local variables of the calling program.
But, O1000 called by G65, will use a new set of local variables which will all be NULL, initially.
Reply With Quote

  #9   Ban this user!
Old 03-10-2009, 08:16 AM
 
Join Date: Jun 2008
Location: United States
Posts: 1,507
stevo1 is on a distinguished road

That makes sense. I guess I have written programs in that manner I just never thought about using the variables coming out of the subprogram M98 as I normally do when nesting the G65 macros. The more I read my question the more I realize it was a pretty stupid question because I knew the answer to it. What I was asking is really no different than setting #1=10 in a main program then calling a sub via M98. #1 can be used as is never changed either by the sub call or the return call.

Brain fart.

Stevo
Reply With Quote

  #10   Ban this user!
Old 03-12-2009, 01:03 AM
 
Join Date: Feb 2006
Location: india
Posts: 1,187
sinha_nsit is on a distinguished road

No question is "stupid". Such a view stops the learning process. Nobody knows everything. In fact, I also have asked several questions on this forum. Many of these might be "stupid questions", but I learnt a lot in the process. Fortunately, many people (including you) on this forum are knowledgeable and helpful. It is great to see that so many people are spending hours to help those who are unknown to them.
Reply With Quote

Sponsored Links
  #11   Ban this user!
Old 03-12-2009, 09:18 AM
 
Join Date: Jun 2008
Location: United States
Posts: 1,507
stevo1 is on a distinguished road

I agree there is no stupid question. I was just referring my stupidity to the fact that I asked a question that I knew the answer to but didn’t take the time to really look at what I was asking.

It is nice to see so many people help each other. I love to share the knowledge. I believe in the pay it forward method. I have had a lot of people message me saying thanks I don’t know how I will every repay you. My response is always help the next person up when they stumble or need advice.

Stevo
Reply With Quote

  #12   Ban this user!
Old 03-18-2009, 08:53 AM
 
Join Date: Feb 2009
Location: india
Posts: 48
chetan is on a distinguished road

Can anyone tell me. How G160 works? My machine is Tornos Bechler Enc 162 and in every program there is G160 H9810. I ref. program manual in which it is stated that it is Tornos- Bechler sub routine used to calculate no. of pieces. Can we read this sub routine 9810 on screen? As it is not available in program library. Below is the example
%
:0070
G10P10001X0Z-7.2R0Q9
G10P10002X0Z-11.2R0Q9
G10P10022X0Z-11.2R0Q9
G10P10004X0Z-9.9R0Q9
G161A13.2B0.06C0404F-34.38H2.5J2K1M15Q0
M8
G4X2
M4S4000
G160H9810
G160H9901
N5
G0Z0.2
X17T5000
M90
G92Z0.4
T0101
M4S5000
G0X14Z0
G1X-0.6F0.05
X4.03
N40Z0
N41X4.43Z-0.2F0.03
Z-3.6
N50G0X13.1Z-3.4
Z-4.38
N51G1X12.1Z-3.88F0.03
X4.44F0.05
X12.5Z-3.7F0.2
G0X17T0
T1300
T0202
M4S4000
M24
G0X13.2Z-4.98
G1X12.2Z-5.48F0.01
X5.125F0.03
Z-12.0F0.04
G1Z-12.23F0.01
T3222
G3X4.725Z-12.43R0.2F0.004
G1X4.71F0.01
X4.75Z-33.7F0.05
Z-33.88F0.01
G3X3.91Z-34.28R0.4F0.005
G1X13F0.2
G0X17T0
T0404
M4S4000
G0X13.2Z-34.18
M28
G1X5F0.08
X-0.2F0.04
M25
X-1.6F0.06
M29
M1
T1100
G160H9902
G65H80P5
M2
%
Reply With Quote

Reply




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro B Question Bluetech Fanuc 7 03-10-2009 12:58 AM
custom Macro B options gup Fanuc 2 03-09-2009 11:41 AM
Custom Macro Screens, Series 0MC RLMTS Fanuc 0 01-03-2007 05:54 AM
Custom Macro B On A 18t. JIMMYZ Fanuc 3 10-18-2006 10:08 PM
custom macro The Metal Daewoo/Doosan 2 09-28-2006 07:26 AM




All times are GMT -5. The time now is 08:19 PM.





Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Content Relevant URLs by vBSEO
Template-Modifications by TMS

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361