Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Single- and Multi-Chip Microcontroller Interfacing For the Motorola 68HC12 (G.J. Lipovski, 1999).pdf
Скачиваний:
112
Добавлен:
12.08.2013
Размер:
41.97 Mб
Скачать

5,4 Fast SynchronizationMechanisms

259

5.4.1 Direct Memory Access

One of the fastest ways to input data to a buffer is direct memory access. Compared to techniques discussed earlier, this technique requires considerably more hardware and is considerably faster. A DMA channel is the additional logic needed to move data to or from an I/O device. In DMA, a word is moved from the device to a memory in a DMA transfer. The device requests transferring a word to or from memory; the microprocessor CPU, which may be in the middle of an operation, simply stops what it is doing for one to five memory cycles and releases control of the address and data buses to its memory by disabling the tristate drivers that drive these buses; the I/O system including the DMA channel is then expected to use those cycles to transfer words from its input port to a memory location. Successive words are moved this way into or from a buffer.

The DMA device has a DESTINATION address, a COUNT, and a DONE status bit. The DESTINATION and COUNT registers are initialized before DMA begins, and are incremented and decremented, respectively, as each word is moved.

Two DMA techniques are generally available. An internal I/O device or an external I/O device can use DMA. If an external I/O device wishes to input or output data, it causes an edge on a pin control signal, which steals a memory cycle to transfer one word in cycle steal mode, or it asserts a level that halts the microprocessor to transfer one or more words in burst mode,as long as the level remains asserted. This sequence of events happens when a DMA request is made to input a byte using cycle stealing.

1. A falling edge occurs on an input pin, signaling the availability of data.

2.In the DMA controller, a request is made and granted, and a memory cycle is stolen from the processor.

3.The controller signals the I/O device to read a byte from a port.

4.The byte is written into memory using a DESTINATION address.

5.The COUNT value is decremented. If it becomes 0, the DONE status bit is set, The program gadflies or interrupts on this DONE bit, and resumes when it is set.

There is a two-level BUSY/DONE state associated with DMA, as with any I/O transfer that fills or empties a buffer, as discussed at the beginning of this chapter. The low-level BUSY/DONE state is associated with the transfer of single words. BUSY is when a word is requested from an input device and has not been input, or is sent to an output device and has not been fully output (the hardware is punching the paper in the paper-tape example). The high-level BUSY/DONE state is associated with the transfer of the buffer. BUSY is when the buffer is being written into from an input device and has not been completely filled, or the buffer is being read from into an input device and has not been completely emptied. The DMA channel synchronizes to the low-level BUSY/DONE state to move words into or out of the I/O device. The computer can synchronize with the high-level BUSY/DONE state in the ways discussed so far. A real-- time synchronization would have the processor do some program or execute a wait loop until enough time has elapsed for the buffer to be filled or emptied. Gadfly synchronization was used in the example given above. An interrupt could be used to indicate that the buffer is full.

268

Chapter 5 Interrupts and Alternatives

Do You Know These Terms?

See page 36for instructions.

synchronization

microprocessor

Universal Product

context switching

IDLE

sees a request

Code (UPC)

context

BUSY

request is pending

bar-code reader

DMA channel

DONE

honors an interrupt

real-time interrupt

DMA transfer

starting

handler

timer

release control

stopping

arm

multithread

steal a memory

completing

armed

scheduling

cycle

real-time

disarmed

tick

cycle steal mode

synchronization

enable

thread

burst mode

gadfly

disabled

sleep

buffered I/O

gadfly loop

critical section

sleepTime

cached I/O

handshake

software disarming

priority

cache

opto-isolator

interrupt handler

age

lazy buffer

signal

polls

background thread

management

interrupt

priority order

high-priority thread

eager buffer

device requests

service routine

n-key rollover

management

an interrupt

round-robin

shuffle stack

I/O channel

interrupts are

vectored interrupt

WAI

I/O channel

enabled

interrupt vector

STOP

program

microprocessor is

contact bounce

exit

shuttle memory

enabled

wait-and-see

compile-time

indirect memory

microprocessor is

X-10

breakpoint

time-multiplexed

masked

linear-select

loStreams

memory

microprocessor

keyboard

pipe

transparent DMA

is disabled

coincident-select

direct memory

 

non-XIRQ

keyboard

access

 

308 Chapter 7 Analog Interfacing

Two kinds of analog signals are important. These correspond to AM and FM radio. In this chapter, we consider analog signals whose amplitude carries the value, whether he signal is direct current or alternating current, as AM radios carry the sound. In the next chapter, we consider analog signals whose frequency or phase carries the value of he signal, as FM radios carry the sound. Amplitude analog signals are more pervasive in interface design. It is hard to find examples of interface hardware that do not have some analog circuitry (we had to search long and hard to find some decent problems for Chapter 3 that did not have analog circuits in them). It is even hard to discuss frequency analog circuits without first discussing amplitude analog circuits. So we study amplitude analog circuits in this chapter and frequency analog circuits in Chapter 8.

Analog signals are converted to digital signals by analog-to-digital converters (A- o-D converters), and digital signals are converted to analog by digital-to-analog converters (D-to-A converters) such that the digital signal – usually a binary number or a binary-coded decimal number - corresponds in numerical value to the analog signal level. Analog signals are also converted to a single digital bit (H or L) by a comparator, and digital signals control analog signals by means of analog switches. The frequency

of an AC signal can be converted to or from a voltage by

voltage-to-frequency

converters (V-to-F converters) or by frequency-to-voltage

converters (F-to-V

converters). Finally, analog signals are generated by transducers that change other measurements into voltages or currents, such as temperature-to-voltage transducers, and are amplified and modified by operationalamplifiers (OP AMPs).

A basic theme of this chapter is that many functions can be done using digital or analog hardware, or using software. The smart designer determines the best technique from among many alternatives to implement a particular function. Thus, the designer should know a little about analog circuitry. On the one hand, a basic understanding of he operation and use of analog circuits is essential in making intelligent hardware/software trade-offs and is quite useful even for programmers who write code to interface to such devices. So we want to include the required material in this chapter. On he other hand, to use them well, one can devote an entire year's study to these devices. We have to refrain from covering that much detail. Therefore, our aim is to give enough detail so readers can make good hardware/software trade-offs in the design of microprocessor analog systems and to encourage those who seek more detail to read some of the many excellent books devoted to the topic of analog signal processing.

In the following sections, we will discuss conversion of physical quantities to voltages and from voltages, the basics of operational amplifiers and their use in signal conditioning and keyboard/display systems, digital-to-analog conversion, analog-to- digital conversion, and data acquisition systems. Much of the material is hardware oriented and qualitative. However, to make the discussion concrete, we discuss in some detail the use of the popular CAS140 operational amplifier and the 4066 and 4051 analog switches. Some practical construction information will be introduced as well. The reader might wish to try out some of the examples to understand firmly these principles.

This chapter should provide enough background on the analog part of a typical microcomputer I/O system so the reader is aware of the capabilities and limitations of analog components used in I/O and can write programs that can accommodate them.

312 Chapter 7 Analog Interfacing

series with the lamp and usually need higher voltages. Their radiant energy is confined to specific wavelengths that are determined by the material in the lamp. While these are sometimes used with microprocessors, their relatively high voltage and current requirements, and the electrical noise generated by gas discharge lamps and fluorescent lamps, limit their usefulness. More popular are the LEDs and LCDs. An LED is basically a diode that will emit light if about 10 mA are sent through it. The light is generated in specific wavelengths: red and infrared are the easiest to generate; but green, yellow, and orange are also widely available. Current passing through an LED drops about 1.7 to 2.3 V, depending on the diode material. LEDs are often used in displays to indicate some output from a microcomputer and are also used in communications systems to carry information. Inexpensive LEDs can be pulse modulated at better than 10 KHz, and special ones can work at around 1 GHz. An LCD is electrically a capacitor that is clear if the RMS voltage across it is less than about a volt and opaque if more than about two volts; it consumes very little power. The voltage across an LCD must be AC, however, because DC will polarize and destroy the material in the LCD. Usually, one terminal has a square-wave signal. If the other terminal has a square-wave signal in phase with the first, the display is clear, and if it has a square-wave signal out of phase with the first, the display is opaque.

Radiant energy is often measured in industrial control systems. A photodetector converts the amplitude to a voltage or resistance for a given bandwidth of the very high frequency sine wave carrier. Often this bandwidth covers part of the visible spectrum and/or part of the infrared spectrum. The photomultiplier can measure energy down to the photon - the smallest unit of radiation - and has an amplification of about one million. However, it requires a regulated high voltage power supply. The photodiode is a semiconductor photodetector able to handle signals carried on the amplitude of the radiant energy around 10 MHz. The current through the diode is linearly proportional to the radiation if the voltage drop across it is kept small. This is done by external circuitry. However, it is inefficient because a unit of radiant energy produces only 0.001 units of electrical energy. A photodiode might be used in a communication linkage to carry a signal on a light beam because of its high bandwidth and ease of use with integrated circuits. If the diode is built into a transistor, a phototmnsistor is made that relates about one unit of electrical energy to one unit of radiant energy, but the signal carried on the amplitude is reproduced up to about 100 KHz. Finally, a photoresistor is a device whose resistance varies with the intensity of the light shone upon it. While this device is also temperature sensitive, has poor frequency response, and is quite nonlinear, it can be used to isolate a triac, as we discuss later.

Photodiodes, phototransistors, photoresistors, and other detectors are often used with LEDs or lamps to sense the position of objects or to isolate an external system from the microcomputer. Photodetectors are commonly used with an LED light source to detect the presence or absence of an object between the light source and the photodetector. To sense the pattern on the disk under the contacts, a shaft encoder or tooth counter can use his kind of sensor in place of a mechanical contact. Similar techniques place an LED and a phototransistor inside an integrated circuit package, called an opto-isolator, to isolate the circuitry driving the LED from the circuitry connected to the detector so that hey can be kilovolts apart and so that electrical noise in the driver circuitry is not ransmitted to the detector circuitry.