A Serial Numbering Custom Macro

The custom macro shown below will allow you to mill numbers on your workpieces. Though it has some limitations that can be easily improved upon, the macro shows the logic behind how serializing can be done.

Columns From: 8/1/2007 Modern Machine Shop,

The custom macro shown below will allow you to mill numbers on your workpieces. Though it has some limitations that can be easily improved upon, the macro shows the logic behind how serializing can be done.
A permanent common variable (#500) is used to keep track of the current serial number. Prior to starting a production run, the operator must reset this variable to zero. This custom macro allows you to serialize numbers from 1 to 999, which should cover most production runs. If you need to serialize higher, then you can figure out the logic for doing so from our example.

You’ll call the serializing custom macro from your main program after you’ve commanded that the engraving tool be placed in the spindle. The variables you’ll place in the call statement to the custom macro include: X and Y position to start (X, Y); the Z surface into which to engrave (Z); the spacing you desire between the characters (S); the feedrate for milling (F); and the depth to which you want to engrave (D). The custom macro does the rest, stepping the serial number each time the it is called, and milling the current number.

Ten subprograms are required, one for each number (0 through 9). The program for the number zero is O5000. Number one is O5001. Number two is O5002 and so on through O5009. We’ve included one example number (one, program O5001), but there isn’t room here to show them all. If you want the rest of them, then visit www.cncci.com/resources/tips/serial.htm. However, it’s likely that you’ll need to create your own number programs, based upon the size and font you require (the numbers you can find on my Web site are 1.0-inch high).

Here is a sample calling program—just enough to show the custom macro being called:

O0001 (MAIN PROGRAM)
N005 T01 M06 (ENGRAVING TOOL)
N010 G54 G90 S440 M03
N015 G00 X0 Y0
N020 G43 H01 Z1.0 M08
N025 G65 P4999 X1.0 Y1. Z0.0 F4.0 S0.75 D0.01
N030 G91 G28 Z0 M19
N035 M30

Here is the serializing custom macro program:
O4999 (SERIAL NUMBERING CUSTOM MACRO)
#111=#24 (FIND CURRENT X ABS)
#112=#25 (FIND CURRENT Y ABS)
#113= #26 (FIND CURRENT Z ABS)
#500 = #500+1 (STEP SERIAL NUMBER)
#110 = #19 (SPACING)
#121 = #9 (FEEDRATE)
(1 THROUGH 1O)
IF [#500 GT 9] GOTO 10
G52 X#111 Y#112
#105 = 5000 + #500
G65 P#105 Z#26 D#7
G52 X0 Y0
GOTO 99

(10 THROUGH 99)
N10 IF [#500 GT 99] GOTO 20
G52 X#111 Y#112
#100 = FIX[#500/10] (GET FIRST)
#105 = 5000 + #100
M98 P#105
G52 X[#111+#110]
#101 = #500 - #100*10
G65 P[5000+ #101] Z#26 D#7
G52 X0 Y0
GOTO 99

(100 THROUGH 999)
N20 IF [#500 GT 999] GOTO 30
G52 X#111 Y#112
#100 = FIX[#500/100] (GET FIRST)
G65 P[5000 +#100] Z#26 D#7
G52 X[#111+#110] Y#112
#101 = #500 - #100*100
#102 = FIX [#101/10] (GET SECOND)
G65 P[5000+ #102] Z#26 D#7
G52 X[#111+#110*2] Y#112
#103 = #101 - #102*10 (GET THIRD)
#105 = 5000 +#103
G65 P#105 Z#26 D#7
G52 X0 Y0

GOTO 99
N30 #3000 = 100 (OUT OF RANGE)
N99
M99

Here is the subprogram for the number one (1):

O5001
G00Z[#26+0.1]
X0.5183Y0.0
Z[#26+0.1]
G01Z[#26-#7]F#121
X0.3961Y0.0
X0.3961Y0.7792
X0.3723Y0.7582
X0.345Y0.7371
X0.3143Y0.716
X0.2802Y0.695
X0.2453Y0.6752
X0.2122Y0.6581
X0.1809Y0.6436
X0.1515Y0.6318
X0.1515Y0.75
X0.2012Y0.7754
X0.2476Y0.8033
X0.2908Y0.8338
X0.3308Y0.8668
X0.3664Y0.9009
X0.3964Y0.9344
X0.4208Y0.9675
X0.4395Y1.0
X0.5183Y1.0
X0.5183Y0.0
M99

Comments are reviewed by moderators before they appear to ensure they meet Modern Machine Shop’s submission guidelines.
blog comments powered by Disqus
MMS ONLINE
Channel Partners
  • Techspex