427
Applications
A CNC System for a Lathe Using a Low Cost PC V.V. A t h a n i * and H . N . Vinod • Electrical Engineering Department, Indian Institute of Technology Bombay, Powm. Bomhav 400 076, INDIA. This paper shows how a low cost personal computer, Sinclair ZX Spectrum, may be used in a high technology and sophisticated application, such as a Computer Numerical Control (CNC) system for a lathe. The paper describes the set of ' user friendly' software modules that have been developed for both pre- and post-processing operation. Software modules for preprocessing enable the user to define a new job, and save it after editing. Post-processing modules perform interpolation and auxiliary functions, as well as execute the job. Hardware development includes stepping motor drives for carriage and croos-slides. It also includes an I / O expander module for interfacing the stepping motor drives to ZX Spectrum.
Kevwordg." C N C ZX Spectrum, Numerical control PC, Lathe control, ('AM, C N C software, CNC lathe, Stepping motor
V.V. Athani obtained his B.E. degree in Electrical Engineering from University of Poona (India) in 1955, M.E. degree in Power Engineering from Indian Institute of Science, Bangalore in 1957, and M.S. degree from University of Illinois, Urbana, IL (USA) in 1962 in Control and Computers. He joined the Indian Institute of -~ Technology, Bombay in 1958, where he is working as a Professor in the Electrical Engineering Department. His specialization is control systems. His current interests are microprocessor applications, especially in control and instrumentation, C N C - D N C - C A D systems, and robotics. He is also active in development of stepping motors and high performance controllers for them. He has more than 60 publications to his credit. His textbook on'Digital Control Systems' is under publication by Tata-McGraw-Hill, New Delhi, India. He is a Senior Member, IEEE (USA), and a member of IEEE Control Systems, and Computer Societies.
North-Holland Computers in Industry 7 (1986) 427-434
1. Introduction
Numerical Control (NO) systems for machine tools constitute an important area of computer application. NC, Computer Numerical Control (CNC), Direct Numerical Control, (DNC), and Computer Aided Manufacturing (CAM) represent progressively advanced stages in computer applications in the machine tool control area [1,2]. Mainframe computers were employed in the beginning of NC (late 50s and early 60s). It was, however, the development of the minicomputer that made NC systems really popular (late 60s and early 70s). The development of the microprocessor in the 70s added tremendously to y c systems [3]. This paper shows how even a low cost personal computer, such as Sinclair zx Spectrum, may be used in a sophisticated application like CNC system for a lathe. The system block diagram is shown in Fig. 1.
2. Software Development
Comprehensive software has been developed to cater to both pre-processing and post-processing. Two major factors that have been kept in mind while developing software for CNC system for a lathe are: (a) user friendliness (b) modular approach. This has greatly simplified the task of the user. Five software modules have been developed for the CNC system as listed in Table 1. Details of the software routines in each of the above software modules are given in Table 2. Note that these routines are called by single key strokes, thus further simplifying the task of the programmer. Details of these routines are given below.
0166-3615/86/$3.50 ,~,~1986 Elsevier Science Publishers B.V. (North-Holland)
Applications
428
( omputers in Industry
/ CRT ] MONI TON TV
l WATCH MAKER'S LATHE
,
~/-----~l
SINCLAIR ~ ~ zX SPECTRUMI
I~A2~Ir~l~[,~ PERSONAL
I
EXP110 ANI:~ERIJ I IpA~
I
~
COMPUTER
j .........
MOTOR ~-~ONTRO-L ~
~
cRgs
LLER
F i g . 1. B l o c k d i a g r a m o f z x S p e c t r u m - b a s e d
__> TO CARRIAGE
SLIDE
CNC s y s t e m .
Table l
2.1 Monitor Routines
S o f t w a r e m o d u l e s f o r a CNC s y s t e m S.No.
Name
Cursor Description
1.
MONITOR
MCR > M o n i t o r c o n s o l e r o u t i n e s
2.
EDITOR
EDT > E d i t o r r o u t i n e s
3.
FUNCTION
FUN > F u n c t i o n r o u t i n e s
4.
ADDRESS
ADR > A d d r e s s r o u t i n e s
5.
VALUE
VAL > V a l u e r o u t i n e s
These routines enable the user to define a new job, store it on a cassette, load from the cassette, edit and run it. There are eight routines, as shown in Table 3.
Table 2 S o f t w a r e r o u t i n e s f o r a CNC s y s t e m M o d e 1 (MCR)
M o d e 2 (EDT)
M o d e 3 (FUN)
M o d e 4 (ADR)
Monitor Keys
Editor Keys
Function
Address Keys
A - NEWJOB
P - DELETE
g -- P r e p a r a t o r y
B - RESUME
Q - INSERT
f -- F e e d r a t e
u,v,w -
Secondary motions parallel
C - EDIT
R - APPEND
S -- S p i n d l e s p e e d
p,q,r -
Tertiary motions parallel
O - PROCESS
S - NEXT
t - Tool function
i,j,k -
Words used by circular interpolation
E
T -
PREV
m - Miscellaneous function
a,b,c -
Circular motions around
F - LOAD
U
DISPLAY
h
d,e
Special words
a
V - OVER
O
Terminate
Keys function
×,y,z -
Primary motions parallel to p r i m a r y a x e s to p r i m a r y o n e s to s e c o n d a r y o n e s
SAVE
primary axes
- EXECUTE
- -
(not printed) H - HELP (Universal Key, not printed)
LOB
] - EOJ
address inputs
Computers in Industry
V.V. Athani and H.N. Vinod / CNC System for a Lathe
2.2 1 / 0
Table 4 I / O routines
Routines
T h e s e k e y s are m e a n t e s s e n t i a l l y f o r i n p u t - o u t p u t . T h e r e are six r o u t i n e s in this m o d u l e as
Key
Routine
Description
]
GETKEY
2
PRINTKEY
3
PRINT-
Reads the keyboard in all the five modes shown in Table 1 and returns corresponding key value Echoes the keyword on CRT monitor Displays the appropriate error messages to help to user detect and correct errors A major data input routine called by NEWJOB, ADDRESSand ARRANGE routines. It enables the user to input appropriate g. f, s, t, m, h, I values Inputs addresses and their values for a 'g' function Data may be input by the user in a random order. This routine arranges them in the proper order to form a data file
i n d i c a t e d in T a b l e 4.
2.3 Edit Routines Table 5 shows the edit routines that enable the u s e r to c o r r e c t a n d m o d i f y t h e c u r r e n t j o b file. Eight sub-modules, numbered
from 1-8
ERROR
have
b e e n s p e c i a l l y w r i t t e n to f a c i l i t a t e t h e a b o v e e d i t -
4
FUNCTION
5.
ADDRESS
6
ARRANGE
ing operations.
2.4 Function Routines T h e s e keys, s h o w n in T a b l e 2, e n a b l e t h e u s e r to i n c l u d e a p p r o p r i a t e rate),
g (preparatory), f
s (spindle speed),
neous),
h
(end
of block)
t (tool), and
m
(feed
(miscella-
l (end
of job)
429
f u n c t i o n s in his p a r t p r o g r a m . T h e s e f u n c t i o n s form
a part
of the postprocessor, and
are de-
s c r i b e d in d e t a i l l a t e r on.
2.5 Address Routines
2.6 Value Routines
These routines enable primary, secondary and
Numerical
values required
by o t h e r routines
t e r t i a r y m o t i o n s a n d c e r t a i n s p e c i a l w o r d s to b e
s u c h as f u n c t i o n , a d d r e s s , etc. r o u t i n e s are s u p -
i n c l u d e d in p a r t p r o g r a m s .
plied by the value routines.
Table 3 Monitor routines A
NEWJOB
B
RESUME
C
EDIT
D
PROCESS
E
SAVE
F
LOAD
G
EXECUTE
H
HELP
Defines a new job by opening a user file and invoking appropriate function keys Resumes machining on a job that was suspended on receipt of a hold request Invokes the appropriate edit routine and transfers control thereto Executes post processor by generating Excute file data Transfers current user data file to audio cassette Loads current user data file from audio cassette Invokes Execute module and transfers control to it A special key to advise the user on which keys he can use at any stage of developing his job program
Table 5 Edit routines Key
Routine
Description
P
DELETE
Q
INSERT
R
APPEND
S T
NEXT PREV
U
DISPLAY
V
OVER
Deletes a block from current user file and rearranges subsequent blocks Adds a block of data at the desired point in the user file and rearranges the subsequent blocks Adds a block of data at the end of the current user file Displays contents of next block Displays contents of previous block Displays contents of the desired block Marks the end of editing operations and returns control to monitor
430
Computers in lndustO'
Applications Table 6 Auxiliary function
PRE PROCESSOR'SOUTPUT INPUT ] READ,CHECK,PRINT
J
[
1__
MOTION FEEL.~RATE AL"~,PTION COORUINATE F TRANSFORMATION
AUXILIARY ~PINDLE
-
COOLANT
OUTPUT 1 PUNCH
PRINT
TAPE
LIST
Fig. 2. Postprocessor structure.
2.7 Post-processor Postprocessor accepts preprocessed data and converts them into a form acceptable to the machine control unit (MCU). The MCU serves as the link between software and the system hardware, viz. servo drives for the carriage and cross-slide. A typical post processor contains five elements as shown in Fig. 2. 2.7.1 The Input Element This reads cutter location (CL) data and miscellaneous information from preprocessor, and transfers them to the remaining elements of postprocessor. 2.7.2 The Motion Analysis Element This constitutes the main element of the postprocessor and has two sections: geometry and dynamics sections. The geometry section converts CL data into the specified machine tool coordinates. It also checks tolerance and constraints imposed by the machine. The dynamics section computes tool velocities and acceleration/deceleration at p r o g r a m m e d feed rates.
Function
Descript on
g00 g01 g02 g03 g04 g05 g08 g09 mOO m06
Point-to-point positioning Linear interpolation Circular interpolation (w Circular interpolation ccw Programmable dwell Programmable hold Acceleration Deceleration Program stop Tool change
2.7. 3 Auxiliarv Functions These include spindle, coolant, gear change, etc. functions. It also incorporates canned cycles. These are listed in Table 6. 2.7.4 The Output Element This receives output data from motion and auxiliary elements and converts them into a form acceptable by MCU. 2.7.5 The Control and Diagnostic Element This ensures smooth flow of data between the remaining elements of the postprocessor. It also diagnosis various errors that might be committed by the user. The post processor may be realized either hardwarewise or softwarewise. In cNc systems, the postprocessor is realized softwarewise. In our work, the postprocessor has been p r o g r a m m e d on the same zx Spectrum Personal Computer. The postprocessor is specific to the servo drive used. In our system, stepping motor drives have been employed for carriage and cross spindle.
Table 7 System status flags Status Flag HOLD STOP PGM-ON EDIT EXECUTE MANUAL-ON
When set External hold request received External stop request received Part-programming is in progress Editor is invoked Machine operation is in progress External manual model signal received
431
Computers in Industry
V.V. Athani and H.N. Vinod / C N C S~vstem for a Lathe
2.8 The Executor Routine
been produced which compute the incremental motions of the X and Z stepping motors.
This routine uses the output file created by the postprocessor. It loads the appropriate data from the data file. It calls the specified interpolation routine to generate the required path. The timer generates timing pulses to actuate the stepping motor drives. It also generates the required phase sequence software-wise. The executor also handles external interrupt requests. It also puts up the appropriate status flags out of those mentioned in Table 7.
4. Hardware Development Our CNC system hardware consists of zx Spectrum Personal Computer, I / O expansion board, and stepping motor drives for the lathe [4]. These are briefly described below.
4.1 Z X Spectrum Personal Computer
3. Interpolation Interpolation is the process of generating intermediate points between starting and end points generated by the preprocessor, with a view to generating the specified path. The paths usually specified in NC systems are straight line, arc of a circle or a section of a parabola. In our work linear and circular interpolation have been provided [4]. Two basic techniques of interpolation are: (a) binary rate multiplier (BRM), and (b) digital differential analyzer (DDA). The latter technique has been adopted our system. Software modules have
The main hardware, around which our CNC system has been designed, is the Sinclair zx Spectrum, a low-cost personal computer shown in Fig. 3. It has the following specifications: c P v : Zilog Z80 operating at 3.5 MHz clock Memory: 16K system ROM + 48K DRAM Peripheral I/F for: Audio Cassette, TV Modulator, Printer, etc.
4.2 I / 0
This PCB has been specifically designed to enable zx Spectrum to the stepping motor drives. Fig. 4 shows the block diagram of this board. It is meant to be connected at the rear end of zx
TV
KEY BOARD
R
DATA ,~BUS CASSETTE RECORDER
VIDEO SIGNALS
Fig. 3. zx Spectrum block diagram.
Expansion Board
432
Applications
Computers in Industry
N ~ O u ~
I" ~ N"
U
II
Lo
I~I=
m I~/
I--- t/3
4
+
m
t i
o'~
i
/,ll// ifll/
i
1
I !,
]o I
/
.a
g
~o
g~
2 ,.9 0 z
g~gg
i ~
©
c~o
Computers in lndusto"
V.V. Athani and H.N. Vinod / CNC System for a Lathe
Table 8 z80vlO Pin a s s i g n m e n t
The remaining two timers are left free for future use.
Pin N o .
A s s i g n e d to
Ao - A1
Output: Input : Output: Input : Input : Output: Output:
A 2
-- A 3
A4 - A 5 A6 Av B0 - B 1 B 2 - By
4.3 Stepping Motor Controller
Phase sequence for Z motor L i m i t switch i n t e r r u p t s R e s e t for h o l d i n t e r r u p t s Hold interrupt Stop interrupt P h a s e s e q u e n c e for X m o t o r S y s t e m s t a t u s flags
Two bifilar wound permanent magnet (PM) stepping motors have been used for actuating the cross slide and carriage of the lathe. Two stepping motor controllers have been designed for them. The block diagram of a typical stepping motor controller is shown in Fig. 5. It consists of the following units: (a) Variable pulse rate controller (VPRC) that generates pulses at a rate dictated by the interpolator (b) Phase sequence generator (Ps6) generates the Phase sequences required for c w and c c w rotation of the stepping motor as indicated in Table 9. Note that the logic states of A~ - A : B x - B : windings are complementary to each other. This fact has been exploited in PSG design, wherein only two lines of z80PIO have been used per motor instead of the usual four. This economizing has enabled us to accommodate all I/O operations with the help of two parallel ports in one z80PIO. (c) Power driver circuit (PDC): special unipolar linear constant current (LCC) drives have been
Spectrum where all the buses have been brought out for extension. Our I / o expansion board contains (i) buffers and drives for data, address and control buses, (ii) I/O mapping and chip selection logic, and (iii) one z80vxo and one Z80CTC chips. Furthermor.e, all relevant signals, such as data bus, address bus, control bus, PIO port-bus, CTC control, I/O interface signal, are brought out at the output connector to facilitate further expansion. z80vlo has two parallel I / o ports. They have been programmed in mode 3, viz. control mode, and have pin assignments as shown in Table 8. z80cTc has four programmable timer/counters. One of them is used for generating 4 kHz clock pulses for the interpolators, while the other produces output pulses for the stepping motors.
+ VM From timer
Wdg I Wdg 2 MOTOR WINDING
I
433
PDC
Wdg3
VPRG PSG
w~g
DIR
VPRG-Variable pulse rate generator P S G - Phase sequence
generator
Z e r o count PDC
cOunt Fig. 5. Block d i a g r a m of s t e p p e r m o t o r controller.
Power driver c i r c u i t s
Rs
434
('omputers in ]n(]ustrl
Applications
m m / s t e p whereas the minimum programmable distance is 0.01 mm. The spindle is separately driven by a 3-phase induction motor.
Table 9 PHSE Sequencesfor bifilar PM stepping motors Step No.
A1
A2
B1
B2
1 2 3 4
~,"
1 0 0 1
0 1 1 0
1 1 0 0
0 0 1 1
1
cw
1
1
0
CCW
designed f~or switching the motor windings on and off. Using this PDC it has been possible for us to run the stepping motors at 1380 steps/sec instead of 530 steps/sec possible with L / R drive [4,5].
4. 4 Lathe
The lathe, which has been used in order to try out our software and hardware is a small watchmaker's lathe having 12" travel for carriage and 4" travel for cross slide. The pitch of both the leadscrews is 1 mm. The stepping motors used have torque ratings of 10 kg -~m for carriage and 1.5 kg -cm for cross slide respectively. A 2 0 : 4 0 gear reduction has been employed for both the stepping motors. The least count is 0.0025
5. Conclusion
Thus a low cost CNC system for a lathe has been designed using zx Spectrum p(. The necessary software and hardware for the system have been designed. The CNC system can be retrofitted on any lathe when certain modifications have been carried out. Although inexpensive, the CNC system possesses a number of advanced and sophisticated features. References [11 Koren, Y. and Ben-Uri, J., Numerical control o~ machine tools", New Delhi, K h a n n a Publishers, 1983. [2] Koren, Y., Computer control of manufacturing systems. New York, McGraw-Hill, 1983. [3] Bol!inger, J. and Mills, J., Role of microprocessors in fi~ture CNC systems. Annals of CIRP, vol. 25, pp. 323-328, 1976. [4] Vinod, H.N., CNC of a lathe using stepper motor drives, M. Tech. Thesis, I.I.T. Bombay, 1984. [5] Athani, V.V., and Vinod, H.N., Linear Constant Current Drive for Permanent Magnet Stepping Motors. Eh,ctronic Engineering, to be published.