MT2 Introduction Embedded Systems MT2.1 Mechatronic systems Mechatronics is the synergistic integration of mechanical engineering, with electronics and intelligent computer control in the design and manufacturing of industrial products and processes. Mechantronics brings together areas of technology involving sensors and measurement systems, drive and actuation systems, analysis of the behavior of systems, control systems and microprocessor systems. Consider an automatic washing machine. It is good example for a mechatronics system. Its actions are strictly ordered in time or in an event driven sequence. Its operation is controlled by a control unit which comprises of the microcontroller or a microprocessor. In a washing machine sensors are used to estimate the water level, water temperature, drum speed and whether the door is closed etc. These sensors provide data regarding the above mentioned parameters to the control unit. This data is used by the control unit to calculate the next setting of the washing process. In order to control the washing process the control unit sends signals to the correction elements such as pumps, valves, heaters or motors. This process is repeated until the process is complete. A general schematic diagram of a mechatronics system is shown as above. The main components of the system include control unit, correction elements, process and the sensors. The control unit of the system may comprise of a microcontroller, microprocessor or even a computer motherboard. The correction elements may comprise motors, valves, pumps pr
heaters. In order to control a process the current state of the process has to be estimated. This is done using sensors. Sensors provide distance, angle, pressure, temperature, acceleration etc. MT2.2 Embedded systems An embedded system is a computer based system which is specifically designed to perform one or a several dedicated functions in real-time. It is embedded as part of a complete device often including hardware and mechanical parts. An embedded system comprises of a combination of computer hardware and software and perhaps additional parts, either mechanical or electronic which are designed to perform a dedicated task. An embedded system is usually designed to execute a specific task. In the washing machine example the embedded system in the washer is programmed to perform the task of washing. In contrast, laptops, desktops are designed for performing a wide variety of tasks. Embedded systems are often interfaced with sensors in order to get feedback of process parameters. The sensor feedback is used for controlling the process. Embedded systems often perform real time operations. In such applications, timeliness of the response is critical. For example the cruise control system of a car measures the speed of the car and increases or decreases the throttle in order to control the speed in real time. In some cases, these systems are designed to operate under harsh environments. For example in places where human access is difficult such as nuclear power plants etc. there are robots that perform handling of nuclear waste etc. The operation of these embedded systems should not be affected by high rates of radiation in such environments. Embedded systems comprise of hardware such as a central processing unit (CPU), timers, memory, communication interfaces, input/output ports etc. Usually an embedded system is designed to use a minimum amount of hardware resources. The central processing unit (CPU) of the embedded system is the most important element of the system. The CPU is essentially a processor. Two typical components of a CPU are the arithmetic logic unit (ALU), which performs arithmetic and logical operations, and the control unit (CU), which extracts instructions from memory and decodes and executes them, calling on the ALU when necessary. It executes the instructions that are in a machine code. Embedded systems control many devices in common use today. Consumer electronics items such as mobile phones, mp3 players, videogame consoles, digital cameras, DVD players and GPS receivers use such embedded systems. Many household appliances, such as microwave ovens, washing machines and dishwashers uses embedded systems as they provide flexibility and efficiency. The above are just a few out of many examples.
MT2.3 Microcontrollers A microcontroller is an integration of a CPU, memory and programmable input/output peripherals on a single chip which is designed and manufactured to be employed in embedded system applications. This is basically a small computer on a single integrated circuit chip. A basic schematic diagram of a general microcontroller is shown in figure below. A microcontroller is basically an integration of various components which could comprise of the following. Central processing unit - Ranging from small and simple 4-bit processors to complex 32- or 64-bit processors. In-circuit programming and debugging support. Clock generator - often an oscillator for a quartz timing crystal, resonator or RC circuit. Volatile memory (RAM) for data storage.
Read-only memory (ROM), erasable programmable read only memory (EPROM), Electrically Erasable Programmable Read-Only Memory (EEPROM) or Flash memory for program and operating parameter storage. Discrete input and output bits, allowing control or detection of the logic state of an individual package pin. Serial input/output such as serial ports (UARTs). Serial communications interfaces like I²C, Serial Peripheral Interface and Controller Area Network for system interconnect Peripherals such as timers, event counters, Pulse width modulation (PWM) generators, and watchdog timers. Analog-to-digital converters and digital-to-analog converters There are different microcontroller architectures based on the manufacturer. These include Atmel, Microchip (PIC), Intel etc. MT2.4 PIC18F4550 Microcontroller PIC18F4550 is a general purpose 8-bit microcontroller which is developed by Microchip Technology Inc. It uses an 8-bit data bus which makes it possible to access 8 bits of data in a single machine instruction cycle. The speed of a processor is measured in terms of million instruction cycles per second (MIPS). This microcontroller has a speed of 12 MIPS. This microcontroller has 40 pins. A simplified version of the schematic diagram of the PIC18F4550 microcontroller is shown below.
In the above figure only a selected set of pins used for interfacing. Pin 1 (MCLR) is used for clearing the device memory and to reset it. Pin 18 (USB) is used as one of the main pins used to connect the USB cable to power the board, load the compiled code and for data transfer. It is the Internal +3.3V voltage regulator input. In addition to this the USB uses pins 23 (C4) and 24 (C5) for data communication and a ground pin. The power is connected to pins 11 and 32. It uses a voltage of +5V for as the input voltage. This chip is grounded using pins 12 and 31. The rest of the pins are used as either input pins or input/output pins. These chips also require a precise clock input for operation. This is provided by a crystal oscillator. This is an electronic oscillator circuit which uses the mechanical resonance of a vibrating crystal of piezoelectric material (such as quartz) to create an electrical signal with a very precise frequency. This frequency is used for various timing purposes. A crystal oscillator with an input frequency of 20 MHz is connected to pins 13 (CLKI) and 14 (CLKO). This chip uses a Phase Lock Loop (PLL) frequency multiplier boost the operating frequency of the chip to 48 MHz. Microcontrollers could also be used for other applications such as timers, sending PWM signals, and interfacing various digital components, serial communication etc. In this section we will consider only some of the selected applications.
MT2.4.1 Applications of the PIC18F4550 microcontroller 1. Sending and receiving digital signals using PIC18F4550 microcontroller The general digital input/output pins are shown in figure above. These pins could receive a digital signal or output any digital signal. The pins shown in above figure could only be used as digital input pins.
2. Measuring analog voltages using the PIC18F4550 microcontroller This chip has four pins which could be used to measure analog voltages. Pins 2,3,4,5 and 7 can be used to measure analog voltages between 0 and +5 V. It is done by using the analog to digital converters (A/D) in these pins. It measures these analog voltages and displays them as a 10-bit digital number. This means that a voltage of 0 V will correspond to a digital number of 0 and a voltage of +5 V will correspond to a full 10-bit digital value of 1023. Analog voltages could be measured in real time using the microcontroller. 3. Sending a PWM signal using the PIC18F4550 microcontroller The pin 16 (C1) could be used to send a PWM signals for driving DC motors. Pin C1 could be used to send a PWM signal to drive DC motors. The PWM signal send by PIC has a resolution of 10-bit (0-1023 in decimal). The frequency of the PWM signal is 2.44 khz.
Some of the important features of the PIC18F4550 microcontroller is given in table below.
Table: Selected Features of a PIC18F4550 microcontroller Parameter Name Value Operating frequency 48 MHz Program Memory (KB) 32 CPU Speed (MIPS) 12 RAM Bytes 2,048 Data EEPROM (bytes) 256 Digital Communication Peripherals Serial(RS232), USB, SPI, I2C Capture/Compare/PWM Peripherals 1 (10-bit, 2.44 khz) Timers 1 x 8-bit, 3 x 16-bit ADC 4, 10-bit Comparators 2 USB (channels, speed, compliance) 1, Full Speed, USB 2.0 Temperature Range ( o C) -40 to 85 Operating Voltage Range (V) 2 to 5.5 Pin Count 40 MT2.5 Microcontroller development tools MT2.5.1 Hardware A printed circuit Board (PCB) should be used to mechanically support and electrically connect electronic components using conductive pathways, tracks or signal traces etched from copper sheets laminated onto a non-conductive substrate. Usually the printed circuit boards are made out of FR4. FR-4 is a composite material composed of woven fiberglass cloth with an epoxy resin binder that is flame resistant. If this microcontroller is used for various real life applications it should be mounted on to a PCB which is specifically designed for the purpose. The MUNDer board is a custom designed printed circuit board that could be used for various mechatronics applications.
A MUNDer board is shown above. The parts of the MUNDer board are: 1. PIC18F4550 microcontroller. 2. Push buttons 3. Serial communication port (Bluetooth, RS232 etc) 4. USB connector 5. Power jack 6. Indicator LEDs 7. Port A 8. Port E 9. Port B 10. Port D
11. Port C 12. +5 V Port 13. Ground Port 14. LED display port The main component of the MUNDer board is the PIC18F4550 microcontroller. In the MUNDer board the PIC18F4550 is hard wired using the copper traces. It is powered using pins 11 & 32 and grounded using 12 & 31. It also has 20 MHz which is needed for the microcontroller. It has input output ports A to E, +5 V power port and a ground port. There is a terminal to connect a bluetooth communication device for data transfer. The MUNder board could be powered off the USB or an external power supply. It s built in power jack could be connected to voltages between +5 V and +18 V. It has a port for fixing a LCD display. This could be used to display data and messages. The USB connector in board is hardwired. This could be used to power this board from an external computer. It can also be sued for sending and receiving data from a computer. In addition it could also be used to load the compiled programs in to the PIC. It also has two push buttons. These are used to bring the MUNDer board to the boatload mode and running various programs. In the boot load mode, existing memory of the PIC microcontroller is cleared and the new program is loaded. The red LED lights are used as indicators to show when a PIC is brought to a bootload mode. These LEDs could also be programmed for blinking. MT2.5.2 Software A set of specific instructions have to be given to the microcontroller to perform various tasks. This requires a software in order to write a set of instructions. An Integrated Development Environment (IDE) is a software application that facilitates all aspects developing of embedded software. Such an IDE has a source code editor, a compiler and a debugger.
MPLab IDE version 8 is used in this course. Using this development environment instructions are written in human friendly C language. It uses C18 complier to convert this c code into a machine friendly hex code. This hex code could be loaded to the microcontroller using a bootloader program. References: Michael Barr & Anthony J. Massa, 2006, Programming embedded systems: with C and GNU development tools (Second Edition), O'Reilly Media, California. F. Harshama, M. Tomizuka, & T. Fukuda, Mechatronics What is it, why, and how? an editorial, IEEE/ASME Transactions on Mechatronics, Vol. 1, No. 1, 1996, pp. 1 4. W. Bolton, 2008, Mechatronics: A Multidisciplinary Approach (4th Edition), Pearson Education Canada. Microchip Technology Inc. (www.microchip.com)