M. Amer Iqbal Qureshi


How does a timer operate?



tải về 3.06 Mb.
Chế độ xem pdf
trang22/132
Chuyển đổi dữ liệu09.12.2022
Kích3.06 Mb.
#53945
1   ...   18   19   20   21   22   23   24   25   ...   132
Amer Iqbal - Teach Yourself PIC Microcontrollers for Absolute Beginners-Microtronics Pakistan (2001)

How does a timer operate? 
In practice, everything works as follows: pulses coming from quartz oscillator are once per each machine 
cycle directly or via pre-scaler brought to the circuit which increments number in the timer register. If one 
instruction (one machine cycle) lasts for four quartz oscillator periods then, by embedding quartz with the 
frequency of 4MHz, this number will be changed a million times per second (each microsecond). 
It is easy to measure short time intervals (up to 256 microseconds) in a way described above because it is 
the largest number that one register can contain. This obvious disadvantage may be easily overcome in 
several ways by using slower oscillator, registers with more bits, prescaler or interrupts. The first two 
solutions have some 
weaknesses so it is more 
recommended to use 
prescaler and/or interrupt. 
Using prescaler in 
timer operating 
A prescaler is an 
electronic device used to 
reduce a frequency by a 
pre-determined factor. 


Teach Yourself PIC Microcontrollers | www.electronicspk.com | 23 
Meaning that in order to generate one pulse on its output, it is necessary to bring 1, 2 , 4 or more pulses to 
its input. One such circuit is built in the microcontroller and its division rate can be changed from within the 
program. It is used when it is necessary to measure longer periods of time. 
One prescaler is usually shared by timer and watch-dog timer, which means that it cannot be used by both 
of them simultaneously. 
Using interrupt in timer operating 
If the timer register consists of 8 bits, the largest number that can be written to it is 255 (for 16-bit registers 
it is the number 65535). If this number is exceeded, the timer will be automatically reset and counting will 
start from zero. This condition is called overflow. If enabled from within the program, such overflow can 
cause interrupt, which gives completely new possibilities. For example, the state of registers used for 
counting seconds, minutes or days can be changed in an interrupt routine. The whole this process (except 
interrupt routine) is automatically performed “in the background”, which enables main circuits of the 
microcontroller to perform other operations. 

tải về 3.06 Mb.

Chia sẻ với bạn bè của bạn:
1   ...   18   19   20   21   22   23   24   25   ...   132




Cơ sở dữ liệu được bảo vệ bởi bản quyền ©hocday.com 2024
được sử dụng cho việc quản lý

    Quê hương