Файл: Embedded Controller Hardware Design (Ken Arnold, 2000).pdf
ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 13.06.2025
Просмотров: 2697
Скачиваний: 0
175CHAPTER EIGHT
Basic I/O Interfaces
register must be polled to determine if the device is ready. If the program is written to loop continuously waiting for the device to become ready, a lot of CPU time is wasted if the data is not available shortly after the polling begins. An example would be a keyboard, where keys are pressed at relatively slow and unpredictable rates. In order to minimize the time wasted in polling for these irregular data, interrupts are used. An interrupt is triggered by an event that is not synchronized to the main program and calls a special subroutine, referred to as an interrupt service routine (ISR that transfers the data. This “on-demand” processing is more efficient when data rates are relatively slow or unpredictable. At the other extreme however, when peak data transfer rates are high as they are in a disk drive, another technique that reduces the amount of work the CPU must do to transfer I/O data is used. The I/O interface transfers data directly between the I/O device and memory without CPU intervention using direct memory access (DMA).
Real-Time Processing
Some applications demand that the CPU respond to external events and process them in a finite amount of time. Real-time processing means that data are processed at the same rate that they occur. They are event-driven which means they are triggered by external events, such as the tick of a clock, completion of I/O, etc. Examples of real-time PC programs are the flight control program on the Space Shuttle, arcade games, speech processing software, and flight simulators. Examples of non-real-time PC programs would be word processors and accounting programs.
Direct Memory Access (DMA)
Direct memory access (DMA) requires that the I/O interface be active and semiintelligent, since it must count the words and increment the memory address for each element transferred in addition to performing the actual transfer.
The transfer process involved with DMA is typically as follows:
1)The program writes into the I/O control register of the interface:
a)The type of transfer (I or O).
b)The number of bytes or “block size” to transfer.
176EMBEDDED CONTROLLER
Hardware Design
c)The physical address in memory where the data will be transferred.
d)A start command is given to begin the transfer.
2)Data is transferred directly between memory and I/O devices under control of the I/O interface.
3)When the transfer is complete, the I/O interface sets a completion bit in the status register, and may also initiate an interrupt to the CPU.
Figure 8-10 compares program-controlled and DMA I/O.
Direct memory access is used for high speed I/O. The I/O device interface takes over the bus from the CPU and controls the transfer of data between memory and I/O directly, without any intervention by the CPU (as shown in Figure 8-10). Data is generally transferred in larger blocks, such as a disk file block.
Program Controlled I/O
CPU |
Memory |
I/O |
||
DMA (Direct Memory Access) I/O
CPU |
Memory |
I/O |
||
Devices on a bus can talk with each other without
talking with the CPU, except to tell it when done. DMA is good for disk and network transfers because the rates are much higher than the CPU can handle using program controlled I/O. There are two ways of doing DMA transfers: single cycle DMA and burst DMA modes.
Burst vs. Single Cycle DMA
In burst mode DMA, the DMA device gets control of the bus, transfers a whole block of data (a disk sector, for example), and then releases the memory back to the CPU. A single cycle DMA device gets the bus, transfers just one word of data, and releases the bus. Arbitration is the process of determining what device will have control of the memory bus.
177CHAPTER EIGHT
Basic I/O Interfaces
Burst mode has low overhead and can handle the highest peak data rates, but the CPU can get locked out of memory for intervals that are as long as the longest block to be transferred. If the transfer is longer than the shortest interrupt interval, such as the real time clock tick interval, interrupts can get lost.
Cycle Stealing
In this mode, DMA transfers are completed during bus cycles that are not used by the CPU, so no arbitration needs to be done. Most modern, high performance processors utilize almost 100% of available memory bandwidth however, so there isn’t much available for DMA. To save time, it is possible to perform arbitration and data transfer overlapping in time.
In general, burst mode DMA is more effective when relatively short time durations are needed to transfer the data block. Under those conditions, the bus is fully utilized for a short time interval. The DMA controller acquires access to the memory, transfers an entire block of data, and then releases the memory. An entire block of data is transferred in one short burst. The disadvantage is that a burst mode DMA device “hogs” the bus, thus preventing any other device from accessing memory during the burst. If the burst lasts too long, it may prevent the CPU from servicing certain time critical events, such as the real time clock interval (clock tick). In that case, the clock would run slower than it should because it would cause the CPU to miss some of the clock ticks. Therefore, burst mode DMA is most effective for data that is transferred at a high peak rate for short intervals. Typically, the data within a burst comes in too quickly to allow the arbitration handshaking required for the DMA controller to acquire and release the data between each data element. An example of this situation is the transmission or reception of data on a high-speed local area network interface. Small packets of data come across the network in high-speed (less than one microsecond per byte) bursts, with relatively low packet rates (milliseconds between packets).
For single cycle mode, the DMA controller acquires access to memory, transfers one word, and releases the memory. That allows other memory transfers to be interleaved with the DMA. That is why this mode is also referred to as “interleaved DMA.” Single cycle DMA is better suited to transferring data over longer periods of time, where there is enough time to acquire and release the bus for every word transferred. In this case, the CPU and other devices can still access
178EMBEDDED CONTROLLER
Hardware Design
the memory, at a reduced bandwidth. As a result, the CPU may be a bit slower because it will sometimes have to wait for a DMA cycle to complete, but it is not entirely shut out when a DMA transfer is in progress. When a single cycle DMA transfer occurs, more time is used in acquiring and transferring control of the memory to and from the DMA controller since it happens so much more frequently. This “overhead” frequently reduces the overall available memory bandwidth, especially when it is performed sequentially with the data transfers. Some systems overlap the memory bus arbitration handshaking with the memory data transfers so that the arbitration does not slow down the data transfers.
Direct memory access is required when the CPU is too slow to transfer the data under program control. Because the CPU does not have to participate directly in the item-by-item transfer of data, DMA is also useful when there are other tasks that the CPU can perform. In those cases, DMA transfers may be used even though they are not strictly required by the data rate.
Elementary I/O Devices and Applications
Parallel ports are the simplest form of I/O, but there are many different types of electrical interfaces ranging from the simple open collector TTL outputs used on a PC printer port to high-speed peripheral interfaces such as the IEEE-488 and SCSI buses. Most embedded controller ICs have some pins that are configurable as parallel input or output. These interfaces are appropriate for simple I/O, such as key switch and display interfacing. They are also appropriate for controlling and monitoring high-level interfaces such as solid-state relays.
The parallel I/O ports available on the 8051 family and similar processors are fairly versatile, with special internal circuitry to allow a port bit to be configured individually as an input or output. Some microcontrollers also provide considerable current source and sink capability, however the 8051 family parts are usually fairly weak in that regard.
Serial ports, also referred to as asynchronous or synchronous communications (COM) interfaces, are commonly used to interconnect with devices, such as modems, which inherently transmit the data one bit at a time over a communication link such as a phone line. The RS-232 serial interface used in a PC’s COM port is an asynchronous serial data stream. An asynchronous interface
179CHAPTER EIGHT
Basic I/O Interfaces
has no explicit clock signal to synchronize the transfer of data. The timing of bits is based on the absolute bit rate, and is synchronized on every character with a start bit. The serial to parallel conversion is performed by a UART (universal asynchronous receiver-transmitter). When transmitting data, the UART appends a start bit before the data, shifts out the data LSB first, and adds a stop bit after the data. Once the transmission is complete, the UART sets a status bit indicating that the data has been sent and that it is ready to begin transmission of another character.
When receiving data, the UART looks for and synchronizes to the leading edge of a start bit. Then, it delays for one and one-half of a bit period, so that it samples the LSB in the middle of the bit period. Then, the UART delays one bit period, samples the next to the LSB, etc. until all the bits have been shifted in. Once all the data has been received, it is loaded into a buffer register and a status bit is set to indicate that the receive buffer contains a character and may be read by the CPU. In order for this method to work, the two UARTS at each end of the communication must have bit rate clocks that are accurate enough to guarantee that the data will be sampled at the right time. This typically requires a sample clock that is 16 times the data rate, accurate to 1% to 2%.
Timers and counters, which are present in most microcontroller chips, allow generation of pulses and interrupts at regular intervals. They can also be used to count pulses and measure event timing. Some of the more sophisticated versions can measure frequency, pulse width, and relative pulse timing on inputs. Outputs can be defined to have a given repetition rate, pulse width, and even complex sequences of pulses in some cases. In most cases, one of the timers can be used to generate the necessary serial clocks required to operate a microcontroller’s on-chip UART. In order to meet the approximately1% clock frequency accuracy for the 16x data rate clocks, the crystal frequency is often chosen to allow exact integer division of the crystal frequency resulting in an accurate, standard serial data rate. This is why 8051 family parts that use their internal counters and serial port to connect to standard 9600 bps and higher data rates use the crystal frequency 11.059 MHz rather than an even 12 MHz.
Analog to digital converters (ADCs) and digital to analog converters (DACs) are used to convert continuously variable real world parameters to digital form and back to analog. Examples include conversion of the output voltage of a temperature sensor into digital form for processing, and converting control
180EMBEDDED CONTROLLER
Hardware Design
values back into analog form to adjust the temperature. Most of the quantities of interest in the real world tend to be continuous and analog in nature, so these converters are critical for many applications.
Timing and Level Conversion Considerations
Depending upon the rate and load on the processor, peripherals can be interfaced using interrupt driven, program controlled, or DMA I/O. High speed devices will generally require DMA, while devices that generate small amounts of data at unpredictable times are better handled with interrupts and program controlled I/O.
Level Conversion
Many types of devices that need to be interfaced to the processor are not compatible with standard logic levels. For example, many serial interfaces comply with an interface standard, such as the EIA RS-232 specification, which defines the voltage level and pin out. RS-232 levels are nominally plus and minus 12 volts, instead of the 0 to 5 volt levels that most processors use. As a result, level shifting devices are needed to translate between the 0 to5 and +/-12 volt signals. Single ICs that provide the translation as well as generating the +/-12 volt supplies from a single +5 volt supply, are now available (Maxim MAX232 and others), making this much easier for embedded system designers.
Intermediate DC voltages can often be handled using simple open-collector outputs, or a separate transistor and pull up resistor to drive output voltages higher than the logic supply. Power switching FETs are also available that can handle relatively high currents and voltages, and can be driven directly by logic-level outputs.
Power Relays
High-level outputs, such as 110 volt AC loads, must be switched using solid state or magnetic relays. The magnetic relay windings are inductive coils that must be clamped using a diode to prevent large inductive transients from
181CHAPTER EIGHT
Basic I/O Interfaces
damaging the relay driver circuits. Solenoid valves and other devices are used to control external flow and have similar inductive characteristics. Solid-state relays are much easier to use, as they are isolated from the high voltage and provide a simple logic level interface. Optical isolation is also used to sense high voltage inputs and convert them to logic levels. There are even standardized modules (OPTO-22 and equivalents) available that can be interchanged with each other, resulting in very flexible configuration options.
Chapter Eight Problems
1.Using an 8031 Port 1 I/O bit, design an interface to an LED that requires 20 milliamperes of output current for full brightness.
2.A DMA device transfers blocks of data consisting of 256 bytes, and the bytes in the burst are spaced 10 microseconds apart. The real time clock tick interval is 1 millisecond. What kind of DMA should be used, burst mode or single cycle?
3.If an 8031 CPU executes one instruction per microsecond, estimate the maximum rate that data can be transferred to or from an I/O port, assuming that a status bit must be polled before transferring data.
4.Design a 4-row by 3-column telephone keypad matrix for connection to the 8051 Port 1 pins, to be polled using software scanning.
This is a blank page.
9 |
|
CHAPTER NINE |
183 |
Other Interfaces
and Bus Cycles
There are two kinds of interrupts software and hardware. Software interrupts are just another kind of subroutine call that can be used to access subroutines with entry points at fixed memory locations. Operating system services are often accessed using software interrupts, which are simply instructions that cause an interrupt subroutine to be called at whatever point in the program they are placed. These interrupts are synchronized with the program in that they always occur at the same place in the program. They are referred to as “synchronous events because their execution is solely dependent upon the sequence of execution of the program instructions.
Some processor manufacturers refer to “traps” or “exceptions,” but these are synonymous with the term “interrupt” as used here, which may be either a hardware or software interrupt. Unless otherwise specified, however, the word “interrupt” is generally used to imply a hardware interrupt. Hardware interrupts are triggered by a physical event, such as the closure of a switch, that causes a specific subroutine to be called. They can be thought of as a sort of hardware initiated subroutine call. They can and do occur at any time in the program, depending on when the event occurs. These are referred to as “asynchronous events because they may occur during the execution of any part of the program. Interrupts allow the programs to respond to an event when it occurs. In a printing application, the printer may interrupt the processor to inform the program that it has printed all the data in its buffer and is ready for more. A serial interface might activate an interrupt to indicate that a character has been received and it is available to be processed. These kinds of applications are “event driven” because no action will take place until an event occurs. In the case of a typical embedded application, event driven programs are used when it is necessary to respond to an external event within a fixed time period. A system