Chapter 1 Introduction To Embedded Systems: Objectives
Chapter 1 Introduction To Embedded Systems: Objectives
Objectives
Understand the purpose and categories of embedded systems Understand the embedded system hardware and software Use Keil Vision3 C51 Development Kit Use C8051F005DK microcontroller development kit
Overview
By name, an embedded system is a special-purpose computing device designed to perform dedicated functions. Some of the embedded systems with real-time constraints are called real-time embedded systems. An embedded system consists of its hardware and software. The hardware includes microprocessor or microcontroller with additional attached external memory, I/O, and other components such as sensors, keypad, LEDs, LCDs, and any kind of actuators. The embedded software is the driving force of an embedded system. Most real-time embedded system software have specific application programs supported by Real Time Operating System(RTOS). The embedded software is usually called firmware because this type software is loaded to ROM, EPROM, or Flash memory and once it is loaded and it will never be changed unless it needs to be reloaded for replacement.
2.
Real-time embedded systems A system is said to be real-time if the response time is critical. In other word, some particular work must be done in a specified time period. In addition to functional correctness, the time constraint must be satisfied. There are two type real-time embedded systems: hard real-time and soft real-time embedded systems. i. Hard real-time systems. For a hard or immediate real-time system, the completion of an operation after its deadline may lead to a critical failure and result in live loss and property damage. The response time deadline for such system is very critical (in milliseconds or even shorter). These systems usually interact directly with physical hardware instead of human being. You can even find hard real-time embedded system in your daily life.
For example: a car airbag control system is a hard real-time system because a delayed reaction may cause drivers life and the delay response in heart pacemakers will also lead a severe result. It is imperative for such system to react an event within a strict deadline and missing a deadline will constitutes failure of the system. Hardware and software of hard real-time systems must allow a worst case execution (WCET) analysis that guarantees the execution be completed within a ii Soft real-time system strict deadline. In some other embedded system, there is response deadline but the lateness can be tolerated in some degrees. The violation of time constraints will result in degraded quality, but the system can continue to operate. Microwave and washing machine fall into this subcategory. Although there is a response time deadline for any operation the allowed latency delay can be seconds rather than ms. In soft real-time systems, the design focus is to offer a guaranteed bandwidth to each real-time task and allocate a percentage of the resources to each task.
Actually, many real-time systems have both hard event and soft events mixed. The hardware resource (CPU time) and software resources (high priority interrupts) should be allocated to these processes handling hard-real-time events. 3. Networked embedded systems The networked embedded systems are connected to network with network interfaces to be accessed or to access other resources. The connected network can be Local Area Network (LAN), Wide Area Network(WAN), or Internet. The connection can be wired or wireless. You can simply group the networked embedded systems into wired and wireless sub-categories. But in many systems these two type systems are merged together. A home security system is an example of LAN networked embedded system where all sensors (e.g.
Contd
Pervasive computing is the new trend of networked embedded systems application towards increasingly ubiquitous environment with all very tiny and even invisible embedded devices, either mobile or embedded in almost any type of thinkable objects where information and computational resources are organized as a ubiquitous service grid. Although you classify all embedded systems into these three major categories the division is not absolute. A sub-system of a networked embedded system can be real-timed or no-real-timed. A real-time system can be stand-alone or networked.
Scale based categories. For example, small scaled embedded system supported by single 8-16 bit microprocessor or microcontroller with on-chip RAM and ROM is designed to perform simple task; medium scaled embedded system supported by a 16/32 bit microprocessor or microcontroller with external RAM and ROM to perform more complex operations; large scaled networked embedded system supported by 32-bit or 64-bit multiple chips which conduct distributed jobs.
Smart board, smart room, OCR, calculator, smart cord Signal generator, signal processor, power supplier Router, hub, cellular phone, IP phone, web camera Fuel injection controller, anti-locking brake system, air-bag system, GPS, cruise control MP3, video game, MindStorm, smart toy Navigation system, automatic landing system, flight attitude controller, space explorer, space robotics Assembly line, data collection system, monitoring systems on pressure, voltage, current, temperature, hazard detecting system, industrial robot PDA, iPhone, palmtop, data organizer CT scanner, MRI, Glucose monitor, blood pressure monitor, medical diagnostic device ATM, smart vendor machine, cash register Elevator, tread mill
The constraints of embedded system are also the challenges for the system design and development. Resource constraint: Embedded systems are constrained for their size, power capacity (may be battery operated), limited memory capacity(especially RAM size), CPU speed and function capacity Time constraints: Real-time system has response time deadline to meet. Environment constraint: extreme operation condition such as high or low temperature, high pressure, high humidity, under water, under collision, etc. Cost Constraint: Cost reduction of products has huge impact on the market competition because the large volume of products For high volume systems such as MP3 players or PDAs, minimizing cost is usually the primary design consideration. The selected hardware should be just good enough to cover the necessary functions. Time to market constraint: Design and development cycle is very limit in order to beat the competent in the market.
Contd
Wide variety of chips for selection Many RTOS selections available, even the selection of using RTOS or not Language selections on high level or assembly Many I/O accessories components selections Programming on direct port operations Programming with multi-tasking and multithreading execution Must use cross compiler and development tools Need special emulation tools to debug Testing on Multitasking and scheduling execution Testing on the real world environment because embedded software is embedded into devices.
Control Unit
AD/DA
Parallel
Serial
Timer
Sensor/ Actuator
OSC/ Clock
Control
OSC/Clock
INT
256 RAM
8k ROM
Timers
CPU
SPI/SCI
ADC ADC
Port A
Port B
Port C
Port D
Port E
PB0-7/A8-15
PC0-7/A0-7
PE0-7/ANALOG 0-7
Ex- Memory
External interrupts
Interrupt control
Timer 0/1
CPU
OSC/Clock
Bus Control
4 I/O Ports
Serial Port
P0 P1 P2 P3
TxD RxD
The Intel 80C51(CMOS) microcontroller has a 8 bit microprocessor running at 1MIPS/12MHz with small on-chip RAM of 128 bytes for data and 4K on-chip ROM for code. It is integrated with 4 bidirectional I/O ports, two counter/timers, and Universal Asynchronous Receiver Transmitter(UART) for RS232 serial communication. It can support up to 64K external RAM and ROM. 8051 microcontroller to discuss due to its popularity, low cost, and especially the availability of many affordable IDE development kits such as the Keil vision development kit and C8051F005DK development kits(the target board included) with support of C programming language.
Memory
Embedded system memory can come on-chip or off-chip. For same type memory, on-chip memory access is much fast than off-chip memory but the size of on-chip memory is much smaller than the size of off-chip memory. Usually, it takes at least two I/O ports as external address lines plus a few control lines such as R/W and ALE control lines to enable the extended memory. E.g., 16 bits of I/O port P0 and P2 are used to address 64k external memory in 8051. ( 216 = 26 x 210 = 64k byte memory space)
RAM
The 8051 memory is divided into Data Memory and Code Memory. Most of data are stored in Random Access Memory (RAM) and code are stored Read Only Memory ( ROM). This is due to the RAM constraint of embedded system and the memory organizations
RAM(Contd.)
The RAM size of microprocessor and microcontroller is rather small (<256 bytes in most cases). In order to access any byte in a 256 bytes memory space, there need 8 address lines (internal address bus) because 28 = 256. One ASCII character takes one byte memory space. For example, character A has its ASCII code 6510 , i.e., in binary 010000012 (8 bits = 1 byte); A integer number 102410 takes 11 bits(100000000002) which needs 2 bytes to store it. A simplest machine instruction itself takes one byte but some other memory access machine instruction The small amount of automatic variable data ( local take multiple bytes. variables of functions and interrupt service routine functions, stacks) are stored on the on-chip RAM for fast and frequent access and update while the large amount temporary data (array, table) can be stored in off-chip RAM. The RAM chip can be SRAM (static) or DRAM(dynamic) depending on the manufacture. SRAM is faster than DRAM but is more expensive
ROM
The ROM, EPROM, and Flash memory are all read only type memory used to store code in embedded system. The embedded system code does not change after the code is loaded into memory. The ROM is programmed at the factory and can not be changed over time. The newer microcontroller comes with EPROM or Flash instead of ROM. Most of microcontroller development kits come with EPROM as well. EPROM and Flash memory are easier to rewrite than ROM. EPROM is a Erasable Programmable ROM in which the contents can be field programmed by a special burner and can be erased by a UV light bulb. The size of EPROM ranges up to 32kb in most embedded systems.
ROM (Contd.)
All ROM type memory are non-volatile. This is one of the reasons the embedded code firmware is store in ROM type memory. When the power is on, the first instruction in ROM is loaded into the PC and then the CPU fetches the instruction from the location in the ROM pointed by PC and stores it in the IR to start the CPU fetch and execution cycle continuously. The PC is advanced to the address of next instruction depending on the length of The 68HC11 comes with 256 bytes RAM, 512 bytes the current instruction or the destination of the Jump EPROM, and 8k bytes ROM. Here 1k is 1024 bytes (210) instruction.13 and 8k = 2 bytes. There need to be 13 address lines available to cover 8k bytes space. The 8051 comes with 128 bytes RAM and 4k ROM. The EPROM or Flash memory can be attached as extended memory.
Bus
All the CPU, memory, and I/O ports are connected by the buses. There are three type buses: data bus, address bus, and control bus. The bus is a pathway to connect all the microcontroller components A 8 bits or 16 bits data bus delivers data from one component to another component within the microcontroller. The address bus is used to specify the memory location for CPU to load instructions to be executed or to access data in the memory or ports. The control bus is used for CPU to control the operation in sequence with the timing tick paces and specify the read/write memory access operation. In order to run an instruction in the ROM, CPU needs to load the instruction from the ROM to IR based on the PC, extract the op-code and operands, load the operands from memory, perform the instruction operation in ALU, store the results in the destination, and starts new fetchexecution cycle, all of these are controlled by the control
I/O Ports
The I/O ports are used to connect input and output devices. The common input devices for an embedded system include keypad, switch, button, knob, all kind sensors (light, temperature, pressure, ..) The output devices include Light Emitting Diode(LED), Liquid Crystal display(LCD), print, alarm, actuator, etc. Both input and output such as communication interfaces include Network Interface Card (NIC), modem, and mobile phone
Parallel Port
A microcontroller is integrated with several parallel I/O ports which are used to interface the microcontroller to outside devices such as switches, LCD, keypad, and actuators. The parallel ports get or send 8 bits data at a time from/to connected outside devices. Many microcontrollers have 4-8 ports, e.g., both the 8051 and 68HC11 have 8-bit I/O ports.
Some of the ports are input only(port E of 68HC11) to connect input devices such as keypad, sensors. Some of the ports are used for output only (Port D of 68HC11) to connect output devices such as LCD and any actuator. Some I/O ports are partial input/output like the port A in 68HC11. The bi-directional ports are the most common I/O ports in any microcontrollers. The 8051 I/O ports are all bi-directional. The multiplexers and demultiplexers facilitate multiple channel communications via a single common port.
p0.1 p0.7
D0 D7
8051
LCD
P2.0 p2.2
E RS R/W
Serial Ports
Some I/O ports such as the port D of 68HC11 and port3 of 8051 can be used to connect a external serial device. The serial communication exchanges data one bit at a time with single data line plus reference lines if needed. The typical application of serial port is to connect a PC with a serial cable to take advantages of PC for embedded software debug, testing, and deployments. A serial ports also allow data to flow between microcontrollers, or between microcontrollers and any serial device.
Serial Communication There must be a protocol (rule) to governor the handshaking between two parties so that the receiver can recognize the beginning of the new coming byte and the ending of the byte. Assume the base logic is high 1 and once the transfer starts, the line is lowed to 0 for a period of time to signal the receiver that the start bit is coming soon, then the receiver activates its accepting circuit. Both sender and receiver follow the same clock pace so that the receiver can sample the right data. The logic 1 is resumed after the 8 bits delivered to mark the end of transmission of one byte data. The RS232 is a serial communication standard which specifies the handshaking rules between two sites. E.g., the communication of a 9-pin COM port connecting to a PC COM port with serial cable complies the RS232 protocol. The data is transferred at a specified baud rate (bps number of bits per second). The baud rate at both sites must be set same so that the signals can be synchronized. It is called asynchronous communication because there is no clock control line between for transmitter and receiver synchronizes the pace.
mark
Serial out
1111 01000011
11111
Serial in
UART 8051
COM port
Computer
SBUF 8 bits
8 bits
fullduplex
Serial out
TxD
TxD RxD
ground
TxD RxD
TxD in UART TI
Serial Communications
The asynchronous serial communication is support by a built UART circuit. It is possible to get and send data at same time in a full-duplex mode or at separate time in the half-duplex mode. In transmission the UART streams out 8 bits in sequence via TxD pin at the specified baud rate. After 1 byte data is out the UART set the TI flag to 1 to notify the completion of the transmission and makes the buffer ready for next byte data. The 68HC11 or 8051 provide TxD and RXD separate pins for microcontroller to send and get data to/from a connected serial device. The low left block diagram only depicts the UART in transition. The receiver works in the opposition direction via the RxD pin and the completion of receiving one byte is notified by the RI flag.
INT ALE RD WS
2. Deply the executable code produced in the host machine into the target machine (the embedded system itself) to run it on the target machine for the integration testing.
Com puter
Host
Target
.h, .c
SRC (option )
Code 1 Code 2
Data 1 Data 2
Most embedded software is multi-tasking based software which supports multiple tasks running concurrently on the same CPU. One CPU can only run one instruction at a time but multiple tasks are running simultaneously in a macro view. E.g.,, A temperature control embedded system has a thermal sensor and control panel with keypad and LCD. The embedded system maintains the room temperature with a range of 70F ~ 80F. If the temperature goes up 80+ then a red LED is turned on, falls below 70-F then a green LED is on; Both LEDs are off if the temperature is between up and lower bounds. The current temperature is always displayed on the LCD. Users can reset the upper and lower bounds by the keypad at any time. The software must run at least two tasks concurrently.
Task1 Task2
while(1) { sample ADC with sensor; reset temp; if (temp>up_T) turn on Red; else if (temp<low_T) turn on Green; else turn off both wait(100ms); } while(1) { If (input from keypad) reset the up_T or Low_Tif wait(100ms); }
The task1 mainly monitors the current temperature and takes action when the temperature goes beyond the limits. It samples the sensor every 100 ms. The task2 is ready to take user inputs from keypad to rest the temperature upper limit and lower limit. This simple embedded software deals with real time and multiple tasks. You can design this software in multitasking by Real time Operating System (RTOS) or using the interrupt mechanisms supported by all microcontrollers. There are many commercial or open source RTOS available for you to choose from based on the microcontroller systems. RTX51 is a RTOS which comes with the Keil development kit
Summary
The foundational concepts of microprocessors and microcontrollers
The hardware and software structure of embedded systems, categories and application of embedded systems, the constraints and design criteria and challenges in embedded system design and development. a road map of embedded software design and development including software modeling, software coding, cross-compilation, multi-tasking programming, and RTOS implementation. Two getting started labs with the C8051F005DK development kit (with target board) of Silicon Labs and stand-alone C51 Keil software development kit are provided to help you get start with embedded system design in aspects of both hardware and software.