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

8

Counters and Timers

The counter/timer is one of the most flexible parts of a single-chip microcomputer. It can generate a square wave. The square wave can be used to generate sine waves, or any periodic wave. Sine waves can be used in telephone systems (touch-tone), and signals to the user (bleeps). The counter/timer can be used to generate single-shot pulses. These can control motors, solenoids, or lights to give precisely timed pulses that are independent of the timing errors to which the real-time programmed microprocessor is susceptible, such as dynamic memory and DMA cycle steals, and interrupts. The counter/timer can itself provide interrupts to coordinate a program, to effect an instruction step, or to effect a real-time clock. To effect an instruction step, the timer is set up as the monitor is left so that it allows one instruction to be executed in the user program before the interrupt returns control to the monitor. The monitor is used to examine or modify memory or registers, then the monitor is left and the next instruction in the user program is executed, and so on. Or a real-time clock can be effected if the timer interrupts every millisecond. The device can be used to count the number of events (falling edges of a signal input to the device), and thus the number of events in a fixed interval of time (the frequency). It is also capable of measuring pulse width and period. Several things can be converted to the period of a signal: voltage can be converted using the voltage-to-frequency converter's integrated circuits, and resistance or capacitance can be converted to the period of a waveform using a linear timer integrated circuit like the ubiquitous 555. We also observe that a single signal can be easily isolated using optical isolators, so the voltage of the system being measured can be kept from the microcomputer and the user. The 'A4 counter/timer was designed for these purposes.

The counter/timer is the principal component, then, in interfacing to frequency analog signals. These signals, like FM radio signals, are easier to handle than amplitude analog signals and are comparatively free of noise. We observe that, at the time of writing, amplitude analog signals are pervasively used in interface circuits; but we believe that frequency (or phase) analog signals will become equally important.

The primary objective of this chapter is to explain the principles of using the counter/timer device. To make these principles concrete, the "A4counter/timer system is introduced. A further objective of this chapter is to emphasize a fundamental principle of top-down design. A counter/timerin a microcomputer is so fascinating that the designer

361