Microcontroller and Embedded Programming • Day 1 Microcontroller and Embedded Programming IOT Lab Learning Outcome Course Objectives: Students will try to learn: 1. The concepts and architecture of embedded systems 2. Basic of microcontroller 8051. 3. The concepts of microcontroller interface. 4. The concepts of ARM architecture 5. The concepts of real-time operating system 6. Different design platforms used for an embedded systems application Course Outcomes: Students will be able to: 1. Explain the embedded system concepts and architecture of embedded systems 2. Describe the architecture of 8051 microcontroller and write embedded program for 8051 microcontroller. 3. Design the interfacing for 8051 microcontroller. 4. Understand the concepts of ARM architecture. 5. Demonstrate the open source RTOS and solve the design issues for the same. 6. Select elements for an embedded systems tool. Prerequisite: COA, Microprocessors and Assembly Programming languages Syllabus Syllabus Syllabus Text Books IOT Lab outcome Lab Objectives: Students will try to: 1. Address the real world problems and find the required solution. 2. Design the problem solution as per the requirement analysis done. 3. Study the basic concepts of programming/ hardware/ emulator for Raspberry pi/Arduino/ ARM Cortex/ Intel Galileo etc. 4. Fabricate and implement the mini project intended solution for project based learning. 5. Build and test the mini project successfully. 6. Improve the team building, communication and management skills of the students. Lab Outcomes: Student will be able to: 1. Identify the requirements for the real world problems. 2. Conduct a survey of several available literatures in the preferred field of study. 3. Study and enhance software/ hardware skills. 4. Demonstrate and build the project successfully by hardware requirements, coding, emulating and testing. 5. To report and present the findings of the study conducted in the preferred domain 6. Demonstrate an ability to work in teams and manage the conduct of the research study. IOT Lab Guidelines 1. The mini project work is to be conducted by a group of three students 2. Each group will be associated with a subject Incharge/ mini project mentor. The group should meet with the concerned faculty during Laboratory hours and the progress of work discussed must be documented. 3. The students may do survey for different application using Raspberry pi/Arduino/ ARM Cortex/Intel Galileo etc topics for the mini project. University of Mumbai, B. E. (Information Technology), Rev 2016 100 4. Each group will identify the Hardware and software requirement for their mini project problem statement. 5. Prototype/Design your own circuit board using Raspberry pi/Arduino/ ARM Cortex/ Intel Galileo etc. 6. Installation, configure and manage your Raspberry pi/Arduino/ ARM Cortex/ Intel Galileo etc board/kit. IOT Lab Guidelines 7. Work with operating system and do coding to for input devices on board. 8. The project assessment for term work will be done at least two times at department level by giving presentation to panel members which consist of at least three (3) members as Internal examiners (including the project guide/mentor) appointed by the Head of the department of respective Programme. 9. Create and interface using Web to publish or remotely access the data on Internet. 10. Each group along with the concerned faculty shall identify a potential problem statement, on which the study and implementation is to be conducted. 11. Each group may present their work in various project competitions and paper presentations. 12. A detailed report is to be prepared as per guidelines given by the concerned faculty. Microcontroller and Embedded Programming TE SEM 5 Information Technology Department Topics Covered in Todays Class •Revision of Microcomputer system terminologies •High Level, Machine Level and Assembly Level programming •Difference between Microprocessor and Microcontroller What is inside a Computer? A Computer is an electronic machine that can solve different problems, process data, store & retrieve data and perform calculations faster and efficiently than humans Functional Units • A computer consists of 5 functionally independent main parts: 1) Input 2) Memory 3) ALU 4) Output & 5) Control units Arithmetic and logic Input Memory Output Control I/O Processor Basic functional units of a computer Functional Units 1. Input Unit: Computer accepts encoded information through input unit. The standard input device is a keyboard. Whenever a key is pressed, keyboard controller sends the code to CPU/Memory. • Examples include Keyborad, Mouse, Joystick, Tracker ball, Light pen, Digitizer, Scanner etc. 2. Output Unit: Computer after computation returns the computed results, error messages, etc. via output unit. The standard output device is a video monitor, LCD/TFT monitor. Other output devices are printers, plotters etc. Functional Units 3. Memory Unit: Memory unit stores the program instructions (Code), data and results of computations etc. Memory unit is classified as: • Primary /Main Memory • Secondary /Auxiliary Memory Primary memory is a semiconductor memory that provides access at high speed. Run time program instructions and operands are stored in the main memory. Main memory is classified again as ROM and RAM. ROM holds system programs and firmware routines such as BIOS, POST, I/O Drivers that are essential to manage the hardware of a computer. RAM is termed as Read/Write memory or user memory that holds run time program instruction and data. While primary storage is essential, it is volatile in nature and expensive. Additional requirement of memory could be supplied as auxiliary memory at cheaper cost. Secondary memories are non volatile in nature. Functional Units 4. Arithmetic and logic unit: ALU consist of necessary logic circuits like adder, comparator etc., to perform operations of addition, multiplication, comparison of two numbers etc. 5. Control Unit: Control unit co-ordinates activities of all units by issuing control signals. Control signals issued by control unit govern the data transfers and then appropriate operations take place. Control unit interprets or decides the operation/action to be performed. The control Unit and the Arithmetic and Logic unit of a computer system are jointly known as the Central Processing Unit (CPU). Processor Bus Structure • There are many ways to connect different parts inside a computer together. • A group of lines that serves as a connecting path for several devices is called a bus. • Address/data/control Input Output Memory Single-bus structure. Processor Bus Structure Architecture Illustration of the steps taken by the CPU to execute an instruction that adds two numbers. The instruction is: R = X + Y. High level, Machine level and Assembly level Programming Hardware / Software Interface BASIC OPERATIONAL CONCEPTS An Instruction consists of 2 parts, 1) Operation code (Opcode) and 2) Operands. OPCODE OPERANDS • The data/operands are stored in memory. • The individual instructions are brought from the memory to the processor. • Then, the processor performs the specified operation BASIC OPERATIONAL CONCEPTS Let us see a typical instruction ADD LOCA, R0 This instruction is an addition operation. The following are the steps to execute the instruction: Step 1: Fetch the instruction from main-memory into the processor. Step 2: Fetch the operand at location LOCA from main-memory into the processor. Step 3: Add the memory operand (i.e. fetched contents of LOCA) to the contents of register R0. Step 4: Store the result (sum) in R0. BASIC OPERATIONAL CONCEPTS IR: Instruction-Register PC: Program Counter MAR: Memory Address Register MDR: Memory Data Register Memory MAR MDR Control PC R 0 R 1 Processor IR ALU R n- 1 n general purpose registers Connection Between the Processor and the Memory BASIC OPERATIONAL CONCEPTS • • • • • • • • • • • • • The processor contains ALU, control-circuitry and many registers. The processor contains “n‟ general-purpose registers R0 through Rn-1. The IR holds the instruction that is currently being executed. The control-unit generates the timing-signals that determine when a given action is to take place. The PC contains the memory-address of the next-instruction to be fetched & executed. During the execution of an instruction, the contents of PC are updated to point to next instruction. The MAR holds the address of the memory-location to be accessed. The MDR contains the data to be written into or read out of the addressed location. MAR and MDR facilitates the communication with memory. IR: Instruction-Register PC: Program Counter MAR: Memory Address Register MDR: Memory Data Register BASIC OPERATIONAL CONCEPTS STEPS TO EXECUTE AN INSTRUCTION 1) The address of first instruction (to be executed) gets loaded into PC. 2) The contents of PC (i.e. address) are transferred to the MAR & control-unit issues Read signal to memory. 3) After certain amount of elapsed time, the first instruction is read out of memory and placed into MDR. 4) Next, the contents of MDR are transferred to IR. At this point, the instruction can be decoded & executed. 5) To fetch an operand, it's address is placed into MAR & control-unit issues Read signal. As a result, the operand is transferred from memory into MDR, and then it is transferred from MDR to ALU. 6) Likewise required number of operands is fetched into processor. 7) Finally, ALU performs the desired operation. 8) If the result of this operation is to be stored in the memory, then the result is sent to the MDR. 9) The address of the location where the result is to be stored is sent to the MAR and a Write cycle is initiated. 10) At some point during execution, contents of PC are incremented to point to next instruction in the program. Question List the steps needed to execute the machine instruction: Add R1, R2, R3 in terms of transfers between the components of processor and some simple control commands. Assume that the address of the memory-location containing this instruction is initially in register PC. Solution 1. Transfer the contents of register PC to register MAR. 2. Issue a Read command to memory. And, then wait until it has transferred the requested word into register MDR. 3. Transfer the instruction from MDR into IR and decode it. 4. Transfer contents of R1 and R2 to the ALU. 5. Perform addition of two operands in the ALU and transfer answer into R3. 6. Transfer contents of PC to ALU. 7. Add 1 to operand in ALU and transfer incremented address to PC. MICROPROCESSOR MICROCONTROLLER COMPARISON Microprocessor and Microcontroller Embedded System • Definition: An Embedded System is one that has computer hardware with software embedded in it as one of its important components. • Its software embeds in ROM (Read Only Memory). • A microcontroller can be considered a selfcontained system with a processor, memory and peripherals and can be used as an embedded system. • The majority of microcontrollers in use today are embedded in other machinery, such as automobiles, telephones, appliances, and peripherals for computer systems. Purpose Of Embedded Systems Each Embedded system is designed to serve the purpose of any one or a combination of the following tasks. 1.Data collection/Storage/Representation 2.Data communication 3.Data (Signal) processing 4.Monitoring 5.Control 6.Application specific user interface COMPONENTS OF EMBEDDED SYSTEM • It has Hardware: Microcontroller, Timers, Interrupt controller, I/O Devices, Memories, Ports, etc. • It has main Application Software which may perform concurrently the series of tasks or multiple tasks. • It has Real Time Operating System (RTOS) RTOS defines the way the system work. Which supervise the application software. It sets the rules during the execution of the application program. A small scale embedded system may not need an RTOS. Windows CE(Consumer Electronics device) an RTOS is used in Audio and video equipment for the home, including CD and DVD players, stereos, TVs and home theater components and also many handheld devices. RTLinux is other example of RTOS. Day 3 Embedded system Architecture Embedded System Microcontroller • A microcontroller is a functional computer system-on-a-chip. It contains a processor, memory, and programmable input/output peripherals. • Microcontrollers include an integrated CPU, memory (a small amount of RAM, program memory, or both) and peripherals capable of input and output. • VARIOUS MICROCONTROLLERS INTEL • 8031,8032,8051,8052,8751,8752 PIC • 8-bit PIC16, PIC18, • 16-bit DSPIC33 / PIC24, • PIC16C7x Motorola • MC68HC11 EMBEDDED PROCESSOR • Special microprocessors & microcontrollers often called, Embedded processors. • An embedded processor is used when fast processing fast context-switching & atomic ALU operations are needed. • Examples : ARM 7, INTEL i960, AMD 29050 • ARM processors are extensively used in consumer electronic devices such as smartphones, tablets, multimedia players and other mobile devices, such as wearables. Because of their reduced instruction set, they require fewer transistors, which enables a smaller die size for the integrated circuitry (IC). 8051 Bus width Communication Protocols Speed Memory Power Consumption Average 8051 variants Vast NXP, Atmel, Silicon Labs, Dallas, Cyprus, Infineon, etc. Manufacturer Cost (as compared to features provide) Very Low Other Feature Popular Microcontrollers 8/16/32-bit 8/32-bit UART, USART, SPI, PIC, UART, USART, I2C, (special purpose LIN, CAN, Ethernet, AVR support CAN, UART, USART,SPI,I2C SPI, I2S USB, Ethernet) 12 Clock/instruction 1 clock/ instruction cycle 4 Clock/instruction cycle cycle Flash, SRAM, ROM, SRAM, FLASH SRAM, FLASH EEPROM CLSC Von Neumann Memory Architecture architecture Community AVR Microcontrollers 8-bit for standard core ISA Families PIC RISC Some feature of RISC ARM 32-bit mostly also available in 64-bit UART, USART, LIN, I2C, SPI, CAN, USB, Ethernet, I2S, DSP, SAI (serial audio interface), IrDA 1 clock/ instruction cycle Flash, SDRAM, EEPROM RISC Modified Harvard architecture Harvard architecture Modified Low PIC16,PIC17, PIC18, PIC24, PIC32 Low Tiny, Atmega, Xmega, special purpose AVR Low Very Good Very Good Microchip Average Atmel Vast Apple, Nvidia, Qualcomm, Samsung Electronics, and TI etc. Average Average Known for its Standard Cheap Cheap, effective PIC18fXX8, PIC16f88X, Atmega8, 16, 32, AT89C51, P89v51, etc. PIC32MXX Arduino Community ARMv4,5,6,7 and series Low High speed operation Vast LPC2148, ARM CortexM0 to ARM Cortex-M7, etc. Embedded System Categories Small Scale Embedded System • • • • • Single 8 bit or 16bit Microcontroller. Little hardware and software complexity. They May even be battery operated. Usually “C” is used for developing these system. The need to limit power dissipation when system is running continuously. • Programming tools: Editor, Assembler and Cross Assembler Medium Scale Embedded System • Single or few 16 or 32 bit microcontrollers or Digital Signal Processors(DSP) or Reduced Instructions Set Computers(RISC). • Both hardware and software complexity. • Programming tools: RTOS, Sourcecode Engineering Tool, Simulator, Debugger and Integrated Development Environment(IDE). • Example: DSP as a GPP is a single chip VLSI unit. It includes the computational capabilities of microprocessor and multiply & accumulate units (MAC). DSP has large number of applications such as image processing, audio, video & telecommunication processing systems. It is used when signal processing functions are to be processed fast. Examples : TMS320Cxx, SHARC, Motorola 5600xx Sophisticated Embedded System • Enormous hardware and software complexity • Which may need scalable processor or configurable processor and programming logic arrays. • Constrained by the processing speed available in their hardware units. • Programming Tools: • For these systems may not be readily available at a reasonable cost or may not be available at all. A compiler or retargetable compiler might have to be developed for this. Types of Processors/controllers in Embedded System • General Purpose Processors • Single purpose Processors • Application Specific Processors General Purpose Processors • Microprocessors • Microcontrollers • Digital Signal Processors Almost 80% of Embedded systems are processor/Controller based. The processor may be a Microprocessor or a Micro-controller or a Digital signal Processor depending on domain and application. Most of the embedded system in the industrial control and monitoring applications make use of the commonly available microprocessors or microcontrollers. Where as domains which require signal processing such as speech coding, speech reorganization, etc. make use of Digital signal processors supplied by manufactures like Analog Devices, Texas Instruments, etc. • Features • –Program memory • –General data path with large register file and general ALU Single Purpose Processor • Digital circuit designed to execute exactly one program • –a.k.a. coprocessor, accelerator or peripheral Features –Contains only the components needed to execute a single program –No program memory Application Specific Processors • Application Specific Integrated Circuits (ASIC) : Application Specific Integrated Circuits (ASICs) is a microchip designed to perform a specific or unique application. • It is used as replacement to conventional general purpose logic chips. • It integrates several functions into a single chip and there by reduces the system development cost. • Programmable processor optimized for a particular class of applications having common characteristics Features –Program memory –Optimized data path –Special functional units (ex: custom ALU) Embedded System Applications • Purpose Of Embedded Systems:-Each Embedded system is designed to serve the purpose of any one or a combination of the following tasks. 1.Data collection/Storage/Representation 2.Data communication 3.Data (Signal) processing 4.Monitoring 5.Control 6.Application specific user interface Real Time Embedded Systems • Real-time systems control the external environment by input & output interfaces and sensors. • Controlling heat, elevators, lights, and doors in buildings • Robots • Traffic control system including railway tracks, airspace, shipping lines, highways • Radio, satellite and telephone communication • Patient monitoring system • Radiation therapy system in the hospital • Computer games • Multimedia systems which consist of video, audio, text and graphics interfaces • Military usage that includes tracking, weapons, and command & control Data communication • Embedded data communication systems are developed in applications ranging from complex satellite communication systems to simple home networking systems. • Figure: -A wireless network router for data communication Data (Signal) Processing • The data collected by embedded system may be used for various kinds of signal processing. • A digital hearing aid is a typical example of an embedded system employing dataprocessing Monitoring • All embedded products coming under the medical domain are with monitoring functions only. They are used for determing the state of some variables using input sensors. • A very good example is the electrocardiogram(ECG) machine for monitoring the heart beat of patient. Control • Embedded system with control functionalities impose control over some variables according to the input variables. • A system with control functionality contains both sensors and actuators. • Sensors are input ports for capturing the changes in environment variables or measuring variable. • Actuators are output ports are controlled according to the changes in input variable • Ex: Air conditioner for controlling room temperature Application specific user interface • Theseareembeddedsystemswithapplicationsp ecificuserinterfaceslikebuttons,switches,keypa d,lights,bells,displayunits,etc.. • Mobilephoneisanexampleforthis,inmobileph onetheuserinterfaceisprovidedthroughthekey board,graphicLCDmodule,systemspeaker,vibra tionalert,etc… Performance • Performance can also be improved by using higher clock speed for processor and pipeline architecture. Motherboard –Circuit Diagram Every computer has the “clock generator” to generate clock signals used throughout the system. Timing in a computer system is critical, particularly to synchronize the activities within the various chips. To do this, a crystal is used. Clock Crystal Clock Processor Clock • • • • • • • • Processor circuits are controlled by a timing signal called a Clock. The clock defines regular time intervals called Clock Cycles. To execute a machine instruction, the processor divides the action to be performed into a sequence of basic steps such that each step can be completed in one clock cycle. Let P = Length of one clock cycle, R = Clock rate. Relation between P and R is given by R=(1/P) R is measured in cycles per second. Cycles per second is also called Hertz (Hz) Clcok cycles measure the execution of instructions Time Dummy Example to understand Clock timing Signal u The higher the clock speed a CPU has, the faster it can process instructions. BASIC PERFORMANCE EQUATION • T – processor time required to execute a program that has been prepared in high-level language • N – number of actual machine language instructions needed to complete the execution (note: loop) • S – average number of basic steps needed to execute one machine instruction. Each step completes in one clock cycle • R – clock rate • Note: these are not independent to each other N S T R How to improve T ? Pipeline and Superscalar Operation • Instructions are not necessarily executed one after another. • The value of S doesn’t have to be the number of clock cycles to execute one instruction. • Pipelining – overlapping the execution of successive instructions. • Superscalar operation – multiple instruction pipelines are implemented in the processor. • Goal – reduce S (could become <1!) N S T R CISC vs RISC CISC and RISC comparison • RISC: It stands for Reduced Instruction Set Computer. It is a type of microprocessor architecture that uses a small set of instructions of uniform length. These are simple instructions which are generally executed in one clock cycle. RISC chips are relatively simple to design and inexpensive. The setback of this design is that the computer has to repeatedly perform simple operations to execute a larger program having a large number of processing operations. • CISC: It stands for Complex Instruction Set Computer. These processors offer the users, hundreds of instructions of variable sizes. CISC architecture includes a complete set of special purpose circuits that carry out these instructions at a very high speed. These instructions interact with memory by using complex addressing modes. CISC processors reduce the program size and hence lesser number of memory cycles are required to execute the programs. This increases the overall speed of execution. • Intel 8051 is an example of CISC machine whereas microchip PIC 18F87X, ARM 7,8,9 series is an example of RISC machine. CISC and RISC • Tradeoff between N and S • A key consideration is the use of pipelining S is close to 1 even though the number of basic steps per instruction may be considerably larger It is much easier to implement efficient pipelining in processor with simple instruction sets • Reduced Instruction Set Computers (RISC) – Large N, small S • Complex Instruction Set Computers (CISC) – Small N, large S N S T R RISC v/s CISC Compiler • A compiler translates a high-level language program into a sequence of machine instructions. • To reduce N, we need a suitable machine instruction set and a compiler that makes good use of it. • Goal – reduce N×S • A compiler may not be designed for a specific processor; however, a high-quality compiler is usually designed for, and with, a specific processor.