Course Code: EEE 4846 International Islamic University Chittagong (IIUC) Department of Electrical and Electronic Engineering (EEE) Course Title: Embedded System Sessional Exp. 1: Familiarization with necessary resources of Embedded system laboratory. 1.1 Objective: The objectives of this experiment are- (a) To learn about embedded system. (b) To learn some basic information about microcontroller. (c) To learn about required hardware and software to develop microcontroller based embedded system. 1.2 What is Embedded System? Embedded systems are designed for the specific function within the larger system. It has the processing circuit like Microprocessor, DSP and FPGA that allows the data communication very easily. The characteristic of the embedded system to handle the particular task allows the design engineer to reduce the size and cost of the system and at the same time also make the system more reliable. An embedded system is a combination of microprocessor based hardware and the suitable software to undertake a specific task. A general purpose computer (e.g. a personal computer) is defined not to be an embedded system. Example: Television, radio, mobile phone etc. are the example of embedded device. Figure 1.1: Some embedded device. In this course we shall learn microcontroller and FPGA based embedded system. Prepared By: Mohammed Abdul Kader, Lecturer, EEE, IIUC Page 1
1.3 About Microcontroller Microcontroller is a device that includes microprocessor, memory and input/output devices on a single chip. Microcontroller has a CPU, in addition with a fixed amount of RAM, ROM and other peripherals all embedded on a single chip. At times it is also termed as a mini computer or a computer on a single chip. Timer/ I/O Figure 1.2: Basic architecture of a Microcontroller 1.3.1 Name of Some Microcontroller Manufacturer ATMEL (AVR microcontroller) Microchip (PIC microcontroller) Texas Instruments (TI) Freescale Philips Motorola 1.3.2 About PIC Microcontroller The original name of this microcontroller is PICmicro (Peripheral Interface Controller), but it is better known as PIC Its ancestor, called the PIC1650, was designed in 1975 by General Instruments At first, READ ONLY MEMORY (ROM) used in these microcontrollers were Masked ROM (MROM), then One Time Programmable ROM (OTP ROM), then UV Erasable Programmable ROM (UV EPROM), and finally Flash Memory (program can be written and cleared practically an unlimited number of times) Prepared By: Mohammed Abdul Kader, Lecturer, EEE, IIUC Page 2
Its programming is very user friendly. There are several PIC family (e.g. PIC10FXXX, PIC16FXXX, PIC12HVXXX etc.) of PIC Microcontroller. Each family includes many of microcontrollers. 1.3.3 Overview of Development Process PIC PIC Figure 1.3: Steps to develop microcontroller based system 1) A circuit is designed in which a PIC microcontroller will be used. 2) Using a text editor on a desktop or laptop computer, a program is written in C that is intended to run on the PIC microcontroller. 3) The C program is compiled into a binary file formatted for the target PIC microcontroller. 4) A programming software sends the compiled program to a programmer (Loader) that is connected to the computer's serial, parallel, or USB port. 5) The Programmer (hardware) programs or "burns" the compiled program into the PIC microcontroller. 1.4 Hardware Needed According to circuit requirement many hardware components may be needed. The common parts are described below- 1.4.1 Linear Voltage Regulator (LM7805) We never connect microcontroller power supply to an adaptor. Because the voltage of adaptor is not constant, when the load draws variable current. The voltage decreases as the current drawn by the load increases. This is due to the use of transformer in adaptor. More current increase the losses of the transformer, therefore the terminal voltage decreases. That s why we have to use a linear voltage regulator IC known as LM 7805. It is a three terminal positive voltage regulator. Its input voltage may vary 7V to 20V but output voltage is constant at 5V. Input Voltage Output voltage Current Rating 7-20 V 5V (may vary from 4.75 to 5.25V) Up to 1A Prepared By: Mohammed Abdul Kader, Lecturer, EEE, IIUC Page 3
1.4.2 Heat Sink Figure 1.4: Linear Voltage Regulator A heat sink should attach with LM 7805 to protect it from excessive heat. Suppose input voltage of LM7805 = 12 V Output is always fixed at 5 V If microcontroller and other components in the circuit draws a current 0.5 amp, the output power of 7805 will be, P out = 5*0.5 = 2.5 W Input Power of 7805, P in =12*0.5 = 6 W. Power dissipation in 7805, P loss =(6-2.5) W = 3.5 W=3.5 J/s This power loss generates 3.5 J heat energy per second. The surface of 7805 is not enough to release 3.5 J heat per second in the environment. Heat sink acts as an extra surface to increase the heat releasing capacity. 1.4.3 Microcontroller Programmer Figure 1.5: Heat sink A microcontroller programmer or microcontroller burner is a hardware device accompanied with software which is used to transfer the machine language code to the microcontroller/eeprom from the PC. The compiler converts the code written in languages like assembly, C, java etc to machine language code (which is understandable by the machines/microcontrollers) and stores it in a hex file. A microcontroller programmer acts as an interface between the PC and the target controller. The API/software of the programmer reads data from the hex file stored on the PC and feeds it into the controller s memory. The target controller on which the program needs to be Prepared By: Mohammed Abdul Kader, Lecturer, EEE, IIUC Page 4
burned is placed on the programmer using a ZIP socket. The software transfers the data from the PC to the hardware using serial, parallel or USB port. Figure 1.6: Interfacing programmer with PC Depending on the way it interacts with PC, there are three types of microcontroller programmers: Parallel Programmer uses the parallel port of the PC. They are low cost programmer but not widely used. Serial Programmers uses the serial port to interact with PC via RS232 protocols. They are more popular among hobbyist working on PC. However both the serial and parallel programmers will become obsolete in near future. The major reason being unavailability of parallel and serial ports in the PCs & Laptops in the coming years. USB Programmer uses the USB interface to transfer the data from PC. The main advantage of the USB burner is that they are powered from the PC itself and there is no need of any additional supply. The USB programmers have already become popular and will soon replace the serial and parallel programmer. In Laboratory we will use a USB programmer which is the clone of Pickit2. This programmer supports Pickit2 software. It is a low-cost development tool with an easy to use interface for programming. It supports baseline (PIC10F, PIC12F5xx, and PIC16F5xx), midrange (PIC12F6xx, PIC16F), PIC18F, PIC24, dspic30, dspic33, and PIC32 families of 8-bit, 16-bit, and 32-bit microcontrollers, and many Microchip Serial EEPROM products. Prepared By: Mohammed Abdul Kader, Lecturer, EEE, IIUC Page 5
1.4.4 Clock Sources Figure 1.7: Programmer available at lab. Why? The clock of a microcontroller is its heart beat. We can call the clock sources as Heart of Microcontroller. As microcontroller is a register based device, it needs clock to execute instruction or manipulate data. Normal instructions for the chip take one to three clock cycles to complete; a clock cycle is the low-high-low transition of the clock. So, the faster the clock runs the faster the chip works. Selecting Clock Sources: There are a few different ways to generate a clock for a microcontroller. You can use an external clock that feeds in the low-high pulse stream. Some chips have built in RC oscillator. So, the options are: 1) Internal Oscillator 2) External oscillator a) Crystal Oscillator. b) Ceramic Oscillator. c) RC (Resistor, Capacitor) Oscillator. The optimal clock source for an application depends on many factors including cost, accuracy, and environmental parameters. Although it is often appropriate to use the internal RC oscillator as the processor clock source, there are some situations where it is more appropriate to use some external clock circuitry, for reasons such as: Great Accuracy and Stability: A crystal or ceramic resonator is significantly more accurate than the internal RC oscillator, with less frequency drift due to temperature and voltage variations. Prepared By: Mohammed Abdul Kader, Lecturer, EEE, IIUC Page 6
Generating a specific frequency: For example, the signal from 32,768 KHz crystal can be readily divided down to 1Hz. Or, to produce the accurate timing for RS-232 serial data transfer, a crystal frequency such as 1.843200 MHz can be used, since it exact multiple of common bit rates, such as 38400 or, 9600 (1843200=48*38400=192*9600). Synchronizing with other components: Clocking a number of devices from a common source, so that their outputs change synchronously. Fastest operation: Most Mid-range PIC s can operate at a clock rate up to 20MHz, while internal RC oscillator generally runs at only 4 or, 8MHz. If you need more speed than the internal oscillator can provide, you need to use a crystal or other external clock oscillator. Lower power consumption: At a given supply voltage, microcontroller draw less current when they are clocked at lower speed. Power consumption can be minimized by running the uc at the slowest practical clock speed as for many application high clock speed is unnecessary. The disadvantage of using external oscillator is that you will lose two I/O pins of microcontroller as oscillator needs two I/O pins to connect with uc. Comparison between Crystal and Ceramic Resonator The crystal is a very accurate and (in theory) simple way to get a clock. As well crystals do not change their value (much) with a changing external temperature. Crystals are available in many frequencies and sizes, and needs two external 'load capacitors' to work. A ceramic resonator is similar to a crystal, except that it is much cheaper. However as a consequence it is also not as accurate and the value can change at different temperatures. An advantage is that they are less fragile than a crystal - so in high-vibration environments they can perform (fairly) well. Two types of ceramic resonator available: (i) two pin ceramic resonator and (ii) Three pin ceramic resonator. The two pin ceramic resonator needs two external 'loading capacitors'. The three pin ceramic resonator is similar to the two pin - except that it doesn't need the external loading capacitors as they are built in. One pin of the resonator goes to ground, one to XTAL1 and one to XTAL2 (it doesn't matter which pin goes to XTAL1 or XTAL2, but the pin to ground matters!) 1.4.5 Microcontroller (PIC16F887) In laboratory we shall use the most familiar microcontroller chip PIC16F887. The features of this chip is given below- Features Operating Frequency Power Supply Flash Program Memory (ROM) DC-20MHz 2-5.5 V 8K Prepared By: Mohammed Abdul Kader, Lecturer, EEE, IIUC Page 7
Data Memory (RAM) EEPROM Memory I/O Ports Timers 368 Bytes 256 Bytes PORTS A,B,C,D,E 3 (Two 8-bits and one 16-bits) Captures/Compare/PWM Modules 2 Serial Communications Parallel Communications 10-bit ADC Instruction Set USART, MSSP PSP 14 input channel 35 instructions Figure 1.8: Pin diagram of PIC16F887 1.5 Necessary Software To write the code and simulate circuit we will use the following software s- (a) MikroC Pro : To write and compile the code. Prepared By: Mohammed Abdul Kader, Lecturer, EEE, IIUC Page 8
(b) PIC Simulator IDE: To simulate the code. (c) Proteus: To simulate the complete circuit. 1.5.1 MikroC Pro The mikroc PRO for PIC is a powerful, feature-rich development tool for PIC microcontrollers. It is designed to provide the programmer with the easiest possible solution to developing applications for embedded systems, without compromising performance or control. Following figure shows the interface of MikroC Pro window- Figure 1.9: Interface of MikroC Pro To know the detailed about MikroC Pro you can take help from MikroC Pro User Manual 1.5.2 PIC Simulator IDE PIC Simulator IDE is powerful application that supplies PIC developers with user-friendly graphical development environment for Windows with integrated simulator (emulator), Basic compiler, assembler, disassembler and debugger. Prepared By: Mohammed Abdul Kader, Lecturer, EEE, IIUC Page 9
1.5.3 Proteus Figure 1.10: Interface of PIC Simulator IDE PROTEUS is very strong circuit simulation software. To simulate the complete circuit containing microcontroller and other I/O devices you may use PROTEUS. Figure 1.11: Interface of Proteus Simulator Prepared By: Mohammed Abdul Kader, Lecturer, EEE, IIUC Page 10