You are on page 1of 35

A SHORT COURSE ON MECHATRONICS

16th 20th August 2011

Date / time

Session I 10- 11.30 Registration & Inauguration

Session II 11.45 1.15 - Programme objective - Introduction to Mechatronics Actuators & its types

Session III 2.15- 3.45

Session VI 4-5.30

Tuesday 16.8.11

Automation of manufacturing systems

Wednesday 17.8.11 Thursday 18.8.11 Friday 19.8.11 Programmable logic controller

Sensors, transducers and its applications

Use of programmable logic controller Building and editing of circuits using PLC software Demonstration of different types of microprocessor and micro controllers Visit

Introduction to Microprocessors, Micro controllers & its applications

Saturday 20.8.11

Use of pneumatic simulator Building and editing of circuits using P Simulator software

Programme feedback and valedictory

Microprocessor

The microprocessor, (or CPU), is the brain of the computer. The picture above shows a slot 1 processor with heatsinks and a fan, which prevent it from overheating. Below is the processor without the heatsinks and fan, being inserted into a slot 1 motherboard connection. Slot 1 processors have the microprocessor and level 2 cache memory mounted on a circuit board, (or card), which is enclosed inside of a protective shell.

The enclosed slot 1 processor card contains the central processing unit, (or CPU), with its level 1 cache memory. The central processing unit also contains the control unit and the arithmetic/logic unit, both working together as a team to process the computer's commands. The control unit controls the flow of events inside the processor. It fetches instructions from memory and decodes them into commands that the computer can understand. The arithmetic/logic unit handles all of the math calculations and logical comparisons. It takes the commands from the control unit and executes them, storing the results back into memory. These 4 steps, (fetch, decode, execute, and store), are what's called the "machine cycle" of a computer. These 4 basic steps are how the computer runs each and every program. The microprocessor's level 1 cache memory, is memory that is contained within the CPU itself. It stores the most frequently used instructions and data. The CPU can access the cache memory much faster than having to access the RAM, (or Random Access Memory). Below is a picture of what's inside of a Pentium 3 processor. The control unit, arithmetic/logic unit, and level 1 cache are

contained within the center CPU chip. Level 2 cache memory is visible on the right-hand side of the processor card.

Level 1 cache memory is memory that is included inside of the CPU itself. It is usually smaller and faster than level 2 cache memory. Level 2 cache memory is memory between the RAM and CPU. It is used when the level 1 cache memory is full or is too small to hold the intended data. Originally it was not directly on the CPU chip itself. *Read the update at the bottom of this page.* The photo above shows level 2 cache memory on the processor card, beside the CPU. Below are two photos of a CPU. The photo on the bottom is a view of the CPU chip from the outside. The photo on the top is a large map of the inside of the CPU, showing the different areas and what their function is. See if you can find the areas that fetch, decode, and execute the instructions. Can you also find the level 1 cache areas that store information? The pipelined floating point area, logic areas, and superscalar integer execution units area are part of what? Did you guess the arithmetic/logic unit? If so, you're right!

At the top you can also see the clock driver. The clock driver is what times, or sets the pace, for the computer. The clock's speed, is how CPUs are rated. Each machine cycle consists of two beats. Each beat the control unit fetches and decodes data, which is called the "instruction cycle." At the same time the arithmetic/logic unit executes and stores data, which is called the "execution cycle." The speed of a clock is rated by how many beats per second it can accomplish. 1 billion beats per second is referred to as 1Ghz. For every beat, (except the very first), a machine cycle is completed. Common CPUs available today perform at 3Ghz and faster. This means that a 3Ghz CPU can execute 3,000,000,000 instructions in a single second!

*Update*
The slot 1 processor is no longer being produced. Below are two photos of an AMD Athlon 64 FX socket 939 processor and one photo of a Pentium 4 Extreme Edition socket 775 processor. These are later model processors than the slot 1. Currently AMD is using the socket 939, socket 940, and socket 754 processors. Pentium is using the socket 775 and socket 478 processors. All of these processors look similar, but they do have some differences, including the number of contact points, (or pins), that they have. Another difference in some of the newer processors is that the level 2 cache memory is located directly on the CPU chip itself. Any cache memory located outside of a CPU like this is called level 3 cache memory. The usage is still the same though. Level 1 cache memory is still located closest to the core of the CPU and is still usually smaller and faster than the level 2 cache memory. Some of the newer processors even have level 3 cache memory located directly on the CPU itself. Any cache memory located outside of a CPU like this is called level 4 cache memory. As with the other levels of cache memory, the higher the level, the further away from the core of the CPU it is located. The higher levels of cache memory also are usually larger and slower than the smaller levels. The first photo below shows the front and back of a Pentium 4 Extreme Edition socket 775 processor. It has

level 3 cache memory located directly on the CPU itself. The second photo below shows the front and back of an AMD Athlon 64 FX socket 939 processor. It has level 2 cache memory located directly on the CPU itself. The third photo below shows the AMD processor installed on a motherboard with a heatsink and fan.

Microcontroller v/s microprocessor How does a Microcontroller work? General architecture of a microcontroller Features of Microcontrollers Applications History & Key developments Comparative study of different families: 8051, AVR, PIC Criteria for choosing a microcontroller Future of microcontrollers and applications

Microcontroller v/s microprocessor


Microprocessors are used to execute big and generic applications, while a microcontroller will only be used to execute a single task within one application. Some of the benefits of microcontrollers include the following: Cost advantage: The biggest advantage of microcontrollers against larger microprocessors is that the design and hardware costs are much lesser and can be kept to a minimum. A microcontroller is cheap to replace, while microprocessors are ten times more expensive.

Lesser power usage: Microcontrollers are generally built using a technology known as Complementary Metal Oxide Semiconductor (CMOS). This technology is a competent fabrication system that uses less power and is more immune to power spikes than other techniques.

All-in-one: A microcontroller usually comprises of a CPU, ROM, RAM and I/O ports, built within it to execute a single and dedicated task. On the other hand, a microprocessor generally does not have a RAM, ROM or IO pins and generally uses its pins as a bus to interface to peripherals such as RAM, ROM, serial ports, digital and analog IO. Top

How does a Microcontroller work?


Microcontroller has an input device in order to get the input and an output device (such as LED or LCD Display) to exhibit the final process. Let us look into the illustration of how a microcontroller works in a Television.

The Television has a remote control as an Input device and the TV screen as the output device. The signal sent from the remote control is captured by the microcontroller. The microcontroller controls the channel selection, the amplifier system and picture tube adjustments such as hue, brightness, contrast etc. Top

General architecture of a microcontroller

The architecture of a microcontroller depends on the application it is built for. For example, some designs include usage of more than one RAM, ROM and I/O functionality integrated into the package.

The architecture of a typical microcontroller is complex and may include the following: 1. A CPU, ranging from simple 4-bit to complex 64-bit processers. 2. Peripherals such as timers, event counters and watchdog. 3. RAM (volatile memory) for data storage. The data is stored in the form of registers, and the general-purpose registers store information that interacts with the arithmetic logical unit (ALU). 4. ROM, EPROM, EEPROM or flash memory for program and operating parameter storage. 5. Programming capabilities. 6. Serial input/output such as serial ports. 7. A clock generator for resonator, quartz timing crystal or RC circuit. 8. Analog-to-digital convertors. 9. Serial ports. 10. Data bus to carry information. Top

Features of microcontrollers
1. Architectural features:

Most microcontrollers built today are based on the CISC (Complex Instruction Set Computer) platform. A typical CISC microcontroller has over 80 instructions and it is quite common for the instructions to all behave quite differently.

The main advantage of CISC architecture is that the instructions are macro-like, allowing the programmer to use one instruction in place of many simpler instructions.

2.

Advanced Memory features: a. Electrically Erasable Programmable Read Only Memory (EEPROM):

Many microcontrollers use the economic EEPROM for smaller amount of memory that have frequently changeable data. This type of memory is relatively slow, and the number of erase/write cycles allowed in its lifetime is limited. b. FLASH (EPROM):

Flash provides microcontrollers with a better solution than EEPROM for requirements of large amounts in non-volatile program memory. EPROM is faster and permits more erase/write cycles than EEPROM.

3.

Power Management features

A majority of microcontrollers usually support an operation of 3 - 5.5 V. As consumer goods become trendier, compact and lighter, the focus is on microcontrollers to ensure that products with less power usage are efficiently built and then used by end-users.

Top

Applications
Microcontrollers are used in products that are controlled automatically. The various products that make use of microcontrollers in our everyday life are given below: 1. Home: Television, DVD player, Telephone, Fax machine, Cellular phones, Security systems, Camera, Sewing

machine, Musical Instrument, Exercising machine, Video games, Computer, Microwave oven. 2. Office: Computers, Printers, Telephones, Fax machine, Security systems. Top

History and Key Developments


In 1975, Intel fabricated a chip (Intel 8048) with inbuilt RAM and ROM which was widely used in numerous applications. The microcontrollers had two variants namely EPROM which was erasable but expensive and PROM which could be programmed only once. In 1993, EEPROM memory was introduced in the microcontrollers which electrically erasable and at affordable price. Atmel used the Flash memory and launched the first microcontroller. After this, many companies fabricated microcontrollers with both type of memory.

The microcontroller became popular after Intel Corporation released an 8-bit version in 1981 called the 8051. Intel allowed other manufacturers to make alternate versions of the 8051, and this ensured that numerous versions of the 8051 entered the market. Some of these controllers had different speeds with multiple ROMs mounted on a single chip.

The family of 8051 microcontrollers signalled an electronic revolution with the end user reaping the benefits in technology and science.

As years passed by, microcontrollers have grown to offer much more to end-users and businesses. Some of the key developments in the microcontroller lifecycle are as follows: 1. More ease-of-use and ability to reach market faster. 2. More energy efficiency. 3. More integrated features like RF and USB. 4. Smaller form factors. 5. Increasing processing power.

In future, MRAM (Magnetoresistive Random Access Memory) could be used in microcontrollers as it can store large amount of data which allows it to access faster consuming less power of battery.

Top

Comparative study of different families: 8051, AVR/ATmega, PIC

8051: These microcontrollers are old but still trendy and most of the companies fabricate these microcontrollers. The older types of 8051 have 12 clocks per instruction that make it sluggish whereas the recent 8051 have 6 clocks per instruction. The 8051 microcontroller does not have an in built memory bus and A/D converters. In 1980, Intel fabricated the single chip microcontroller 8051 with Harvard architecture.

PIC: Programmable Interface Controller is usually referred as PIC. They are slightly older than 8051 microcontrollers but excel cause of their small low pin count devices. They perform well and are affordable. The Microchip technology

fabricated the single chip microcontroller PIC with Harvard architecture. The programming part is very tedious and hence it is not recommended for beginners.

AVR: In 1996, Atmel fabricated this single chip microcontroller with a modified Harvard Architecture. This chip is loaded with C- compiler, Free IDE and many more features. This microcontroller is a bit difficult for the starters to handle. Top

Criteria for choosing a microcontroller


The most important factor is that the microcontroller should be cost-efficient and work capably to handle the dedicated task. Some questions that should be asked while deciding on a microcontroller are as follows: 1. 2. 3. 4. 5. What is the maximum speed of the microcontroller? What is the amount of RAM and ROM on chip? How easy it is to upgrade to higher upgrade or lower consumption versions? Is the microcontroller readily available at cheaper rates? What is the number of I/O pins and timer on the chip? Top

Future of microcontrollers and applications

The future is bright and shining for microcontroller manufacturers. This is because the global economies are booming and microcontrollers have a role to play in almost every gadget present on earth. The list of applications for these microcontrollers is: 1. Energy Management:

Technology for energy management is in great demand due to government initiatives that focus on energy. Efficient metering systems help in controlling energy usage in homes and industrial applications. These metering systems are made capable by incorporating microcontrollers. 2. Touch screens:

A touch screen is accepted as the most efficient method to implement user control. They enable dynamic user interfaces and allow increased productivity. Touch screen controller implementation is microcontroller-based and therefore, ample opportunities lie ahead for microcontroller providers that incorporate touch-sensing capabilities in their designs. Portable electronics such as home appliances, cell phones, media players, gaming devices are some of the domains where microcontroller-based touch screens will be in demand. 3. Automobiles:

Microcontrollers find wide usage in hybrid vehicles, especially to ensure smooth and simultaneous functioning of electric and petrol engines. Additionally, almost every car manufacturer uses microcontrollers to control functions within their vehicles and to ensure error-free rides for their customers.

4.

LED Lighting:

Microcontrollers are used for led lighting in residential and industrial locations to enable greater control and power savings. 5. Personal Medical Devices:

The rise and popularity of portable medical devices such as blood pressure and glucose monitors have ensured that microcontrollers will have a role in the medical industry. Microcontrollers are used to display date and increase reliability in providing medical results.

INTRODUCTION TO MICROCONTROLLERS

What are microcontrollers? They are what their name suggests. Today they can be found in almost any complex electronic device - from portable music devices to washing machines to your car. They are programmable, cheap, small, can handle abuse, require almost zero power, and there are so many variaties to suit every need. This is what makes them so useful for robotics - they are like tiny affordable computers that you can put right onto your robot. Augmented Microcontrollers and Development Boards In a pure sense, a microcontroller is just an IC (integrated circuit, or a black chip thing with pins coming out of it). However it is very common to add additional external components, such as a voltage regulator, capacitors, LEDs, motor driver, timing crystals, rs232, etc to the basic IC. Formally, this is called an augmented microcontroller. But in reality, most people just say 'microcontroller' even if it has augmentation. Other abbreviations would be ucontroller and MicroController Unit (MCU). Usually when I say 'microcontroller' what I really mean to say is 'augmented microcontroller.'

As a beginner it is probably best to buy an augmented microcontroller. Why? Well because they have tons of goodies built onto them that are all assembled and debugged for you. They also often come with tech support, sample code, and a community of people to help you with them. My microcontroller parts list shows the more popular types that you can buy. They tend to cost from $30 to $150 depending on the features. This will give you a good introductory to microcontroller programming without having to be concerned with all the technical stuff.

In the long term however you should build your own augmented microcontroller so that you may understand them better. The advantage to making your own is that it will probably cost you from $10-$30.

Between getting a full augmented board and doing it yourself is something called a development board. These boards come pre-augmented with just the bare basics to get you started. They are designed for prototyping and testing of new ideas very quickly. They typically cost between $15 and $40.

What comes with the IC? There is a huge variety of microcontrollers out on the market, but I will go over a few common features that you will find useful for your robotics project. For robots, ore important than any other feature on a microcontroller, is the I/O ports. Input ports are used for taking in sensor data, while output is used for sending commands to external hardware such as servos. There are two types of I/O ports, analog and digital. Analog Input Ports Analog Ports are necessary to connect sensors to your robot. Also known as an analog to digital converter (ADC), they recieve analog signals and convert them to a digital number within a certain numerical range. So what is analog? Analog is a continuous voltage range and is typically found with sensors. However computers can only operate in the digital realm with 0's and 1's. So how does a microcontroller convert an analog signal to a digital signal?

First, the analog is measured after a predefined period of time passes. At each time period, the voltage is recorded as a number. This number then defines a signal of 0's and 1's as shown:

The advantage of digital over analog is that digital is much better at eliminating background noise. Cell phones are all digital today, and although the digital signal is less representative than an analog signal, it is much less likely to degrade since computers can restore damaged digital signals. This allows for a clearer output signal to talk to your mom or whoever. MP3's are all digital too, usually encoded at 128 kbps. Higher bit rates obviously mean higher quality because they better represent the analog signal. But higher bit rates also require more memory and processing power. Most microcontrollers today are 8 bit, meaning they have a range of 256 (2^8=256). There are a few that are 10 bit, 12 bit, and even 32 bit, but as you increase precision you also need a much faster processor. What does this bit stuff mean for ADC? For example, suppose a sensor reads 0V to an 8 bit ADC. This would give you a digital ouput of 0. 5V would be 255. Now suppose a sensor gave an output of 2.9V, what would the ADC output be? Doing the math:

2.9V/5V = X/255 X = 2.9*255/5 = 148 So how do you use an analog port? First make sure your sensor output does not exceed your digital logic voltage (usually 0V > 5V). Then plug that output directly to the analog port. This bit range could also be seen as a resolution. Higher resolutions mean higher accuracy, but occasionally can mean slower processing and more succeptability to noise. For example, suppose you had a 3 bit controller which has a range of 2^3=8. Then you have a distance sensor that outputed a number 0->7 (a total of 8) that represents the distance between your robot and the wall. If your sensor can see only 8 feet, then you get a resolution of 1 bit per foot (8 resolution / 8 feet = 1). But then suppose you have an 8 bit controller, you would get 256/8=32 ~ 1 bit per centimeter - way more accurate and useful! With the 3 bit controller, you could not tell the difference between 1 inch and 11 inches. Digital I/O Ports Digital ports are like analog ports, but with only 1 bit (2^1=2) hence a resolution of 2 - on and off. Digital ports obviously for that reason are rarely used for sensors, except for maybe on/off switches . . . What they are mostly used for is signal output. You can use them to control motors or LED's or just about anything. Send a high 5V signal to turn something on, or a low 0V to turn something off. Or if you want to have an LED at only half brightness, or a motor at half speed, send a square wave. Square waves are like turning something on and off so fast that its almost like sending out an analog voltage of your choice. Neat, huh?

This is an example of a square wave for PWM:

These squarewaves are called PWM, short for pulse width modulation. They are most often used for controlling servos or DC motor H-Bridges. Also a quick side note, analog ports can be used as digital ports. Serial Communication, RS232, UART A serial connection on your microcontroller is very useful for communication. You can use it to program your controller from a computer, use it to output data from your controller to your computer (great for debugging), or even use it to operate other electronics such as digital video cameras. Usually the microcontroller would require an external IC to handle everything, such as an RS232. To learn more, read my microcontroller UART tutorial. Timers A timer is the method by which the microcontroller measures the passing of time - such as for a clock, sonar, a pause/wait command, timer interrupts, etc. To learn more, read my microcontroller timer tutorial.

I^2C I^2C (pronounced 'I-squared-C') is also useful for communicating, but I have never used it. Just make sure your controller has some method of communicating data to you for easy and effective debugging/testing of your robot programs. Its actually somewhat complicated, but usually the manufacturer has simplified it so all you have to do is plug-n-play and do a few print statements. To learn more, read the I^2C tutorial. Motor Driver To run a DC motor you need to either have an H-Bridge or a Motor Driver IC. The IC is great for small robots that do not exceed 1 or 2 amps per motor and the rated motor voltage is not higher than about 12V. The homemade H-Bridge would need to be used if you wanted to exceed those specs. There are a few H-Bridge controllers commercially available to buy, but usually they are way too expensive and are designed for battlebot type robots. The IC is small, very cheap, and can usually handle two motors. I highly recommend opting for the IC. Also, do not forget to put a heatsink onto the motordriver. Motordrivers give off pretty fireworks when they explode from overheating =) Another interesting note, you can stack IC's in parallel to double the allowable current and heat dissipation. Theoretically you can stack as many as you want, as long as the current is high enough to still operate the logic of the IC. This works for voltage regulators too. Output Indicators Im referring to anything that can be used for debugging by communicating information to you. LED's, buzzers, LCD screens, anything that gives output. The better the indicator, the easier the debugging. The best indicator is to have your robot tethered and print or data log sensor and action data to your computer, but it isn't always possible to have your robot tethered. Programming Languages The lowest form of programming languages is the machine language. Microcontrollers need to be programmed with this. An example of machine language: 3A 10 51 E6 DF 32 38 00

Obviously neither of us could ever memorize what all those seemingly random numbers and letters do, so we would program in a higher language that makes much more sense: If (language = = easy) print "yay!"; These higher languages would then be compiled automatically into a machine language, which then you can upload into your robot. Probably the easiest language to learn would be BASIC, with a name true to itself. The BASIC Stamp microcontroller uses that language. But BASIC has its limitations, so if you have any programming experience at all, I recommend you program in C. This language was the precurser to C++, so if you can already program in C++, it should be really simple for you to learn. What complicates this is that there is no standard to programming microcontrollers. Each has its own features, its own language, its own compiler, and its own uploading to the controller method. This is why I do not go into too much detail because there are too many options out there to talk about. The support documents that come with the controllers should answer your specific questions. Also, if you decide to use a PIC, understand that the compiler program (at least the good ones) can cost hundred of dollars. Most microcontrollers also require a special interface device between your computer and the chip for programming which could also cost from $10-$40. Costs With possibly the exception of DC motors, the microcontroller is the most expensive part of your robot. There is just no escaping the costs, especially for the beginner. But remember, after buying all this for your first robot, you do not need to buy any of it again as you can reuse everything. So here is the breakdown of costs. The chip itself, without augmentation, would only cost dollars. But understand the chip is useless without the augmentation, so you would need to do it yourself if you do not buy it already augmented. This could potentially cost just as much with the augmentation, and could cause you many frustrations. If however you are more experienced (and for some odd reason still reading this), you can customize your own circuit to do exactly what you want. Why have a motordriver when you are only using servos anyway? If you decide to buy an augmented MCU, the cost will range from about $50-$150. To compile your program, you would need to get special compiling software. Atmel and BASIC Stamps have free compilers. PIC's however have fairly expensive compilers. There are some free ones available online, but they are of poor quality in my opinion. CCSC PIC C compiler is about $125, but I think it is worth getting if you are going to use PIC's.

You will also need an uploader to transfer the program from your computer to the chip. This generally requires more special software and a special interface device. The Cerebellum PIC based controller has this built in which is really nice and convienent, but for any others expect to spend from $10-$40. People often opt to just make their own as the circuit isnt too complicated. As a prototyper, what you probably want most is a MCU development board. These augmented microcontrollers are designed for the prototyper in mind. To find these augmented MCU's, do a search for 'pic development board,' 'atmel development board,' 'stamp development board,' etc. Conclusion If you have more specific questions about microcontrollers, or would like me to go into more detail about something, just write me and I will. Update I've created a microcontroller product, called the Axon, that's both easy to learn and powerful in features. I use it for all my robot creations now, and will continuously release source code updates and tutorials using it. Feel free to check it out!

To understand the principles and qualities of the digital controller it is necessary to test this at concrete examples. To show the whole variety of the possibilities and problems, as many applications as possible have to be shown from the different disciplines. There is, however, the danger that one loses the summary of the essential, namely the digital controller. For this reason we will model only one example from the beginning of this eBook over the analogous and digital controller until the end of the eBook. On this MECHATRONIC example position-control of DC-motor we can show all the main features of the analog and digital control theory. The eBook is so divided like a realistic development which structurally leads to the final result step by step. At first gradual Scilab is explained and the linear model of the plant-model. After that, an analog and digital PID controller is developed for this linear plant. After that, the plant will become some nonlinearities, quantisation and so on to see the robustness of the system.

Everything what is here introduced can be summarized under the concept mechatronics:

Model creation from different disciplines (electrical engineering, mechanical engineering and computer science) Simulation of the complete system (analog-plant and digital-controller) Analog- and digital-control engineering (controller-structure and parameter) Implementing in an Embedded-System (C-program) and this all with the Free software SCILAB and XCOS the Open-Source for MATLAB and SIMULINK

You can free of charge download the current version of SCILAB on the page www.scilab.org. You must download the binary version for the corresponding operating system because you can install these. And do not forget to load the Help files.

To the end some further controller strategy will be shown.

You might also like