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 07-30-2008, 09:01 PM
 
Join Date: Mar 2005
Location: usa
Posts: 214
Harryman is on a distinguished road
how to write a subroutine

I'm using Wincnc and am attempting to write some simple subroutines. I've got the actual gcode figured out and how to write it in Wincnc, the problem is, I can't figure out when you call it, where you're calling it from. Where would the subroutine be filed? There's no folder for subs in Wincnc, although there's one for macros. I tried putting it in the main Wincnc folder and also the folder I normally run programs from without success.

I've searched for info and there's plenty on calling subroutines but never where they live. I got a feeling it's really simple so it's never mentioned......
__________________
www.harryhamilldesigns.com
CAD sculpting and services
Reply With Quote

  #2  
Old 07-31-2008, 10:05 AM
HuFlungDung's Avatar
Moderator
 
Join Date: Mar 2003
Location: Canada
Posts: 4,825
HuFlungDung is on a distinguished road

From a casual read of the manual, it looks like they use M98 "Filename" to call the subprogram and M99 to return from the sub.

The main program will contain the M98 Filename command on the exact line where you want to leave the main program. Obviously, you put either the name of your file in place of Filename, or else, standard practice would dictate that you use a program number to describe the program, but instead of using the big O for the filename, you would use P or sometimes another letter. So if the subprogram is a file called O12345,
M98 P12345
would be a typical subcall.

Now perhaps they've got this setup so that you can use a DOS type 8 character filename, but I'd try it simple first, to get it working.

At the end of your subprogram, you'll need a simple M99 and the controller should then return to the main program.

As for paths, one would think that if you kept both the main and the sub programs in the same folder, that the control should be able to find it.
__________________
First you get good, then you get fast. Then grouchiness sets in.

(Note: The opinions expressed in this post are my own and are not necessarily those of CNCzone and its management)
Reply With Quote

  #3   Ban this user!
Old 07-31-2008, 12:07 PM
 
Join Date: Mar 2005
Location: usa
Posts: 214
Harryman is on a distinguished road

Thanks,

I'll try a different naming format, I just tried a standard text name without any luck. As you saw, they don't specify how to name the sub but the manual tends written for those who already know what they are doing, not for those who don't.
__________________
www.harryhamilldesigns.com
CAD sculpting and services
Reply With Quote

  #4   Ban this user!
Old 07-31-2008, 02:45 PM
 
Join Date: Jun 2008
Location: United States
Posts: 1,507
stevo1 is on a distinguished road

HuFlung is correct with calling a sub program. Here is an example of a typical sub call.

O0001(Main Program)
G0G90G54
X0Y0Z0
M98P1234------------This will leave program 1 and start running 1234
G0G80
M30

O1234(Sub Program)
...
...
...
M99-------------------This is were program 1234 will end and go back to program 1. It will go back to program 1 were it left from so it will start with the G0G80 line and continue.

A macro Call works the exact same way except you would use G65P1234 and the assign variables to carry over with it. A, B, H, D, R etc. This would all be in the same line and you would say A=5 for number of holes B=81 for drilling cycle H=20 for part height etc. This would call to program 1234 then when it reads M99 will come back to here but start at the M30 program end. This however uses your local variable assignments #1 #2 #3 etc. So your sub would be using something like G0Z#3.

G65P1234A5.B81H20.
M30

Stevo
Reply With Quote

  #5   Ban this user!
Old 08-01-2008, 10:53 AM
 
Join Date: Mar 2005
Location: usa
Posts: 214
Harryman is on a distinguished road

Hmmm, I tried what you guys suggested and it's still not working. When I run a simple test program and it calls the sub, I get an error "Can't find sub123" or whatever I name it. I've tried placing it in different locations, although putting it in the folder I use for my usual programs seems the most logical.
__________________
www.harryhamilldesigns.com
CAD sculpting and services
Reply With Quote

Sponsored Links
  #6   Ban this user!
Old 08-01-2008, 11:02 AM
 
Join Date: Jun 2008
Location: United States
Posts: 1,507
stevo1 is on a distinguished road

Your not running this on the control? You are running from a PC? I am not sure how the folders are suppose to be set up when running from the PC. When the M98P123 is seen by the control it is looking for program 123 in the machine directory. If it is not registered in the directory it will give you and alarm "program not found".

If you are doing it via PC is there a reason that you want sub programs?

The other way to make it work would be to write your sub program and register it in the control as program O0123. Then when the control sees M98P123 in the main program it will run it from memory.

Stevo
Reply With Quote

  #7   Ban this user!
Old 08-01-2008, 12:04 PM
cnc-king's Avatar  
Join Date: Jul 2003
Location: united states
Posts: 232
cnc-king is on a distinguished road

if you are using your control to call the sub from a PC you need to use M198Pxxxx not M98 Pxxxx

there is a parameter you have to set so the control is looking for a prog and not a file, not sure what it is on your control.
__________________
If you can ENVISION it I can make it
Reply With Quote

  #8   Ban this user!
Old 08-01-2008, 12:50 PM
 
Join Date: Jun 2008
Location: United States
Posts: 1,507
stevo1 is on a distinguished road

I have never called sub programs from PC we run everything from the control. The king is right about the M198Pxxxx according to the book. I do not know what kind of control you are on but for the 15B series control it appears to be parameter #2404 bit 5. If =1 specify file, if =0 specify program. Then on the 18i series controls it appears to be parameter #3404 bit 2. If =1specify program, if =0 specify file.

Stevo
Reply With Quote

  #9   Ban this user!
Old 08-01-2008, 01:47 PM
 
Join Date: Mar 2005
Location: usa
Posts: 214
Harryman is on a distinguished road

If you are doing it via PC is there a reason that you want sub programs?
I'm customizing my screen and I want to set up a button to pull up Z, go to XY coordinates, then lower Z. Wincnc doesn't allow that much code in it's screen file, only a single line and thought a sub would be better. I thought it would be a decent thing to learn too, might come in handy.


Your not running this on the control? You are running from a PC?
I'm using Wincnc on a PC, it drives steppers with built in control boards via a PCI card. It's a desktop mill, there's no "built in" controller if that's what you're referring to. I'm not a machinist, so forgive my ignorance in how larger commercial machines are set up.


if you are using your control to call the sub from a PC you need to use M198Pxxxx not M98 Pxxxx
I'll try that and see
__________________
www.harryhamilldesigns.com
CAD sculpting and services
Reply With Quote

  #10   Ban this user!
Old 08-01-2008, 05:21 PM
 
Join Date: Mar 2005
Location: usa
Posts: 214
Harryman is on a distinguished road

I've gotten it figured out, thanks for all the help.

I actually got help from a support person at Wincnc, it's a rare event, but I hear they have different management these days so hopefully it will be more common.

You have to set up your subs as a macro and the file has to have a .MAC extension and be in their main folder. You can name it what you want and M98 "name" will work.
__________________
www.harryhamilldesigns.com
CAD sculpting and services
Reply With Quote

Sponsored Links
  #11   Ban this user!
Old 08-04-2008, 08:36 AM
 
Join Date: May 2007
Location: USA
Posts: 913
g-codeguy is on a distinguished road

Although I am not familiar with your system, I want to thank you for getting back to us with the proper solution.

I wish everyone would.
Reply With Quote

  #12   Ban this user!
Old 08-04-2008, 11:04 AM
 
Join Date: Mar 2005
Location: usa
Posts: 214
Harryman is on a distinguished road

It was the least I could do..... <bow>
__________________
www.harryhamilldesigns.com
CAD sculpting and services
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
Need Help!- M97, M98 subroutine call. How to use bob1112 Haas Mills 11 03-12-2008 07:41 PM
Example of a Subroutine? donl517 Fadal 14 06-27-2007 10:05 AM
Help with calling a subroutine hindocarina Mach Mill 2 02-11-2007 09:32 PM
trying to call a subroutine hindocarina G-Code Programing 4 02-11-2007 08:01 PM
Need help with subroutine 2_jammer General CAM Discussion 1 01-17-2005 10:46 PM




All times are GMT -5. The time now is 10:15 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