Design and implementation of a standalone CNC controller
Abstract
Grado en Ingeniería de Tecnologías Específicas de Telecomunicación
Full text
Universidad de Valladolid E.T.S.I. Telecomunicación Trabajo Fin de Grado Grado en Ingenierías Específicas de Telecomunicación, Mención en Telemática Design and implementation of a standalone CNC controller Ontwerp en implementatie van een stand-alone CNC-besturingseenheid Autor: Elias Verstappe Tutor de UVa: Dr. Jesús M. Hernández Mangas Tutor de Universidad Vives (Brugas, Bélgica): Mr. Tom Cordemans Valladolid, Junio 2019
Title: Design and implementation of a standalone CNC controller Author: Elias Verstappe Tutor: Dr. Jes´us M. Hern´andez Mangas Department: Department of Electronics Court Chairman: Dr. Mart´ın Jara´ız Maldonado Member: Dr. Jes´us Arias ´ Alvarez Secretary: Dr. Jes´us M. Hern´andez Mangas Substitute: Dr. Ruth Pinacho Substitute: Dr. Pedro L´opez Date: 21 of June 2019 Qualification:
Preface and acknowledgements Writing a thesis is the final step in obtaining a degree. It is a unique opportunity to apply all acquired knowledge in one large project. Obviously, the development of such a project does not go without a hitch. It is a mountain that is impossible to get over without falling and getting back up. I would not have succeeded without a strong start and necessary support along the way. Therefore I would like to use this opportunity to express my gratitude to the people who have contributed to the realization of this work. Therefore, first of all, a sincere thanks to my teachers. Your motivated, enthusiastic and communicative way of working and your course of action is a permanent source of inspiration for me. In addition, a special thanks goes to my internship promoter, Mr. Tom Cordemans. Thank you for the practical support (in connection with Erasmus) and the confidence that you have placed in me from the start. This thesis would not have been realised without your help. An additional word of thanks goes out to my two promoters at the University of Valladolid, Dr. Jesús M. Hernández Mangas and Dr. Jesús Arias Álvarez. Day after day you have guided me and at the moments that I started going on the wrong path, your expertise broadened my field of vision. Finally, I want to thank my parents. You have supported me from the beginning. Not just morally and financially, but in many other areas. Thank you for supporting my choice of studying electronics. Not to be forgotten are the friends with whom I have been able to spend a nice time. Thank you for the experiences we shared together, the moral support and the enjoyable breaks.
Abstract English This bachelor thesis has been developed by Daan Ver Eecke and Elias Verstappe. We are two students at the ‘Hogeschool Vives’ in Bruges (Belgium) and both participate in the Erasmus program. The thesis has been worked out at the University of Valladolid in Spain. The general purpose of a bachelor’s thesis is to solve a specific problem (in our case with regard to the field of study electronics). This thesis describes how we control an old machine with the help of modern electronics. In a world where technological development is happening faster than ever, it is important that the possibility remains to control old devices. Due to the enormous growth, older machines are no longer supported by new operating systems. Two lecturers from the University of Valladolid, Dr. Jesús M. Hernández Mangas and Dr. Jesús Arias Álvarez, have confronted us with the following challenge: an old CNC machine is currently controlled with the help of an old computer. The program that controls the machine runs on the MS-DOS operating system. Our assignment is to design a custom controller that takes over the task of the old computer. An additional requirement is to also be able to control the (CNC) machine via a website. A fully custom printed circuit board is designed to solve this problem. The firmware that is responsible for all control is also developed by us. Briefly summarized, the requirements are the following: With the help of an SD card, a certain PCB design can be read in the machine. The machine can be controlled in two ways: on the one hand everything can be operated using the touchscreen, and on the other hand the machine must be able to be fully controlled via a website. Now that the project is finished, we can conclude that thanks to the enormous development of technology in recent years, nowadays you can easily and cheaply design a control unit for old devices. We can simulate the operation of a computer that is 25 years old with a small and simple printed circuit board that costs 45 euros (development costs not included). This result shows that you could create a ‘man in the middle’ with new hardware for many old machines. This way of working can certainly be applied to other machines. You could even apply this way of working for development of new machines. We were instructed to control a machine with a certain interface. In principle you can compare it with the development of a controller for a machine. In that case, it does not really matter what or how old the machine is. I
Dutch Deze bachelor-thesis is uitgewerkt door Daan Ver Eecke en Elias Verstappe. Wij zijn twee studenten aan de ‘Hogeschool Vives’ in Brugge (België) en nemen beiden deel aan het Erasmus-programma. De thesis is uitgewerkt aan de Universiteit van Valladolid in Spanje. Het algemene doel van een bachelor proef is om een concreet probleem (in ons geval met betrekking tot de afstudeerrichting elektronica) op te lossen. Dit eindwerk beschrijft hoe we een oude machine aansturen met behulp van moderne elektronica. In een wereld waar de technologische ontwikkeling sneller dan ooit verloopt, is het belangrijk dat de mogelijkheid blijft bestaan om oude toestellen aan te sturen. Door de enorme groei worden oudere machines niet meer ondersteund door nieuwe besturingssystemen. Twee docenten van de Universiteit van Valladolid, Dr. Jesús M. Hernández Mangas en Dr. Jesús Arias Álvarez, hebben ons voor de volgende uitdaging geplaatst: een oude CNC-machine wordt momenteel bestuurd met behulp van een oude computer. Het programma die de machine bestuurt draait op het MS-DOS besturingssysteem. Het is onze opdracht om een op maat gemaakte controller (besturingseenheid) te ontwerpen, die de taak van de oude computer overneemt. Een extra vereiste is om de (CNC-) machine ook via een website te kunnen besturen. Om dit probleem aan te pakken en op te lossen wordt een volledig op maat gemaakte printplaat ontworpen. De firmware die verantwoordelijk is voor alle sturing wordt ook door ons ontwikkeld. Kort samengevat zijn de vereisten de volgende: Met behulp van een SD-kaart kan een bepaald PCB-ontwerp in de machine gelezen worden. De besturing van de machine kan op twee manieren: enerzijds kan alles bediend worden met behulp van het touchscreen, anderzijds moet de machine volledig bestuurd kunnen worden via een website. Nu het project uitgewerkt is kunnen we besluiten dat je dankzij de enorme ontwikkeling van de technologie, vandaag gemakkelijk en goedkoop een besturingseenheid kan ontwerpen voor oude toestellen. Wij kunnen nu de werking van een computer die 25 jaar oud is nabootsen met een klein en simpel printplaatje dat 45 euro kost (ontwikkelingskost niet inbegrepen). Dit resultaat toont aan dat met nieuwe hardware voor veel oude machines als het ware een ‘man in the middle’ ontwikkeld kan worden. Deze manier van werken kan zeker toegepast worden op andere machines, zelfs op nieuwe machines. Wij verkregen een opdracht om met een bepaalde interface een machine te besturen. In principe kun je het vergelijken met het ontwikkelen van een besturingseenheid voor een machine. Dan maakt het eigenlijk niet zoveel uit welke of hoe oud de machine is. II
Contents 1 Introduction 1 1.1 Definitionofterms........................................ 1 1.2 Statementoftheproblem .................................... 1 1.3 Descriptionofthechapters ................................... 2 1.4 Requirements and specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 2 Hardware 3 2.1 Usedsoftware........................................... 3 2.2 Designapproach ......................................... 3 2.2.1 Powersupply....................................... 4 2.2.2 USB to UART converter and switch between controllers . . . . . . . . . . . . . . . 5 2.2.3 Microcontroller...................................... 6 2.2.4 TFTshield ........................................ 7 2.2.5 Parallelport ....................................... 9 2.3 Thelayout............................................. 10 2.4 Poweranalysis .......................................... 12 2.5 Heatdissipation ......................................... 13 3 Firmware 14 3.1 Tasksofthemicrocontroller................................... 15 3.1.1 Detaileddescription ................................... 15 3.1.2 Screenhandler ...................................... 16 3.2 LCDscreen ............................................ 18 3.2.1 Pixel............................................ 18 3.2.2 Line ............................................ 18 3.2.3 Bresenham’s line algorithm[3] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 3.2.4 Characterandstring................................... 20 3.3 Touchcontrol........................................... 22 3.3.1 Calibration[5]....................................... 22 3.4 Interfacingwiththemachine .................................. 23 3.4.1 Pressingabutton..................................... 23 3.4.2 Checking if a spot is touched . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 3.5 ControltheCNCmachine.................................... 25 3.5.1 CNCroutines....................................... 25 3.5.2 Speedupandslowdown................................. 25 3.5.3 Movethehead ...................................... 26 3.5.4 Circularbuffer[7]..................................... 27 3.6 ReadSD-card........................................... 28 3.6.1 Readcontentsofafile.................................. 28 3.6.2 HPGLfiles ........................................ 29 3.6.3 Excellonfiles ....................................... 31 3.7 Emergencybutton ........................................ 33 3.8 Communication with WiFi module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 3.8.1 Frame........................................... 34 3.8.2 Payloadstructure..................................... 34 III
3.8.3 Transmission ....................................... 35 3.8.4 Reception......................................... 35 4 User manual 36 4.1 Startup/mainscreen...................................... 36 4.2 Configuration........................................... 38 4.3 Tools................................................ 39 4.4 Offset ............................................... 40 4.5 LoadandStart.......................................... 41 5 Cost study 43 5.1 Material.............................................. 43 5.2 Labour............................................... 45 5.3 Total................................................ 45 6 Conclusions 46 Bibliography 47 A PCB schematic 49 B PCB Layout 56 C Bill of materials 62 D Design errors 64 E Explanation of calibration in touchscreen systems 66 F Source code 75 IV
1.3 Description of the chapters Chapter 1 has a detailed description of the specific requirements that were set when the idea of this thesis was developed. Chapter 2 describes the specific details about the PCB design. In Chapter 3 you can read about the firmware that manages the various tasks the controller has. Furthermore, Chapter 4 is a user manual that describes all parameters that can be set and describes how the ‘operating system’ that runs on the board works. Chapter 5 gives you an idea of how much the development this project would cost. Finally, Chapter 6 contains conclusion of the final work and discusses the achieved results. 1.4 Requirements and specification Specific requirements of the project are the following: •The controller needs to operate fully independently, no computer will be required when using the CNC machine. •The design that you wish to manufacture by the CNC machine is supplied to the controller via an SD card. •The (CNC) machine should be fully controllable using a web page. •The (CNC) machine should be fully controllable via a touchscreen. •The firmware will be written in C (reason being that C provides us with a lot of low level control over hardware components) 2
Chapter 2 Hardware 2.1 Used software The software that was used to develop the PCB is Proteus Design Suite. This software tool is used to design and develop schematics for PCB’s. It was developed by Labcenter Electronics Ltd. One of the reasons why Proteus was used is that we can easily simulate our design on the computer. This is useful, reason being that we can already start writing firmware for the design while we wait for the manufacturer to develop our circuit board. 2.2 Design approach Figure 2.1 gives you a closer look at how the circuit board is designed and shows which components are present. The following subsections describe the major parts of the board. We need specific hardware to meet the requirements. A list of all integrated circuits (IC’s) and other components can be found in the bill of materials, which is one of the appendices of this study. USB to UART (FT232RL) MCU (LPC2106) SD card Touch panel (XPT2046) Display control (SSD1963) TFT shield I/O expander (MCP23S17) Parallel port WiFi module (ESP8266) Switch USB 5V 1V8 Data 3V3 3V3 40 pin header Level converter (74HCT04D) 5V 5V 3V3 3V31V8 3V3 > 1V8 (MC33375) 5V > 3V3 (TC2117) 3V3 Power Figure 2.1: Simplified hardware schematic 3
2.2.1 Power supply Power is provided by the USB connection. Our circuit uses both 5V and 3,3V as well as 1,8V. The 5V is directly derived from the USB connection, the 3,3V and 1,8V are achieved by using voltage regulators. Specific design can be found in the PCB layout, which is included as an appendix. Every power rail is connected to ground via a capacitor of 22µF. The datasheet suggest that we use 10µF capacitors, but for stock reasons 22µF capacitors were used. This has no negative effect on the working of the power supply. With the help of two voltage regulators the voltage is converted from 5V to 3,3V and then from 3,3V to 1,8V. The figure below shows how this was implemented. Figure 2.2: Power supply You may have noticed that there is another component between the power supply of the USB connector and the 5V power rail (component L1). This is a ferrite bead. A ferrite bead[2] is an electric component that suppresses high-frequency noise in electronic circuits. No safety measures have been taken in connection with a potential electrostatic discharge. This is not the main focus of this study and we do not expect problems in that regard. More information about the power analysis can be found at section 2.4 of this chapter. 4
2.2.2 USB to UART converter and switch between controllers The microcontroller (when ‘the microcontroller’ is used, I’m refering to the LPC2106) and WiFi module will be programmed via USB. The board will also be powered via USB. A USB to UART converter is needed to be able to communicate with the microcontroller and WiFi-module. We only want to use one USB to UART converter (and one USB connection). To be able to choose which microcontroller we program, we use a switch. The schematic below gives a clearer view of how these parts are connected. This can also be found in the schematic itself, which is one of the appendices. TXD RXD USB to UART D- D+ FT232RL RxD0 TxD0 (P0.1) (P0.0) Microcontroller TxD1 RxD1 (P0.8) (P0.9) LPC2106 TXD RXD WiFi module ESP8266 1 2 3 4 5 6 USB_TXD USB_RXD ESP_RXD ESP_TXD TxD0RxD0 Figure 2.3: Switch between controllers for programming When the slide switch is in one position, the converter’s transmit signal is connected to the microcontroller’s receive pin. Also, the converter’s receive signal is connected to the microcontroller’s transmit pin. This results in data communication between converter and microcontroller. When the switch is in the other position, data is beeing shared between the converter and the WiFi module. You can also see that the WiFi modules UART interface is connected to the second UART interface of the microcontroller. This connection is present because we need to be able to control the CNC machine via a website. Because the microcontroller is responsible for the management and control of the CNC machine, the WiFi module has to tell the main microcontroller what the user wants to do. 5
2.2.3 Microcontroller The microcontroller that we use is an LPC2106/01. This is an ARM based microcontroller (or MCU). We chose this controller because we have experience using it and the lecturers who developed the idea of this project can help us during development if any major problems would arise. The microcontroller runs on a frequency of approximately 58,98 MHz. In our application, this frequency is achieved by a clock crystal that produces a frequency of 14,7456 MHz, which is then multiplied by four using a PLL. In figure 2.4 we can see that our microcontroller has 64kB or RAM memory and 128kB of flash memory. UM10275_2 User manual 9 of 282 1. Memory map The LPC2104/05/06 incorporates several distinct memory regions, shown in the following figures. shows the overall map of the entire address space from the user program viewpoint following reset. The interrupt vector area supports address remapping, which is described later in this section. UM10275 Chapter 2: LPC2104/05/06 memory addressing User manual (1) LPC2104/05/06/01 only. Fig 2. LPC2104/05/06 System memory map AHB PERIPHERALS APB PERIPHERALS RESERVED ADDRESS SPACE BOOT BLOCK (RE-MAPPED FROM ON-CHIP FLASH MEMORY RESERVED ADDRESS SPACE 16 kB ON-CHIP STATIC RAM (LPC2104) 32 kB ON-CHIP STATIC RAM (LPC2105) 64 kB ON-CHIP STATIC RAM (LPC2106) RESERVED ADDRESS SPACE FAST GPIO REGISTERS(1) 128 kB ON-CHIP FLASH MEMORY 0xFFFF FFFF 0xF000 0000 0xEFFF FFFF 0xE000 0000 0xC000 0000 0xDFFF FFFF 0x8000 0000 0x7FFF FFFF 0x7FFF E000 0x7FFF DFFF 0x4000 4000 0x4000 3FFF 0x4000 8000 0x4000 7FFF 0x4001 0000 0x4000 FFFF 0x4000 0000 0x3FFF FFFF 0x3FFF C000 0x0002 0000 0x0001 FFFF 0x0000 0000 4.0 GB 3.75 GB 3.5 GB 3.0 GB 2.0 GB 1.0 GB 0.0 GB Figure 2.4: The microcontrollers memory map It might seem that this microcontroller has four gigabyte of storage. In reality, this is not the case. What matters when making the controller is the RAM and flash memory. 6
2.2.4 TFT shield The TFT shield contains three controllers, one is responsible for the touch management. The second one is responsible for controlling the LCD screen and the last one is the SD card itself. Given that these chips (and SD card slot) were already integrated on the shield, we didn’t have to design anything special for this part of our PCB. We only need to correctly connect the pins from the 40 pin connector to the microcontroller. Touch controller The touchscreen is controlled by the XPT2046 IC. This chip communicates with the microcontroller via SPI. The IC controls a resistive touch screen. A resistive touch screen works by applying a voltage across a resistor network and measuring the change in voltage at a given point on the matrix where a screen is touched by an input stylus, pen or finger. The change in the resistance ratio marks the location on the touch screen. ® ©2000 Burr-Brown Corporation AB-158 Printed in U.S.A. April, 2000 TOUCH SCREEN CONTROLLER TIPS By Skip Osgood, CK Ong, and Rick Downs Burr-Brown makes a number of specialized analog-to-digi- tal converters for touch screen applications. The ADS7843, ADS7845, and the new ADS7846 converters all are designed for specific touch screen applications. Applications using these devices can benefit greatly from the tips presented in this application bulletin. Most of the examples discuss the ADS7843, but the techniques shown are applicable to all of the devices. We begin by looking at the theory of operation of a resistive touch screen, and using these specialized A/D converters with such a screen. Techniques are presented for improving accuracy and minimizing errors; the operation of the pen interrupt line (PENIRQ) is explored, ESD protection methods for the converters, and issues surrounding interfacing these converters to popular microprocessors are discussed. RESISTIVE TOUCH SCREENS A resistive touch screen works by applying a voltage across a resistor network and measuring the change in resistance at a given point on the matrix where a screen is touched by an input stylus, pen, or finger. The change in the resistance ratio marks the location on the touch screen. The two most popular resistive architectures use 4-wire or 5-wire configurations (as shown in Figure 1). The circuits determine location in two coordinate pair dimensions, although a third dimension can be added for measuring pressure in 4-wire configurations. THE 4-WIRE TOUCH SCREEN COORDINATE PAIR MEASUREMENT A 4-wire touch screen is constructed as shown in Figure 2. It consists of two transparent resistive layers. The 4-wire touch screen panel works by applying a voltage across the vertical or horizontal resistive network. The A/D converts the voltage measured at the point the panel is touched. A measurement of the Y position of the pointing device is made by connecting the X+ input to a data converter chip, turning on the Y+ and Y– drivers, and digitizing the voltage seen at the X+ input. The voltage FIGURE 1. 4-Wire and 5-Wire Touch Screen Circuits. Four-Wire Five-Wire Conductive Bar Insulating Material (Glass) Silver Ink Transparent Conductor (ITO) Bottom Side Transparent Conductor (ITO) Top Side X+ X– Y+ Y– ITO = Indium Tin Oxide FIGURE 2. 4-Wire Touch Screen Construction. SBAA036 Figure 2.5: Four-wire touch screen circuit Our touch screen is based on the ‘four-wire’ architecture. A four-wire touch screen is constructed as shown in figure 2.6. It consists of two transparent resistive layers. The four-wire touch screen panel works by applying a voltage across the vertical or horizontal resistive network. The A/D converts the voltage measured at the point the panel is touched. A measurement of the Y position of the pointing device is made by connecting the X+ input to a data converter chip, turning on the Y+ and Y- drivers and digitizing the voltage seen at the X+ input. The voltage measured is determined by the voltage divider developed at the point of touch. For this measurement, the horizontal panel resistance in the X+ lead doesn’t affect the conversion due to the high input impedance of the A/D converter. Voltage is then applied to the other axis, and the A/D converts the voltage representing the X position on the screen through the Y+ input. This provides the X and Y coordinates to the associated processor. ® ©2000 Burr-Brown Corporation AB-158 Printed in U.S.A. April, 2000 TOUCH SCREEN CONTROLLER TIPS By Skip Osgood, CK Ong, and Rick Downs Burr-Brown makes a number of specialized analog-to-digi- tal converters for touch screen applications. The ADS7843, ADS7845, and the new ADS7846 converters all are designed for specific touch screen applications. Applications using these devices can benefit greatly from the tips presented in this application bulletin. Most of the examples discuss the ADS7843, but the techniques shown are applicable to all of the devices. We begin by looking at the theory of operation of a resistive touch screen, and using these specialized A/D converters with such a screen. Techniques are presented for improving accuracy and minimizing errors; the operation of the pen interrupt line (PENIRQ) is explored, ESD protection methods for the converters, and issues surrounding interfacing these converters to popular microprocessors are discussed. RESISTIVE TOUCH SCREENS A resistive touch screen works by applying a voltage across a resistor network and measuring the change in resistance at a given point on the matrix where a screen is touched by an input stylus, pen, or finger. The change in the resistance ratio marks the location on the touch screen. The two most popular resistive architectures use 4-wire or 5-wire configurations (as shown in Figure 1). The circuits determine location in two coordinate pair dimensions, although a third dimension can be added for measuring pressure in 4-wire configurations. THE 4-WIRE TOUCH SCREEN COORDINATE PAIR MEASUREMENT A 4-wire touch screen is constructed as shown in Figure 2. It consists of two transparent resistive layers. The 4-wire touch screen panel works by applying a voltage across the vertical or horizontal resistive network. The A/D converts the voltage measured at the point the panel is touched. A measurement of the Y position of the pointing device is made by connecting the X+ input to a data converter chip, turning on the Y+ and Y– drivers, and digitizing the voltage seen at the X+ input. The voltage FIGURE 1. 4-Wire and 5-Wire Touch Screen Circuits. Four-Wire Five-Wire Conductive Bar Insulating Material (Glass) Silver Ink Transparent Conductor (ITO) Bottom Side Transparent Conductor (ITO) Top Side X+ X– Y+ Y– ITO = Indium Tin Oxide FIGURE 2. 4-Wire Touch Screen Construction. SBAA036 Figure 2.6: Four-wire touch screen construction 7
The touch screen is used in differential mode. This basically means that any variation in the touch panels resistance due to change in power supply, changes in driver impedance or changes in temperature will be compensated for by the ratiometric operation of the A/D converter. We use differential mode, as opposed to single-ended mode, because it is more accurate. LCD screen The screen is connected to the microcontroller using sixteen data lines, one read and one write line, a reset line and a chip select line. Data is sent to the LCD screens controller using the sixteen data lines. For colors, only sixteen bits are used, the RGB565 color representation is used for this. This basically means that five data lines are used for the red pixels, six for the green pixels and the five remaining ones are used for the blue pixels. This was done to be able to send the color of one pixel at once, in stead of splitting this process into multiple data transfers. The result is a faster data rate which helps with the responsive feeling and fast working of the screen. SD card The SD card communicates with the microcontroller via SPI. Figure 2.7: Pins related to the TFT shield Also note that P0.2 (touch panel slave select) and P0.3 (strobe) are connected via a resistor to the 3,3V power supply. This is due to the fact that these pins are open-drain. Pull-up resistors are essential in this case. 8
2.2.5 Parallel port I/O expander The output of the parallel port is controlled through the I/O expander. We use the MCP23S17 IC. The reason why the parallel port wasn’t directly connected to the microcontroller is that we don’t have enough I/O pins to our disposal. The microcontroller communicates with the I/O expander via SPI. The I/O expander then controls the pins of the parallel port. Data coming from the CNC machine itself is sent to the microcontroller via the same SPI interface. Level converter As a result of using the I/O expander and because the parallel port needs to be 5V logic, we need a ‘level converter’. The microcontroller works at a voltage level of 3,3V. The I/O expander works with 5V logic. We fixed this problem by placing an integrated circuit that sees a 3,3V signal as a logical ‘1’ between the microcontroller and the I/O expander. The integrated circuit we use is a 74HCT04. This is an inverter circuit that contains six NOT gates. Both the SPI clock and SPI MOSI are connected to the I/O expander via two NOT gates (inverting twice results in the same signal, if we ignore the propagation delay). The two remaining NOT gates are each connected to a different signal, one is connected to the ‘chip select’ (slave select) pin. The last one is connected to the ‘strobe’ pin. The strobe signal has its own dedicated pin because we need very precise control over this signal. It is connected directly to the microcontroller. A final point to take into account is the MISO signal. The pins of the microcontroller are 5V tolerant, but the MISO pin is also connected to other integrated circuits that are not 5V tolerant (for example the touch panel controller or the SD card). For this reason, the signal must be converted from a 5V signal to a 3,3V signal. You can see that this is done by using a simple voltage divider in figure 2.8. Figure 2.8: Resistor devider for level conversion When the I/O expanders ‘slave out’ pin is high (5V), the voltage found on the ‘SPI-MISO pin’ can be calculated as follows: VSP I−MISO =R6 (R6+R7)∗VSO VSP I−MISO =1kΩ (560 + 1kΩ) ∗5V VSP I−MISO = 3,205V 9
2.3 The layout We managed to use a two layer PCB. This means that conductors are only present on the top and bottom side of the circuit board, in contrast to a more-than-two layered design, where additional layers are inside of the board. Most components are SMD components. The only through-hole components that are used are connectors such as the 40-pin header and the 25-pin SUBD connector. The schematic itself can be found in appendix B. Figures of the real board can be found on page 11. We took some options into consideration when placing the components are the following facts: •All connectors (USB and SUBD) are placed at the edge of the PCB, such that you can easily connect a cable to it. •Decoupling capacitors are placed as close as possible to the components. •The button is placed where it is, so that it is located in the centre line of the screen. •The 40 pin header is placed on the side so that the centre of the TFT shield is as close to the centre of the main PCB as possible. •As the datasheet for the WiFi module suggests, it is advised to have no copper under and around the antenna. In this figure you can see that no copper can be found under the antenna and 15mm from the edge of the board. Daan Ver Eecke Elias Verstappe CNC controller This project is a colaboration between & Daan Ver Eecke Elias Verstappe CNC controller This project is a colaboration between & Daan Ver Eecke Elias Verstappe CNC controller This project is a colaboration between & Figure 2.9: Antenna copper cutout •The power pin of the voltage regulators have a small copper plane. Connecting this pin to a larger surface area is done so that the regulator can dissipate some heat via this plane. Figure 2.10: Copper heat plane connected to 3V3 pin 10
Figure 2.11: Real board top view Figure 2.12: Real board bottom view 11
3.2 LCD screen The LCD display needs to display menus, so that the user can interact with the CNC machine. These menus need to be made from scratch. Several functions go into drawing an entire screen. First, some low level functions change the state of output tins of the microcontroller. After that, one function (that uses the low level functions) can select a window in which the pixels can be altered in color. When one pixel can be drawn, this function can be used to draw a line. The function that colors a pixel can also be used to print a character or a bitmap. The screen is 480 pixels by 272 pixels large. 3.2.1 Pixel The drawPixel function and its colored function drawCPixel use several other funcions to color a pixel. To be able to change the change a pixel, we need some more functions that have more low level control over the screen. First, two commands were written to be able to write a command or data to the LCD controller. These functions are the following: void writeCmd(unsigned short cmd) { TFT_RS_L(); TFT_DATA_SET( cmd ); TFT_WR_L(); TFT_WR_H(); } void writeData(unsigned short data) { TFT_RS_H(); TFT_DATA_SET( data ); TFT_WR_L(); TFT_WR_H(); } As you can see, they simply change the state of some pins to the desired value, which is given as an argument to these functions. These abovementioned functions are only directly used by the LCD screen initialization function and the setXY function. The setXY function defines a window in which pixels can be altered. Several commands (set_column_address, set_page_address and write_memory_start) as well as the coordinates of two points are sent to the screen controller. One more function that uses the ‘writeData’ command is the ‘setPixel’ command. Two (or three) arguments are passed to this command. These arguments are the x and y coordinate, as well as the color that the pixel has to be. Because we only have sixteen data lines, and don’t want to split up the pixel’s color to take two clock pulses to process, we have decided to use RGB565 color representation. RGB565 dedicates five bits to the intensity of the red color, six for the blue color and 5 for the green color. To color a pixel, a window is set that covers only that one pixel. Next the data lines are set to represent a certain color. void drawCPixel(int x, int y, int color) { setXY(x, y, x, y); writeData(color); } 3.2.2 Line Several functions were written to draw a line. Two of them are drawHLine and drawVLine. These functions draw a horizontal of vertical line, as they suggest. To draw these lines, the ‘drawPixel’ function is called inside of a loop, with each iteration of the lop incrementing a coordinate which is associated with either the x or y coordinate of the ‘drawPixel’ function. Other functions like fillBox work with the same principle. With the help of a loop this function draws a box that is all one color. The other function can draw a line is simply drawLine. This function calls the simple HLine and VLine functions in case the line is not diagonal. If the line is diagonal, that would mean that the difference between x1and x2AND the difference between y1and y2is not equal to zero. In this case, the Bresenham algorithm is used to help draw a diagonal line. Drawing a diagonal line is not that self-evident as you’d think. Because we don’t want to include floating point arithmetic libraries, the microcontroller only knows integers. See section 3.2.3 for more information about the Bresenham algorithm. All of these functions have colored variants. 18
3.2.3 Bresenham’s line algorithm[3] Bresenham’s line drawing algorithm connects two points with a straight line by calculating all intermediate points on a pixelated canvas. X 0 0 xk xk+1 xk+2 xk+3 xk+4 yk yk+1 yk+2 yk+3 yk+4 Y (x1, y1) (x2, y2) C,(x, y) A B Figure 3.4: Result of Bresenham’s line algorithm The slope of the line can be calculated as follows: m=(y2−y1) (x2−x1) =∆y ∆x Consider that (m <1). In this case the change in x is larger than the change in y. We will be incrementing x by one and we will calculate its respected y. If (m >1) the change in y woud be bigger than the change in x. In the schematic you can see that the line is going on between the ‘A’ and ‘B’ dot.The diagonal line intersects with the grid line at point C, with coordinates (x, y). Two lengths are created, d1(Ax−Cx) and d2(Cx−Bx). The next point on the line is now selected by comparing d1and d2. If d1is larger than d2, point A will be chosen as the next point, because the line is closer to point A. The ratio between d1 and d2is known as the decision parameter. (x1, y1) C,(x, y) A B d1 d2 Figure 3.5: Closup of figure 3.4 This is a general explanation. The functions in C code were obtained from the UTFT library[4] for drawing the line on the screen and some code that had already been written to move the CNC machine. 19
3.2.4 Character and string The printCChar function prints out a character on the display. There is a corresponding array that is used to determine what pixels need to be and what pixels don’t need to be colored. To help explain how this function works, here is a part of the array that contain one of the used fonts. // Font Size : 8x12 // Memory usage : 1144 bytes // # characters : 95 fontdatatype SmallFont[1144] PROGMEM={ 0x08,0x0C,0x20,0x5F, . . 0x00,0x00,0x00,0x00,0x00,0x30,0x48,0x38,0x48,0x3C,0x00,0x00, // a . As you can see, it is an array of characters (fontdatatype is a user defined datatype and basically just is the same as unsigned char). This example is for the small font, which is eight pixels wide by twelve pixels high. The first four bytes of this array give us some information about the font. At the first and second indices the width and height of a character is stored (in this case 0x08 by 0x0C or just eight by twelve pixels). The third element indicates what the first character is. Here we can see that the first character is index 0x20 or 32 in the ASCII table, which is the space character (not shown). The next element tells us how many characters are ‘described’ in this array. In this case, 0x5F which is 95 decimal. To now print a character, one of the ‘lines’ which describes a character is used to determine where a pixel needs to be colored. One of these ‘lines’ is checked, bit by bit. When the current bit equals zero, a pixel should be colored in the background color. If the bit is one, that pixel should be colored in the foreground color. Have a look at the following example with the ‘a’ character. In figure 3.6 you can see how a character is formatted. 0x00, (0000 0000) 0x00, (0000 0000) 0x30, (0011 0000) 0x48, (0100 1000) 0x38, (0011 1000) 0x48, (0100 1000) 0x3C, (0011 1100) 0x00, (0000 0000) 0x00, (0000 0000) 0x00, (0000 0000) 0x00, (0000 0000) 0x00, (0000 0000) 01234567 0 1 2 3 4 5 6 7 8 9 10 11 Figure 3.6: ‘a’ character bitmap 20
To print out this character, two loops are used to cover all pixels. A first loop is responsible for the x coordinate and increments by one every iteration. The y coordinate increments by one every eight incrementations of the x coordinate. In the case of the small font, eight, in the case of another font with other dimensions this could be different. Every time the y coordinate is incremented, the x coordinate is set to the original value. The data that describes the font (the height and width of a characters ‘bitmap’) is taken into account to print out a character. 01234567 0 1 2 Y X Start Figure 3.7: ‘Line feed’ and a ‘carriage return’ Bitmap A bitmap is printed in much the same way as a character. The first few entries of the array contain information about the graphic. The array structure looks something like this: [width, height, actual amount of color entries, start of color entries, ... ]. The difference between this kind of bitmap and a character is that this each entry of the array represents a full color (RGB565) instead of having each bit represent just black or white. This makes graphic bitmaps much larger than a simple character. In the example below, a five by five bitmap is shown. The full graphic is 56 bytes large. The ‘a’ character in figure 3.6 only takes up approximately 16 bytes. A graphic that is almost four times the size only takes up about 30% of space. unsigned short arrow_head_y[28] PROGMEM = { 0x0005, 0x0005, 0x0019, 0x0000, 0x0000, 0x8410, 0x0000, 0x0000, 0x0000, 0x0000, 0xFFFF, 0x0000, 0x0000, 0x0000, 0xC618, 0xFFFF, 0xC618, 0x0000, 0x0000, 0xFFFF, 0xFFFF, 0xFFFF, 0x0000, 0xC618, 0xFFFF, 0xFFFF, 0xFFFF, 0xC618 }; Figure 3.8: Example graphic 21
3.3 Touch control The touch screen is controlled via SPI. To read an x or y coordinate, a control byte is sent to the touch screens controller. This control byte contains a start bit, a bit to tell the controller to measure in differential mode and some bits that tell the controller which coordinate you want to read. The touch controller responds with a twelve bit number. Both the x and y coordinate will be returned as values between 0 and 4096. The LCD screen that lies underneath the transparent touch conductors works with pixels. For x this value can be between 0 and 479 and for y it can be between 0 and 271. y x LCD: (0, 0) Touch: (4096, 4096) LCD: (479, 271) Touch: (0, 0) y x LCD: (0, 0) Touch: (0, 0) LCD: (479, 271) Touch: (479, 271) Figure 3.9: Difference in coordinates It would be handy to have the coordinated from the LCD screen and touch panel match up (and be the same), so that there is no confusion when we check if a certain part of the screen has been touched. For this reason a conversion has to be done. This can easily be done by applying the rule of three. 3.3.1 Calibration[5] Mechanical misalignment and scaling factor can lead to a mismatch between values from a touch panel system (touch screen and touch screen controller) and the display on which the touch screen is mounted. Image transformation The figure below is an exaggerated view of the distortion that might happen to a circle being displayed on an LCD touch screen display. When a finger is traced around the circle (red line), the touch panel system may give out coordinates of an ellipse (blue line). Figure 3.10: Circle transformation due to misalignment and scaling Mathematics The calculations for the calibration can be found in appendix E. A calibration function has been used to obtain the transformation matrix elements, to solve equations. The results (the matrix) is stored as fixed values inside of the microcontroller, not to calibrate the screen each time we power the system on. 22
3.4 Interfacing with the machine The user can control the machine with the aid of the TFT screen. As the touch panel and LCD screen are two separate parts, the firmware has to make sure that they work together. This means that when something that is displayed on the (LCD) screen, is pressed (on the touch panel), something has to happen. The press of a button, a directory, an input field, etc. will give the user visual feedback and could also trigger some other action. For example, clicking the ‘Start’ button when a file is selected will result in the button changing color on pressing it and changing the color back to the original color when releasing it as well as changing the screen and moving the machine. The next section describes bow a button press is handled. 3.4.1 Pressing a button Information about the buttons is stored in the microcontrollers memory. At first, the buttons on the screen. After that, an endless loop is entered. This ‘event’-loop checks all of the buttons. Checking the buttons is done in the following way: The location where the screen is being pressed is compared to the coordinates of the buttons that screen has. If the screen is being pressed on a spot where a button is located, the action associated with the button press is performed. In other words, if the coordinates of the pressed spot are withing the coordinates of a button, the event corresponding to that button is triggered. You can see how this works in figure 3.11. Start Within coordinates of a button? Current state of button = pressed Current state of button = not pressed * * Delay ±10 ms Yes No current state = pressed? & previous state = not pressed? 'Positive edge' on button (1) Yes No current state = not pressed? & previous state = pressed? 'Negative edge' on button (2) Yes No Figure 3.11: Touching a button When the button is touched, a certain action can be given to that event. Figure 3.12 shows the 23
principle of how most of the buttons in this project perform some kind of action. This way of controlling a button is flexible, as it allows the programmer to perform an action exactly when he wants. Functions van be called on touching (1) or releasing (2) the button. These functions will also only be called once, not every time the check is performed when the button is pressed. Button state (1) (2) * draw button in different colors * draw button in 'not pressed' colors * perform action associated with this button pressed not pressed Figure 3.12: Perform an action when button is touched 3.4.2 Checking if a spot is touched As you have read in the previous section and as you can see in figure 3.11, a check is performed to see if a button is touched. This function is quite simple, as it just compares coordinates. The coordinates of the spot that is pressed on the screen are compared to coordinates of the buttons that that screen has. If the spot pressed is inside of an area where a button is located, that button is considered ‘pressed’. An error margin is added to make sure that the user does not have to hit a precise spot. (x1, y1) (x2, y2) (x1 - margin, y1 - margin) (x2 + margin, y2 + margin) Text Text Figure 3.13: Error margin In firmware this functionality is achieved by first requesting the coordinates of the spot is currently being touched, and afterwards checking if the coordinate is bigger than the left(x1) or top(y1) coordinate minus the margin, and checking if value of the coordinate of the spot is smaller than the right(x2) or bottom(y2) coordinate plus the margin. If these conditions are met, the function returns ‘TRUE’, which indicates that the user is touching a spot within the given area. Else it returns ‘FALSE’, which of course means that the area is not touched. Visible canvas (479, 0) (508, -18) Figure 3.14: ‘Touch’ in idle state When the screen is not pressed, ‘a touch’ (which is translated to coordinates) is constantly registered. This is a result of not being able to use the interrupt functionality of the touch controller. This because of a lack of IO pins at the microcontroller. In the idle state (when the screen is not touched), coordinates are still being read, but they are outside of the visible canvas (shown in figure 3.14). 24
3.5 Control the CNC machine The output of the parallel port is controlled by the I/O expander. The reason why the parallel port wasn’t directly connected to the microcontroller is that we don’t have enough I/O pins to our disposal. In figure 3.1 we can see how the microcontroller is connected to the I/O expander and parallel port. If data needs to be written to the parallel port, that data will have to be sent to the I/O expander via SPI. The strobe pin is connected from the microcontroller to one NOT gate (for level conversion), to the parallel port. The CNC machine has a control unit. The way the machine is controlled is by sending commands to that control unit. By hooking up a logic analyzer to the parallel port, and trying to move the machine via the application on MS-DOS, we were able to extract the commands that need to be sent to the control unit to control the machine. This process of measuring the actual voltage levels is called reverse engineering. 3.5.1 CNC routines For more information about the circular buffer, please refer to section 3.5.4. One case where we use a circular buffer is to control the CNC-machine. For example, when it is required to move the head a certain distance in one direction (read more at section 3.5.3). Commands have to be sent to the CNC-machine via the parallel port. The way the machine works is as follows: The axes of the machine are controlled by stepper motors. In our case, one step of te stepper motor results in a movement of 0,0254 mm ( 1 1000 th of an inch or also refered to as one thou[6] or one mill) in a certain direction. The speed at which the head moves is determined by how fast commands are sent. The commands control the machine. We have a list of commands that controls the movement in all three axes, spindle control, initialization of the machine etc. The delays between these commands are in the order of a couple hundred microseconds. The way we are able to control these rather small and precise timings is by means of a timer interrupt. For the implementation two buffers are used. Each command is accompanied by a specific delay. 3.5.2 Speed up and slow down The InitiateSpeed function does several things. First the circular buffer is initialized. Also, an initial delay is put into the buffer so that the timer can run once. Afterwards timer 0 is initialized and configured as an interrupt. Finally we come to the ‘delay initialization’. When the head of the machine moves, we can’t just tell it to go a certain speed. The machines inertia could and probably would make the stepper motors skip a couple of step. We don’t want this. Very precise control over the movement of the head is required. For this reason we need to speed up and slow down all movements. When we use the InitiateSpeed function, the given argument is the desired maximum speed. Because the speed of movement is determined by the delay in between commands, we need a small delay for fast movement and a big delay for slow movement. If you would plot these delays on a graph, it would look like the graph below. As you can see, the delay is decremented in the first 40 steps and incremented for the last 40 steps. This example was calculated for a speed of 5000 mm/min. 0 20 40 60 80 100 120 300 1,500 4,000 6,000 8,000 step delay [µs] Delay in function of steps 25
3.5.3 Move the head One function that is central to make the CNC machine move in any direction, is the setParam_cmd function. This function takes two arguments, a command and a delay. The ‘command’ is an opcode that makes the machine move. An example of such a command would be: #define X_INC (0x4B) Anywhere where X_INC is used, the value will be substituted by 0x4B and the execution of the function will result in the movement of the head in the x-axis. Every movement will call the setParam_cmd command. If this command is executed, a new entry is added to the queue that stores a pair of commands and delays. Figure 3.15 shows this. 300 300 300 300 Delay[µs] setParam_cmd(0x4B, 300); 0x4B 0x4B 0x4B 0x4B Command Figure 3.15: Circular buffer - setParam_cmd command These delays and commands are then processed by a timer interrupt. An interrupt is used to achieve very precise control over timing of commands. The timer is configured in such a way that it will stop (and not restart) counting after a set time. When the setParam_cmd function is called, the time given as an argument is configured as the time the counter will count and the command is processed. This involves setting the data pins of the parallel port to the correct value (the value depends on the action you want the machine to perform) and putting a low pulse on the strobe pin of the port. When the interrupt triggers, after the period of the previous command, a check is performed to see if there are commands to process. If so, this process of enabling the timer and processing the data is repeated with new values. 26
3.5.4 Circular buffer[7] Different circular buffers are used in this project. A circular buffer is a data structure that uses a buffer of a fixed size, as well as two ’pointers’ to indicate where to read or write data. The buffer starts out empty. When something is written to the buffer (a command, an instruction, some data...), the write pointer needs to be increased by one, so that the next write operation can write data on a free entry of the buffer. Now assume that the buffer is totally filled with data. We don’t want unprocessed data to be overwritten. That is why we also have a read pointer. When data from the buffer is processed, the read pointer gets incremented by one. If data must now be written to the buffer, a check is first made to see if there is writable entry in the buffer. In other words, data can be written if the entry is empty or if the entries content has been processed. The read pointer needs to be behind the write pointer. If the read pointer is in front of the write pointer, the program has to wait until more data has been processed. Figure 3.16 illustrates this working. The Wikipedia article about circular buffers [7] has an easy to understand animation that explains this functionality very well. read 0x5F write 0xB1 0 1 2 3 4 5 6 7 0x29 0x9A 0x6E 0x55 0x3D 0x8C write 0x5F 0xB1 0 1 2 3 4 5 6 7 0x3D 0x8C read Figure 3.16: No free entries in the buffer (left) and entries can be filled (right) 27
3.8 Communication with WiFi module The microcontroller and WiFi module communicate with each other via UART. The microcontroller has two UART interfaces. One is used for programming the MCU, the other one is used to communicate with the WiFi module. You can also see the UART connections in figure 2.3. 3.8.1 Frame To successfully transfer data between the microcontrollers, a certain frame format has to be agreed upon. This format is known by both microcontrollers and both microcontrollers send data in that format. For this application, the following frame format has been chosen (figure 3.20). 1 byte 256 byte1 byte 1 byte Start of frame Payload length Payload CRC8 Figure 3.20: Frame format The start of frame character that is chosen is a dollar sign, ‘$’. The maximum payload length per frame will be 256 bytes long. The payload can vary in structure depending on the data. An encoding technique known as byte stuffing is applied to the following parts of the frame: the payload length byte, the payload itself and the checksum. The byte stuffing function escapes characters such as the start of frame character or the escape character itself. These characters are escaped if they are present in either the payload length byte, the payload or the checksum. Escaping these characters is essential, if the payload would contain a dollar sign, the state machine used at the receiving end would see this as a start of frame character. More information about the state machine can be found at section 3.8.4. An error-detection method is also added, to detect changes in raw data between transmitter and receiver. This feature is implemented to check if no data was lost or changed during transmission. If the received data is incorrect, the microcontroller can discard that frame and request to re-transmit that frame. The polynomial that is used is the ‘CRC-8-CCITT’ polynomial and its normal representation is 0x07. 3.8.2 Payload structure Different payload formats have been defined. Figure 3.21 shows you an example. As you can see, the payload starts with two identification bytes. One the first byte contains information about whether the payload contains data about a file or if the payload has information about a screen. In the case of the example, the payload is filled with data about the tools page. Here the first byte would tell the program that data about a screen is incoming. The second byte tells the program what screen is described. All screens get a number. This is followed by the data on each screen. Start of frame Payload length Screen/file Screen number Tool 1 Tool 2 Tool 3 Tool 4 Tool 5 Checksum Payload Figure 3.21: Frame filled with tools data If file data was to be received, the payload would start with a number that would let the microcontroller know that file data is coming. The second byte (‘screen number’) would tell the controller if a ‘.plt’ or ‘.ncd’ file is being sent. The following eight bytes, because these numbers are sent as integers, contain data about the current frame that is sent and about the total amount of frames that will be sent. 34
3.8.3 Transmission To send data from the microcontroller (LPC) to the WiFi module (ESP), a function is used to build up a frame and send it. Building up a frame means sending a start of frame byte, sending the payload length, sending the payload itself and sending a checksum. When sending the payload, the program makes sure to ‘escape’ the dollar sign or the escape character itself. 3.8.4 Reception The UART1 interface, which is the connected to the WiFi module, is configured to trigger an interrupt when the receive buffer of that UART interface is filled with one byte. A state machine is used to decode the incoming data. To decode the data we apply inverse byte stuffing, the result is that we end up with the original payload. Figure 3.22 shows the state machine. any other character S0 S1 S2 '$' '$' '\' '$' '\' Outside frame Decode data Inside frame Figure 3.22: State machine that processes the incoming frame Once the frame is completely received, the payload can be deciphered. Because data from the different screens has a fixed place in the payload, information can easily be extracted from the payload. Much like how the frame is constructed the codes and numbers that describe the data are used to determine values for parameters. Let us continue working with the example of the tool data. Because a fixed structure has been determined, the program knows that if the first two bytes of the payload are ‘0xC3’ and ‘0x03’ (which tell us that the tools screen information is being sent), that bytes 19 to 22 describe the spindle speed of a tool, whose tool number is specified on the second byte. All payloads can be deciphered in much the same way. Start length 0xC3 3 Tool n° Depth (integer) Iterations (integer) 0 21 3 4 5 6 Screen specifier Payload Screen 3: Tools 789 10 X feed (integer) 11 12 13 14 Z feed (integer) 15 16 17 18 Spindle (integer) 19 20 21 22 Depth (integer) Iterations (integer) 24 25 26 27 28 29 30 3123 32 33 34 35 ... Spindle (integer) .. .. .. .. CRC8... Payload Tool n° Figure 3.23: Full description of the tools payload 35
Chapter 4 User manual This chapter describes how to use the controller device. To summarize, the purpose of the controller is to control the CNC machine and ultimately to mill out a certain PCB design using the machine. A design is provided either via an SD card or via the website. Several parameters can be configured with the aid of the touchscreen. In the rest of this chapter you can read an in depth description of the operating system and the meaning of the various adjustable and non-adjustable parameters. The firmware of the controller has a tree-like structure. You can open different screens from the main menu and return to the home screen. 4.1 Start up / main screen When starting up the controller, a screen with the names of the creators of this project is displayed for a short amount of time. After that, you will see the main screen. You can see this screen in figure 4.1. Figure 4.1: Main screen Offset The offset parameter allows you to move the designs zero point from the machines zero point. 36
Board & Base You can enter the printed circuit boards true thickness in millimeters. This input is necessary for the program to determine the Z-axis movement of the machine and the drilling or milling depth. The base sheet is a sheet on your machine between the PCB and the machines bed. A base board is necessary to fully drill through the PCB and not damage the bed of the machine. Base sheet Board (PCB) Z Zero position Free stroke Base thickness Board thickness Machine table Drill depth (max stroke) Figure 4.2: Dimensions Size display The size display, which is located in the bottom left, shows the minimum and maximum X and Y values. These values are displayed in millimeters. They basically tell you the size of the design. Selected file When the machine is just powered on, the ‘Start’ button is greyed out, because no file is selected. After selecting a file from the SD card, you will see that the start button is colored like the rest of the buttons. It is now clickable. Read more about this in section 4.5. 37
4.2 Configuration The configuration screen can be accessed by pressing the ‘Config.’ button on the main menu. Figure 4.3: Configuration screen Stroke The Z-axis stroke limit is essential for the software to calculate the correct height over the machine bed and board. The free stroke setting describes the height of the drill bit when moving above the PCB. Both of these parameters are visually represented in figure 4.2. Correction factor The correction factors are not changeable but they are necessary because they are related to the gearbox transmission of the spindle and the belt tension which is related to X and Y axis movement. These correction factors take into account the aforementioned problems to ensure accurate operation of the machine. 38
4.3 Tools The tools page allows you to customize the settings of a particular tool. Figure 4.4: Tools screen Depth The depth parameter of a tool specifies how deep the tool will drill into the PCB. Xfeed and Zfeed The X- and Zfeed parameters allow you to configure the speed at which the machine moves in the X- and Y-axis (Xfeed) as well as in the Z-axis (Zspeed). Iterations This number is relevant when milling out a board from one big sheet. The parameter indicates in how many times the board will be milled out. Each iteration, the drill will go a little bit deeper. Spindle With the spindle parameter you can configure the speed at which the spindle rotates, expressed in rotations per minute. 39
4.4 Offset Offset mode allows you to manually move the machine axes. This is useful for general testing or to determine a new board zero position, if necessary. First, select a distance. This selection determines how much the machine moves when pressing a button. The ‘coordinate’ of the place where the head is currently located is displayed in the bottom right. Figure 4.5: Offset screen 40
4.5 Load and Start To select a file, press the ‘Load’ button. This will open a new window. If no SD card has been inserted, the controller will tell you that. Figure 4.6: Load file screen - no card inserted Figure 4.7: Load file screen - card inserted If an SD card has been inserted, you will see the contents of your SD card, but only directories, HPGL and Excellon files. To select a particular file, just press on the name. The file will be highlighted on the screen. If your file is located inside of a directory, open the directory by clicking on it. When you have selected a file you can press accept to leave this window and go back to the main menu. You will see that the ‘selected file’ field will be filled in with the file you have selected. When browsing through the directories of the SD card, you can go back to the main or root directory by pressing the ‘Root’ button. You will also notice that prior to selecting a file, the start button is greyed out and not clickable. When a file is selected, the start button is clickable. Figure 4.8: Inactive and active start button 41
When you want the machine to start milling out the design that is selected, press the start button. This will display a new window. Some parameters such as the current tool and the current coordinates of the head are displayed. Figure 4.9: Machine is running If a tool needs to be changed during the process of milling out the design, a pop-up screen will notify you to change the tool. The head will stop moving and the spindle will stop rotating. When the tool has been changed, the user can press the resume button on the pup-up, to make the machine resume and continue routing or milling out the design. Figure 4.10: Pup-up for tool change 42
Chapter 5 Cost study 5.1 Material Tables 5.1 and 5.2 give you a list of the different components that are needed to make this controller. A more detailed version of this list can be found in one of the appendices. Component Quantity Unit cost Modules TFT screen 1 e19,74 WiFi module 1 e2,23 Subtotal e21,97 Capacitors 100nF 8 e0,04 22µF 3 e0,03 33pF 2 e0,02 10µF 1 e0,42 Subtotal e0,87 Resistors 1k 3 e0,01 10k 4 e0,01 3k3 2 e0,01 560 1 e0,14 Subtotal e0,22 Integrated circuits LPC2106 (microcontroller) 1 e10,33 3V3 voltage regulator 1 e0,48 USB to UART converter 1 e2,31 1V8 voltage regulator 1 e0,25 I/O expander 1 e0,83 Level converter 1 e0,09 Subtotal e14,30 Table 5.1: Bill of materials, part 1 43
FILE NAME: BY: DATE: PAGE: CNC CONTROLLER 5/05/2019 Elias Verstappe/ Daan Ver Eecke AB C D E F G H J K A B C D E F G H J K 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 1 of 6 REV: 0.1 TIME: 20:14:38 DESIGN TITLE: CNC CONTROLLER VIVES & UVa Final Project P0.16-TFT_DB0 P0.17-TFT_DB1 P0.18-TFT_DB2 P0.19-TFT_DB3 P0.20-TFT_DB4 P0.21-TFT_DB5 P0.22-TFT_DB6 P0.23-TFT_DB7 P0.24-TFT_DB8 P0.25-TFT_DB9 P0.26-TFT_DB10 P0.27-TFT_DB11 P0.28-TFT_DB12 P0.29-TFT_DB13 P0.30-TFT_DB14 P0.31-TFT_DB15 SPI SCK SPI MISO SPI MOSI SPI /GPIO_CS TXD1 RXD1 TXD0 RXD0 /RESET BTL/EMERGENCY SPI /TP_CS TFT /WR TFT /CS TFT RS TFT /RD STROBE SPI /SD_CS XTAL1 11 XTAL2 12 DBGSEL 27 RTCK 26 P0.0/TxD0/PWM1 13 P0.1/RxD0/PWM3 14 P0.2/SCL/CAP0.0 18 P0.3/SDA/MAT0.0 21 P0.4/SCK/CAP0.1 22 P0.5/MISO/MAT0.1 23 P0.6/MOSI/CAP0.2 24 P0.7/SSEL/PWM2 28 P0.8/TxD1/PWM4 29 P0.9/RxD1/PWM6 30 P0.10/RTS1/CAP1.0 35 P0.11/CTS1/CAP1.1 36 P0.12/DSR1/MAT1.0 37 P0.13/DTR1/MAT1.1 41 P0.14/DCD1/EINT1 44 P0.15/RI1/EINT2 45 P0.16/EINT0/MAT0.2 46 P0.17/CAP1.2/TRST 47 P0.18/CAP1.3/TMS 48 P0.19/MAT1.2/TCK 1 P0.20/MAT1.3/TDI 2 P0.21/PWM5/TDO 3 P0.22/TRACECLK 32 P0.23/PIPESTAT0 33 P0.24/PIPESTAT1 34 P0.25/PIPESTAT2 38 P0.26/TRACESYNC 39 P0.27/TRACEPKT0/TRST 8 P0.28/TRACEPKT0/TMS 9 P0.29/TRACEPKT2/TCK 10 P0.30/TRACEPKT3/TDI 15 P0.31/EXTIN0/TDO 16 V18 5 RST 6 VSS 7VSS 19 VSS 31 VSS 43 V3 17 V3 40 U1 LPC2106FBD48/01,15 QFP50P900X900X160-48 12 X1 LFXTAL030358 XTAL C7 33pF 0805_CAP C8 33pF 0805_CAP 3V3 C9 100nF 0805_CAP C10 100nF 0805_CAP C11 100nF 0805_CAP 1V8 Microcontroller Clock crystal R5 3k3 0805_RES 3V3 GND PIN TFT /WR PIN TFT /CS PIN TFT RS PIN TFT /RD PIN R8 3k3 0805_RES 3V3 Remark: P0.2 & P0.3 are open-drain, this is why pull-up resistors are essential 50
FILE NAME: BY: DATE: PAGE: CNC CONTROLLER 5/05/2019 Elias Verstappe/ Daan Ver Eecke AB C D E F G H J K A B C D E F G H J K 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 2 of 6 REV: 0.1 TIME: 20:14:38 DESIGN TITLE: CNC CONTROLLER VIVES & UVa Final Project USB_TXD USB_RXD /RESET BOOTLOADER L1 2508051217Y0 0805 TXD 1 RXD 5 RTS 3 CTS 11 DTR 2 DSR 9 DCD 10 RI 6 CBUS0 23 CBUS1 22 CBUS2 13 CBUS3 14 CBUS4 12 3V3OUT 17 USBDM 16 USBDP 15 RESET 19 OSCI 27 OSCO 28 VCCIO 4 TEST 26 U3 FT232RL-REEL SOP65P780X200-28 VCC=5V VDD 1 D- 2 D+ 3 NC 4 GND 5 GND 6 J1 67503-1020 USB MINI-8 SMT C1 100nF 0805_CAP C2 100nF 0805_CAP C4 100nF 0805_CAP IN 3OUT 2/4 GND 1 U2 TC2117-3.3VDBTR SOT223-4 IN 3OUT 2/4 GND 1 U4 MC33375ST-1.8T3G SOT223-4 C3 22uF/6.3V 0805_CAP C5 22uF/6.3V 0805_CAP C6 22uF/6.3V 0805_CAP 3V3 1V8 5V 3V3 Power supply Mini USB Tybe B USB to UART converter this package should really be SOT223-3 and not -4 but it is not a problem in our case VDD 1 D- 2 D+ 3 NC 4 GND 5 GND 6 J5 10118194-0001LF MICRO-USB-TYPE-B 3V3 PIN 5V PIN 1V8 PIN USB-TXD PIN USB-RXD PIN /RESET PIN BOOTLOADER PIN Micro USB Type B 51
FILE NAME: BY: DATE: PAGE: CNC CONTROLLER 5/05/2019 Elias Verstappe/ Daan Ver Eecke AB C D E F G H J K A B C D E F G H J K 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 3 of 6 REV: 0.1 TIME: 20:14:38 DESIGN TITLE: CNC CONTROLLER VIVES & UVa Final Project SEL PE BUSY ACK DATA_OUT_7 DATA_OUT_6 DATA_OUT_5 DATA_OUT_4 DATA_OUT_3 SELIN DATA_OUT_2 INIT DATA_OUT_1 ERROR DATA_OUT_0 AUTOF DATA_OUT_0 DATA_OUT_1 DATA_OUT_2 DATA_OUT_3 DATA_OUT_4 DATA_OUT_5 DATA_OUT_6 DATA_OUT_7 SEL PE BUSY ACK SELIN INIT ERROR TFT RS TFT /WR TFT /RD P0.24-TFT_DB8 P0.25-TFT_DB9 P0.26-TFT_DB10 /RESET P0.31-TFT_DB15 P0.30-TFT_DB14 P0.29-TFT_DB13 P0.28-TFT_DB12 P0.27-TFT_DB11 SPI /SD_CS SPI MOSI SPI SCK SPI MISO SPI MISO SPI MOSI SPI /TP_CS SPI SCK P0.23-TFT_DB7 P0.22-TFT_DB6 P0.21-TFT_DB5 P0.20-TFT_DB4 P0.19-TFT_DB3 P0.18-TFT_DB2 P0.16-TFT_DB0 P0.17-TFT_DB1 TFT /CS SPI SCK SPI MOSI SPI /GPIO_CS AUTOF SPI MISO STROBE 1 14 2 15 3 16 4 17 5 18 6 19 7 20 8 21 9 22 10 23 11 24 12 25 13 J3 5504F1-25S-02-03-F1 25 PIN SUBD CONNECTOR GPA0 21 GPA1 22 GPA2 23 GPA3 24 GPA4 25 GPA5 26 GPA6 27 GPA7 28 GPB0 1 GPB1 2 GPB2 3 GPB3 4 GPB4 5 GPB5 6 GPB6 7 GPB7 8 SI 13 CS 11 SO 14 INTA 20 INTB 19 A0 15 A1 16 A2 17 RESET 18 SCK 12 U5 MCP23S17-E/SO SOIC127P1030X265-28 VDD=5V VSS=GND TFT 40 pin header Parallel port 16 bit IO expander R6 560 0805_RES R7 1k 0805_RES 1 2 U8:A 74HCT04D SOIC127P600X180-14 VCC=5V 3 4 U8:B 74HCT04D SOIC127P600X180-14 VCC=5V 5 6 U8:C 74HCT04D SOIC127P600X180-14 VCC=5V 13 12 U8:D 74HCT04D SOIC127P600X180-14 VCC=5V 11 10 U8:E 74HCT04D SOIC127P600X180-14 VCC=5V 98 U8:F 74HCT04D SOIC127P600X180-14 VCC=5V GND 1 3V3 2 NC0 3 RS 4 WR 5 RD 6 DB8 7 DB9 8 DB10 9 DB11 10 DB12 11 DB13 12 DB14 13 DB15 14 CS 15 F_CS 16 RESET 17 NC5 18 LED_A 19 NC1 20 DB0 21 DB1 22 DB2 23 DB3 24 DB4 25 DB5 26 DB6 27 DB7 28 T_CLK 29 T_CS 30 T_DIN 31 NC4 32 T_DO 33 T_IRQ 34 SD_DO 35 SD_CLK 36 SD_DIN 37 SD_CS 38 NC3 39 NC2 40 M1 TFT_43 TFT_43_ONLY_HEADER 3V3 3V3 LEVEL CONVERTER 5V C14 100nF 0805_CAP C15 100nF 0805_CAP 5V Decoupling for IO expander Decoupling for U8 SPI-MISO PIN SPI-MOSI PIN SPI-SCK PIN /SPI-GPIO_CS PIN Remark: ESP (Wifi) - module is not 5V tolerant. These resistors convert a high signal from 5V to 3V3 5V 52
FILE NAME: BY: DATE: PAGE: CNC CONTROLLER 5/05/2019 Elias Verstappe/ Daan Ver Eecke AB C D E F G H J K A B C D E F G H J K 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 4 of 6 REV: 0.1 TIME: 20:14:38 DESIGN TITLE: CNC CONTROLLER VIVES & UVa Final Project USB_TXD ESP_RXD TXD1 RXD0 USB_RXD TXD0 ESP_TXD RXD1 BOOTLOADER BTL/EMERGENCY ESP_BTL ESP_TXD ESP_RXD ESP_BTL /RESET R9 10k 0805_RES Wifi interface 1 2 3 6 5 4 S1 JS202011AQN PACKAGE=JS202011AQN R4 10k 0805_RES 3V3 C12 10uF 0805_CAP 3V3 R11 10k 0805_RES R2 1k 0805_RES R3 10k 0805_RES 3V3 R12 1k 0805_RES UART SWITCH BOOTLOADER RST 1 ADC 2 EN 3 GPIO14 5GPIO16 4 GPIO12 6 GPIO13 7 VCC 8 TXD 22 RXD 21 GPIO5 20 GPIO4 19 GPIO0 18 GPIO2 17 GPIO15 16 GND 15 CSO 9 MISO 10 GPIO9 11 MOSI 13 GPIO10 12 SCLK 14 M2 WIFI_MODULE_ESP12F ESP-12F ESP-TXD PIN ESP-RXD PIN ESP-BTL PIN 1 2 3 4 S2 BUTTON B3F-1050 53
FILE NAME: BY: DATE: PAGE: CNC CONTROLLER 5/05/2019 Elias Verstappe/ Daan Ver Eecke AB C D E F G H J K A B C D E F G H J K 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 5 of 6 REV: 0.1 TIME: 20:14:38 DESIGN TITLE: CNC CONTROLLER VIVES & UVa Final Project ~~~~~~~~~~~~~~~~~ POWER DISSIPATION ~~~~~~~~~~~~~~~~~ +---------------------------------+--------------------------------+-------------------------+ |5V |3V3 |1V8 | +---------------------------------+--------------------------------+-------------------------+ |40uA (level-converter) |15mA (USB to UART controller) |35mA (microcontroller) | |2mA (I/O expander) |200mA (TFT) | | |420.2mA (3V3) |170mA (WIFI module) | | |130uA (3V3 regulater internal) |35mA (1V8) | | | |200uA (1V8 regulator internal) | | +---------------------------------+--------------------------------+-------------------------+ |TOTAL @ 5V = 422.3mA |TOTAL @ 3V3 = 420.2mA |TOTAL @ 1V8 = 35mA | +---------------------------------+--------------------------------+-------------------------+ |POWER @ 5V = 2.12W |POWER @ 3V3 = 1.39W |POWER @ 1V8 = 0.063W | +---------------------------------+--------------------------------+-------------------------+ 54
FILE NAME: BY: DATE: PAGE: CNC CONTROLLER 5/05/2019 Elias Verstappe/ Daan Ver Eecke AB C D E F G H J K A B C D E F G H J K 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 6 of 6 REV: 0.1 TIME: 20:14:38 DESIGN TITLE: CNC CONTROLLER VIVES & UVa Final Project ~~~~~~~~~~~~~~~~ HEAT DISSIPATION ~~~~~~~~~~~~~~~~ +------------------------------+------------------------+-----------------------+----------------------------+ |component |IC code |max temperatur (°C) |conditions | +------------------------------+------------------------+-----------------------+----------------------------+ |microcontroller |LPC2016 |85 |IDD(45mA)@60MHz | |USB to UART |FT232RL |85 |/ | |16 bit I/O expander |MCP23S17 |125 |/ | |level converter (NOT port) |74HCT04D |70 |above 70°C Ptot drops 8mW/K | |wifi interface |ESP-12F |125 |operating temperature | |3V3 voltage regulator |MC33375ST-1.8T3G |245°C/W |/ | |1V8 voltage regulator |TC2117-3.3VDBTR |59°C/W |/ | +------------------------------+------------------------+-----------------------+----------------------------+ ~~~~~~~~~~~~~~~~~~~~~ 1V8 voltage regulator ~~~~~~~~~~~~~~~~~~~~~ P = U * I = 35mA * (3V3-1V8) = 0.0525W => T = 245°C/W * 0.0525W + Ta = 12.86°C + 25°C = 37.86°C ~~~~~~~~~~~~~~~~~~~~~ 3V3 voltage regulator ~~~~~~~~~~~~~~~~~~~~~ P = U * I = 420.2mA * (5V-3V3) = 0.72W => T = 59°C/W * 0.72W + Ta = 42.15°C + 25°C = 67.15°C 55
Appendix B PCB Layout •All layers .....................................................................................57 •Top layer .....................................................................................58 •Bottom layer .................................................................................59 •Real board, top ...............................................................................60 •Real board, bottom ...........................................................................61 56
Daan Ver Eecke Elias Verstappe CNC controller This project is a colaboration between & Daan Ver Eecke Elias Verstappe CNC controller This project is a colaboration between & Daan Ver Eecke Elias Verstappe CNC controller This project is a colaboration between & 57
Daan Ver Eecke Elias Verstappe CNC controller This project is a colaboration between & Daan Ver Eecke Elias Verstappe CNC controller This project is a colaboration between & Daan Ver Eecke Elias Verstappe CNC controller This project is a colaboration between & 58
59
Appendix E Explanation of calibration in touchscreen systems 66
$Q(DV\WR8QGHUVWDQG([SODQDWLRQRI&DOLEUDWLRQLQ7RXFK6FUHHQ6\VWHPV$SSOLFDWLRQ1RWH0D[LP KWWSVZZZPD[LPLQWHJUDWHGFRPHQDSSQRWHVLQGH[PYSLG Mǻxįm > Đěșįģň Șųppǿřț > Țěčħňįčǻŀ Đǿčųměňțș > Ǻppŀįčǻțįǿň Ňǿțěș > Ǻ/Đ ǻňđ Đ/Ǻ Čǿňvěřșįǿň/Șǻmpŀįňģ Čįřčųįțș > ǺPP 5296 Mǻxįm > Đěșįģň Șųppǿřț > Țěčħňįčǻŀ Đǿčųměňțș > Ǻppŀįčǻțįǿň Ňǿțěș > Ǻųțǿmǿțįvě > ǺPP 5296 Mǻxįm > Đěșįģň Șųppǿřț > Țěčħňįčǻŀ Đǿčųměňțș > Ǻppŀįčǻțįǿň Ňǿțěș > İňțěřfǻčě Čįřčųįțș > ǺPP 5296 Ķěỳẅǿřđș: țǿųčħ șčřěěň pǻňěŀș, țǿųčħ șčřěěň čǿňțřǿŀŀěřș, țǿųčħ șčřěěň, țǿųčħ pǻňěŀș, Ň-pǿįňț čǻŀįbřǻțįǿň, čǻŀįbřǻțįǿň, 3-pǿįňț čǻŀįbřǻțįǿň, țǿųčħ șỳșțěmș, řěșįșțįvě Řěŀǻțěđ Pǻřțș ǺPPĿİČǺȚİǾŇ ŇǾȚĚ 5296 Ǻň Ěǻșỳ-țǿ-Ųňđěřșțǻňđ Ěxpŀǻňǻțįǿň ǿf Čǻŀįbřǻțįǿň įň Țǿųčħ- Șčřěěň Șỳșțěmș Bỳ:Fǻįșǻŀ Țǻřįq Ǻbșțřǻčț:Měčħǻňįčǻŀ mįșǻŀįģňměňț ǻňđ șčǻŀįňģ fǻčțǿřș ŀěǻđ țǿ ǻ mįșmǻțčħ běțẅěěň țħě vǻŀųěș čǿmįňģ fřǿm ǻ țǿųčħ șčřěěň pǻňěŀ (ǻș țřǻňșŀǻțěđ bỳ ǻ țǿųčħ șčřěěň čǿňțřǿŀŀěř) ǻňđ țħě đįșpŀǻỳ (țỳpįčǻŀŀỳ ǻň ĿČĐ) ǿň ẅħįčħ țħě țǿųčħ șčřěěň pǻňěŀ įș mǿųňțěđ. Țħįș țųțǿřįǻŀ đįșčųșșěș ħǿẅ țǿ čǻŀįbřǻțě țħě țǿųčħ șčřěěň pǻňěŀ țǿ mǻțčħ țħě đįșpŀǻỳ. Ǻ șįmįŀǻř věřșįǿň ǿf țħįș ǻřțįčŀě ǻppěǻřěđ įň țħě Ǻpřįŀ 20, 2012 įșșųě ǿf ĚĚ Țįměș mǻģǻżįňě. İňțřǿđųčțįǿň Měčħǻňįčǻŀ mįșǻŀįģňměňț ǻňđ șčǻŀįňģ fǻčțǿřș čǻň ŀěǻđ țǿ ǻ mįșmǻțčħ běțẅěěň țħě vǻŀųěș fřǿm ǻ țǿųčħ-pǻňěŀ șỳșțěm (įň țħįș țųțǿřįǻŀ, țħě țǿųčħ-pǻňěŀ șỳșțěm įmpŀįěș ǻ șěțųp čǿmpřįșěđ ǿf ǻ țǿųčħ șčřěěň ǻňđ ǻ țǿųčħ-șčřěěň čǿňțřǿŀŀěř) ǻňđ țħě đįșpŀǻỳ (țỳpįčǻŀŀỳ ǻň ĿČĐ) ǿň ẅħįčħ țħě țǿųčħ șčřěěň įș mǿųňțěđ. Țħįș ǻřțįčŀě đįșčųșșěș țħě mǻțħěmǻțįčǻŀ țěčħňįqųěș țǿ čǻŀįbřǻțě țħě țǿųčħ-pǻňěŀ șỳșțěm șǿ ỳǿų čǻň mǻțčħ țħě ģřǻpħįčș ǿň țħě đįșpŀǻỳ țǿ țħě ǿųțpųț fřǿm țħě țǿųčħ-șčřěěň čǿňțřǿŀŀěř. Ųňđěřșțǻňđįňģ İmǻģě Țřǻňșfǿřmǻțįǿň: Țřǻňșŀǻțįǿň, Řǿțǻțįǿň, ǻňđ Șčǻŀįňģ Fįģųřě 1 įș ǻň ěxǻģģěřǻțěđ vįěẅ ǿf țħě đįșțǿřțįǿň țħǻț mįģħț ħǻppěň țǿ ǻ čįřčŀě běįňģ đįșpŀǻỳěđ ǿň ǻň ĿČĐ țǿųčħ-șčřěěň đįșpŀǻỳ. Ẅħěň ǻ fįňģěř įș țřǻčěđ ǻřǿųňđ țħě čįřčŀě (řěđ ŀįňě), țħě țǿųčħ-pǻňěŀ șỳșțěm mǻỳ ģįvě ǿųț țħě čǿǿřđįňǻțěș ǿf ǻň ěŀŀįpșě (bŀųě ŀįňě) įňșțěǻđ ǿf țħě čįřčŀě, șħǿẅň běŀǿẅ įň Fįģųřě 1. Țħįș čħǻňģě ǿf țħě șħǻpě fřǿm ǻ čįřčŀě țǿ ǻň ěŀŀįpșě čǻň bě ěxpŀǻįňěđ bỳ țħě fǿŀŀǿẅįňģ ģřǻpħįč țřǻňșfǿřmǻțįǿňș: țřǻňșŀǻțįǿň, řǿțǻțįǿň, ǻňđ șčǻŀįňģ. Fįģųřě 1. Ǻ čįřčŀě čħǻňģěș șħǻpě ǿň ǻ țǿųčħ șčřěěň běčǻųșě ǿf ǻ mįșmǻțčħ běțẅěěň țħě đįșpŀǻỳ ǻňđ țħě țǿųčħ-pǻňěŀ șỳșțěm. İňțųįțįǿň șųģģěșțș țħǻț ǻňỳ čǿǿřđįňǻțě pǿįňț x, ỳ įň ǻň x-ỳ pŀǻňě țħǻț ħǻș ųňđěřģǿňě ǻ țřǻňșfǿřmǻțįǿň șħǿųŀđ ŀǿǿķ ŀįķě: x = f1(x , ỳ ) + čǿňșțǻňț1 (Ěq. 1ǻ) ỳ = f2(x , ỳ ) + čǿňșțǻňț2 (Ěq. 1b) Ẅħěřě x ǻňđ ỳ ǻřě țħě țřǻňșfǿřměđ čǿǿřđįňǻțěș; x ǻňđ ỳ ǻřě țħě ǿŀđ čǿǿřđįňǻțěș; f1() ǻňđ f2() ǻřě fųňčțįǿňș țħǻț țřǻňșfǿřm țħě ǿŀđ čǿǿřđįňǻțěș; čǿňșțǻňțș1 ǻňđ 2 ǻřě jųșț țħǻț, čǿňșțǻňțș. ŇĚẄ ǾĿĐ ǾĿĐ ŇĚẄ ǾĿĐ ǾĿĐ ŇĚẄ ŇĚẄ ǾĿĐ ǾĿĐ 67
$Q(DV\WR8QGHUVWDQG([SODQDWLRQRI&DOLEUDWLRQLQ7RXFK6FUHHQ6\VWHPV$SSOLFDWLRQ1RWH0D[LP KWWSVZZZPD[LPLQWHJUDWHGFRPHQDSSQRWHVLQGH[PYSLG İf țħě țřǻňșfǿřmǻțįǿň įș ŀįňěǻř, țħěň fųňčțįǿňș f1() ǻňđ f2() čǻň bě řěpŀǻčěđ bỳ țħě fǿŀŀǿẅįňģ ěqųǻțįǿňș: x = Ǻ x + B ỳ + Č (Ěq. 2ǻ) ỳ = Đ x + Ě ỳ + F (Ěq. 2b) Ẅħěřě Ǻ, B, Č, Đ, Ě, ǻňđ F ǻřě čǿňșțǻňț čǿěffįčįěňțș. Ňǿțě țħǻț f1() = Ǻ x +B ỳ ǻňđ f2() = Đ x + Ě ỳ , ẅħěřě čǿňșțǻňț1 ǻňđ čǿňșțǻňț2 ǻřě Č ǻňđ F, řěșpěčțįvěŀỳ. Țħě Mǻțħěmǻțįčș Běħįňđ Țřǻňșŀǻțįǿň, Řǿțǻțįǿň, ǻňđ Șčǻŀįňģ Ǻň ěxǻmpŀě, șħǿẅįňģ ǻ ģřǻpħįč țřǻňșfǿřmǻțįǿň, ẅįŀŀ đěmǿňșțřǻțě țħǻț țħě fįňǻŀ țřǻňșfǿřmǻțįǿň ěqųǻțįǿňș fřǿm țħįș ěxěřčįșě ẅįŀŀ ŀěǻđ țǿ țħě ǻbǿvě ěqųǻțįǿňș 2ǻ ǻňđ 2b ǻňđ, țħěřěfǿřě, ǿųř įňțųįțįǿň ħǿŀđș țřųě. (Țħě ųșěř čǻň bỳpǻșș țħįș ěxǻmpŀě ǻňđ jųmp đįřěčțŀỳ țǿ țħě Țħřěě-Pǿįňț Čǻŀįbřǻțįǿň ǻňđ Ň-Pǿįňț Čǻŀįbřǻțįǿň đįșčųșșįǿňș běŀǿẅ.) Țħě įŀŀųșțřǻțįǿň běŀǿẅ (Fįģųřě 2) șħǿẅș ǻ șqųǻřě (Șħǻpě Ǻ) țħǻț ħǻș ųňđěřģǿňě țřǻňșŀǻțįǿň, řǿțǻțįǿň, ǻňđ șčǻŀįňģ (Șħǻpě B). İň țħě přǿčěșș įț įș țřǻňșfǿřměđ įňțǿ ǻ řěčțǻňģŀě. Fįģųřě 2. Țřǻňșŀǻțįǿň, řǿțǻțįǿň, ǻňđ șčǻŀįňģ țřǻňșfǿřm ǻ șqųǻřě įňțǿ ǻ řěčțǻňģŀě. Țǿ řǿțǻțě ǻňđ șčǻŀě țħě șqųǻřě (Șħǻpě Ǻ), įț įș įmpǿřțǻňț țǿ mǿvě įțș čěňțěř țǿ țħě ǿřįģįň fįřșț (Fįģųřě 3) țǿ ěňșųřě țħǻț țħě řǿțǻțįǿň ǻňđ șčǻŀįňģ ħǻppěň ųňįfǿřmŀỳ. Fįģųřě 3. Țħě șqųǻřě ǿf Fįģųřě 2 (Șħǻpě Ǻ) įș mǿvěđ șǿ țħǻț įțș čěňțěř ŀįěș ǿň țħě ǿřįģįň ǿf țħě x-ỳ ǻxįș. Țħįș mǿvě țǿ țħě čěňțěř, ǿř țřǻňșŀǻțįǿň țǿ țħě čěňțěř, čħǻňģěș țħě vǻŀųě ǿf ǻŀŀ țħě čǿǿřđįňǻțěș ǿf țħě șqųǻřě. Fǿř șįmpŀįčįțỳ ħěřě, ǿňŀỳ țħě țřǻňșfǿřmǻțįǿň ǿf x , ỳ įň Fįģųřě 2 ẅįŀŀ bě ěxpŀǿřěđ. Čǿňșěqųěňțŀỳ, x , ỳ țřǻňșŀǻțěș țǿ x , ỳ ǻňđ țħě ňěẅ ěqųǻțįǿň řěpřěșěňțįňģ țħįș ňěẅ fįģųřě įș: x = x + Ț (Ěq. 3ǻ) ỳ = ỳ + Ț (Ěq. 3b) Řǿțǻțě țħě ǻbǿvě fįģųřě șǿ țħǻț přǿpěř șčǻŀįňģ čǻň bě đǿňě įň țħě x ǻňđ ỳ đįřěčțįǿňș. Fįģųřě 4 șħǿẅș țħǻț țħě fįģųřě ħǻș běěň řǿțǻțěđ čǿųňțěřčŀǿčķẅįșě bỳ ǻňģŀě ș. ŇĚẄ ǾĿĐ ǾĿĐ ŇĚẄ ǾĿĐ ǾĿĐ ǾĿĐ ǾĿĐ ǾĿĐ ǾĿĐ 1 1 1ǻ 1ǻ 1b 1b 1b 1ǻ x0 1b 1ǻ ỳ0 68
$Q(DV\WR8QGHUVWDQG([SODQDWLRQRI&DOLEUDWLRQLQ7RXFK6FUHHQ6\VWHPV$SSOLFDWLRQ1RWH0D[LP KWWSVZZZPD[LPLQWHJUDWHGFRPHQDSSQRWHVLQGH[PYSLG Fįģųřě 4. Fǿŀŀǿẅįňģ Ěqųǻțįǿň 3, țħě șqųǻřě įș řǿțǻțěđ čǿųňțěřčŀǿčķẅįșě. Țħě ňěẅ čǿǿřđįňǻțěș (x , ỳ ) ǻfțěř țħě řǿțǻțįǿň ǻřě șħǿẅň běŀǿẅ. (Pŀěǻșě șěě țħě Ǻppěňđįx fǿř țħě đěřįvǻțįǿň ǿf țħě ěqųǻțįǿň fǿř țħįș řǿțǻțįǿň.) x = x Čǿșș - ỳ Șįňș(Ěq. 4ǻ) ỳ = x Șįňș + ỳ Čǿșș(Ěq. 4b) Șųbșțįțųțě Ěqųǻțįǿňș 3ǻ ǻňđ 3b įňțǿ Ěqųǻțįǿňș 4ǻ ǻňđ 4b, ǻňđ șįmpŀįfỳ: x = x Čǿșș - ỳ Șįňș + Ķ (Ěq. 5ǻ) ỳ = x Șįňș + ỳ Čǿșș + Ķ (Ěq. 5b) Ẅħěřě Ķ = Ț Čǿșș - Ț Șįňș ǻňđ Ķ = Ț Șįňș + Ț Čǿșș. Ňǿẅ șčǻŀě țħě șqųǻřě įň bǿțħ țħě x ǻňđ ỳ đįřěčțįǿňș țǿ mǻķě įț țħě șǻmě șįżě ǻș țħě řěčțǻňģŀě įň Fįģųřě 2 (Șħǻpě B). İf ẅě șǻỳ țħǻț Ģ įș țħě șčǻŀįňģ fǻčțǿř įň țħě x đįřěčțįǿň ǻňđ Ģ įș țħě șčǻŀįňģ fǻčțǿř įň țħě ỳ đįřěčțįǿň, țħěň țħě șqųǻřě ẅįŀŀ țřǻňșfǿřm įňțǿ ǻ řěčțǻňģŀě (Fįģųřě 5). Fįģųřě 5. Țřǻňșfǿřm țħě șqųǻřě įňțǿ ǻ řěčțǻňģŀě ųșįňģ șčǻŀįňģ fǻčțǿřș Ģ fǿř țħě x đįřěčțįǿň, ǻňđ Ģ fǿř țħě ỳ đįřěčțįǿň. Mųŀțįpŀỳįňģ Ěqųǻțįǿňș 5ǻ ǻňđ 5b ẅįțħ țħě șčǻŀįňģ fǻčțǿřș Ģ ǻňđ Ģ ỳįěŀđș Ěqųǻțįǿňș 6ǻ ǻňđ 6b, ẅħįčħ ǻřě țħě čǿǿřđįňǻțěș fǿř țħě řěčțǻňģŀě șħǿẅň įň Fįģųřě 5. x = x Ģ Čǿșș - ỳ Ģ Șįňș + Ķ Ģ (Ěq. 6ǻ) ỳ = x Ģ Șįňș + ỳ Ģ Čǿșș + Ķ Ģ (Ěq. 6b) Řǿțǻțě țħě řěčțǻňģŀě bỳ ǻ șǿ țħǻț įț mǻțčħěș țħě řǿțǻțįǿňǻŀ ǿřįěňțǻțįǿň ǿf Șħǻpě B įň Fįģųřě 2. Țħįș ŀěǻđș țǿ țħě țřǻňșfǿřmǻțįǿň ǿf (x , ỳ ) įňțǿ (x , ỳ ), ǻș șħǿẅň įň țħě Fįģųřě 6. Fįģųřě 6. Țħě řěčțǻňģŀě ǿf Fįģųřě 5 įș řǿțǻțěđ șǿ țħǻț įț mǻțčħěș țħě ǿřįěňțǻțįǿň ǿf Șħǻpě B įň Fįģųřě 2. Ǿňčě ǻģǻįň țħě řǿțǻțįǿň įș čǿųňțěřčŀǿčķẅįșě. Țħě ěqųǻțįǿňș fǿř (x , ỳ ) įň țěřmș ǿf (x , ỳ ) ǻřě: 1č 1č 1č 1b 1b 1č 1b 1b 1č 1ǻ 1ǻ x 1č 1ǻ 1ǻ ỳ x x0 ỳ0 ỳ x0 ỳ0 x ỳ x ỳ x ỳ 1đ 1ǻ x 1ǻ x x x 1đ 1ǻ ỳ 1ǻ ỳ ỳ ỳ 1đ 1đ 1ě 1ě 1ě 1ě 1đ 1đ 69
$Q(DV\WR8QGHUVWDQG([SODQDWLRQRI&DOLEUDWLRQLQ7RXFK6FUHHQ6\VWHPV$SSOLFDWLRQ1RWH0D[LP KWWSVZZZPD[LPLQWHJUDWHGFRPHQDSSQRWHVLQGH[PYSLG x = x ČǿșĮ - ỳ ȘįňĮ + Ķ (Ěq. 7ǻ) ỳ = x ȘįňĮ + ỳ ČǿșĮ + Ķ (Ěq. 7b) Șųbșțįțųțě Ěqųǻțįǿňș 6ǻ ǻňđ 6b įňțǿ Ěqųǻțįǿňș 7ǻ ǻňđ 7b, ǻňđ șįmpŀįfỳ: x = x Ǻ + ỳ B + P (Ěq. 8ǻ) ỳ = x Đ + ỳ Ě + Q (Ěq. 8b) Ẅħěřě: Ǻ = Ģ Čǿșș ČǿșĮ - Ģ Șįňș ČǿșĮ B = - Ģ Șįňș ČǿșĮ - Ģ Čǿșș ČǿșĮ P = Ķ Ģ ČǿșĮ - Ķ Ģ ȘįňĮ Đ = Ģ Čǿșș ȘįňĮ + Ģ Șįňș ČǿșĮ Ě = -Ģ Șįňș ȘįňĮ + Ģ Čǿșș ČǿșĮ Q = Ķ Ģ ȘįňĮ + Ķ Ģ ČǿșĮ Ňǿẅ ǻ țřǻňșŀǻțįǿň (Fįģųřě 7) ňěěđș țǿ bě đǿňě țǿ mǿvě țħě řǿțǻțěđ řěčțǻňģŀě țǿ ẅħěřě Șħǻpě B ǻppěǻřș įň Fįģųřě 2. Fįģųřě 7. Țřǻňșŀǻțįǿň ǿf țħě řěčțǻňģŀě fřǿm țħě ǿřįģįň țǿ țħě ŀǿčǻțįǿň ẅħěřě Șħǻpě B ǻppěǻřș įň Fįģųřě 2. Ǻșșųmě țħǻț țħě țřǻňșŀǻțįǿň įň țħě x ǻňđ ỳ đįřěčțįǿň įș Ț ǻňđ Ț , řěșpěčțįvěŀỳ. Țħěřěfǿřě, Ěqųǻțįǿňș 8ǻ ǻňđ 8b ẅįŀŀ čħǻňģě țǿ: x = x Ǻ + ỳ B + Č (Ěq. 9ǻ) ỳ = x Đ + ỳ Ě + F (Ěq. 9b) Ẅħěřě Č = P + Ț ǻňđ F = Q + Ț . Ěqųǻțįǿňș 9ǻ ǻňđ 9b ǻřě ẅħǻț ẅě ẅǻňț—țħěỳ mǻțčħ Ěqųǻțįǿňș 1ǻ ǻňđ 1b. Ňǿțě țħǻț țħě čǿǿřđįňǻțě (x , ỳ ) įș įň țěřmș ǿf (x , ỳ ). İň țħě țǿųčħ pǻňěŀ mǿųňțěđ ǿň ǻ đįșpŀǻỳ țħě ųșěř ẅįŀŀ ħǻvě țǿ đěțěřmįňě țħě Ǻ, B, Č, Đ, Ě, ǻňđ F đųřįňģ čǻŀįbřǻțįǿň. Pŀěǻșě ňǿțě țħǻț țħě pųřpǿșě ǿf țħįș ěxěřčįșě įș țǿ ģįvě țħě ųșěř ǻň ǻppřěčįǻțįǿň ǿf țħě ģěňěřǻŀ fǿřm ǿf țħě ěqųǻțįǿň fǿř țħě țřǻňșfǿřmǻțįǿň, șħǿẅň bỳ Ěqųǻțįǿňș 9ǻ ǻňđ 9b. Țħįș ǻřțįčŀě șħǿẅș țħǻț ẅě ẅįŀŀ ǻřřįvě ǻț țħįș ģěňěřǻŀ fǿřm įřřěșpěčțįvě ǿf țħě đįřěčțįǿň ǻňđ mǻģňįțųđě ǿf řǿțǻțįǿň, țřǻňșŀǻțįǿň, ǻňđ șčǻŀįňģ. Țħřěě-Pǿįňț Čǻŀįbřǻțįǿň Ẅě șțǻřț ẅįțħ ǻ pǻįř ǿf ěqųǻțįǿňș, țħě fįňǻŀ pǻįř įň ǿųř mǻțħěmǻțįčǻŀ ěxěřčįșě ǻbǿvě. x = x Ǻ + ỳ B + Č (Ěq. 9ǻ) ỳ = x Đ + ỳ Ě + F (Ěq. 9b) Țħě ģǿǻŀ ǿf țħě țǿųčħ-pǻňěŀ șỳșțěm čǻŀįbřǻțįǿň įș țǿ șǿŀvě țħě Ěqųǻțįǿňș 2ǻ ǻňđ 2b (ǿř șįmįŀǻřŀỳ Ěqųǻțįǿňș 9ǻ ǻňđ 9b) țǿ đěřįvě vǻŀųěș fǿř Ǻ, B, Č, Đ, Ě, ǻňđ F. Ŀǿǿķįňģ ǻț țħěșě ěqųǻțįǿňș ẅě ķňǿẅ țħǻț țħěřě ǻřě șįx ųňķňǿẅňș. Țħěřěfǿřě, ẅě ẅįŀŀ ňěěđ șįx ěqųǻțįǿňș țǿ șǿŀvě fǿř țħěșě ųňķňǿẅňș ǻňđ țħįș čǻň bě ǻčħįěvěđ bỳ đǿįňģ ǻ țħřěě-pǿįňț čǻŀįbřǻțįǿň fǿř ǻ țǿųčħ-pǻňěŀ șỳșțěm. Țħě ųșěř ẅįŀŀ ģěňěřǻțě țħřěě pǻįřș ǿf (x, ỳ) čǿǿřđįňǻțěș bỳ țǿųčħįňģ țħě pǻňěŀ ǻț țħě țħřěě pǻįřș ǿf đįșpŀǻỳ čǿǿřđįňǻțěș: (x , ỳ ), (x , ỳ ) ǻňđ (x , ỳ ). İf țħěįř čǿřřěșpǿňđįňģ țǿųčħ-șčřěěň vǻŀųěș (ǻș přěșěňțěđ bỳ țħě țǿųčħ-șčřěěň čǿňțřǿŀŀěř) ǻřě (x , ỳ ), (x , ỳ ), ǻňđ (x , ỳ ), țħěň 1ě 1đ 1đ x 1ě 1đ 1đ ỳ 1ě 1ǻ 1ǻ 1ě 1ǻ 1ǻ x ỳ x ỳ x x ỳ ỳ x ỳ x ỳ x x ỳ ỳ x ỳ 1f 1ǻ 1ǻ 1f 1ǻ 1ǻ x ỳ 1f 1f 1ǻ 1ǻ 1f 1ǻ 1ǻ 1f 1ǻ 1ǻ 1đ 1đ 2đ 2đ 3đ 3đ 1 1 2 2 3 3 70
$Q(DV\WR8QGHUVWDQG([SODQDWLRQRI&DOLEUDWLRQLQ7RXFK6FUHHQ6\VWHPV$SSOLFDWLRQ1RWH0D[LP KWWSVZZZPD[LPLQWHJUDWHGFRPHQDSSQRWHVLQGH[PYSLG țħě șįx ųňķňǿẅňș čǻň bě șǿŀvěđ bỳ țħě ěqųǻțįǿňș șħǿẅň běŀǿẅ. Țħěșě pǿįňțș mųșț bě įňđěpěňđěňț ǿf ěǻčħ ǿțħěř, ǻș șħǿẅň įň Fįģųřě 8. Fįģųřě 8. ĿČĐ pǻňěŀ șħǿẅįňģ țħřěě đįșpŀǻỳ čǿǿřđįňǻțěș fǿř țħě ųșěř țǿ țǿųčħ. x = x Ǻ + ỳ B + Č x = x Ǻ + ỳ B + Č x = x Ǻ + ỳ B + Č ỳ = x Đ + ỳ Ě + F ỳ = x Đ + ỳ Ě + F ỳ = x Đ + ỳ Ě + F Ňǿẅ ẅįțħ șįx ěqųǻțįǿňș fǿř țħě șįx ųňķňǿẅňș, țħě ǻbǿvě čǻň bě ẅřįțțěň įň mǻțřįx fǿřm ǻș: Țħěřěfǿřě, ǻ ŀįțțŀě mǻțřįx mǻňįpųŀǻțįǿň ẅįŀŀ ỳįěŀđ Ǻ, B, Č, Đ, Ě, ǻňđ F, ǻș șħǿẅň běŀǿẅ: Ẅħěřě, Ż įș țħě įňvěřșě mǻțřįx ǿf Ż. Țħřěě-Pǿįňț Čǻŀįbřǻțįǿň Ěxǻmpŀě Ẅě ẅįŀŀ ųșě țħě MǺX11800 țǿųčħ-șčřěěň čǿňțřǿŀŀěř įň țħįș ěxǻmpŀě. Ǻșșųmě țħǻț ǻň ĿČĐ pǻňěŀ đįșpŀǻỳ ħǻș ǻ řěșǿŀųțįǿň ǿf 256 x 768 ǻňđ țħǻț țħě țħřěě čǻŀįbřǻțįǿň pǿįňțș čħǿșěň ǻřě (65, 350), (200, 195), ǻňđ (195, 550). Țħěșě ǻřě țħě ěxǻčț pǿįňțș țħǻț ẅě ẅǻňț țħě țǿųčħ pǻňěŀ țǿ șħǿẅ ẅħěň įț įș țǿųčħěđ. Ħǿẅěvěř, șįňčě țħě řěșǿŀųțįǿň fǿř țħě MǺX11800 įș 4096 x 4096 (12 bįțș) ǻňđ běčǻųșě ǿf měčħǻňįčǻŀ mįșǻŀįģňměňț, țħě čǿǿřđįňǻțě ẅįŀŀ čǿmě ǿųț đįffěřěňțŀỳ. Fǿř țħįș ěxěřčįșě, ẅě ǻșșųmě țħǻț țħěșě vǻŀųěș ǻřě: (650, 2000), (2800, 1350), ǻňđ (2640, 3500), řěșpěčțįvěŀỳ. Pŀěǻșě ňǿțě: țħěșě vǻŀųěș ǻřě mǻđě ųp ǻňđ șěřvě ǻș ǻň ěxǻmpŀě ǿňŀỳ. Șǿŀvįňģ fǿř Ǻ, B, Č, Đ, Ě, ǻňđ F ųșįňģ Ěqųǻțįǿňș 10ǻ ǻňđ 10b, ẅě ģěț țħě fǿŀŀǿẅįňģ: Ǻ = 0.0635 B = 0.0024 Č = 18.9116 Đ = -0.0227 Ě = 0.1634 F = 37.8887 Țħěřěfǿřě, țħě ěqųǻțįǿňș țħǻț ẅįŀŀ ģěňěřǻțě țħě x ǻňđ ỳ čǿǿřđįňǻțěș fǿř țħįș pǻřțįčųŀǻř ěxǻmpŀě ǻřě: 1đ 1 1 2đ 2 2 3đ 3 3 1đ 1 1 2đ 2 2 3đ 3 3 -1 71
$Q(DV\WR8QGHUVWDQG([SODQDWLRQRI&DOLEUDWLRQLQ7RXFK6FUHHQ6\VWHPV$SSOLFDWLRQ1RWH0D[LP KWWSVZZZPD[LPLQWHJUDWHGFRPHQDSSQRWHVLQGH[PYSLG x = 0.0635 x + 0.0024 ỳ + 18.9116 ỳ = -0.0227 x + 0.1634 ỳ + 37.8887 Ẅħěřě (x, ỳ) ǻřě țħě čǿǿřđįňǻțěș čǿmįňģ fřǿm țħě țǿųčħ-pǻňěŀ șỳșțěm ǻňđ (x , ỳ ) įș țħě ǻđjųșțěđ vǻŀųě. Ň-Pǿįňț Čǻŀįbřǻțįǿň Țħě ųșěř mǻỳ čħǿǿșě țǿ čǻŀįbřǻțě ųșįňģ mǿřě pǿįňțș. Ǻ ģěňěřǻŀįżěđ fǿřm ǿf țħě șěțș ǿf ěqųǻțįǿňș ẅįŀŀ ŀǿǿķ ŀįķě țħě fǿŀŀǿẅįňģ: x = x Ǻ + ỳ B + Č x = x Ǻ + ỳ B + Č x = x Ǻ + ỳ B + Č ... x = x Ǻ + ỳ B + Č (Ěq. șěț 11ǻ) ỳ = x Đ + ỳ Ě + F ỳ = x Đ + ỳ Ě + F ỳ = x Đ + ỳ Ě + F ... ỳ = ỳ Đ + ỳ Ě + F (Ěq. șěț 11b) Ẅħěřě, (x , ỳ )...(x , ỳ ) ǻřě čǿǿřđįňǻțěș ģěňěřǻțěđ bỳ țħě đįșpŀǻỳ; (x , ỳ )...(x , ỳ ) ǻřě țħě čǿřřěșpǿňđįňģ vǻŀųěș (fǿř ň pǿįňțș) đěțěřmįňěđ bỳ țħě MǺX11800 fřǿm țħě țǿųčħ-șčřěěň pǻňěŀ. Țħě ģǿǻŀ įș țǿ đěțěřmįňě țħě čǿěffįčįěňțș ųșįňģ țħěșě vǻŀųěș. İň țħě Ěqųǻțįǿň șěț 11ǻ țħěřě ǻřě țħřěě ųňķňǿẅňș, Ǻ, B, ǻňđ Č, bųț țħě șěț ǿf čǿǿřđįňǻțěș įș mǿřě țħǻň țħřěě. Țħįș įmpŀįěș țħǻț țħěřě ǻřě mǿřě ěqųǻțįǿňș țħǻň ųňķňǿẅňș. Țħěřěfǿřě, įň țħįș įňșțǻňčě įț mǻķěș șěňșě țǿ ųșě țħě ŀěǻșț șqųǻřě fįț țǿ ųțįŀįżě ǻŀŀ țħě pǿįňțș ǻňđ đěřįvě ǻň ǻvěřǻģě vǻŀųě ǿf țħě čǿěffįčįěňțș. Țħįș ǻŀșǿ měǻňș țħǻț mǿřě čǻŀįbřǻțįǿň pǿįňțș ẅǿųŀđ ħěŀp ŀǿẅěř ěřřǿřș. Țħě ŀěǻșț șqųǻřě fįț įș řěpřěșěňțěđ įň Fįģųřě 9. Țħě șǻmě țěčħňįqųě ẅįŀŀ bě ǻppŀįěđ fǿř đěțěřmįňįňģ țħě ųňķňǿẅňș Đ, Ě, ǻňđ F fǿř țħě ỳ vǻŀųěș. Fįģųřě 9. Ǻň ǻvěřǻģě vǻŀųě fǿř țħě čǿěffįčįěňțș Ǻ, B, ǻňđ Č įș fǿųňđ bỳ ǻppŀỳįňģ țħě ŀěǻșț șqųǻřě fįț țǿ țħě pǿįňțș. Ěqųǻțįǿň șěțș 11ǻ ǻňđ 11b čǻň bě ẅřįțțěň įň mǻțřįx fǿřm, ǻș șħǿẅň: Bỳ ųșįňģ țħě ŀěǻșț șqųǻřě fįț įň țħįș mǻțřįx fǿřm, țħě čǿěffįčįěňțș ǻřě ģįvěň bỳ țħě ěqųǻțįǿňș běŀǿẅ. (Pŀěǻșě řěfěř țǿ ǻ bǿǿķ ǿň řěģřěșșįǿň ǻňǻŀỳșįș fǿř țħě đěřįvǻțįǿň ǿf țħě mǻțřįx fǿřm ǿf țħě ŀěǻșț șqųǻřě fįț fǿřm.) đ đ đ đ 1đ 1 1 2đ 2 2 3đ 3 3 ňđ ň ň 1đ 1 1 2đ 2 2 3đ 3 3 ňđ ň 3 1đ 1đ ňđ ňđ 1 1 ň ň 72
$Q(DV\WR8QGHUVWDQG([SODQDWLRQRI&DOLEUDWLRQLQ7RXFK6FUHHQ6\VWHPV$SSOLFDWLRQ1RWH0D[LP KWWSVZZZPD[LPLQWHJUDWHGFRPHQDSSQRWHVLQGH[PYSLG Ň-Pǿįňț Čǻŀįbřǻțįǿň Ěxǻmpŀě Ǿňčě ǻģǻįň, ǻșșųmě țħǻț ǻň ĿČĐ pǻňěŀ đįșpŀǻỳ ħǻș ǻ řěșǿŀųțįǿň ǿf 256 x 768 ǻňđ țħě fįvě čǻŀįbřǻțįǿň pǿįňțș ǻřě (100, 350), (50, 200), (200, 200), (210, 600), ǻňđ (65, 600). Țħěșě ǻřě țħě ěxǻčț pǿįňțș țħǻț ẅě ẅǻňț țħě țǿųčħ pǻňěŀ țǿ șħǿẅ ẅħěň įț įș țǿųčħěđ. Ħǿẅěvěř, șįňčě țħě řěșǿŀųțįǿň fǿř țħě MǺX11800 įș 4096 x 4096 (12 bįțș) ǻňđ běčǻųșě ǿf měčħǻňįčǻŀ mįșǻŀįģňměňț, țħě pǿįňțș mǻỳ čǿmě ǿųț đįffěřěňțŀỳ. Ǻģǻįň ǻșșųmě țħǻț țħěỳ ǻřě (1700, 2250), (750, 1200), (3000, 1500), (2500, 3400), ǻňđ (600, 3000), řěșpěčțįvěŀỳ. Pŀěǻșě ňǿțě: țħěșě vǻŀųěș ǻřě mǻđě ųp ǻňđ měǻňț țǿ șěřvě ǻș ǻň ěxǻmpŀě ǿňŀỳ. Șǿŀvįňģ fǿř Ǻ, B, Č, Đ, Ě, ǻňđ F ųșįňģ Ěqųǻțįǿňș 12ǻ ǻňđ 12b, ẅě ģěț: Ǻ = 0.0677 B = 0.0190 Č = -33.7973 Đ = -0.0347 Ě = 0.2100 F = -27.4030 Țħěřěfǿřě, țħě ěqųǻțįǿňș țǿ ģěňěřǻțě țħě x ǻňđ ỳ čǿǿřđįňǻțěș fǿř țħįș pǻřțįčųŀǻř ěxǻmpŀě ǻřě: x = 0.0677 x + 0.0190 ỳ - 33.7973 ỳ = -0.0347 x + 0.2100 ỳ - 27.4030 Ẅħěřě (x, ỳ) ǻřě țħě čǿǿřđįňǻțěș čǿmįňģ fřǿm țħě țǿųčħ-pǻňěŀ čǿňțřǿŀŀěř, ǻňđ (x , ỳ ) įș țħě ǻđjųșțěđ čǿǿřđįňǻțě vǻŀųě țǿ mǻțčħ ẅħǻț įș șħǿẅň ǿň țħě đįșpŀǻỳ. Ěxǻmpŀě Șųmmǻřỳ İf țħě ŀěǻșț șqųǻřěș țěčħňįqųě įș ųșěđ ǿň țħřěě pǿįňțș, įț ẅįŀŀ ỳįěŀđ țħě șǻmě čǿěffįčįěňț ǻș țħě țħřěě-pǿįňț čǻŀįbřǻțįǿň. İț įș mǻțħěmǻțįčǻŀŀỳ ěǻșįěř, țħěřěfǿřě, țǿ ħǻňđŀě țħě țħřěě-pǿįňț čǻŀįbřǻțįǿň ǻș țħřěě șįmųŀțǻňěǿųș ŀįňěǻř ěqųǻțįǿňș ẅįțħ țħřěě ųňķňǿẅňș įňșțěǻđ ǿf țħě ŀěňģțħįěř čǻŀčųŀǻțįǿň ẅįțħ țħě ŀěǻșț șqųǻřěș țěčħňįqųě. Ǻppěňđįx: Đěřįvǻțįǿň ǿf țħě Ěqųǻțįǿň fǿř ǻ Čǿųňțěřčŀǿčķẅįșě Řǿțǻțįǿň Țħě ǿřįģįňǻŀ pǿįňț (x, ỳ) čǻň bě ẅřįțțěň įň pǿŀǻř fǿřm ǻș: x = ř Čǿșș ǻňđ ỳ = ř Șįňș, (Ěq. Ǻ) Ẅħěřě ř įș țħě řǻđįǻŀ đįșțǻňčě fřǿm țħě ǿřįģįň țǿ țħě (x, ỳ) čǿǿřđįňǻțě. Ǻfțěř țħě řǿțǻțįǿň țħě (x, ỳ) čǿǿřđįňǻțěș běčǿmě (x', ỳ'): x' = ř Čǿș(ș + ĭ) ǻňđ ỳ' = ř Șįň(ș + ĭ) (Ěq. B) Ųșįňģ țħě țřįģ įđěňțįțįěș běŀǿẅ: Čǿș(ș + ĭ) = Čǿșĭ Čǿșș - Șįňĭ Șįňș Șįň(ș + ĭ) = Șįňĭ Čǿșș - Čǿșĭ Șįňș(Ěq. Č) Ǻňđ șųbșțįțųțįňģ įň Ěqųǻțįǿň B, ẅě ģěț: đ đ đ đ 73
$Q(DV\WR8QGHUVWDQG([SODQDWLRQRI&DOLEUDWLRQLQ7RXFK6FUHHQ6\VWHPV$SSOLFDWLRQ1RWH0D[LP KWWSVZZZPD[LPLQWHJUDWHGFRPHQDSSQRWHVLQGH[PYSLG 7ZHHW Ǿțħěř Čħǻňňěŀș Ěmǻįŀ x' = ř Čǿșĭ Čǿșș - ř Șįňĭ Șįňș ỳ' = ř Șįňĭ Čǿșș - ř Čǿșĭ Șįňș(Ěq. Đ) Șųbșțįțųțįňģ Ěqųǻțįǿň Ǻ įňțǿ Ěqųǻțįǿň Đ: x' = x Čǿșĭ - ỳ Șįňĭ ỳ' = x Șįňĭ - ỳ Čǿșĭ(Ěq. Ě) Țħě đěřįvǻțįǿň fǿř țħě čŀǿčķẅįșě řǿțǻțįǿň įș ŀěfț ǻș ǻň ěxěřčįșě fǿř țħě ųșěř. Řěŀǻțěđ Pǻřțș MǺX11800 Ŀǿẅ-Pǿẅěř, Ųŀțřǻ-Șmǻŀŀ Řěșįșțįvě Țǿųčħ-Șčřěěň Čǿňțřǿŀŀěřș ẅįțħ İðČ/ȘPİ İňțěřfǻčě MǺX11801 Ŀǿẅ-Pǿẅěř, Ųŀțřǻ-Șmǻŀŀ Řěșįșțįvě Țǿųčħ-Șčřěěň Čǿňțřǿŀŀěřș ẅįțħ İðČ/ȘPİ İňțěřfǻčě MǺX11802 Ŀǿẅ-Pǿẅěř, Ųŀțřǻ-Șmǻŀŀ Řěșįșțįvě Țǿųčħ-Șčřěěň Čǿňțřǿŀŀěřș ẅįțħ İðČ/ȘPİ İňțěřfǻčě MǺX11803 Ŀǿẅ-Pǿẅěř, Ųŀțřǻ-Șmǻŀŀ Řěșįșțįvě Țǿųčħ-Șčřěěň Čǿňțřǿŀŀěřș ẅįțħ İðČ/ȘPİ İňțěřfǻčě MǺX11811 ȚǻčȚǿųčħ™, Ŀǿẅ-Pǿẅěř, Ųŀțřǻ-Șmǻŀŀ, Řěșįșțįvě Țǿųčħ- Șčřěěň Čǿňțřǿŀŀěř ẅįțħ Ħǻpțįč Đřįvěř Ňěxț Șțěpș ĚĚ-Mǻįŀ Șųbșčřįbě țǿ ĚĚ-Mǻįŀ ǻňđ řěčěįvě ǻųțǿmǻțįč ňǿțįčě ǿf ňěẅ đǿčųměňțș įň ỳǿųř ǻřěǻș ǿf įňțěřěșț. Đǿẅňŀǿǻđ Đǿẅňŀǿǻđ, PĐF Fǿřmǻț(247.4ķB) Șħǻřě țħįș pǻģě țǿ ǻň ǻșșǿčįǻțě ǿř fřįěňđ. © Mǻỳ 07, 2012, Mǻxįm İňțěģřǻțěđ Přǿđųčțș, İňč. Țħě čǿňțěňț ǿň țħįș ẅěbpǻģě įș přǿțěčțěđ bỳ čǿpỳřįģħț ŀǻẅș ǿf țħě Ųňįțěđ Șțǻțěș ǻňđ ǿf fǿřěįģň čǿųňțřįěș. Fǿř řěqųěșțș țǿ čǿpỳ țħįș čǿňțěňț, čǿňțǻčț ųș. ǺPP 5296: Mǻỳ 07, 2012 ǺPPĿİČǺȚİǾŇ ŇǾȚĚ 5296, ǺŇ5296, ǺŇ 5296, ǺPP5296, Ǻppňǿțě5296, Ǻppňǿțě 5296 0HJXVWD © 2015 Mǻxįm İňțěģřǻțěđ | Čǿňțǻčț Ųș | Čǻřěěřș | Ŀěģǻŀ | Přįvǻčỳ | Čǿǿķįě Pǿŀįčỳ | Șįțě Mǻp | Fǿŀŀǿẅ Ųș: 74
Appendix F Source code main.c .....................................76 lib – calibrate.h ...............................79 – calibrate.c ...............................81 – cncroutines.h . ... . .. . ... ... ... . .. . ... ... . 90 – cncroutines.c .. . .. . ... ... . .. . ... ... . .. . .. 92 – display_manager.h . ... ... . .. . ... ... . .. . 105 – display_manager.c ... ... . .. . ... ... . .. . . 106 – execute_file.h .. . ... ... . .. . ... ... . .. . ... 108 – execute_file.c . .. . ... ... . .. . ... ... . .. . ...109 – font.c ...................................116 – graphics.c ..............................126 – initialization.h . . ... ... . .. . ... ... . .. . ... .129 – initialization.c .. ... . .. . ... ... . .. . ... ... . 130 – integer.h ................................131 – lpc2106.h ...............................133 – mcp23s17.h .............................139 – mcp23s17.c .............................141 – pff.h ....................................143 – pff.c ....................................148 – screens.h ...............................173 – screens.c ................................174 – sd.c ....................................182 – ssd1963.h ...............................190 – ssd1963.c ...............................194 – system.h ................................211 – timerinterrupt.h . . ... ... . .. . ... ... . .. . .. 213 – timerinterrupt.c . .. . ... ... . .. . ... ... ... . 214 – touchcontrol.h .... . .... .... . .... . .... ... 217 – touchcontrol.c . .. . ... ... . .. . ... ... . .. . .. 219 – types.h .................................238 – uart1.h .................................240 – uart1.c .................................242 – vardec.h ................................249 – xpt2046.h ..............................250 – xpt2046.c ...............................251 75
55 *|D,E,F| represents the factors used to translate *\− −/ the available touch screen point values *into the corresponding display *coordinates. * 60 * *Note that for practical considerations, the utilitities *within this file do not use the matrix coefficients as *defined above, but instead use the following *equivalents, since floating point math is not used: 65 * *A = An/Divider *B = Bn/Divider *C = Cn/Divider *D = Dn/Divider 70 *E = En/Divider *F = Fn/Divider * * * 75 *The functions provided within this file are: * *setCalibrationMatrix() −calculates the set of factors *in the above equation, given *three sets of test points. 80 *getDisplayPoint() −returns the actual display *coordinates, given a set of *touch screen coordinates. *translateRawScreenCoordinates() −helper function to transform *raw screen points into values 85 *scaled to the desired display *resolution. * * */ 90 #define _CALIBRATE_C_ 95 /****************************************************/ /* */ /*Included files */ /* */ 100 /****************************************************/ #include "calibrate.h" 105 /****************************************************/ /* */ /*Local Definitions and macros */ /* */ 110 /****************************************************/ 82
/****************************************************/ 115 /* */ /*Global variables */ /* */ /****************************************************/ 120 /****************************************************/ /* */ /*Forward Declaration of local functions */ 125 /* */ /****************************************************/ 130 /********************************************************************** * 135 *Function: setCalibrationMatrix() * *Description: Calling this function with valid input data *in the display and screen input arguments *causes the calibration factors between the 140 *screen and display points to be calculated, *and the output argument −matrixPtr −to be *populated. * *This function needs to be called only when new 145 *calibration factors are desired. * * *Argument(s): displayPtr (input) −Pointer to an array of three *sample, reference points. 150 *screenPtr (input) −Pointer to the array of touch *screen points corresponding *to the reference display points. *matrixPtr (output) −Pointer to the calibration *matrix computed for the set 155 *of points being provided. * * *From the article text, recall that the matrix coefficients are *resolved to be the following: 160 * * *Divider = (Xs0 −Xs2)*(Ys1 −Ys2) −(Xs1 −Xs2)*(Ys0 −Ys2) * * 165 * *(Xd0 −Xd2)*(Ys1 −Ys2) −(Xd1 −Xd2)*(Ys0 −Ys2) *A = −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− *Divider 83
* 170 * *(Xs0 −Xs2)*(Xd1 −Xd2) −(Xd0 −Xd2)*(Xs1 −Xs2) *B = −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− *Divider * 175 * *Ys0*(Xs2*Xd1 −Xs1*Xd2) + *Ys1*(Xs0*Xd2 −Xs2*Xd0) + *Ys2*(Xs1*Xd0 −Xs0*Xd1) *C = −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− 180 *Divider * * *(Yd0 −Yd2)*(Ys1 −Ys2) −(Yd1 −Yd2)*(Ys0 −Ys2) *D = −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− 185 *Divider * * *(Xs0 −Xs2)*(Yd1 −Yd2) −(Yd0 −Yd2)*(Xs1 −Xs2) *E = −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− 190 *Divider * * *Ys0*(Xs2*Yd1 −Xs1*Yd2) + *Ys1*(Xs0*Yd2 −Xs2*Yd0) + 195 *Ys2*(Xs1*Yd0 −Xs0*Yd1) *F = −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− *Divider * * 200 *Return: OK −the calibration matrix was correctly *calculated and its value is in the *output argument. *NOT_OK −an error was detected and the *function failed to return a valid 205 *set of matrix values. *The only time this sample code returns *NOT_OK is when Divider == 0 * * 210 * *NOTE! NOTE! NOTE! * *setCalibrationMatrix() and getDisplayPoint() will do fine *for you as they are, provided that your digitizer 215 *resolution does not exceed 10 bits (1024 values). Higher *resolutions may cause the integer operations to overflow *and return incorrect values. If you wish to use these *functions with digitizer resolutions of 12 bits (4096 *values) you will either have to a) use 64−bit signed 220 *integer variables and math, or b) judiciously modify the *operations to scale results by a factor of 2 or even 4. * * */ 225 int setCalibrationMatrix( POINT *displayPtr, 84
POINT *screenPtr, MATRIX *matrixPtr) { 230 int retValue = OK ; matrixPtr−>Divider = ((screenPtr[0].x −screenPtr[2].x) *(screenPtr[1].y − screenPtr[2].y)) − 235 ((screenPtr[1].x −screenPtr[2].x) *(screenPtr[0].y − screenPtr[2].y)) ; if( matrixPtr−>Divider == 0 ) { retValue = NOT_OK ; 240 } else { matrixPtr−>An = ((displayPtr[0].x −displayPtr[2].x) *(screenPtr[1].y − screenPtr[2].y)) − ((displayPtr[1].x −displayPtr[2].x) *(screenPtr[0].y − screenPtr[2].y)) ; 245 matrixPtr−>Bn = ((screenPtr[0].x −screenPtr[2].x) *(displayPtr[1].x − displayPtr[2].x)) − ((displayPtr[0].x −displayPtr[2].x) *(screenPtr[1].x − screenPtr[2].x)) ; matrixPtr−>Cn = (screenPtr[2].x *displayPtr[1].x −screenPtr[1].x * displayPtr[2].x) *screenPtr[0].y + 250 (screenPtr[0].x *displayPtr[2].x −screenPtr[2].x * displayPtr[0].x) *screenPtr[1].y + (screenPtr[1].x *displayPtr[0].x −screenPtr[0].x * displayPtr[1].x) *screenPtr[2].y ; matrixPtr−>Dn = ((displayPtr[0].y −displayPtr[2].y) *(screenPtr[1].y − screenPtr[2].y)) − ((displayPtr[1].y −displayPtr[2].y) *(screenPtr[0].y − screenPtr[2].y)) ; 255 matrixPtr−>En = ((screenPtr[0].x −screenPtr[2].x) *(displayPtr[1].y − displayPtr[2].y)) − ((displayPtr[0].y −displayPtr[2].y) *(screenPtr[1].x − screenPtr[2].x)) ; matrixPtr−>Fn = (screenPtr[2].x *displayPtr[1].y −screenPtr[1].x * displayPtr[2].y) *screenPtr[0].y + 260 (screenPtr[0].x *displayPtr[2].y −screenPtr[2].x * displayPtr[0].y) *screenPtr[1].y + (screenPtr[1].x *displayPtr[0].y −screenPtr[0].x * displayPtr[1].y) *screenPtr[2].y ; } return( retValue ) ; 265 }/*end of setCalibrationMatrix() */ 85
270 /********************************************************************** * *Function: getDisplayPoint() * *Description: Given a valid set of calibration factors and a point 275 *value reported by the touch screen, this function *calculates and returns the true (or closest to true) *display point below the spot where the touch screen *was touched. * 280 * * *Argument(s): displayPtr (output) −Pointer to the calculated *(true) display point. *screenPtr (input) −Pointer to the reported touch 285 *screen point. *matrixPtr (input) −Pointer to calibration factors *matrix previously calculated *from a call to *setCalibrationMatrix() 290 * * *The function simply solves for Xd and Yd by implementing the *computations required by the translation matrix. * 295 */− −\ */− −\ /− −\ | | *| | | | | Xs | *| Xd | | A B C | | | *| | = | | *| Ys | 300 *| Yd | | D E F | | | *| | | | | 1 | *\− −/ \− −/ | | *\− −/ * 305 *It must be kept brief to avoid consuming CPU cycles. * * *Return: OK −the display point was correctly calculated *and its value is in the output argument. 310 *NOT_OK −an error was detected and the function *failed to return a valid point. * * * 315 *NOTE! NOTE! NOTE! * *setCalibrationMatrix() and getDisplayPoint() will do fine *for you as they are, provided that your digitizer *resolution does not exceed 10 bits (1024 values). Higher 320 *resolutions may cause the integer operations to overflow *and return incorrect values. If you wish to use these *functions with digitizer resolutions of 12 bits (4096 *values) you will either have to a) use 64−bit signed 86
*integer variables and math, or b) judiciously modify the 325 *operations to scale results by a factor of 2 or even 4. * * */ int getDisplayPoint( POINT *displayPtr, 330 POINT *screenPtr, MATRIX *matrixPtr ) { int retValue = OK ; 335 if( matrixPtr−>Divider != 0 ) { /*Operation order is important since we are doing integer */ /*math. Make sure you add all terms together before */ 340 /*dividing, so that the remainder is not rounded off */ /*prematurely. */ displayPtr−>x = ( (matrixPtr−>An *screenPtr−>x) + (matrixPtr−>Bn *screenPtr−>y) + 345 matrixPtr−>Cn ) / matrixPtr−>Divider ; displayPtr−>y = ( (matrixPtr−>Dn *screenPtr−>x) + (matrixPtr−>En *screenPtr−>y) + 350 matrixPtr−>Fn ) / matrixPtr−>Divider ; } else { 355 retValue = NOT_OK ; } return( retValue ) ; 360 }/*end of getDisplayPoint() */ void calibrate() 365 { POINT displaySample[MAX_SAMPLES] = { { 72, 41 }, { 240, 231 }, 370 { 408, 136 }, } ; POINT perfectScreenSample[3] = { 375 { 72, 41 }, { 240, 231 }, { 408, 136 }, } ; 380 87
POINT perfectDisplaySample[3] = { { 72, 41 }, { 240, 231 }, { 408, 136 }, 385 } ; int retValue = OK ; 390 // MATRIX matrix ; POINT display ; int n ; 395 setCalibrationMatrix( &perfectDisplaySample[0], &perfectScreenSample[0], 400 &matrix ) ; _printf("\n\nLook at the unity matrix:\n\n" 405 "matrix.An = %d matrix.Bn = %d matrix.Cn = %d\n" "matrix.Dn = %d matrix.En = %d matrix.Fn = %d\n" "matrix.Divider = %d\n", matrix.An,matrix.Bn,matrix.Cn, matrix.Dn,matrix.En,matrix.Fn, 410 matrix.Divider ) ; int clbPointArray[10] = {0}; 415 readPoints(&clbPointArray); POINT screenSample[MAX_SAMPLES] = { { clbPointArray[0], clbPointArray[1] }, 420 { clbPointArray[2], clbPointArray[3] }, { clbPointArray[4], clbPointArray[5] }, { clbPointArray[6], clbPointArray[7] }, { clbPointArray[8], clbPointArray[9] }, } ; 425 setCalibrationMatrix( &displaySample[0], &screenSample[0], &matrix ) ; 430 _printf("\n\nThis is the actual calibration matrix that we will use\n" "for all points (until we calibrate again):\n\n" "matrix.An = %d matrix.Bn = %d matrix.Cn = %d\n" "matrix.Dn = %d matrix.En = %d matrix.Fn = %d\n" 435 "matrix.Divider = %d\n", matrix.An,matrix.Bn,matrix.Cn, matrix.Dn,matrix.En,matrix.Fn, 88
matrix.Divider ) ; 440 _printf("\n\nShow the results of our work:\n\n" " Screen Sample Translated Sample Display Sample\n\n" ) ; 445 for(n=0;n<MAX_SAMPLES ; ++n ) { getDisplayPoint( &display, &screenSample[n], &matrix ) ; _printf(" % 6d,%−6d % 6d,%−6d % 6d,%−6d\n", screenSample[n].x, screenSample[n].y, 450 display.x, display.y, displaySample[n].x, displaySample[n].y ) ; } } 89
lib/cncroutines.h 0#pragma once #include "system.h" #define CNC_DATA 0 5#define CNC_STATUS 1 #define CNC_CONTROL 2 #define CNC_OK 0x00 #define CNC_Home 0x20 10 #define CNC_Overload 0x10 #define CNC_Haube 0x30 #define CNC_OverTemp 0x08 #define CNC_Tool 0x28 15 // Signal gets inverted, clear the pin at the LPC to het a logic '1' at the port #define STROBE_PIN (1<<3) //Strobe = P0.3 #define STROBE_H() {FIOCLR=STROBE_PIN;} #define STROBE_L() {FIOSET=STROBE_PIN;} 20 extern BOOLEAN CNC_Motor; unsigned char readStrobePin(); 25 void outportb(int port, int data); int inportb(int port); int CNC_Status(); // −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− 30 #define C_INIT 0xD0 #define C_MOTOR_ON 0x90 #define C_XINC 0x4B #define C_XDEC 0x09 #define C_YINC 0x4E 35 #define C_YDEC 0x06 #define C_XINCYINC 0x4F #define C_XDECYDEC 0x05 #define C_XINCYDEC 0x07 #define C_XDECYINC 0x0D 40 #define C_ZINC 0x50 #define C_ZDEC 0x30 #define C_NOTBRAKE 0x80 #define C_BRAKE 0xC2 45 #define C_STATUS 0x00 #define C_DELAY 0xFF #define N_OUT 45 #define N_Vel 40 50 extern int delay_buffer[N_OUT]; extern int command_buffer[N_OUT]; extern int speed_buffer[N_OUT]; extern volatile int read_pointer, write_pointer; 90
55 extern int CNC_XPos_n, CNC_YPos_n, CNC_ZPos_n; extern int CNC_Step; extern unsigned char CNC_SpeedIndex; 60 extern int isr_cnc_status; extern volatile int dataCommandReturn; int dataCommand(int parameter); 65 void moveX(int steps, int speed); void moveY(int steps, int speed); void moveZ(int steps, int speed); void moveHome(); void moveToXYZ(int x1, int y1, int z1); 70 char CNC_XYZStep(int x, int y, int z, int max); void moveToXY(int x1, int y1); char CNC_XYStep(int x, int y, int max); void InitiateSpeed(unsigned int vel); void setParam_cmd(unsigned int command, unsigned int delay); 75 void moveZUp(); void moveZDown(); void drill(); BOOLEAN CNC_MotorOn_n(int rpm); void CNC_MotorOff_n(); 80 void CNCInit(); void moveAxis(int command, int distance); void keepTimerAlive(); 91
}while (!(CNC_Status() == CNC_Home || CNC_Status() == CNC_Haube)); if( CNC_Status() == CNC_Home ) { 335 CNC_XPos_n = 0; CNC_YPos_n = 0; CNC_ZPos_n = 0; } _printf("Homing complete: [%3d, %3d, %2d]\n", CNC_XPos_n, CNC_YPos_n, CNC_ZPos_n ); setParam_cmd(C_DELAY, 50000); } 340 void moveToXYZ(int x1, int y1, int z1) { int x = CNC_XPos_n, y = CNC_YPos_n, z = CNC_ZPos_n; 345 int dx = x1 −x, dy = y1 −y, dz = z1 −z; int sx = (dx > 0 ? 1 : (dx < 0 ? −1 : 0)); int sy = (dy > 0 ? 1 : (dy < 0 ? −1 : 0)); int sz = (dz > 0 ? 1 : (dz < 0 ? −1 : 0)); int ax, ay, az, decx, decy, decz, max; 350 unsigned char var; CNC_Step = 0; dx = abs(dx); dy = abs(dy); dz = abs(dz); 355 ax = dx<<1, ay = dy<<1, az = dz<<1; max = dx; var = 0; if ( dy > max ) { max = dy; var = 1; } 360 if ( dz > max ) { max = dz; var = 2; } switch ( var ) { case 0 : 365 for(decy = ay−dx, decz = az−dx; ; x += sx, decy += ay, decz += az) { if ( !CNC_XYZStep(x, y, z, max) ) break; if (x==x1)break; if ( decy >= 0 ) { decy −= ax, y += sy; } 370 if ( decz >= 0 ) { decz −= ax, z += sz; } } break; case 1 : 375 for(decx = ax−dy, decz = az−dx; ; y += sy, decx += ax, decz += az) { if ( !CNC_XYZStep(x, y, z, max) ) break; if (y==y1)break; if ( decx >= 0 ) { decx −= ay, x += sx; } 380 if ( decz >= 0 ) { decz −= ay, z += sz; } } break; case 2 : 385 for(decx = ax−dz, decy = ay−dz; ; z += sz, decx += ax, decy += ay) { 98
if ( !CNC_XYZStep(x, y, z, max) ) break; if (z==z1)break; if ( decx >= 0 ) { decx −= az, x += sx; } 390 if ( decz >= 0 ) { decy −= az, y += sy; } } break; } if (CNC_XPos_n<0) CNC_XPos_n=0; 395 if (CNC_YPos_n<0) CNC_YPos_n=0; if (CNC_ZPos_n<0) CNC_ZPos_n=0; while(read_pointer != write_pointer){ if ((delay_buffer[read_pointer]) != speed_buffer[(N_OUT−1)]) 400 { enableTimer(0); } } } 405 char CNC_XYZStep(int x, int y, int z, int max) { int dx, dy, dz; int delta; 410 char command; char state = CNC_Status(); dx = x −CNC_XPos_n; CNC_XPos_n = x; dy = y −CNC_YPos_n; CNC_YPos_n = y; 415 if ( !dx && !dy && !dz ) return 1; command = 0x00; if (dy==0) 420 { if ( dx > 0 ) command = C_XINC; if ( dx < 0 ) command = C_XDEC; } else 425 if (dx==0) { if ( dy > 0 ) command = C_YINC; if ( dy < 0 ) command = C_YDEC; } 430 else if (dx>0) { if ( dy > 0 ) command = C_XINCYINC; if ( dy < 0 ) command = C_XDECYDEC; 435 } else if (dx<0) { if ( dy > 0 ) command = C_XDECYINC; 440 if ( dy < 0 ) command = C_XDECYDEC; } if ( dz > 0 ) command |= C_ZINC; 99
if ( dz < 0 ) command = command | C_ZDEC; 445 CNC_Step++; if ( CNC_Step < N_Vel ) CNC_SpeedIndex = CNC_Step; if ( CNC_Step > max−N_Vel ) CNC_SpeedIndex = max−CNC_Step; 450 setParam_cmd(command, (speed_buffer[CNC_SpeedIndex])); if (state != CNC_Status()) 455 {// TODO: Check if these values are correct (0x01 & 0x03) if ( (CNC_Status() == 0x01) | (CNC_Status() == 0x03) ) { return 0; }else return 1; 460 } else return 1; } char CNC_XYStep(int x, int y, int max) 465 { int dx, dy; int delta; char command; char state = CNC_Status(); 470 dx = x −CNC_XPos_n; CNC_XPos_n = x; dy = y −CNC_YPos_n; CNC_YPos_n = y; if ( !dx && !dy ) return 1; 475 command = 0x00; if (dy==0) { if ( dx > 0 ) command = C_XINC; 480 if ( dx < 0 ) command = C_XDEC; } else if (dx==0) { 485 if ( dy > 0 ) command = C_YINC; if ( dy < 0 ) command = C_YDEC; } else if (dx>0) 490 { if ( dy > 0 ) command = C_XINCYINC; if ( dy < 0 ) command = C_XDECYDEC; } else 495 if (dx<0) { if ( dy > 0 ) command = C_XDECYINC; if ( dy < 0 ) command = C_XDECYDEC; } 500 100
CNC_Step++; if ( CNC_Step < N_Vel ) CNC_SpeedIndex = CNC_Step; if ( CNC_Step > max−N_Vel ) CNC_SpeedIndex = max−CNC_Step; 505 setParam_cmd(command, (speed_buffer[CNC_SpeedIndex])); if (state != CNC_Status()) 510 {// TODO: Check if these values are correct (0x01 & 0x03) if ( (CNC_Status() == 0x01) | (CNC_Status() == 0x03) ) { return 0; }else return 1; 515 } else return 1; } 520 void moveToXY(int x1, int y1) { // _printf("Move to function entered. [%2d, %2d], RD{%d} WR{%d}\n", x1, y1, read_pointer, write_pointer); int x = CNC_XPos_n, y = CNC_YPos_n; int dx = x1 −x, dy = y1 −y; 525 int sx = (dx > 0 ? 1 : (dx < 0 ? −1 : 0)); int sy = (dy > 0 ? 1 : (dy < 0 ? −1 : 0)); int ax, ay, decx, decy, max; unsigned char var; 530 CNC_Step = 0; dx = abs(dx); dy = abs(dy); ax = dx<<1, ay = dy<<1; 535 max = dx; var = 0; if ( dy > max ) { max = dy; var = 1; } // _printf("1\n"); switch ( var ) 540 { case 0 : for(decy = ay−dx; ; x += sx, decy += ay) { // _printf("2\n"); 545 if ( !CNC_XYStep(x, y, max) ) break; if (x==x1)break; if ( decy >= 0 ) { decy −= ax, y += sy; } } break; 550 case 1 : for(decx = ax−dy; ; y += sy, decx += ax) { // _printf("3\n"); 555 if ( !CNC_XYStep(x, y, max) ) break; if (y==y1)break; 101
if ( decx >= 0 ) { decx −= ay, x += sx; } } break; 560 } if (CNC_XPos_n<0) CNC_XPos_n=0; if (CNC_YPos_n<0) CNC_YPos_n=0; 565 // _printf("Before enabling, RD{%d} != WR{%d}\n", read_pointer, write_pointer); while(read_pointer != write_pointer){ if ((delay_buffer[read_pointer]) != speed_buffer[(N_OUT−1)]) { 570 // _printf("enabling timer\n"); enableTimer(0); } } } 575 /** *@brief This function should be called once. It is responible for speeding up and slowing down the CNC−head when making a movement. 580 * *@param vel is a chosen speed, measured in mm/min */ void InitiateSpeed(unsigned int vel) { 585 unsigned int i; long V; // FIFO buffer initialization read_pointer = 0; 590 write_pointer = 0; delay_buffer[read_pointer] = 30; // Configure interrupt for TIMER0 #define TIMER0 (4) 595 VICVectAddr1 = (unsigned int)IRQ_CNC_Timer_Routine; VICVectCntl1 = (1<<5)|TIMER0; // Enable vector VICVectAddr=−1; VICIntEnable = (1<<TIMER0); // Enable interrupt 600 // Configure timer resetTimer(0); // T0TCR = 2; // Reset TIMER0 // Time = (T0PR+1)/PCLK // 1e−3 = (T0PR+1//(14745600*4) // T0PR = 58981 605 //T0PR = 58981; // every step is 1 ms T0PR = 59; // every step is 1 us T0MCR = 7; // Stop and reset counter and generate interrupt T0MR0 = 1000; // Period for Timer0 interrupt (first time 1 ms) 610 // Enable interrupts asm volatile ("mrs r0,cpsr\n bic r0,r0,#0x80\n msr cpsr,r0"); 102
STROBE_H(); 615 // Delay initialization // _printf("Delay calculation for a speed of %4d mm/min\r\n", vel); // _printf("Delay is measured in us\r\n"); for (i=0;i<N_Vel; i++ ) { 620 V=(long)vel*(i+1)/(long)N_Vel; // Velocity = V mm/min x 1 step/0.0254 mm x 1 min/60 sec // The inverse is in sec/step −−> 1524000 (usec/step) / V(mm/min) V = 1524000/V; // usec/step speed_buffer[i] = (int) (V); // measured in usec 625 // _printf("[%2d]: %5d\r\n", i, speed_buffer[i]); } } 630 /** *@brief Puts a command and a corresponding delay in the buffers * *@param command is an 8−bit hex code that controls the CNC machine *@param delay is the delay between this command and the next command, measured in ¸ts 635 */ void setParam_cmd(unsigned int command, unsigned int delay) { int isig; 640 command_buffer[write_pointer] = command; delay_buffer[write_pointer] = delay; // enableTimer(0); isig = write_pointer + 1; 645 if (isig >= N_OUT) isig = 0; do {/*_printf("waiting\n");*/}while (isig == read_pointer); // Wait for space at buffers write_pointer = isig; enableTimer(0); // _printf("ISR0 RD{%d}, WR{%d}\n", read_pointer, write_pointer ); 650 } void CNCInit() { MCPsetIODirCNC(); 655 _delay_ms(200); STROBE_H(); outportb(CNC_CONTROL, 4); _delay_ms(10); 660 outportb(CNC_CONTROL, 0); _delay_ms(250); outportb(CNC_CONTROL, 4); _delay_ms(10); 665 setParam_cmd(C_INIT, 20000); setParam_cmd(C_INIT, 2000); 103
// moveHome(); } 670 BOOLEAN CNC_MotorOn_n(int rpm) { unsigned char command; if(rpm < 30000 || rpm > 60000) return FALSE; 675 if(rpm == 60000) command = 0x9F; else command = 0x90 | (rpm−30000)/1875; setParam_cmd(C_NOTBRAKE, 2000); setParam_cmd(command, 50000); // 0,05 second delay 680 int i; for (i = 0; i < 40; i++) setParam_cmd(C_DELAY, 50000); // 40 times 50ms = 2 second delay 685 if(CNC_Status() == CNC_OK) CNC_Motor = TRUE; else CNC_Motor = FALSE; return CNC_Motor; } 690 void CNC_MotorOff_n() { setParam_cmd(C_BRAKE, 2000); setParam_cmd(C_INIT, 50000); 695 CNC_Motor = FALSE; } 700 void keepTimerAlive() { while(read_pointer != write_pointer){ if ((delay_buffer[read_pointer]) != speed_buffer[(N_OUT−1)]) { 705 enableTimer(0); } } } 104
lib/display_manager.h 0#ifndef DISPLAY_MANAGER_H #define DISPLAY_MANAGER_H typedef enum e_display_states { 5e_disp_route_pro, e_disp_config, e_disp_tools, e_disp_offset, e_disp_warning, 10 e_disp_load, e_disp_execute_file } display_states_t; extern display_states_t g_display_state; 15 extern display_states_t g_previous_display; extern char button_interrupt_flag; void display_manager_init_state(); 20 void display_manager_set_state(display_states_t new_state); void display_manager_process_state(); void set_display_change_flag(); void clear_display_change_flag(); 25 void set_button_interrupt_flag(); void clear_button_interrupt_flag(); #endif //DISPLAY_MANAGER_H 105
lib/display_manager.c 0#include "display_manager.h" display_states_t g_display_state; display_states_t g_previous_display; char display_change_flag = 0; 5char button_interrupt_flag = 0; void display_manager_init_state() { 10 g_display_state = e_disp_route_pro; display_manager_set_state(g_display_state); } void display_manager_set_state(display_states_t new_state) 15 { //If new display is warning and warning is already displayed, do nothing. if(new_state == e_disp_warning && g_display_state == e_disp_warning) { }else 20 { g_previous_display = g_display_state; g_display_state = new_state; set_display_change_flag (); } 25 } void display_manager_process_state() 30 { switch (g_display_state) { case e_disp_route_pro: if(display_change_flag==1) {clear_display_change_flag(); initRP();} 35 scanRP(); break; case e_disp_config: if(display_change_flag==1) {clear_display_change_flag(); initConf();} 40 scanConf(); break; case e_disp_tools: if(display_change_flag==1) {clear_display_change_flag(); initTD();} 45 scanTD(); break; case e_disp_offset: if(display_change_flag==1) {clear_display_change_flag(); initOTS();} 50 scanOTS(); break; case e_disp_warning: if(display_change_flag==1) {clear_display_change_flag(); initWRNG(" 106
Emergency stop");} 55 scanWRNG("Emergency stop"); break; case e_disp_load: if(display_change_flag==1) {clear_display_change_flag(); initLF();} 60 scanLF(); break; case e_disp_execute_file: if(display_change_flag==1) {clear_display_change_flag(); initEF();} 65 scanEF(); break; default: if(display_change_flag==1) {clear_display_change_flag(); initLF();} 70 scanRP(); break; } } 75 void set_display_change_flag() { display_change_flag = 1; } 80 void clear_display_change_flag() { display_change_flag = 0; } 85 void set_button_interrupt_flag() { button_interrupt_flag = 1; } 90 void clear_button_interrupt_flag() { button_interrupt_flag = 0; } 107
character if (!strcmp(BUF,"M48")) _printf ("−>Start of file\r\n"); else if(!strcmp(BUF,"M30")) _printf ("−>End of file\n\n"); 280 else if(BUF[0]=='%') _printf("−>End of header\r\n"); else if(BUF[0]=='T') { if(strlen(BUF)==3) // Process Txx tool change commands { 285 tool= atoi(&BUF[1]); _printf("−>Select tool : %02d\r\n", tool ); updateTool(tool); }// Ignore commands as T01F00S00C0.020 } 290 else if(BUF[0]=='X') // Drill at { if(format24) // 24 means 2 digits are integer part and 4 digits are fractiona part { for(i=0;i<7;i++) s[i]=BUF[i+1]; 295 s[8]=0; x = atoi(s); for(i=0;i<7;i++) s[i]=BUF[i+9]; y = atoi(s); _printf("−> Drill at %3d,%3d\r\n",x,y); 300 moveToXY(x,y); } else // Trailing zeroes included (TZ) INCH 2.3 { k=0; 305 s[6]=0; for(i=0;BUF[i]!='Y';i++,k++) s[k]=BUF[i+1]; s[k−1]=0; x = atoi(s); 310 k=0; for(;i<strlen(BUF);i++,k++) s[k]=BUF[i+1]; s[k]=0; y = atoi(s); 315 _printf("−> Drill at %3d,%3d\r\n", x, y); moveToXY(x,y); } } else if(!strcmp(BUF,"INCH,TZ")) 320 { format24 = 0; _printf("−> Format 2.3\r\n"); } // Ignore rest of commands 325 } void clearFileBuffer() { int i; 330 for (i = 0; i < amountoffiles; i++) { dirArray[i][0] = 0; 114
fileArray[i][0] = 0; fileAndInf[i][0] = 0; 335 yCoords[i] = 300; } } 115
lib/font.c 0// #pragma once #if defined(__AVR__) #include <avr/pgmspace.h> #define fontdatatype const uint8_t 5#elif defined(__PIC32MX__) #define PROGMEM #define fontdatatype const unsigned char #elif defined(__arm__) #define PROGMEM 10 #define fontdatatype const unsigned char #endif // SmallFont.c // Font Size : 8x12 15 // Memory usage : 1144 bytes // # characters : 95 fontdatatype SmallFont[1144] PROGMEM={ 0x08,0x0C,0x20,0x5F, 20 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // <Space> 0x00,0x00,0x20,0x20,0x20,0x20,0x20,0x20,0x00,0x20,0x00,0x00, // ! 0x00,0x28,0x50,0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // " 0x00,0x00,0x28,0x28,0xFC,0x28,0x50,0xFC,0x50,0x50,0x00,0x00, // # 0x00,0x20,0x78,0xA8,0xA0,0x60,0x30,0x28,0xA8,0xF0,0x20,0x00, // $ 25 0x00,0x00,0x48,0xA8,0xB0,0x50,0x28,0x34,0x54,0x48,0x00,0x00, // % 0x00,0x00,0x20,0x50,0x50,0x78,0xA8,0xA8,0x90,0x6C,0x00,0x00, // & 0x00,0x40,0x40,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // ' 0x00,0x04,0x08,0x10,0x10,0x10,0x10,0x10,0x10,0x08,0x04,0x00, // ( 0x00,0x40,0x20,0x10,0x10,0x10,0x10,0x10,0x10,0x20,0x40,0x00, // ) 30 0x00,0x00,0x00,0x20,0xA8,0x70,0x70,0xA8,0x20,0x00,0x00,0x00, // * 0x00,0x00,0x20,0x20,0x20,0xF8,0x20,0x20,0x20,0x00,0x00,0x00, // + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x40,0x80, // , 0x00,0x00,0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00, // − 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00, // . 35 0x00,0x08,0x10,0x10,0x10,0x20,0x20,0x40,0x40,0x40,0x80,0x00, // / 0x00,0x00,0x70,0x88,0x88,0x88,0x88,0x88,0x88,0x70,0x00,0x00, // 0 0x00,0x00,0x20,0x60,0x20,0x20,0x20,0x20,0x20,0x70,0x00,0x00, // 1 0x00,0x00,0x70,0x88,0x88,0x10,0x20,0x40,0x80,0xF8,0x00,0x00, // 2 0x00,0x00,0x70,0x88,0x08,0x30,0x08,0x08,0x88,0x70,0x00,0x00, // 3 40 0x00,0x00,0x10,0x30,0x50,0x50,0x90,0x78,0x10,0x18,0x00,0x00, // 4 0x00,0x00,0xF8,0x80,0x80,0xF0,0x08,0x08,0x88,0x70,0x00,0x00, // 5 0x00,0x00,0x70,0x90,0x80,0xF0,0x88,0x88,0x88,0x70,0x00,0x00, // 6 0x00,0x00,0xF8,0x90,0x10,0x20,0x20,0x20,0x20,0x20,0x00,0x00, // 7 0x00,0x00,0x70,0x88,0x88,0x70,0x88,0x88,0x88,0x70,0x00,0x00, // 8 45 0x00,0x00,0x70,0x88,0x88,0x88,0x78,0x08,0x48,0x70,0x00,0x00, // 9 0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x20,0x00,0x00, // : 0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x20,0x20,0x00, // ; 0x00,0x04,0x08,0x10,0x20,0x40,0x20,0x10,0x08,0x04,0x00,0x00, // < 0x00,0x00,0x00,0x00,0xF8,0x00,0x00,0xF8,0x00,0x00,0x00,0x00, // = 50 0x00,0x40,0x20,0x10,0x08,0x04,0x08,0x10,0x20,0x40,0x00,0x00, // > 0x00,0x00,0x70,0x88,0x88,0x10,0x20,0x20,0x00,0x20,0x00,0x00, // ? 0x00,0x00,0x70,0x88,0x98,0xA8,0xA8,0xB8,0x80,0x78,0x00,0x00, // @ 0x00,0x00,0x20,0x20,0x30,0x50,0x50,0x78,0x48,0xCC,0x00,0x00, // A 0x00,0x00,0xF0,0x48,0x48,0x70,0x48,0x48,0x48,0xF0,0x00,0x00, // B 116
55 0x00,0x00,0x78,0x88,0x80,0x80,0x80,0x80,0x88,0x70,0x00,0x00, // C 0x00,0x00,0xF0,0x48,0x48,0x48,0x48,0x48,0x48,0xF0,0x00,0x00, // D 0x00,0x00,0xF8,0x48,0x50,0x70,0x50,0x40,0x48,0xF8,0x00,0x00, // E 0x00,0x00,0xF8,0x48,0x50,0x70,0x50,0x40,0x40,0xE0,0x00,0x00, // F 0x00,0x00,0x38,0x48,0x80,0x80,0x9C,0x88,0x48,0x30,0x00,0x00, // G 60 0x00,0x00,0xCC,0x48,0x48,0x78,0x48,0x48,0x48,0xCC,0x00,0x00, // H 0x00,0x00,0xF8,0x20,0x20,0x20,0x20,0x20,0x20,0xF8,0x00,0x00, // I 0x00,0x00,0x7C,0x10,0x10,0x10,0x10,0x10,0x10,0x90,0xE0,0x00, // J 0x00,0x00,0xEC,0x48,0x50,0x60,0x50,0x50,0x48,0xEC,0x00,0x00, // K 0x00,0x00,0xE0,0x40,0x40,0x40,0x40,0x40,0x44,0xFC,0x00,0x00, // L 65 0x00,0x00,0xD8,0xD8,0xD8,0xD8,0xA8,0xA8,0xA8,0xA8,0x00,0x00, // M 0x00,0x00,0xDC,0x48,0x68,0x68,0x58,0x58,0x48,0xE8,0x00,0x00, // N 0x00,0x00,0x70,0x88,0x88,0x88,0x88,0x88,0x88,0x70,0x00,0x00, // O 0x00,0x00,0xF0,0x48,0x48,0x70,0x40,0x40,0x40,0xE0,0x00,0x00, // P 0x00,0x00,0x70,0x88,0x88,0x88,0x88,0xE8,0x98,0x70,0x18,0x00, // Q 70 0x00,0x00,0xF0,0x48,0x48,0x70,0x50,0x48,0x48,0xEC,0x00,0x00, // R 0x00,0x00,0x78,0x88,0x80,0x60,0x10,0x08,0x88,0xF0,0x00,0x00, // S 0x00,0x00,0xF8,0xA8,0x20,0x20,0x20,0x20,0x20,0x70,0x00,0x00, // T 0x00,0x00,0xCC,0x48,0x48,0x48,0x48,0x48,0x48,0x30,0x00,0x00, // U 0x00,0x00,0xCC,0x48,0x48,0x50,0x50,0x30,0x20,0x20,0x00,0x00, // V 75 0x00,0x00,0xA8,0xA8,0xA8,0x70,0x50,0x50,0x50,0x50,0x00,0x00, // W 0x00,0x00,0xD8,0x50,0x50,0x20,0x20,0x50,0x50,0xD8,0x00,0x00, // X 0x00,0x00,0xD8,0x50,0x50,0x20,0x20,0x20,0x20,0x70,0x00,0x00, // Y 0x00,0x00,0xF8,0x90,0x10,0x20,0x20,0x40,0x48,0xF8,0x00,0x00, // Z 0x00,0x38,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x38,0x00, // [ 80 0x00,0x40,0x40,0x40,0x20,0x20,0x10,0x10,0x10,0x08,0x00,0x00, // <Backslash> 0x00,0x70,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x70,0x00, // ] 0x00,0x20,0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // ^ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFC, // _ 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // ' 85 0x00,0x00,0x00,0x00,0x00,0x30,0x48,0x38,0x48,0x3C,0x00,0x00, // a 0x00,0x00,0xC0,0x40,0x40,0x70,0x48,0x48,0x48,0x70,0x00,0x00, // b 0x00,0x00,0x00,0x00,0x00,0x38,0x48,0x40,0x40,0x38,0x00,0x00, // c 0x00,0x00,0x18,0x08,0x08,0x38,0x48,0x48,0x48,0x3C,0x00,0x00, // d 0x00,0x00,0x00,0x00,0x00,0x30,0x48,0x78,0x40,0x38,0x00,0x00, // e 90 0x00,0x00,0x1C,0x20,0x20,0x78,0x20,0x20,0x20,0x78,0x00,0x00, // f 0x00,0x00,0x00,0x00,0x00,0x3C,0x48,0x30,0x40,0x78,0x44,0x38, // g 0x00,0x00,0xC0,0x40,0x40,0x70,0x48,0x48,0x48,0xEC,0x00,0x00, // h 0x00,0x00,0x20,0x00,0x00,0x60,0x20,0x20,0x20,0x70,0x00,0x00, // i 0x00,0x00,0x10,0x00,0x00,0x30,0x10,0x10,0x10,0x10,0x10,0xE0, // j 95 0x00,0x00,0xC0,0x40,0x40,0x5C,0x50,0x70,0x48,0xEC,0x00,0x00, // k 0x00,0x00,0xE0,0x20,0x20,0x20,0x20,0x20,0x20,0xF8,0x00,0x00, // l 0x00,0x00,0x00,0x00,0x00,0xF0,0xA8,0xA8,0xA8,0xA8,0x00,0x00, // m 0x00,0x00,0x00,0x00,0x00,0xF0,0x48,0x48,0x48,0xEC,0x00,0x00, // n 0x00,0x00,0x00,0x00,0x00,0x30,0x48,0x48,0x48,0x30,0x00,0x00, // o 100 0x00,0x00,0x00,0x00,0x00,0xF0,0x48,0x48,0x48,0x70,0x40,0xE0, // p 0x00,0x00,0x00,0x00,0x00,0x38,0x48,0x48,0x48,0x38,0x08,0x1C, // q 0x00,0x00,0x00,0x00,0x00,0xD8,0x60,0x40,0x40,0xE0,0x00,0x00, // r 0x00,0x00,0x00,0x00,0x00,0x78,0x40,0x30,0x08,0x78,0x00,0x00, // s 0x00,0x00,0x00,0x20,0x20,0x70,0x20,0x20,0x20,0x18,0x00,0x00, // t 105 0x00,0x00,0x00,0x00,0x00,0xD8,0x48,0x48,0x48,0x3C,0x00,0x00, // u 0x00,0x00,0x00,0x00,0x00,0xEC,0x48,0x50,0x30,0x20,0x00,0x00, // v 0x00,0x00,0x00,0x00,0x00,0xA8,0xA8,0x70,0x50,0x50,0x00,0x00, // w 0x00,0x00,0x00,0x00,0x00,0xD8,0x50,0x20,0x50,0xD8,0x00,0x00, // x 0x00,0x00,0x00,0x00,0x00,0xEC,0x48,0x50,0x30,0x20,0x20,0xC0, // y 110 0x00,0x00,0x00,0x00,0x00,0x78,0x10,0x20,0x20,0x78,0x00,0x00, // z 0x00,0x18,0x10,0x10,0x10,0x20,0x10,0x10,0x10,0x10,0x18,0x00, // { 117
0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, // | 0x00,0x60,0x20,0x20,0x20,0x10,0x20,0x20,0x20,0x20,0x60,0x00, // } 0x40,0xA4,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // ~ 115 }; // BigFont.c (C)2010 by Henning Karlsen // Font Size : 16x16 // Memory usage : 3044 bytes 120 // # characters : 95 fontdatatype BigFont[3044] PROGMEM={ 0x10,0x10,0x20,0x5F, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // <Space> 125 0x00,0x00,0x00,0x00,0x07,0x00,0x0F,0x80,0x0F,0x80,0x0F,0x80,0x0F,0x80,0x0F,0x80,0x07 ,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x07,0x00,0x07,0x00,0x00,0x00, // ! 0x00,0x00,0x0E,0x38,0x0E,0x38,0x0E,0x38,0x0E,0x38,0x06,0x30,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // " 0x00,0x00,0x0C,0x30,0x0C,0x30,0x0C,0x30,0x7F,0xFE,0x7F,0xFE,0x0C,0x30,0x0C,0x30,0x0C ,0x30,0x0C,0x30,0x7F,0xFE,0x7F,0xFE,0x0C,0x30,0x0C,0x30,0x0C,0x30,0x00,0x00, // # 0x00,0x00,0x02,0x40,0x02,0x40,0x0F,0xF8,0x1F,0xF8,0x1A,0x40,0x1A,0x40,0x1F,0xF0,0x0F ,0xF8,0x02,0x58,0x02,0x58,0x1F,0xF8,0x1F,0xF0,0x02,0x40,0x02,0x40,0x00,0x00, // $ 0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x10,0x0E,0x30,0x0E,0x70,0x00,0xE0,0x01,0xC0,0x03 ,0x80,0x07,0x00,0x0E,0x70,0x0C,0x70,0x08,0x70,0x00,0x00,0x00,0x00,0x00,0x00, // % 130 0x00,0x00,0x00,0x00,0x0F,0x00,0x19,0x80,0x19,0x80,0x19,0x80,0x0F,0x00,0x0F,0x08,0x0F ,0x98,0x19,0xF8,0x18,0xF0,0x18,0xE0,0x19,0xF0,0x0F,0x98,0x00,0x00,0x00,0x00, // & 0x00,0x00,0x00,0x00,0x07,0x00,0x07,0x00,0x07,0x00,0x0E,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // ' 0x00,0x00,0x00,0x00,0x00,0xF0,0x01,0xC0,0x03,0x80,0x07,0x00,0x0E,0x00,0x0E,0x00,0x0E ,0x00,0x0E,0x00,0x07,0x00,0x03,0x80,0x01,0xC0,0x00,0xF0,0x00,0x00,0x00,0x00, // ( 0x00,0x00,0x00,0x00,0x0F,0x00,0x03,0x80,0x01,0xC0,0x00,0xE0,0x00,0x70,0x00,0x70,0x00 ,0x70,0x00,0x70,0x00,0xE0,0x01,0xC0,0x03,0x80,0x0F,0x00,0x00,0x00,0x00,0x00, // ) 0x00,0x00,0x00,0x00,0x01,0x80,0x11,0x88,0x09,0x90,0x07,0xE0,0x07,0xE0,0x3F,0xFC,0x3F ,0xFC,0x07,0xE0,0x07,0xE0,0x09,0x90,0x11,0x88,0x01,0x80,0x00,0x00,0x00,0x00, // * 135 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x01,0x80,0x01,0x80,0x0F,0xF0,0x0F ,0xF0,0x01,0x80,0x01,0x80,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x07,0x00,0x07,0x00,0x0E,0x00,0x00,0x00, // , 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xF8,0x1F ,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // − 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x07,0x00,0x07,0x00,0x00,0x00,0x00,0x00, // , 118
0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x06,0x00,0x0E,0x00,0x1C,0x00,0x38,0x00,0x70,0x00 ,0xE0,0x01,0xC0,0x03,0x80,0x07,0x00,0x0E,0x00,0x1C,0x00,0x00,0x00,0x00,0x00, // / 140 0x00,0x00,0x00,0x00,0x0F,0xF0,0x1C,0x38,0x1C,0x78,0x1C,0xF8,0x1C,0xF8,0x1D,0xB8,0x1D ,0xB8,0x1F,0x38,0x1F,0x38,0x1E,0x38,0x1C,0x38,0x0F,0xF0,0x00,0x00,0x00,0x00, // 0 0x00,0x00,0x00,0x00,0x01,0x80,0x01,0x80,0x03,0x80,0x1F,0x80,0x1F,0x80,0x03,0x80,0x03 ,0x80,0x03,0x80,0x03,0x80,0x03,0x80,0x03,0x80,0x1F,0xF0,0x00,0x00,0x00,0x00, // 1 0x00,0x00,0x00,0x00,0x0F,0xE0,0x1C,0x70,0x1C,0x38,0x00,0x38,0x00,0x70,0x00,0xE0,0x01 ,0xC0,0x03,0x80,0x07,0x00,0x0E,0x38,0x1C,0x38,0x1F,0xF8,0x00,0x00,0x00,0x00, // 2 0x00,0x00,0x00,0x00,0x0F,0xE0,0x1C,0x70,0x1C,0x38,0x00,0x38,0x00,0x70,0x03,0xC0,0x03 ,0xC0,0x00,0x70,0x00,0x38,0x1C,0x38,0x1C,0x70,0x0F,0xE0,0x00,0x00,0x00,0x00, // 3 145 0x00,0x00,0x00,0x00,0x00,0xE0,0x01,0xE0,0x03,0xE0,0x06,0xE0,0x0C,0xE0,0x18,0xE0,0x1F ,0xF8,0x1F,0xF8,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x03,0xF8,0x00,0x00,0x00,0x00, // 4 0x00,0x00,0x00,0x00,0x1F,0xF8,0x1C,0x00,0x1C,0x00,0x1C,0x00,0x1C,0x00,0x1F,0xE0,0x1F ,0xF0,0x00,0x78,0x00,0x38,0x1C,0x38,0x1C,0x70,0x0F,0xE0,0x00,0x00,0x00,0x00, // 5 0x00,0x00,0x00,0x00,0x03,0xE0,0x07,0x00,0x0E,0x00,0x1C,0x00,0x1C,0x00,0x1F,0xF0,0x1F ,0xF8,0x1C,0x38,0x1C,0x38,0x1C,0x38,0x1C,0x38,0x0F,0xF0,0x00,0x00,0x00,0x00, // 6 0x00,0x00,0x00,0x00,0x1F,0xFC,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x00,0x1C,0x00,0x38,0x00 ,0x70,0x00,0xE0,0x01,0xC0,0x03,0x80,0x03,0x80,0x03,0x80,0x00,0x00,0x00,0x00, // 7 0x00,0x00,0x00,0x00,0x0F,0xF0,0x1C,0x38,0x1C,0x38,0x1C,0x38,0x1F,0x38,0x07,0xE0,0x07 ,0xE0,0x1C,0xF8,0x1C,0x38,0x1C,0x38,0x1C,0x38,0x0F,0xF0,0x00,0x00,0x00,0x00, // 8 150 0x00,0x00,0x00,0x00,0x0F,0xF0,0x1C,0x38,0x1C,0x38,0x1C,0x38,0x1C,0x38,0x1F,0xF8,0x0F ,0xF8,0x00,0x38,0x00,0x38,0x00,0x70,0x00,0xE0,0x07,0xC0,0x00,0x00,0x00,0x00, // 9 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x80,0x03,0x80,0x03,0x80,0x00,0x00,0x00 ,0x00,0x03,0x80,0x03,0x80,0x03,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // : 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x80,0x03,0x80,0x03,0x80,0x00,0x00,0x00 ,0x00,0x03,0x80,0x03,0x80,0x03,0x80,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // ; 0x00,0x00,0x00,0x70,0x00,0xE0,0x01,0xC0,0x03,0x80,0x07,0x00,0x0E,0x00,0x1C,0x00,0x1C ,0x00,0x0E,0x00,0x07,0x00,0x03,0x80,0x01,0xC0,0x00,0xE0,0x00,0x70,0x00,0x00, // < 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xFC,0x3F,0xFC,0x00,0x00,0x00 ,0x00,0x3F,0xFC,0x3F,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // = 155 0x00,0x00,0x1C,0x00,0x0E,0x00,0x07,0x00,0x03,0x80,0x01,0xC0,0x00,0xE0,0x00,0x70,0x00 ,0x70,0x00,0xE0,0x01,0xC0,0x03,0x80,0x07,0x00,0x0E,0x00,0x1C,0x00,0x00,0x00, // > 0x00,0x00,0x03,0xC0,0x0F,0xF0,0x1E,0x78,0x18,0x38,0x00,0x38,0x00,0x70,0x00,0xE0,0x01 ,0xC0,0x01,0xC0,0x00,0x00,0x00,0x00,0x01,0xC0,0x01,0xC0,0x01,0xC0,0x00,0x00, // ? 0x00,0x00,0x0F,0xF8,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0xFC,0x1C,0xFC,0x1C ,0xFC,0x1C,0xFC,0x1C,0x00,0x1C,0x00,0x1C,0x00,0x1F,0xF0,0x07,0xF8,0x00,0x00, // @ 0x00,0x00,0x00,0x00,0x03,0xC0,0x07,0xE0,0x0E,0x70,0x1C,0x38,0x1C,0x38,0x1C,0x38,0x1C 119
,0x38,0x1F,0xF8,0x1C,0x38,0x1C,0x38,0x1C,0x38,0x1C,0x38,0x00,0x00,0x00,0x00, // A 160 0x00,0x00,0x00,0x00,0x1F,0xF0,0x0E,0x38,0x0E,0x38,0x0E,0x38,0x0E,0x38,0x0F,0xF0,0x0F ,0xF0,0x0E,0x38,0x0E,0x38,0x0E,0x38,0x0E,0x38,0x1F,0xF0,0x00,0x00,0x00,0x00, // B 0x00,0x00,0x00,0x00,0x07,0xF0,0x0E,0x38,0x1C,0x38,0x1C,0x00,0x1C,0x00,0x1C,0x00,0x1C ,0x00,0x1C,0x00,0x1C,0x00,0x1C,0x38,0x0E,0x38,0x07,0xF0,0x00,0x00,0x00,0x00, // C 0x00,0x00,0x00,0x00,0x1F,0xE0,0x0E,0x70,0x0E,0x38,0x0E,0x38,0x0E,0x38,0x0E,0x38,0x0E ,0x38,0x0E,0x38,0x0E,0x38,0x0E,0x38,0x0E,0x70,0x1F,0xE0,0x00,0x00,0x00,0x00, // D 0x00,0x00,0x00,0x00,0x1F,0xF8,0x0E,0x18,0x0E,0x08,0x0E,0x00,0x0E,0x30,0x0F,0xF0,0x0F ,0xF0,0x0E,0x30,0x0E,0x00,0x0E,0x08,0x0E,0x18,0x1F,0xF8,0x00,0x00,0x00,0x00, // E 0x00,0x00,0x00,0x00,0x1F,0xF8,0x0E,0x18,0x0E,0x08,0x0E,0x00,0x0E,0x30,0x0F,0xF0,0x0F ,0xF0,0x0E,0x30,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x1F,0x00,0x00,0x00,0x00,0x00, // F 165 0x00,0x00,0x00,0x00,0x07,0xF0,0x0E,0x38,0x1C,0x38,0x1C,0x38,0x1C,0x00,0x1C,0x00,0x1C ,0x00,0x1C,0xF8,0x1C,0x38,0x1C,0x38,0x0E,0x38,0x07,0xF8,0x00,0x00,0x00,0x00, // G 0x00,0x00,0x00,0x00,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1F,0xF0,0x1F ,0xF0,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x00,0x00,0x00,0x00, // H 0x00,0x00,0x00,0x00,0x0F,0xE0,0x03,0x80,0x03,0x80,0x03,0x80,0x03,0x80,0x03,0x80,0x03 ,0x80,0x03,0x80,0x03,0x80,0x03,0x80,0x03,0x80,0x0F,0xE0,0x00,0x00,0x00,0x00, // I 0x00,0x00,0x00,0x00,0x01,0xFC,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00 ,0x70,0x38,0x70,0x38,0x70,0x38,0x70,0x38,0x70,0x0F,0xE0,0x00,0x00,0x00,0x00, // J 0x00,0x00,0x00,0x00,0x1E,0x38,0x0E,0x38,0x0E,0x70,0x0E,0xE0,0x0F,0xC0,0x0F,0x80,0x0F ,0x80,0x0F,0xC0,0x0E,0xE0,0x0E,0x70,0x0E,0x38,0x1E,0x38,0x00,0x00,0x00,0x00, // K 170 0x00,0x00,0x00,0x00,0x1F,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E ,0x00,0x0E,0x00,0x0E,0x08,0x0E,0x18,0x0E,0x38,0x1F,0xF8,0x00,0x00,0x00,0x00, // L 0x00,0x00,0x00,0x00,0x1C,0x1C,0x1E,0x3C,0x1F,0x7C,0x1F,0xFC,0x1F,0xFC,0x1D,0xDC,0x1C ,0x9C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x00,0x00,0x00,0x00, // M 0x00,0x00,0x00,0x00,0x1C,0x1C,0x1C,0x1C,0x1E,0x1C,0x1F,0x1C,0x1F,0x9C,0x1D,0xDC,0x1C ,0xFC,0x1C,0x7C,0x1C,0x3C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x00,0x00,0x00,0x00, // N 0x00,0x00,0x00,0x00,0x03,0xE0,0x07,0xF0,0x0E,0x38,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C ,0x1C,0x1C,0x1C,0x1C,0x1C,0x0E,0x38,0x07,0xF0,0x03,0xE0,0x00,0x00,0x00,0x00, // O 175 0x00,0x00,0x00,0x00,0x1F,0xF0,0x0E,0x38,0x0E,0x38,0x0E,0x38,0x0E,0x38,0x0F,0xF0,0x0F ,0xF0,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x1F,0x00,0x00,0x00,0x00,0x00, // P 0x00,0x00,0x00,0x00,0x03,0xE0,0x0F,0x78,0x0E,0x38,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C ,0x1C,0x1C,0x7C,0x1C,0xFC,0x0F,0xF8,0x0F,0xF8,0x00,0x38,0x00,0xFC,0x00,0x00, // Q 0x00,0x00,0x00,0x00,0x1F,0xF0,0x0E,0x38,0x0E,0x38,0x0E,0x38,0x0E,0x38,0x0F,0xF0,0x0F ,0xF0,0x0E,0x70,0x0E,0x38,0x0E,0x38,0x0E,0x38,0x1E,0x38,0x00,0x00,0x00,0x00, // R 0x00,0x00,0x00,0x00,0x0F,0xF0,0x1C,0x38,0x1C,0x38,0x1C,0x38,0x1C,0x00,0x0F,0xE0,0x07 ,0xF0,0x00,0x38,0x1C,0x38,0x1C,0x38,0x1C,0x38,0x0F,0xF0,0x00,0x00,0x00,0x00, // S 120
0x00,0x00,0x00,0x00,0x1F,0xFC,0x19,0xCC,0x11,0xC4,0x01,0xC0,0x01,0xC0,0x01,0xC0,0x01 ,0xC0,0x01,0xC0,0x01,0xC0,0x01,0xC0,0x01,0xC0,0x07,0xF0,0x00,0x00,0x00,0x00, // T 180 0x00,0x00,0x00,0x00,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C ,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x0F,0xE0,0x00,0x00,0x00,0x00, // U 0x00,0x00,0x00,0x00,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C ,0x70,0x1C,0x70,0x1C,0x70,0x0E,0xE0,0x07,0xC0,0x03,0x80,0x00,0x00,0x00,0x00, // V 0x00,0x00,0x00,0x00,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x9C,0x1C ,0x9C,0x1C,0x9C,0x0F,0xF8,0x0F,0xF8,0x07,0x70,0x07,0x70,0x00,0x00,0x00,0x00, // W 0x00,0x00,0x00,0x00,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x0E,0xE0,0x07,0xC0,0x03,0x80,0x03 ,0x80,0x07,0xC0,0x0E,0xE0,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x00,0x00,0x00,0x00, // X 0x00,0x00,0x00,0x00,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x0E,0xE0,0x07 ,0xC0,0x03,0x80,0x03,0x80,0x03,0x80,0x03,0x80,0x0F,0xE0,0x00,0x00,0x00,0x00, // Y 185 0x00,0x00,0x00,0x00,0x1F,0xF8,0x1C,0x38,0x18,0x38,0x10,0x70,0x00,0xE0,0x01,0xC0,0x03 ,0x80,0x07,0x00,0x0E,0x08,0x1C,0x18,0x1C,0x38,0x1F,0xF8,0x00,0x00,0x00,0x00, // Z 0x00,0x00,0x00,0x00,0x07,0xF0,0x07,0x00,0x07,0x00,0x07,0x00,0x07,0x00,0x07,0x00,0x07 ,0x00,0x07,0x00,0x07,0x00,0x07,0x00,0x07,0x00,0x07,0xF0,0x00,0x00,0x00,0x00, // [ 0x00,0x00,0x00,0x00,0x10,0x00,0x18,0x00,0x1C,0x00,0x0E,0x00,0x07,0x00,0x03,0x80,0x01 ,0xC0,0x00,0xE0,0x00,0x70,0x00,0x38,0x00,0x1C,0x00,0x07,0x00,0x00,0x00,0x00, // <Backslash> 0x00,0x00,0x00,0x00,0x07,0xF0,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00 ,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x07,0xF0,0x00,0x00,0x00,0x00, // ] 0x00,0x00,0x01,0x80,0x03,0xC0,0x07,0xE0,0x0E,0x70,0x1C,0x38,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // ^ 190 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFF,0x7F,0xFF, // _ 0x00,0x00,0x00,0x00,0x1C,0x00,0x1C,0x00,0x07,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // ' 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xE0,0x00,0x70,0x00 ,0x70,0x0F,0xF0,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x0F,0xD8,0x00,0x00,0x00,0x00, // a 0x00,0x00,0x00,0x00,0x1E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0F,0xF0,0x0E,0x38,0x0E ,0x38,0x0E,0x38,0x0E,0x38,0x0E,0x38,0x0E,0x38,0x1B,0xF0,0x00,0x00,0x00,0x00, // b 195 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xE0,0x1C,0x70,0x1C ,0x70,0x1C,0x00,0x1C,0x00,0x1C,0x70,0x1C,0x70,0x0F,0xE0,0x00,0x00,0x00,0x00, // c 0x00,0x00,0x00,0x00,0x00,0xF8,0x00,0x70,0x00,0x70,0x00,0x70,0x0F,0xF0,0x1C,0x70,0x1C ,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x0F,0xD8,0x00,0x00,0x00,0x00, // d 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xE0,0x1C,0x70,0x1C ,0x70,0x1F,0xF0,0x1C,0x00,0x1C,0x70,0x1C,0x70,0x0F,0xE0,0x00,0x00,0x00,0x00, // e 0x00,0x00,0x00,0x00,0x03,0xE0,0x07,0x70,0x07,0x70,0x07,0x00,0x07,0x00,0x1F,0xE0,0x1F ,0xE0,0x07,0x00,0x07,0x00,0x07,0x00,0x07,0x00,0x1F,0xC0,0x00,0x00,0x00,0x00, // 121
f 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xD8,0x1C,0x70,0x1C ,0x70,0x1C,0x70,0x1C,0x70,0x0F,0xF0,0x07,0xF0,0x00,0x70,0x1C,0x70,0x0F,0xE0, // g 200 0x00,0x00,0x00,0x00,0x1E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0xF0,0x0F,0x38,0x0F ,0x38,0x0E,0x38,0x0E,0x38,0x0E,0x38,0x0E,0x38,0x1E,0x38,0x00,0x00,0x00,0x00, // h 0x00,0x00,0x00,0x00,0x01,0xC0,0x01,0xC0,0x01,0xC0,0x00,0x00,0x0F,0xC0,0x01,0xC0,0x01 ,0xC0,0x01,0xC0,0x01,0xC0,0x01,0xC0,0x01,0xC0,0x0F,0xF8,0x00,0x00,0x00,0x00, // i 0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x00,0x03,0xF0,0x00,0x70,0x00 ,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x1C,0x70,0x0C,0xF0,0x07,0xE0, // j 0x00,0x00,0x00,0x00,0x1E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x38,0x0E,0x70,0x0E ,0xE0,0x0F,0xC0,0x0E,0xE0,0x0E,0x70,0x0E,0x38,0x1E,0x38,0x00,0x00,0x00,0x00, // k 0x00,0x00,0x00,0x00,0x0F,0xC0,0x01,0xC0,0x01,0xC0,0x01,0xC0,0x01,0xC0,0x01,0xC0,0x01 ,0xC0,0x01,0xC0,0x01,0xC0,0x01,0xC0,0x01,0xC0,0x0F,0xF8,0x00,0x00,0x00,0x00, // l 205 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xF8,0x1C,0x9C,0x1C ,0x9C,0x1C,0x9C,0x1C,0x9C,0x1C,0x9C,0x1C,0x9C,0x1C,0x9C,0x00,0x00,0x00,0x00, // m 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xE0,0x1C,0x70,0x1C ,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x00,0x00,0x00,0x00, // n 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xE0,0x1C,0x70,0x1C ,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x0F,0xE0,0x00,0x00,0x00,0x00, // o 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1B,0xF0,0x0E,0x38,0x0E ,0x38,0x0E,0x38,0x0E,0x38,0x0E,0x38,0x0F,0xF0,0x0E,0x00,0x0E,0x00,0x1F,0x00, // p 210 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xB0,0x38,0xE0,0x38 ,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x1F,0xE0,0x00,0xE0,0x00,0xE0,0x01,0xF0, // q 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1E,0xF0,0x0F,0xF8,0x0F ,0x38,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x1F,0x00,0x00,0x00,0x00,0x00, // r 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xE0,0x1C,0x30,0x1C ,0x30,0x0F,0x80,0x03,0xE0,0x18,0x70,0x18,0x70,0x0F,0xE0,0x00,0x00,0x00,0x00, // s 0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x03,0x00,0x07,0x00,0x1F,0xF0,0x07,0x00,0x07 ,0x00,0x07,0x00,0x07,0x00,0x07,0x70,0x07,0x70,0x03,0xE0,0x00,0x00,0x00,0x00, // t 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x70,0x1C,0x70,0x1C ,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x0F,0xD8,0x00,0x00,0x00,0x00, // u 215 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x70,0x1C,0x70,0x1C ,0x70,0x1C,0x70,0x1C,0x70,0x0E,0xE0,0x07,0xC0,0x03,0x80,0x00,0x00,0x00,0x00, // v 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x1C,0x1C,0x1C,0x1C ,0x1C,0x1C,0x9C,0x1C,0x9C,0x0F,0xF8,0x07,0x70,0x07,0x70,0x00,0x00,0x00,0x00, // w 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0xE0,0x1C,0xE0,0x0F ,0xC0,0x07,0x80,0x07,0x80,0x0F,0xC0,0x1C,0xE0,0x1C,0xE0,0x00,0x00,0x00,0x00, // x 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x38,0x0E,0x38,0x0E 122
,0x38,0x0E,0x38,0x0E,0x38,0x07,0xF0,0x03,0xE0,0x00,0xE0,0x01,0xC0,0x1F,0x80, // y 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xE0,0x18,0xE0,0x11 ,0xC0,0x03,0x80,0x07,0x00,0x0E,0x20,0x1C,0x60,0x1F,0xE0,0x00,0x00,0x00,0x00, // z 220 0x00,0x00,0x00,0x00,0x01,0xF8,0x03,0x80,0x03,0x80,0x03,0x80,0x07,0x00,0x1C,0x00,0x1C ,0x00,0x07,0x00,0x03,0x80,0x03,0x80,0x03,0x80,0x01,0xF8,0x00,0x00,0x00,0x00, // { 0x00,0x00,0x01,0xC0,0x01,0xC0,0x01,0xC0,0x01,0xC0,0x01,0xC0,0x01,0xC0,0x01,0xC0,0x01 ,0xC0,0x01,0xC0,0x01,0xC0,0x01,0xC0,0x01,0xC0,0x01,0xC0,0x01,0xC0,0x00,0x00, // | 0x00,0x00,0x00,0x00,0x1F,0x80,0x01,0xC0,0x01,0xC0,0x01,0xC0,0x00,0xE0,0x00,0x38,0x00 ,0x38,0x00,0xE0,0x01,0xC0,0x01,0xC0,0x01,0xC0,0x1F,0x80,0x00,0x00,0x00,0x00, // } 0x00,0x00,0x00,0x00,0x1F,0x1C,0x3B,0x9C,0x39,0xDC,0x38,0xF8,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 // ~ }; 225 // SevenSegNumFont.c // Font Size : 32x50 // Memory usage : 2004 bytes // # characters : 10 230 // fontdatatype SevenSegNumFont[2004] PROGMEM={ // 0x20,0x32,0x30,0x0A, // 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFE,0x00,0x01,0xFF,0xFF,0x00,0 x03,0xFF,0xFF,0x80,0x01,0xFF,0xFF,0x60,0x0C,0xFF,0xFE,0xF0,0x1E,0x00,0x01,0xF8,0 x3F,0x00,0x01,0xF8,0x3F,0x00,0x01,0xF8,0x3F,0x00,0x01,0xF8,0x3F,0x00,0x01,0xF8,0 x3F,0x00,0x01,0xF8,0x3F,0x00,0x01,0xF8,0x3F,0x00,0x01,0xF8,0x3F,0x00,0x01,0xF8,0 x3F,0x00,0x01,0xF8,0x3F,0x00,0x01,0xF8,0x3F,0x00,0x01,0xF8,0x3F,0x00,0x01,0xF8,0 x3F,0x00,0x01,0xF8,0x3E,0x00,0x00,0x78,0x38,0x00,0x00,0x18,0x20,0x00,0x00,0x08,0 x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x38,0x00,0x00,0x18,0x3E,0x00,0x00,0x78,0 x3F,0x00,0x01,0xF8,0x3F,0x00,0x01,0xF8,0x3F,0x00,0x01,0xF8,0x3F,0x00,0x01,0xF8,0 x3F,0x00,0x01,0xF8,0x3F,0x00,0x01,0xF8,0x3F,0x00,0x01,0xF8,0x3F,0x00,0x01,0xF8,0 x3F,0x00,0x01,0xF8,0x3F,0x00,0x01,0xF8,0x3F,0x00,0x01,0xF8,0x3F,0x00,0x01,0xF8,0 x3F,0x00,0x01,0xF8,0x3F,0x00,0x01,0xF8,0x1E,0x00,0x00,0xF0,0x0C,0xFF,0xFE,0x60,0 x01,0xFF,0xFF,0x00,0x03,0xFF,0xFF,0x80,0x01,0xFF,0xFF,0x00,0x00,0xFF,0xFE,0x00,0 x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0 // 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0 x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0xF0,0x00,0x00,0x01,0xF8,0 x00,0x00,0x01,0xF8,0x00,0x00,0x01,0xF8,0x00,0x00,0x01,0xF8,0x00,0x00,0x01,0xF8,0 x00,0x00,0x01,0xF8,0x00,0x00,0x01,0xF8,0x00,0x00,0x01,0xF8,0x00,0x00,0x01,0xF8,0 x00,0x00,0x01,0xF8,0x00,0x00,0x01,0xF8,0x00,0x00,0x01,0xF8,0x00,0x00,0x01,0xF8,0 x00,0x00,0x01,0xF8,0x00,0x00,0x00,0x78,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x08,0 x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x78,0 x00,0x00,0x01,0xF8,0x00,0x00,0x01,0xF8,0x00,0x00,0x01,0xF8,0x00,0x00,0x01,0xF8,0 x00,0x00,0x01,0xF8,0x00,0x00,0x01,0xF8,0x00,0x00,0x01,0xF8,0x00,0x00,0x01,0xF8,0 x00,0x00,0x01,0xF8,0x00,0x00,0x01,0xF8,0x00,0x00,0x01,0xF8,0x00,0x00,0x01,0xF8,0 x00,0x00,0x01,0xF8,0x00,0x00,0x01,0xF8,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x60,0 x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0 x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 1 235 // 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFE,0x00,0x01,0xFF,0xFF,0x00,0 x03,0xFF,0xFF,0x80,0x01,0xFF,0xFF,0x60,0x00,0xFF,0xFE,0xF0,0x00,0x00,0x01,0xF8,0 x00,0x00,0x01,0xF8,0x00,0x00,0x01,0xF8,0x00,0x00,0x01,0xF8,0x00,0x00,0x01,0xF8,0 x00,0x00,0x01,0xF8,0x00,0x00,0x01,0xF8,0x00,0x00,0x01,0xF8,0x00,0x00,0x01,0xF8,0 x00,0x00,0x01,0xF8,0x00,0x00,0x01,0xF8,0x00,0x00,0x01,0xF8,0x00,0x00,0x01,0xF8,0 123
lib/initialization.c 0#include "initialization.h" #include "system.h" void init_io_config() { 5#ifdef REAL_SYSTEM SCS = 1; // Enable FAST GPIO #endif FIODIR = 0b11111111111111111011110111011101; 10 FIOSET = 0xFFFFFFFF; PINSEL0 = 0x20051505; PINSEL1 = 0x00000000; 15 EXTMODE = (1<<1); EXTPOLAR = (0<<1); EXTINT = (1<<1); FIOCLR = (1<<7); 20 } void init_external_interrupt() { VICIntEnable |= (1<<15); 25 VICVectAddr0=(unsigned int)IRQ_Button_Routine; VICVectCntl0=(1<<5)|15; } void init_spurious_interrupt() 30 { VICDefVectAddr=(unsigned int)IRQ_Spurious_Routine; VICVectAddr=−1; } 130
lib/integer.h 0/* *File: integer.h *Author: Nelson Lombardo *Year: 2015 *e−mail: [email protected] 5*License at the end of file. */ /*****************************************************************************/ /*Integer type definitions */ 10 /*****************************************************************************/ #ifndef _INTEGER_H_ #define _INTEGER_H_ #include <stdint.h> 15 /*16−bit, 32−bit or larger integer */ typedef int16_t INT; typedef uint16_t UINT; 20 /*8−bit integer */ typedef int8_t CHAR; typedef uint8_t UCHAR; typedef uint8_t BYTE; typedef uint8_t BOOL; 25 /*16−bit integer */ typedef int16_t SHORT; typedef uint16_t USHORT; typedef uint16_t WORD; 30 typedef uint16_t WCHAR; /*32−bit integer */ typedef int32_t LONG; typedef uint32_t ULONG; 35 typedef uint32_t DWORD; /*Boolean type */ typedef enum { FALSE = 0, TRUE } BOOLEAN; typedef enum { LOW = 0, HIGH } THROTTLE; 40 #endif // ´ ninteger.hÂ˙ z is part of: /* −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−/ 45 / ulibSD −Library for SD cards semantics (C)Nelson Lombardo, 2015 /−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−/ / ulibSD library is a free software that opened under license policy of / following conditions. / 50 / Copyright (C) 2015, ChaN, all right reserved. / / 1. Redistributions of source code must retain the above copyright notice, / this condition and the following disclaimer. / 131
55 / This software is provided by the copyright holder and contributors "AS IS" / and any warranties related to this software are DISCLAIMED. / The copyright owner or contributors be NOT LIABLE for any damages caused / by use of this software. /−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− */ 60 // Derived from Mister Chan works on FatFs code (http://elm−chan.org/fsw/ff/00 index_e.html): /* −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−/ / FatFs −FAT file system module R0.11 (C)ChaN, 2015 /−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−/ 65 / FatFs module is a free software that opened under license policy of / following conditions. / / Copyright (C) 2015, ChaN, all right reserved. / 70 / 1. Redistributions of source code must retain the above copyright notice, / this condition and the following disclaimer. / / This software is provided by the copyright holder and contributors "AS IS" / and any warranties related to this software are DISCLAIMED. 75 / The copyright owner or contributors be NOT LIABLE for any damages caused / by use of this software. /−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− */ 132
lib/lpc2106.h 0/***********************************************************************/ /* */ /*LPC2103.H: Header file for Philips LPC2101 / LPC2102 / LPC2103 */ /* */ /***********************************************************************/ 5 #ifndef __LPC2103_H #define __LPC2103_H /*Vectored Interrupt Controller (VIC) */ 10 #define VICIRQStatus (*((volatile unsigned long *) 0xFFFFF000)) #define VICFIQStatus (*((volatile unsigned long *) 0xFFFFF004)) #define VICRawIntr (*((volatile unsigned long *) 0xFFFFF008)) #define VICIntSelect (*((volatile unsigned long *) 0xFFFFF00C)) #define VICIntEnable (*((volatile unsigned long *) 0xFFFFF010)) 15 #define VICIntEnClr (*((volatile unsigned long *) 0xFFFFF014)) #define VICSoftInt (*((volatile unsigned long *) 0xFFFFF018)) #define VICSoftIntClr (*((volatile unsigned long *) 0xFFFFF01C)) #define VICProtection (*((volatile unsigned long *) 0xFFFFF020)) #define VICVectAddr (*((volatile unsigned long *) 0xFFFFF030)) 20 #define VICDefVectAddr (*((volatile unsigned long *) 0xFFFFF034)) #define VICVectAddr0 (*((volatile unsigned long *) 0xFFFFF100)) #define VICVectAddr1 (*((volatile unsigned long *) 0xFFFFF104)) #define VICVectAddr2 (*((volatile unsigned long *) 0xFFFFF108)) #define VICVectAddr3 (*((volatile unsigned long *) 0xFFFFF10C)) 25 #define VICVectAddr4 (*((volatile unsigned long *) 0xFFFFF110)) #define VICVectAddr5 (*((volatile unsigned long *) 0xFFFFF114)) #define VICVectAddr6 (*((volatile unsigned long *) 0xFFFFF118)) #define VICVectAddr7 (*((volatile unsigned long *) 0xFFFFF11C)) #define VICVectAddr8 (*((volatile unsigned long *) 0xFFFFF120)) 30 #define VICVectAddr9 (*((volatile unsigned long *) 0xFFFFF124)) #define VICVectAddr10 (*((volatile unsigned long *) 0xFFFFF128)) #define VICVectAddr11 (*((volatile unsigned long *) 0xFFFFF12C)) #define VICVectAddr12 (*((volatile unsigned long *) 0xFFFFF130)) #define VICVectAddr13 (*((volatile unsigned long *) 0xFFFFF134)) 35 #define VICVectAddr14 (*((volatile unsigned long *) 0xFFFFF138)) #define VICVectAddr15 (*((volatile unsigned long *) 0xFFFFF13C)) #define VICVectCntl0 (*((volatile unsigned long *) 0xFFFFF200)) #define VICVectCntl1 (*((volatile unsigned long *) 0xFFFFF204)) #define VICVectCntl2 (*((volatile unsigned long *) 0xFFFFF208)) 40 #define VICVectCntl3 (*((volatile unsigned long *) 0xFFFFF20C)) #define VICVectCntl4 (*((volatile unsigned long *) 0xFFFFF210)) #define VICVectCntl5 (*((volatile unsigned long *) 0xFFFFF214)) #define VICVectCntl6 (*((volatile unsigned long *) 0xFFFFF218)) #define VICVectCntl7 (*((volatile unsigned long *) 0xFFFFF21C)) 45 #define VICVectCntl8 (*((volatile unsigned long *) 0xFFFFF220)) #define VICVectCntl9 (*((volatile unsigned long *) 0xFFFFF224)) #define VICVectCntl10 (*((volatile unsigned long *) 0xFFFFF228)) #define VICVectCntl11 (*((volatile unsigned long *) 0xFFFFF22C)) #define VICVectCntl12 (*((volatile unsigned long *) 0xFFFFF230)) 50 #define VICVectCntl13 (*((volatile unsigned long *) 0xFFFFF234)) #define VICVectCntl14 (*((volatile unsigned long *) 0xFFFFF238)) #define VICVectCntl15 (*((volatile unsigned long *) 0xFFFFF23C)) /*Pin Connect Block */ 133
55 #define PINSEL0 (*((volatile unsigned long *) 0xE002C000)) #define PINSEL1 (*((volatile unsigned long *) 0xE002C004)) /*General Purpose Input/Output (GPIO) */ #define IOPIN (*((volatile unsigned long *) 0xE0028000)) 60 #define IOSET (*((volatile unsigned long *) 0xE0028004)) #define IODIR (*((volatile unsigned long *) 0xE0028008)) #define IOCLR (*((volatile unsigned long *) 0xE002800C)) /*Fast General Purpose Input/Output (GPIO) */ 65 #define FIODIR (*((volatile unsigned long *) 0x3FFFC000)) #define FIOMASK (*((volatile unsigned long *) 0x3FFFC010)) #define FIOPIN (*((volatile unsigned long *) 0x3FFFC014)) #define FIOSET (*((volatile unsigned long *) 0x3FFFC018)) #define FIOCLR (*((volatile unsigned long *) 0x3FFFC01C)) 70 /*Memory Accelerator Module (MAM) */ #define MAMCR (*((volatile unsigned char *) 0xE01FC000)) #define MAMTIM (*((volatile unsigned char *) 0xE01FC004)) #define MEMMAP (*((volatile unsigned char *) 0xE01FC040)) 75 /*Phase Locked Loop (PLL) */ #define PLLCON (*((volatile unsigned char *) 0xE01FC080)) #define PLLCFG (*((volatile unsigned char *) 0xE01FC084)) #define PLLSTAT (*((volatile unsigned long *) 0xE01FC088)) 80 #define PLLFEED (*((volatile unsigned char *) 0xE01FC08C)) /*APB Divider */ #define APBDIV (*((volatile unsigned char *) 0xE01FC100)) 85 /*Power Control */ #define PCON (*((volatile unsigned char *) 0xE01FC0C0)) #define PCONP (*((volatile unsigned long *) 0xE01FC0C4)) /*External Interrupts */ 90 #define EXTINT (*((volatile unsigned char *) 0xE01FC140)) #define EXTWAKE (*((volatile unsigned char *) 0xE01FC144)) #define EXTMODE (*((volatile unsigned char *) 0xE01FC148)) #define EXTPOLAR (*((volatile unsigned char *) 0xE01FC14C)) 95 /*Timer 0 */ #define T0IR (*((volatile unsigned char *) 0xE0004000)) #define T0TCR (*((volatile unsigned char *) 0xE0004004)) #define T0TC (*((volatile unsigned long *) 0xE0004008)) #define T0PR (*((volatile unsigned long *) 0xE000400C)) 100 #define T0PC (*((volatile unsigned long *) 0xE0004010)) #define T0MCR (*((volatile unsigned long *) 0xE0004014)) #define T0MR0 (*((volatile unsigned long *) 0xE0004018)) #define T0MR1 (*((volatile unsigned long *) 0xE000401C)) #define T0MR2 (*((volatile unsigned long *) 0xE0004020)) 105 #define T0MR3 (*((volatile unsigned long *) 0xE0004024)) #define T0CCR (*((volatile unsigned long *) 0xE0004028)) #define T0CR0 (*((volatile unsigned long *) 0xE000402C)) #define T0CR1 (*((volatile unsigned long *) 0xE0004030)) #define T0CR2 (*((volatile unsigned long *) 0xE0004034)) 110 #define T0CR3 (*((volatile unsigned long *) 0xE0004038)) #define T0EMR (*((volatile unsigned long *) 0xE000403C)) 134
#define T0CTCR (*((volatile unsigned char *) 0xE0004070)) #define T0PWMCON (*((volatile unsigned long *) 0xE0004074)) 115 /*Timer 1 */ #define T1IR (*((volatile unsigned char *) 0xE0008000)) #define T1TCR (*((volatile unsigned char *) 0xE0008004)) #define T1TC (*((volatile unsigned long *) 0xE0008008)) #define T1PR (*((volatile unsigned long *) 0xE000800C)) 120 #define T1PC (*((volatile unsigned long *) 0xE0008010)) #define T1MCR (*((volatile unsigned long *) 0xE0008014)) #define T1MR0 (*((volatile unsigned long *) 0xE0008018)) #define T1MR1 (*((volatile unsigned long *) 0xE000801C)) #define T1MR2 (*((volatile unsigned long *) 0xE0008020)) 125 #define T1MR3 (*((volatile unsigned long *) 0xE0008024)) #define T1CCR (*((volatile unsigned long *) 0xE0008028)) #define T1CR0 (*((volatile unsigned long *) 0xE000802C)) #define T1CR1 (*((volatile unsigned long *) 0xE0008030)) #define T1CR2 (*((volatile unsigned long *) 0xE0008034)) 130 #define T1CR3 (*((volatile unsigned long *) 0xE0008038)) #define T1EMR (*((volatile unsigned long *) 0xE000803C)) #define T1CTCR (*((volatile unsigned char *) 0xE0008070)) #define T1PWMCON (*((volatile unsigned long *) 0xE0008074)) 135 /*Universal Asynchronous Receiver Transmitter 0 (UART0) */ #define U0RBR (*((volatile unsigned char *) 0xE000C000)) #define U0THR (*((volatile unsigned char *) 0xE000C000)) #define U0IER (*((volatile unsigned long *) 0xE000C004)) #define U0IIR (*((volatile unsigned long *) 0xE000C008)) 140 #define U0FCR (*((volatile unsigned char *) 0xE000C008)) #define U0LCR (*((volatile unsigned char *) 0xE000C00C)) #define U0LSR (*((volatile unsigned char *) 0xE000C014)) #define U0SCR (*((volatile unsigned char *) 0xE000C01C)) 145 #define U0DLL (*((volatile unsigned char *) 0xE000C000)) #define U0DLM (*((volatile unsigned char *) 0xE000C004)) #define U0ACR (*((volatile unsigned long *) 0xE000C020)) #define U0FDR (*((volatile unsigned long *) 0xE000C028)) #define U0TER (*((volatile unsigned char *) 0xE000C030)) 150 /*Universal Asynchronous Receiver Transmitter 1 (UART1) */ #define U1RBR (*((volatile unsigned char *) 0xE0010000)) #define U1THR (*((volatile unsigned char *) 0xE0010000)) #define U1IER (*((volatile unsigned long *) 0xE0010004)) 155 #define U1IIR (*((volatile unsigned long *) 0xE0010008)) #define U1FCR (*((volatile unsigned char *) 0xE0010008)) #define U1LCR (*((volatile unsigned char *) 0xE001000C)) #define U1MCR (*((volatile unsigned char *) 0xE0010010)) #define U1LSR (*((volatile unsigned char *) 0xE0010014)) 160 #define U1MSR (*((volatile unsigned char *) 0xE0010018)) #define U1SCR (*((volatile unsigned char *) 0xE001001C)) #define U1DLL (*((volatile unsigned char *) 0xE0010000)) #define U1DLM (*((volatile unsigned char *) 0xE0010004)) #define U1ACR (*((volatile unsigned long *) 0xE0010020)) 165 #define U1FDR (*((volatile unsigned long *) 0xE0010028)) #define U1TER (*((volatile unsigned char *) 0xE0010030)) /*Inter−Integrated Circuit interface 0 (I2C0) */ 135
#define I2C0CONSET (*((volatile unsigned char *) 0xE001C000)) 170 #define I2C0STAT (*((volatile unsigned char *) 0xE001C004)) #define I2C0DAT (*((volatile unsigned char *) 0xE001C008)) #define I2C0ADR (*((volatile unsigned char *) 0xE001C00C)) #define I2C0SCLH (*((volatile unsigned long *) 0xE001C010)) #define I2C0SCLL (*((volatile unsigned long *) 0xE001C014)) 175 #define I2C0CONCLR (*((volatile unsigned char *) 0xE001C018)) /*Serial Peripheral Interface 0 (SPI0) */ #define S0SPCR (*((volatile unsigned long *) 0xE0020000)) #define S0SPSR (*((volatile unsigned char *) 0xE0020004)) 180 #define S0SPDR (*((volatile unsigned long *) 0xE0020008)) #define S0SPCCR (*((volatile unsigned char *) 0xE002000C)) #define S0SPINT (*((volatile unsigned char *) 0xE002001C)) /*Real Time Clock (RTC) */ 185 #define ILR (*((volatile unsigned char *) 0xE0024000)) #define CTC (*((volatile unsigned long *) 0xE0024004)) #define CCR (*((volatile unsigned char *) 0xE0024008)) #define CIIR (*((volatile unsigned char *) 0xE002400C)) #define AMR (*((volatile unsigned char *) 0xE0024010)) 190 #define CTIME0 (*((volatile unsigned long *) 0xE0024014)) #define CTIME1 (*((volatile unsigned long *) 0xE0024018)) #define CTIME2 (*((volatile unsigned long *) 0xE002401C)) #define SEC (*((volatile unsigned char *) 0xE0024020)) #define MIN (*((volatile unsigned char *) 0xE0024024)) 195 #define HOUR (*((volatile unsigned char *) 0xE0024028)) #define DOM (*((volatile unsigned char *) 0xE002402C)) #define DOW (*((volatile unsigned char *) 0xE0024030)) #define DOY (*((volatile unsigned long *) 0xE0024034)) #define MONTH (*((volatile unsigned char *) 0xE0024038)) 200 #define YEAR (*((volatile unsigned long *) 0xE002403C)) #define ALSEC (*((volatile unsigned char *) 0xE0024060)) #define ALMIN (*((volatile unsigned char *) 0xE0024064)) #define ALHOUR (*((volatile unsigned char *) 0xE0024068)) #define ALDOM (*((volatile unsigned char *) 0xE002406C)) 205 #define ALDOW (*((volatile unsigned char *) 0xE0024070)) #define ALDOY (*((volatile unsigned long *) 0xE0024074)) #define ALMON (*((volatile unsigned char *) 0xE0024078)) #define ALYEAR (*((volatile unsigned long *) 0xE002407C)) #define PREINT (*((volatile unsigned long *) 0xE0024080)) 210 #define PREFRAC (*((volatile unsigned long *) 0xE0024084)) /*Analog/Digital Converter (ADC) */ #define ADCR (*((volatile unsigned long *) 0xE0034000)) #define ADGDR (*((volatile unsigned long *) 0xE0034004)) 215 #define ADINTEN (*((volatile unsigned long *) 0xE003400C)) #define ADDR0 (*((volatile unsigned long *) 0xE0034010)) #define ADDR1 (*((volatile unsigned long *) 0xE0034014)) #define ADDR2 (*((volatile unsigned long *) 0xE0034018)) #define ADDR3 (*((volatile unsigned long *) 0xE003401C)) 220 #define ADDR4 (*((volatile unsigned long *) 0xE0034020)) #define ADDR5 (*((volatile unsigned long *) 0xE0034024)) #define ADDR6 (*((volatile unsigned long *) 0xE0034028)) #define ADDR7 (*((volatile unsigned long *) 0xE003402C)) #define ADSTAT (*((volatile unsigned long *) 0xE0034030)) 225 136
/*Inter−Integrated Circuit interface 1 (I2C1) */ #define I2C1CONSET (*((volatile unsigned char *) 0xE005C000)) #define I2C1STAT (*((volatile unsigned char *) 0xE005C004)) #define I2C1DAT (*((volatile unsigned char *) 0xE005C008)) 230 #define I2C1ADR (*((volatile unsigned char *) 0xE005C00C)) #define I2C1SCLH (*((volatile unsigned long*) 0xE005C010)) #define I2C1SCLL (*((volatile unsigned long*) 0xE005C014)) #define I2C1CONCLR (*((volatile unsigned char *) 0xE005C018)) 235 /*Synchronous Serial Port interface (SSP) (Direcciones MAL) #define SSPCR0 (*((volatile unsigned long *) 0xE0068000)) #define SSPCR1 (*((volatile unsigned char *) 0xE0068004)) #define SSPDR (*((volatile unsigned long *) 0xE0068008)) #define SSPSR (*((volatile unsigned char *) 0xE006800C)) 240 #define SSPCPSR (*((volatile unsigned char *) 0xE0068010)) #define SSPIMSC (*((volatile unsigned char *) 0xE0068014)) #define SSPRIS (*((volatile unsigned char *) 0xE0068018)) #define SSPMIS (*((volatile unsigned char *) 0xE006801C)) #define SSPICR (*((volatile unsigned char *) 0xE0068020)) 245 *//*Synchronous Serial Port interface (SSP) */ //0xE005C000 #define SSPCR0 (*((volatile unsigned long *) 0xE005C000)) #define SSPCR1 (*((volatile unsigned char *) 0xE005C004)) #define SSPDR (*((volatile unsigned long *) 0xE005C008)) 250 #define SSPSR (*((volatile unsigned char *) 0xE005C00C)) #define SSPCPSR (*((volatile unsigned char *) 0xE005C010)) #define SSPIMSC (*((volatile unsigned char *) 0xE005C014)) #define SSPRIS (*((volatile unsigned char *) 0xE005C018)) #define SSPMIS (*((volatile unsigned char *) 0xE005C01C)) 255 #define SSPICR (*((volatile unsigned char *) 0xE005C020)) /*Timer 2 */ #define T2IR (*((volatile unsigned char *) 0xE0070000)) #define T2TCR (*((volatile unsigned char *) 0xE0070004)) 260 #define T2TC (*((volatile unsigned long *) 0xE0070008)) #define T2PR (*((volatile unsigned long *) 0xE007000C)) #define T2PC (*((volatile unsigned long *) 0xE0070010)) #define T2MCR (*((volatile unsigned long *) 0xE0070014)) #define T2MR0 (*((volatile unsigned long *) 0xE0070018)) 265 #define T2MR1 (*((volatile unsigned long *) 0xE007001C)) #define T2MR2 (*((volatile unsigned long *) 0xE0070020)) #define T2MR3 (*((volatile unsigned long *) 0xE0070024)) #define T2CCR (*((volatile unsigned long *) 0xE0070028)) #define T2CR0 (*((volatile unsigned long *) 0xE007002C)) 270 #define T2CR1 (*((volatile unsigned long *) 0xE0070030)) #define T2CR2 (*((volatile unsigned long *) 0xE0070034)) #define T2EMR (*((volatile unsigned long *) 0xE007003C)) #define T2CTCR (*((volatile unsigned char *) 0xE0070070)) #define T2PWMCON (*((volatile unsigned long *) 0xE0070074)) 275 /*Timer 3 */ #define T3IR (*((volatile unsigned char *) 0xE0074000)) #define T3TCR (*((volatile unsigned char *) 0xE0074004)) #define T3TC (*((volatile unsigned long *) 0xE0074008)) 280 #define T3PR (*((volatile unsigned long *) 0xE007400C)) #define T3PC (*((volatile unsigned long *) 0xE0074010)) #define T3MCR (*((volatile unsigned long *) 0xE0074014)) 137
#define T3MR0 (*((volatile unsigned long *) 0xE0074018)) #define T3MR4 (*((volatile unsigned long *) 0xE007401C)) 285 #define T3MR2 (*((volatile unsigned long *) 0xE0074020)) #define T3MR3 (*((volatile unsigned long *) 0xE0074024)) #define T3CCR (*((volatile unsigned long *) 0xE0074028)) #define T3CR0 (*((volatile unsigned long *) 0xE007402C)) #define T3CR1 (*((volatile unsigned long *) 0xE0074030)) 290 #define T3CR2 (*((volatile unsigned long *) 0xE0074034)) #define T3EMR (*((volatile unsigned long *) 0xE007403C)) #define T3CTCR (*((volatile unsigned char *) 0xE0074070)) #define T3PWMCON (*((volatile unsigned long *) 0xE0074074)) 295 /*Reset Source Identification */ #define RSIR (*((volatile unsigned char *) 0xE01FC180)) /*Code Security Protection */ #define CPSR (*((volatile unsigned long *) 0xE01FC184)) 300 /*Syscon Miscellaneous */ #define SCS (*((volatile unsigned long *) 0xE01FC1A0)) /*Watchdog timer */ 305 #define WDMOD (*((volatile unsigned char *) 0xE0000000)) #define WDTC (*((volatile unsigned long *) 0xE0000004)) #define WDFEED (*((volatile unsigned char *) 0xE0000008)) #define WDTV (*((volatile unsigned long *) 0xE000000C)) 310 #endif // __LPC2103_H 138
lib/mcp23s17.h 0#pragma once #include "system.h" #define MCP_CS (1<<7) 5 #define IODIR_PORTA 0x00 #define IODIR_PORTB 0x4F 10 typedef enum { DATA_OUT_0, DATA_OUT_1, DATA_OUT_2, DATA_OUT_3, 15 DATA_OUT_4, DATA_OUT_5, DATA_OUT_6, DATA_OUT_7, SEL, 20 PE, BUSY, ACK, SELIN, INIT, 25 ERROR, AUTOF } MCPPIN; typedef enum { 30 PORTA, PORTB } MCPPORT; 35 int MCP23S17Read(int address); void MCP23S17Write(int address, int data); void MCPsetIODirCNC(); void MCPSetPort(MCPPORT port, int data); 40 int MCPReadPort(MCPPORT port); #define MCP_CS_L() {FIOSET=MCP_CS;} #define MCP_CS_H() {FIOCLR=MCP_CS;} 45 /*−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− REGISTERS −−−−−−−−−−−−−−−−−−−−−−−−−−−−−− */ #define IODIRA (0x00) 50 #define IODIRB (0x01) #define IPOLA (0x02) #define IPOLB (0x03) #define GPINTENA (0x04) #define GPINTENB (0x05) 139
lib/uart1.c 0#include "uart1.h" char payload[UARTBFRSZ]; volatile char uart1_i, salir, state; volatile char rawLength = 0; 5unsigned int CRC32 = 0; char send_payload[UARTBFRSZ]; #define TOOLFRAMESZ 122 10 char buffer_flag = 0; char uart1_isr_flag = 0; ToolData tool[5]; RouteDrill randd; 15 void __attribute__ ((interrupt("IRQ"))) IRQ_UART1_Routine (void) { char c; 20 while (U1LSR & 1) { c = U1RBR; // _printf("%x ", c); switch(state) 25 { case 0: // Outside frame if(c==SOF) {uart1_i=0; state = 1; }; break; case 1: // Inside frame 30 if(c==ESC) {state = 2; break; }; if(c==SOF) {state = 0; salir = 1; break;}; if(uart1_i == 0) {rawLength = c; uart1_i++;} else{payload[(uart1_i++)−1] = c;}; if (uart1_i >= rawLength+2) {set_buffer_flag(); state = 0;} 35 break; case 2: // Decoding datum if(c==ESC) {payload[(uart1_i++)−1] = ESC; state = 1; break;}; if(c==SOF) {payload[(uart1_i++)−1] = SOF; state = 1; break;}; state = 0; 40 break; } } set_uart1_isr_flag(); 45 VICVectAddr=−1; } int decode_payload(char *buffer) { 50 int i = 0; int k = 0; if (buffer[0] == 0xC3) // Payload contains screen data {// buffer[0]==0xC3? −> after this line 'i' is '1' 242
55 switch (buffer[1]) { case 1: // Config screen break; 60 case 2: // Route−/Drillpro screen setRouteDrill(INTEG(2), INTEG(6), INTEG(10), INTEG(14), INTEG(18), INTEG(22), INTEG(26), INTEG(30), INTEG(34), INTEG(38), INTEG(42), INTEG(46) /*, INTEG(50), INTEG(56)*/); getRouteDrill(); break; 65 case 3: // Tools screen setToolData(INTEG(2+(k*24)), INTEG(6+(k*24)), INTEG(10+(k*24)), INTEG(14+(k*24)), INTEG(18+(k*24)), INTEG(22+(k*24))); k=1;setToolData(INTEG(2+(k*24)), INTEG(6+(k*24)), INTEG(10+(k*24)), INTEG(14+(k*24)), INTEG(18+(k*24)), INTEG(22+(k*24))); k=2;setToolData(INTEG(2+(k*24)), INTEG(6+(k*24)), INTEG(10+(k*24)), INTEG(14+(k*24)), INTEG(18+(k*24)), INTEG(22+(k*24))); 70 k=3;setToolData(INTEG(2+(k*24)), INTEG(6+(k*24)), INTEG(10+(k*24)), INTEG(14+(k*24)), INTEG(18+(k*24)), INTEG(22+(k*24))); k=4;setToolData(INTEG(2+(k*24)), INTEG(6+(k*24)), INTEG(10+(k*24)), INTEG(14+(k*24)), INTEG(18+(k*24)), INTEG(22+(k*24))); getToolData(); 75 break; case 4: // Start screen break; 80 case 5: // Load screen break; case 6: // Offset screen switch (buffer[2]) 85 { case 'L': moveAxis(C_XDEC, (buffer[3] *3937 / 100)); break; case 'B': 90 moveAxis(C_YINC, (buffer[3] *3937 / 100)); break; case 'F': moveAxis(C_YDEC, (buffer[3] *3937 / 100)); break; 95 case 'R': moveAxis(C_XINC, (buffer[3] *3937 / 100)); break; case 'U': moveAxis(C_ZDEC, (buffer[3] *3937 / 100)); 100 break; case 'D': moveAxis(C_ZINC, (buffer[3] *3937 / 100)); break; } 243
105 break; } }else if (buffer[i] == 0xAF) // Payload contains PLT file data { 110 }else if (buffer[i] == 0xA0) // Payload contains NCD file data { }else 115 { return −1; } stateMachine_Init(); } 120 void UART1_Init() { #define UART1IRQ (7) 125 VICVectAddr2 = (unsigned int)IRQ_UART1_Routine; VICVectCntl2 = (1<<5)|UART1IRQ; // Enable vector VICVectAddr=−1; VICIntEnable = (1<<UART1IRQ); // Enable interrupt 130 unsigned char lcr; lcr = 0x03; // 00000011 Line Control Register // .. Character length 11 = 8 bits // . Stop bits 0 = 1 bit // . Parity enable 0 = No parity 135 // . Even parity non sense // . Stick parity non sense // . Break control 0 = No break // . DLAB 0 = No Access to DLM,DLL U1LCR = 0x80 | lcr; // DLAB = 1, Access to DLM,DLL 140 U1DLL = 32; U1DLM = 0; // Baud = 4*14745600/(16*32) = 115200 U1LCR = lcr; // Same a above, but DLAB = 0 = Normal access to RBR/THR & IER U1FCR = 0x07; // 00000111 FIFO Control Register // . FIFO enable 1 = TX&RX FIFOs enabled 145 // . RX FIFO Reset 1 = Reset RX FIFO // . TX FIFO Reset 1 = Reset TX FIFO // .. RX interrupt trigger level 00 = 1 byte U1IER = 1; // Enable the RX line status interrupts } 150 void UART1_putch(char c) { while(!(U1LSR & THR_E)); // while U1LSR.THR_E == 0 155 U1THR = c; } char UART1_getch() 160 { while(!(U1LSR & DR)); // while U1LSR.DR == 0 244
return U1RBR; } 165 void UART1_print(char *s) { int i; i= 0; 170 while(s[i]) UART1_putch(s[i++]); } void UART1_putch_bs(char c) 175 { if(c==SOF) { UART1_putch(ESC); UART1_putch(SOF); 180 } else if(c==ESC) { UART1_putch(ESC); UART1_putch(ESC); 185 } else UART1_putch(c); } 190 void sendFrame(char *s, char len) { int i; char chk = 5; 195 UART1_putch(SOF); _printf("%2x ", SOF); // UART1_putch(len+3); _printf("%2x ", (len+3)); UART1_putch_bs(len); _printf("%2x ", (len)); //frame length 200 for(i=0;i<len; i++) {UART1_putch_bs(s[i]); _printf("%2x ", s[i]);} // chk = CRC8(s, 0x18, 8); // UART1_putch_bs(chk); _printf("%2x", chk); // UART1_putch(SOF); } 205 void stateMachine_Init() { uart1_i = 0; 210 salir = 0; state = 0; clear_buffer_flag(); } 215 void setToolData(unsigned char tool_number, int depth, int iteration, int x_feed, int z_feed, int spindle) { 245
tool[tool_number−1].tool_number = tool_number; tool[tool_number−1].depth = depth; 220 tool[tool_number−1].iteration = iteration; tool[tool_number−1].x_feed = x_feed; tool[tool_number−1].z_feed = z_feed; tool[tool_number−1].spindle = spindle; } 225 void getToolData() { ToolInput1[0].value = tool[0].depth; 230 ToolInput1[1].value = tool[0].iteration; ToolInput1[2].value = tool[0].x_feed; ToolInput1[3].value = tool[0].z_feed; ToolInput1[4].value = tool[0].spindle; 235 ToolInput2[0].value = tool[1].depth; ToolInput2[1].value = tool[1].iteration; ToolInput2[2].value = tool[1].x_feed; ToolInput2[3].value = tool[1].z_feed; ToolInput2[4].value = tool[1].spindle; 240 ToolInput3[0].value = tool[2].depth; ToolInput3[1].value = tool[2].iteration; ToolInput3[2].value = tool[2].x_feed; ToolInput3[3].value = tool[2].z_feed; 245 ToolInput3[4].value = tool[2].spindle; ToolInput4[0].value = tool[3].depth; ToolInput4[1].value = tool[3].iteration; ToolInput4[2].value = tool[3].x_feed; 250 ToolInput4[3].value = tool[3].z_feed; ToolInput4[4].value = tool[3].spindle; ToolInput5[0].value = tool[4].depth; ToolInput5[1].value = tool[4].iteration; 255 ToolInput5[2].value = tool[4].x_feed; ToolInput5[3].value = tool[4].z_feed; ToolInput5[4].value = tool[4].spindle; } 260 void printToolData(unsigned char tool_number) {_printf("−−− Tool %d −−−\ndepth: %7d\niteration: %3d\nx feed: %6d\nz feed: %6d\ nspindle: %5d\n", tool[tool_number−1].tool_number, tool[tool_number−1].depth, tool[tool_number−1].iteration, tool[tool_number−1].x_feed, tool[tool_number−1]. z_feed, tool[tool_number−1].spindle); } 265 void fillPayloadWithTool() { send_payload[0] = 0xC3; send_payload[1] = 3; 270 int i, j, k; char *p; 246
k = 2; for (j = 0; j < 5; j++) 275 { p=(char*)&tool[j]; // sizeof(struct ToolData) = 24 (not 21, because we have 5 ints and one char , there are three bytes padding to fill up the char) for (i=0;i<sizeof(ToolData); i++) { 280 send_payload[k] = p[i]; k++; } } 285 } void setRouteDrill(int x_offset, int x_clip, int x_vectors, int y_offset, int y_clip ,int y_vectors, int z_board, int z_base, int x_min_value, int x_max_value, int y_min_value, int y_max_value /*, int total, int done*/) { 290 randd.x_offset=x_offset; randd.x_clip=x_clip; randd.x_vectors=x_vectors; randd.y_offset=y_offset; randd.y_clip=y_clip; 295 randd.y_vectors=y_vectors; randd.z_board=z_board; randd.z_base=z_base; randd.x_min_value=x_min_value; randd.x_max_value=x_max_value; 300 randd.y_min_value=y_min_value; randd.y_max_value=y_max_value; } 305 void getRouteDrill() { NumpadInput[0].value=randd.x_offset; NumpadInput[1].value=randd.y_offset; NumpadInput[2].value=randd.z_board; 310 NumpadInput[3].value=randd.z_base; NumpadInput[4].value=randd.x_clip; NumpadInput[5].value=randd.y_clip; } 315 void fillPayloadWithRandD() { send_payload[0] = 0xC3; send_payload[1] = 2; 320 int i, j, k; char *p; k = 2; p=(char*)&randd; 325 247
for (i=0;i<sizeof(RouteDrill); i++, k++) { send_payload[k] = p[i]; } 330 } void set_buffer_flag() { buffer_flag = 1; 335 } void clear_buffer_flag() { buffer_flag = 0; 340 } void set_uart1_isr_flag() { uart1_isr_flag = 1; 345 } void clear_uart1_isr_flag() { uart1_isr_flag = 0; 350 } 248
lib/vardec.h 0#pragma once #include "system.h" #define amountoffiles (12) 5#define amountofcharacters (14) 249
lib/xpt2046.h 0#pragma once #include "system.h" #define T_CLK (1<<4) 5#define T_CS (1<<2) #define T_DIN (1<<6) #define T_DOUT (1<<5) #define T_CS_L() {FIOCLR=T_CS;} 10 #define T_CS_H() {FIOSET=T_CS;} #define X_READ (0x50) #define Y_READ (0x10) 15 int TP_read(int ctrlByte); unsigned int getX(); unsigned int getY(); int uncalibratedX(); 20 int uncalibratedY(); int calibratedX(); int calibratedY(); void readPoints(int *points); 25 void measurePoint(int x, int y, int error, int x_store, int y_store, int *points); #define MATRIX_AN (−42336) #define MATRIX_BN (1344) 30 #define MATRIX_CN (1047648) #define MATRIX_DN (0) #define MATRIX_EN (−42940) #define MATRIX_FN (719132) #define MATRIX_DIVIDER (−37968) 250
lib/xpt2046.c 0#include "xpt2046.h" extern const unsigned char *CurrentFont; extern unsigned char SmallFont[]; extern unsigned char BigFont[]; 5extern unsigned char SevenSegNumFont[]; /** *@brief Reads a value from the touch controller, at a certain address * 10 *@param ctrlByte is the address at which data will be read *@return int that is the data read at the provided address */ int TP_read(int ctrlByte) { 15 SPI_CLK_normal(); T_CS_L(); SPI_byte(0x80 | ctrlByte); int result = 0; 20 result = SPI_byte(0)<<8; result |= SPI_byte(0); T_CS_H(); SPI_CLK_fast(); 25 return ((result>>3) & 0x0FFF); } /** 30 *@brief Reads an 'x' coordinate from the touch controller * *@return unsigned int */ unsigned int getX() 35 { return (TP_read(X_READ)); } /** 40 *@brief Reads a raw 'y' coordinate from the touch controller * *@return unsigned int */ unsigned int getY() 45 { return (TP_read(Y_READ)); } 50 /** *@brief Returns a converted, but uncalibrated value between '0' and '479' * *@return int */ 251