Embedded Systems – Processors Processor is the heart of an embedded system. It is the basic unit that takes inputs and produces an output after processing the data. For an embedded system designer, it is necessary to have the knowledge of both microprocessors and microcontrollers. Processors in a System A processor has two essential units − Program Flow Control Unit (CU) Execution Unit (EU) The CU includes a fetch unit for fetching instructions from the memory. The EU has circuits that implement the instructions pertaining to data transfer operation and data conversion from one form to another. The EU includes the Arithmetic and Logical Unit (ALU) and also the circuits that execute instructions for a program control task such as interrupt, or jump to another set of instructions. A processor runs the cycles of fetch and executes the instructions in the same sequence as they are fetched from memory. Types of Processors Processors can be of the following categories − General Purpose Processor (GPP) Microprocessor Microcontroller Embedded Processor Digital Signal Processor Media Processor Application Specific System Processor (ASSP) Application Specific Instruction Processors (ASIPs) GPP core(s) or ASIP core(s) on either an Application Specific Integrated Circuit (ASIC) or a Very Large Scale Integration (VLSI) circuit. Microprocessor A microprocessor is a single VLSI chip having a CPU. In addition, it may also have other units such as coaches, floating point processing arithmetic unit, and pipelining units that help in faster processing of instructions. Earlier generation microprocessors’ fetch-and-execute cycle was guided by a clock frequency of order of ~1 MHz. Processors now operate at a clock frequency of 2GHz Microcontroller A microcontroller is a single-chip VLSI unit (also called microcomputer) which, although having limited computational capabilities, possesses enhanced input/output capability and a number of on-chip functional units. CPU RAM ROM I/O Port Timer Serial COM Port Microcontrollers are particularly used in embedded systems for real-time control applications with on-chip program memory and devices. Microprocessor vs Microcontroller Let us now take a look at the most notable differences between a microprocessor and a microcontroller. Microprocessor Microcontroller Microprocessors are multitasking in nature. Can perform multiple tasks at a time. For example, on computer we can play music while writing text in text editor. Single task oriented. For example, a washing machine is designed for washing clothes only. RAM, ROM, I/O Ports, and Timers can be added externally and can vary in numbers. RAM, ROM, I/O Ports, and Timers cannot be added externally. These components are to be embedded together on a chip and are fixed in numbers. Designers can decide the number of memory or I/O ports needed. Fixed number for memory or I/O makes a microcontroller ideal for a limited but specific task. External support of external memory and I/O ports makes a microprocessor-based system heavier and costlier. Microcontrollers are lightweight and cheaper than a microprocessor. External devices require more space and their power consumption is higher. A microcontroller-based system consumes less power and takes less space. Learning working make money
Category: embedded Systems
Embedded Systems – Quick Guide Embedded Systems – Overview System A system is an arrangement in which all its unit assemble work together according to a set of rules. It can also be defined as a way of working, organizing or doing one or many tasks according to a fixed plan. For example, a watch is a time displaying system. Its components follow a set of rules to show time. If one of its parts fails, the watch will stop working. So we can say, in a system, all its subcomponents depend on each other. Embedded System As its name suggests, Embedded means something that is attached to another thing. An embedded system can be thought of as a computer hardware system having software embedded in it. An embedded system can be an independent system or it can be a part of a large system. An embedded system is a microcontroller or microprocessor based system which is designed to perform a specific task. For example, a fire alarm is an embedded system; it will sense only smoke. An embedded system has three components − It has hardware. It has application software. It has Real Time Operating system (RTOS) that supervises the application software and provide mechanism to let the processor run a process as per scheduling by following a plan to control the latencies. RTOS defines the way the system works. It sets the rules during the execution of application program. A small scale embedded system may not have RTOS. So we can define an embedded system as a Microcontroller based, software driven, reliable, real-time control system. Characteristics of an Embedded System Single-functioned − An embedded system usually performs a specialized operation and does the same repeatedly. For example: A pager always functions as a pager. Tightly constrained − All computing systems have constraints on design metrics, but those on an embedded system can be especially tight. Design metrics is a measure of an implementation”s features such as its cost, size, power, and performance. It must be of a size to fit on a single chip, must perform fast enough to process data in real time and consume minimum power to extend battery life. Reactive and Real time − Many embedded systems must continually react to changes in the system”s environment and must compute certain results in real time without any delay. Consider an example of a car cruise controller; it continually monitors and reacts to speed and brake sensors. It must compute acceleration or de-accelerations repeatedly within a limited time; a delayed computation can result in failure to control of the car. Microprocessors based − It must be microprocessor or microcontroller based. Memory − It must have a memory, as its software usually embeds in ROM. It does not need any secondary memories in the computer. Connected − It must have connected peripherals to connect input and output devices. HW-SW systems − Software is used for more features and flexibility. Hardware is used for performance and security. Advantages Easily Customizable Low power consumption Low cost Enhanced performance Disadvantages High development effort Larger time to market Basic Structure of an Embedded System The following illustration shows the basic structure of an embedded system − Sensor − It measures the physical quantity and converts it to an electrical signal which can be read by an observer or by any electronic instrument like an A2D converter. A sensor stores the measured quantity to the memory. A-D Converter − An analog-to-digital converter converts the analog signal sent by the sensor into a digital signal. Processor & ASICs − Processors process the data to measure the output and store it to the memory. D-A Converter − A digital-to-analog converter converts the digital data fed by the processor to analog data Actuator − An actuator compares the output given by the D-A Converter to the actual (expected) output stored in it and stores the approved output. Embedded Systems – Processors Processor is the heart of an embedded system. It is the basic unit that takes inputs and produces an output after processing the data. For an embedded system designer, it is necessary to have the knowledge of both microprocessors and microcontrollers. Processors in a System A processor has two essential units − Program Flow Control Unit (CU) Execution Unit (EU) The CU includes a fetch unit for fetching instructions from the memory. The EU has circuits that implement the instructions pertaining to data transfer operation and data conversion from one form to another. The EU includes the Arithmetic and Logical Unit (ALU) and also the circuits that execute instructions for a program control task such as interrupt, or jump to another set of instructions. A processor runs the cycles of fetch and executes the instructions in the same sequence as they are fetched from memory. Types of Processors Processors can be of the following categories − General Purpose Processor (GPP) Microprocessor Microcontroller Embedded Processor Digital Signal Processor Media Processor Application Specific System Processor (ASSP) Application Specific Instruction Processors (ASIPs) GPP core(s) or ASIP core(s) on either an Application Specific Integrated Circuit (ASIC) or a Very Large Scale Integration (VLSI) circuit. Microprocessor A microprocessor is a single VLSI chip having a CPU. In addition, it may also have other units such as coaches, floating point processing arithmetic unit, and pipelining units that help in faster processing of instructions. Earlier generation microprocessors’ fetch-and-execute cycle was guided by a clock frequency of order of ~1 MHz. Processors now operate at a clock frequency of 2GHz Microcontroller A microcontroller is a single-chip VLSI unit (also called microcomputer) which, although having limited computational capabilities, possesses enhanced input/output capability and a number of on-chip functional units. CPU RAM ROM I/O Port Timer Serial COM Port Microcontrollers are particularly used in embedded systems for real-time control applications with on-chip program memory and devices. Microprocessor vs Microcontroller Let us now take a look at the most notable differences between a microprocessor and a microcontroller. Microprocessor Microcontroller Microprocessors are multitasking in nature. Can
Embedded Systems – Architecture Types The 8051 microcontrollers work with 8-bit data bus. So they can support external data memory up to 64K and external program memory of 64k at best. Collectively, 8051 microcontrollers can address 128k of external memory. When data and code lie in different memory blocks, then the architecture is referred as Harvard architecture. In case data and code lie in the same memory block, then the architecture is referred as Von Neumann architecture. Von Neumann Architecture The Von Neumann architecture was first proposed by a computer scientist John von Neumann. In this architecture, one data path or bus exists for both instruction and data. As a result, the CPU does one operation at a time. It either fetches an instruction from memory, or performs read/write operation on data. So an instruction fetch and a data operation cannot occur simultaneously, sharing a common bus. Von-Neumann architecture supports simple hardware. It allows the use of a single, sequential memory. Today”s processing speeds vastly outpace memory access times, and we employ a very fast but small amount of memory (cache) local to the processor. Harvard Architecture The Harvard architecture offers separate storage and signal buses for instructions and data. This architecture has data storage entirely contained within the CPU, and there is no access to the instruction storage as data. Computers have separate memory areas for program instructions and data using internal data buses, allowing simultaneous access to both instructions and data. Programs needed to be loaded by an operator; the processor could not boot itself. In a Harvard architecture, there is no need to make the two memories share properties. Von-Neumann Architecture vs Harvard Architecture The following points distinguish the Von Neumann Architecture from the Harvard Architecture. Von-Neumann Architecture Harvard Architecture Single memory to be shared by both code and data. Separate memories for code and data. Processor needs to fetch code in a separate clock cycle and data in another clock cycle. So it requires two clock cycles. Single clock cycle is sufficient, as separate buses are used to access code and data. Higher speed, thus less time consuming. Slower in speed, thus more time-consuming. Simple in design. Complex in design. CISC and RISC CISC is a Complex Instruction Set Computer. It is a computer that can address a large number of instructions. In the early 1980s, computer designers recommended that computers should use fewer instructions with simple constructs so that they can be executed much faster within the CPU without having to use memory. Such computers are classified as Reduced Instruction Set Computer or RISC. CISC vs RISC The following points differentiate a CISC from a RISC − CISC RISC Larger set of instructions. Easy to program Smaller set of Instructions. Difficult to program. Simpler design of compiler, considering larger set of instructions. Complex design of compiler. Many addressing modes causing complex instruction formats. Few addressing modes, fix instruction format. Instruction length is variable. Instruction length varies. Higher clock cycles per second. Low clock cycle per second. Emphasis is on hardware. Emphasis is on software. Control unit implements large instruction set using micro-program unit. Each instruction is to be executed by hardware. Slower execution, as instructions are to be read from memory and decoded by the decoder unit. Faster execution, as each instruction is to be executed by hardware. Pipelining is not possible. Pipelining of instructions is possible, considering single clock cycle. Learning working make money
Discuss Embedded Systems We can broadly define an embedded system as a microcontroller-based, software-driven, reliable, real-time control system, designed to perform a specific task. It can be thought of as a computer hardware system having software embedded in it. An embedded system can be either an independent system or a part of a large system. In this tutorial, we will explain all the steps necessary to design an embedded system and use it. Learning working make money
Embedded Systems – Terms Program Counter The Program Counter is a 16- or 32-bit register which contains the address of the next instruction to be executed. The PC automatically increments to the next sequential memory location every time an instruction is fetched. Branch, jump, and interrupt operations load the Program Counter with an address other than the next sequential location. Activating a power-on reset will cause all values in the register to be lost. It means the value of the PC (program counter) is 0 upon reset, forcing the CPU to fetch the first opcode from the ROM memory location 0000. It means we must place the first byte of upcode in ROM location 0000 because that is where the CPU expects to find the first instruction Reset Vector The significance of the reset vector is that it points the processor to the memory address which contains the firmware”s first instruction. Without the Reset Vector, the processor would not know where to begin execution. Upon reset, the processor loads the Program Counter (PC) with the reset vector value from a predefined memory location. On CPU08 architecture, this is at location $FFFE:$FFFF. When the reset vector is not necessary, developers normally take it for granted and don’t program into the final image. As a result, the processor doesn”t start up on the final product. It is a common mistake that takes place during the debug phase. Stack Pointer Stack is implemented in RAM and a CPU register is used to access it called SP (Stack Pointer) register. SP register is an 8-bit register and can address memory addresses of range 00h to FFh. Initially, the SP register contains value 07 to point to location 08 as the first location being used for the stack by the 8051. When the content of a CPU register is stored in a stack, it is called a PUSH operation. When the content of a stack is stored in a CPU register, it is called a POP operation. In other words, a register is pushed onto the stack to save it and popped off the stack to retrieve it. Infinite Loop An infinite loop or an endless loop can be identified as a sequence of instructions in a computer program that executes endlessly in a loop, because of the following reasons − loop with no terminating condition. loop with a terminating condition that can never be met. loop with a terminating condition that causes the loop to start over. Such infinite loops normally caused older operating systems to become unresponsive, as an infinite loop consumes all the available processor time. I/O operations waiting for user inputs are also called “infinite loops”. One possible cause of a computer “freezing” is an infinite loop; other causes include deadlock and access violations. Embedded systems, unlike a PC, never “exit” an application. They idle through an Infinite Loop waiting for an event to take place in the form of an interrupt, or a pre-scheduled task. In order to save power, some processors enter special sleep or wait modes instead of idling through an Infinite Loop, but they will come out of this mode upon either a timer or an External Interrupt. Interrupts Interrupts are mostly hardware mechanisms that instruct the program that an event has occurred. They may occur at any time, and are therefore asynchronous to the program flow. They require special handling by the processor, and are ultimately handled by a corresponding Interrupt Service Routine (ISR). Interrupts need to be handled quickly. If you take too much time servicing an interrupt, then you may miss another interrupt. Little Endian Vs Big Endian Although numbers are always displayed in the same way, they are not stored in the same way in memory. Big-Endian machines store the most significant byte of data in the lowest memory address. A Big-Endian machine stores 0x12345678 as − ADD+0: 0x12 ADD+1: 0x34 ADD+2: 0x56 ADD+3: 0x78 Little-Endian machines, on the other hand, store the least significant byte of data in the lowest memory address. A Little-Endian machine stores 0x12345678 as − ADD+0: 0x78 ADD+1: 0x56 ADD+2: 0x34 ADD+3: 0x12 Learning working make money
Embedded Systems – Registers Bank/Stack The 8051 microcontroller has a total of 128 bytes of RAM. We will discuss about the allocation of these 128 bytes of RAM and examine their usage as stack and register. RAM Memory Space Allocation in 8051 The 128 bytes of RAM inside the 8051 are assigned the address 00 to 7FH. They can be accessed directly as memory locations and are divided into three different groups as follows − 32 bytes from 00H to 1FH locations are set aside for register banks and the stack. 16 bytes from 20H to 2FH locations are set aside for bit-addressable read/write memory. 80 bytes from 30H to 7FH locations are used for read and write storage; it is called as scratch pad. These 80 locations RAM are widely used for the purpose of storing data and parameters by 8051 programmers. Register Banks in 8051 A total of 32 bytes of RAM are set aside for the register banks and the stack. These 32 bytes are divided into four register banks in which each bank has 8 registers, R0–R7. RAM locations from 0 to 7 are set aside for bank 0 of R0–R7 where R0 is RAM location 0, R1 is RAM location 1, R2 is location 2, and so on, until the memory location 7, which belongs to R7 of bank 0. The second bank of registers R0–R7 starts at RAM location 08 and goes to locations OFH. The third bank of R0–R7 starts at memory location 10H and goes to location to 17H. Finally, RAM locations 18H to 1FH are set aside for the fourth bank of R0–R7. Default Register Bank If RAM locations 00–1F are set aside for the four registers banks, which register bank of R0–R7 do we have access to when the 8051 is powered up? The answer is register bank 0; that is, RAM locations from 0 to 7 are accessed with the names R0 to R7 when programming the 8051. Because it is much easier to refer these RAM locations by names such as R0 to R7, rather than by their memory locations. How to Switch Register Banks Register bank 0 is the default when the 8051 is powered up. We can switch to the other banks using PSW register. D4 and D3 bits of the PSW are used to select the desired register bank, since they can be accessed by the bit addressable instructions SETB and CLR. For example, “SETB PSW.3” will set PSW.3 = 1 and select the bank register 1. RS1 RS2 Bank Selected 0 0 Bank0 0 1 Bank1 1 0 Bank2 1 1 Bank3 Stack and its Operations Stack in the 8051 The stack is a section of a RAM used by the CPU to store information such as data or memory address on temporary basis. The CPU needs this storage area considering limited number of registers. How Stacks are Accessed As the stack is a section of a RAM, there are registers inside the CPU to point to it. The register used to access the stack is known as the stack pointer register. The stack pointer in the 8051 is 8-bits wide, and it can take a value of 00 to FFH. When the 8051 is initialized, the SP register contains the value 07H. This means that the RAM location 08 is the first location used for the stack. The storing operation of a CPU register in the stack is known as a PUSH, and getting the contents from the stack back into a CPU register is called a POP. Pushing into the Stack In the 8051, the stack pointer (SP) points to the last used location of the stack. When data is pushed onto the stack, the stack pointer (SP) is incremented by 1. When PUSH is executed, the contents of the register are saved on the stack and SP is incremented by 1. To push the registers onto the stack, we must use their RAM addresses. For example, the instruction “PUSH 1” pushes register R1 onto the stack. Popping from the Stack Popping the contents of the stack back into a given register is the opposite to the process of pushing. With every pop operation, the top byte of the stack is copied to the register specified by the instruction and the stack pointer is decremented once. Learning working make money
Embedded Systems – Assembly Language Assembly languages were developed to provide mnemonics or symbols for the machine level code instructions. Assembly language programs consist of mnemonics, thus they should be translated into machine code. A program that is responsible for this conversion is known as assembler. Assembly language is often termed as a low-level language because it directly works with the internal structure of the CPU. To program in assembly language, a programmer must know all the registers of the CPU. Different programming languages such as C, C++, Java and various other languages are called high-level languages because they do not deal with the internal details of a CPU. In contrast, an assembler is used to translate an assembly language program into machine code (sometimes also called object code or opcode). Similarly, a compiler translates a high-level language into machine code. For example, to write a program in C language, one must use a C compiler to translate the program into machine language. Structure of Assembly Language An assembly language program is a series of statements, which are either assembly language instructions such as ADD and MOV, or statements called directives. An instruction tells the CPU what to do, while a directive (also called pseudo-instructions) gives instruction to the assembler. For example, ADD and MOV instructions are commands which the CPU runs, while ORG and END are assembler directives. The assembler places the opcode to the memory location 0 when the ORG directive is used, while END indicates to the end of the source code. A program language instruction consists of the following four fields − [ label: ] mnemonics [ operands ] [;comment ] A square bracket ( [ ] ) indicates that the field is optional. The label field allows the program to refer to a line of code by name. The label fields cannot exceed a certain number of characters. The mnemonics and operands fields together perform the real work of the program and accomplish the tasks. Statements like ADD A , C & MOV C, #68 where ADD and MOV are the mnemonics, which produce opcodes ; “A, C” and “C, #68” are operands. These two fields could contain directives. Directives do not generate machine code and are used only by the assembler, whereas instructions are translated into machine code for the CPU to execute. 1.0000 ORG 0H ;start (origin) at location 0 2 0000 7D25 MOV R5,#25H ;load 25H into R5 3.0002 7F34 MOV R7,#34H ;load 34H into R7 4.0004 7400 MOV A,#0 ;load 0 into A 5.0006 2D ADD A,R5 ;add contents of R5 to A 6.0007 2F ADD A,R7 ;add contents of R7 to A 7.0008 2412 ADD A,#12H ;add to A value 12 H 8.000A 80FE HERE: SJMP HERE ;stay in this loop 9.000C END ;end of asm source file The comment field begins with a semicolon which is a comment indicator. Notice the Label “HERE” in the program. Any label which refers to an instruction should be followed by a colon. Assembling and Running an 8051 Program Here we will discuss about the basic form of an assembly language. The steps to create, assemble, and run an assembly language program are as follows − First, we use an editor to type in a program similar to the above program. Editors like MS-DOS EDIT program that comes with all Microsoft operating systems can be used to create or edit a program. The Editor must be able to produce an ASCII file. The “asm” extension for the source file is used by an assembler in the next step. The “asm” source file contains the program code created in Step 1. It is fed to an 8051 assembler. The assembler then converts the assembly language instructions into machine code instructions and produces an .obj file (object file) and a .lst file (list file). It is also called as a source file, that”s why some assemblers require that this file have the “src” extensions. The “lst” file is optional. It is very useful to the program because it lists all the opcodes and addresses as well as errors that the assemblers detected. Assemblers require a third step called linking. The link program takes one or more object files and produces an absolute object file with the extension “abs”. Next, the “abs” file is fed to a program called “OH” (object to hex converter), which creates a file with the extension “hex” that is ready to burn in to the ROM. Data Type The 8051 microcontroller contains a single data type of 8-bits, and each register is also of 8-bits size. The programmer has to break down data larger than 8-bits (00 to FFH, or to 255 in decimal) so that it can be processed by the CPU. DB (Define Byte) The DB directive is the most widely used data directive in the assembler. It is used to define the 8-bit data. It can also be used to define decimal, binary, hex, or ASCII formats data. For decimal, the “D” after the decimal number is optional, but it is required for “B” (binary) and “Hl” (hexadecimal). To indicate ASCII, simply place the characters in quotation marks (”like this”). The assembler generates ASCII code for the numbers/characters automatically. The DB directive is the only directive that can be used to define ASCII strings larger than two characters; therefore, it should be used for all the ASCII data definitions. Some examples of DB are given below − ORG 500H DATA1: DB 28 ;DECIMAL (1C in hex) DATA2: DB 00110101B ;BINARY (35 in hex) DATA3: DB 39H ;HEX ORG 510H DATA4: DB “2591” ;ASCII NUMBERS ORG 520H DATA6: DA “MY NAME IS Michael” ;ASCII CHARACTERS Either single or double quotes can be used around ASCII strings. DB is also used to allocate memory in byte-sized chunks. Assembler Directives Some of the directives of 8051 are as follows − ORG (origin) − The origin directive is used to indicate the beginning of the address. It takes the numbers in
Embedded Systems – Overview System A system is an arrangement in which all its unit assemble work together according to a set of rules. It can also be defined as a way of working, organizing or doing one or many tasks according to a fixed plan. For example, a watch is a time displaying system. Its components follow a set of rules to show time. If one of its parts fails, the watch will stop working. So we can say, in a system, all its subcomponents depend on each other. Embedded System As its name suggests, Embedded means something that is attached to another thing. An embedded system can be thought of as a computer hardware system having software embedded in it. An embedded system can be an independent system or it can be a part of a large system. An embedded system is a microcontroller or microprocessor based system which is designed to perform a specific task. For example, a fire alarm is an embedded system; it will sense only smoke. An embedded system has three components − It has hardware. It has application software. It has Real Time Operating system (RTOS) that supervises the application software and provide mechanism to let the processor run a process as per scheduling by following a plan to control the latencies. RTOS defines the way the system works. It sets the rules during the execution of application program. A small scale embedded system may not have RTOS. So we can define an embedded system as a Microcontroller based, software driven, reliable, real-time control system. Characteristics of an Embedded System Single-functioned − An embedded system usually performs a specialized operation and does the same repeatedly. For example: A pager always functions as a pager. Tightly constrained − All computing systems have constraints on design metrics, but those on an embedded system can be especially tight. Design metrics is a measure of an implementation”s features such as its cost, size, power, and performance. It must be of a size to fit on a single chip, must perform fast enough to process data in real time and consume minimum power to extend battery life. Reactive and Real time − Many embedded systems must continually react to changes in the system”s environment and must compute certain results in real time without any delay. Consider an example of a car cruise controller; it continually monitors and reacts to speed and brake sensors. It must compute acceleration or de-accelerations repeatedly within a limited time; a delayed computation can result in failure to control of the car. Microprocessors based − It must be microprocessor or microcontroller based. Memory − It must have a memory, as its software usually embeds in ROM. It does not need any secondary memories in the computer. Connected − It must have connected peripherals to connect input and output devices. HW-SW systems − Software is used for more features and flexibility. Hardware is used for performance and security. Advantages Easily Customizable Low power consumption Low cost Enhanced performance Disadvantages High development effort Larger time to market Basic Structure of an Embedded System The following illustration shows the basic structure of an embedded system − Sensor − It measures the physical quantity and converts it to an electrical signal which can be read by an observer or by any electronic instrument like an A2D converter. A sensor stores the measured quantity to the memory. A-D Converter − An analog-to-digital converter converts the analog signal sent by the sensor into a digital signal. Processor & ASICs − Processors process the data to measure the output and store it to the memory. D-A Converter − A digital-to-analog converter converts the digital data fed by the processor to analog data Actuator − An actuator compares the output given by the D-A Converter to the actual (expected) output stored in it and stores the approved output. Learning working make money
Embedded Systems Tutorial Job Search We can broadly define an embedded system as a microcontroller-based, software-driven, reliable, real-time control system, designed to perform a specific task. It can be thought of as a computer hardware system having software embedded in it. An embedded system can be either an independent system or a part of a large system. In this tutorial, we will explain all the steps necessary to design an embedded system and use it. Audience This tutorial has been designed to help the students of electronics learn the basic-to-advanced concepts of Embedded System and 8051 Microcontroller. Prerequisites Before proceeding with this tutorial, you should have a good understanding of the concepts of basic electronics such as circuits, logic gates, etc. Learning working make money