Advanced Materials Research Online: 2013-07-31 ISSN: 1662-8985, Vol. 722, pp 428-432 doi:10.4028/www.scientific.net/amr.722.428 2013 Trans Tech Publications, Switzerland Design and Implementation of CNC Operator Panel Control Functions Based on CPLD Huaqun Zhan, Bin Xu College of Communication and Electronics, Jiangxi Science & Technology Normal University, Nanchang, China email: 1666736703@qq.com Keywords: CNC Operator Panel; CPLD; Keyboard scan; Serial communication; Hand wheel; 5M1270ZT144 Abstract. Method of CNC operator panel control functions are introduced in this thesis, which is based on CPLD. First, the paper indicates the theory of system works and the overall structure; second, the thesis mainly introduces the implementation of the keyboard scan, the function of hand wheel and serial communication; Last but not least, the correct simulation results are given as well. The MAX V chip of ALTERA is used in this program, 144 IO ports can be processed at most. It is an effective solution to process lots of IO ports and the problem of hardware space limited. Introduction CNC operator panel is an important component of CNC machine tools, which is the communication tool of operators and CNC machine tools. CNC operator panel can be used by operators to operate CNC machine tools: programming, debugging, setting and modifying the machine parameters, Operators can also grasp and query the operating state of the CNC machine tools.cnc operator panel is the specific input and output member of the CNC machine tools. It is composed of display device, NC keyboard (similar to a computer keyboard keys), machine control panel (MCP), and hand wheel etc. Figure 1.Appearance of CNC operation panel Figure 1 is CNC operator panel. It includes 45 keys of machine control panel, 43 LEDs, two knobs override switch (spindle override switch, cutting feed rate switch), a hand wheel, and the 5 direct connecting switch (start, pause, etc.). If all functions use MCU to achieve, then, large-scale expansion of the peripheral interface circuit is needed, this method not only takes up more hardware resources, increases costs, but also the whole circuit is so bulky and cannot layout all elements on CNC operator panel circuit board. But CPLD is complex programmable logic device; it can replace dozens even hundreds of blocks of common IC chips. CPLD has programmable capabilities, its implementation is easy to change, and the pin attributes can be definition. To sum up, this paper uses CPLD which has high cost-effective to implementation of keyboard scan, the driver of LEDs and knobs override switch processing and serial communication with the host computer etc. The theory of system working and overall structure The whole system is divided into two parts of peripheral interface circuit and control circuit of CPLD driver. Figure 2 is hardware block diagram of system. Peripheral interface circuit is comprised of keyboard matrix circuit which has 8 rows and 10 columns, direct connecting switch All rights reserved. No part of contents of this paper may be reproduced or transmitted in any form or by any means without the written permission of Trans Tech Publications, www.ttp.net. (#69804889, Pennsylvania State University, University Park, USA-17/09/16,22:14:07)
Advanced Materials Research Vol. 722 429 circuit, the circuit of LEDs driver etc.. Control circuit of CPLD driver in Figure 2 is composed of keyboard scan circuit, the circuit of LEDs driver, the circuit of knobs override switch and the circuit of serial communication etc.. The control functions of CPLD is summarized as follows: 1.Access to outside information, including: the information of keyboard scan, the coding information of two knobs override switch; the information of hand wheel; 2.Though the circuit of scanning, the information obtained is send to the host computer by serial transmission mode, then the information is processed by the host computer; 3.The result of processing by the host computer which is send to the CPLD by differential lines, Using the internal of CPLD which has 8 rows and 10 columns keyboard scan circuit to drive the signal of 43 LEDs. Among all IO ports, Keyboard scan circuit and knobs switch circuit are occupied 21 IO ports, the circuit of LEDs driver is occupied 18 IO ports, direct connecting switch occupied 15 IO ports, and serial communication needs 4 IO ports. This paper uses the chip 5M1270ZT144 of MAX V, the device offers 144 programmable IO pins, it offers 1270 Les,980 typical equivalent macrocells and 127 LABs, it has ISP Programming capability as well. Therefore, one chip can meet the requirements which system needs lots of IO ports and more macrocells, Do not need another chip. Figure 2. System block diagram Specific methods of the CPLD control functions The implementation of keyboard scan In order to achieve the matrix keyboard scan circuit which have 8 rows and 10 columns? First, the system clock gets 78 KHZ clock by frequency dividing circuit, this clock is called clk_scan which seen as a key trigger clock. When on the rising edge of clk_scan, by coding, controlling each of the column lines which pull down one by one to achieve the function of keyboard scan. When no key is pressed, each of the column lines keep HIGH, when a key is pressed, the column line where the key located is LOW, At the same time, reading row lines information and sending the information to serial communication module so as to communicate with the host computer. The function of hand wheel The full name of hand wheel is manual pulse generator, also known as the photoelectric encoder. In this paper, hand wheel primarily used to control the X, Y, Z and 4th axis of CNC machine tools. as Figure 3 shown, the hand wheel in the CNC operator panel has a relationship as follows: On the CNC operator panel, hand wheel connection lines marked with A, B. Phase A and Phase B are quadrature pulse signal. Difference between the two is 90 degrees. When hand wheel counterclockwise rotation, phase A lead phase B 90 degrees(phase A is rising edge when Phase B is LOW), and accumulator(cnt_mpg )is counted once as long as there is a edge between phase A and phase B(Either rising edge or falling edge),when hand wheel counterclockwise rotation, cnt_mpg minus 1.When hand wheel clockwise rotation, phase B lead phase A 90 degrees(phase B is rising edge when Phase A is LOW), and accumulator(cnt_mpg)is counted once as long as there is a edge between phase A and phase B(Either rising edge or falling edge),when hand wheel clockwise rotation, cnt_mpg plus 1.One circle in hand wheel is divided into 10 files(0-90),a total of 200 pulses.
430 Optical, Electronic Materials and Applications IV Figure 3.The phase relationship schematic diagram of hand wheel Figure 3 shows the key point of the coding is both phase A and phase B sampling data twice (Simultaneous Sampling),then make the 4 data splice together. One situation is Phase A sampled data are 0 and 1, when hand wheel counterclockwise rotation, phase B sampled data are 0 and 0, therefore the 4 data is 0,1,0,0, written as 4'b0100.By the relationship: When hand wheel counterclockwise rotation, cnt_mpg minus 1.Another situation is phase A sampled data are 0 and 1,when hand wheel clockwise rotation, phase B sampled data are 1 and 1,therefore the 4 data is 0,1,1,1, written as 4'b0111.By the relationship as well: When hand wheel clockwise rotation, cnt_mpg plus 1.The rest can be done in the same manner, a total of 8 kinds of situations. Figure 4 is part of the coding. The function of hand wheel can be realized by the above. Figure 4. Part of the coding of hand wheel The method of serial communication CPLD exchange information with the host computer includes: the information of keyboard scan, the coding information of direct connecting switch, the information of hand wheel and the driver information of LEDs. Since a large amount of information to transmission, therefore, using the differential transport protocol based on the standard RS-422. The protocol has the following features: 1.High-rate 1.25MHz; 2. Hamming code error correction; 3. automatically detect the device. The protocol uses a Master-Slave communication, Master device is the host computer, and Slave device is the CNC operator panel. There are three pairs of differential lines to transmit information: one pair transmits clock information from master device, one pair transmits data from master device, and another pair transmits data from slave device to master device. The data output line of slave device must have a tri-state output enable. The work of master device, master device transmits clock signal by frame. The clock frequency is 1.25MHz. Beginning of each frame, clock line remain LOW for four clock cycles which marked a frame start signal, written as 3.2 µs. Continuous send 60 clock cycles. Master device transmits 60 bits data to slave device and slave device transmits 54 bits data to master device during the 60 clock cycles, Figure 5 shows CPLD can communicate with the host computer through this protocol. Figure 5. Protocol of serial communication Note: See Figure 5, From the top to down, the first line is frequency dividing clock signal; the second line is a data signal which from master device to slave device; the third line is a data signal which from slave device to master device. There are 60 bits data from master device to slave device: 60 bits data=2 start bits(01)+ 4 address bits(the address of slave device)+4 synchronization
Advanced Materials Research Vol. 722 431 bits(0101) +8 alternate data bits+38 Hamming code bits+4 end bits(0101). There are 54 bits data from slave device to master device: 54 bits data=4 acknowledge bits+8 alternate data bits+38 Hamming code bits+4 end bits(0101). The results of simulation This paper is given a correct simulation results which includes the simulation of keyboard scan and the function of hand wheel. The code is used Verilog HDL language, Simulation is used Modelsim 6.6d. Figure 6 shows a simulation result of the keyboard scan. LEDs scanning circuit law is similar to keyboard scan, Simulation results will not repeat here. Figure 6.Keyboard scan simulation Note: See Figure 6, The first line is the signal of system clock; the second line is the signal of reset, LOW active; the third line is the signal of divided counter; the fourth line is the signal of frequency dividing clock; the fifth line is the signal of scan counter(from 0 to 9); the sixth line is the signal of scanned column, scanning column by column(low indicates a key pressed), a total of 10 columns. Seen from the Figure 6,if the counter is 0, then the next clock cycle, the 10 columns is 1111111110, and if the counter is 1, then the next clock cycle, the 10 columns is 1111111101,the rest can be done in the same manner; the seventh line is the signal of scanned row. Seen from the simulation results, the function of keyboard scan achieved the design goals. As Figure 7 shown, the waveform is measured by digital oscilloscope when hand wheel clockwise rotation, measuring the waveform when hand wheel counterclockwise rotation is similar to clockwise rotation, Simulation results will not repeat here. Figure 7. The diagram of hand wheel function Note: Seen Figure 7, From the top to down, The first line is the signal of phase A; the second line is the signal of phase B; Figure 7 shows phase B lead phase A 90 degrees, it is the waveform when hand wheel clockwise rotation. Therefore, the code achieved the requirements. Conclusion Since CNC operator panel needs lots of IO ports and the hardware space is limited. This paper uses one complex programmable logic device (CPLD).it can realize keyboard scan, the driver of LEDs and communicate with the host computer. This thesis is given a correct simulation results about
432 Optical, Electronic Materials and Applications IV some module as well. Currently, CNC operator panel that based on CPLD is applied to some packers. From those packers, CNC operator panel get a good evaluation and have a larger practical application value. Acknowledgment First, I would like to extend my thanks to my tutor, Mr. Zhan, who gave me numerous encouragements and help. Second, I also want to thank my beloved girlfriend Miss. Zeng. Without their generous advices and supports, this paper cannot be accomplished. Thanks very much. References [1] Song Pan, Jiye Huang. Practical course of EDA technology [M]. Science Publishing House, 2006. [2] Ing Zhang, Lisong Wang etc.. Method of CNC operator panel control function based on CPLD [EB/OL]. Control &Detection, 2008. [3] Zhihui Wang, Shuisheng Lin. Design and Implementation of keyboard scan module based on FPGA [J]. International Electronic Elements, 2006. [4] Yihong Wang, Zhitong Chen. Realization of hand wheel function of CNC machine tools based on PMAC [J]. Mechanical Engineers, 2005. [5] Guotao Fang. Hamming code encoding and decoding system based on FPGA [J]. IT Magazine, 2010. [6] Tao Liu, Xing Hua. FPGA digital electronic system design and development examples navigation [M]. The People's Posts and Telecommunications Press(Posts & Telecom Press), 2005. [7] Song Pan etc.. Practical course of EDA technology: Verilog HDL version (Fourth version) [M]. Science Publishing House, 2010.