Ktl-icon-tai-lieu

timers -counter

Được đăng lên bởi Trần Văn Nam
Số trang: 19 trang   |   Lượt xem: 859 lần   |   Lượt tải: 0 lần
MICROCONTROLLERS
CHAPTER 3

TIMERS – COUNTERS MODULES

Dr. Vo Tuong Quan
HCMUT - 2011

TIMER - COUNTER
Definition
-The operations of Timer and Counter in microcontroller are
similar.
-Timer: use to count the time
-Counter: use to count the event or some other things
-The capacity of Timer/Counter is based on the number of bits
they have.
Ex: Timer 8 bits  can be count from 0 to 255
Timer 16 bits  can be count from 0 to 65535
Timer 32 bits  can be count from 0 to 4294967296
-Timer/Counter have two modes: Count Up/ Count Down
- Timer needs a clock source, for example of the clock source
of 10KHz is input to a timer then one increment will take
100uS (micro second). This clock source can be obtained
from the MCU clock.
2

 2011 – Vo Tuong Quan

TIMER - COUNTER
Definition
-The operations of Timer and Counter in microcontroller are
similar.
-Timer: use to count the time
-Counter: use to count the event or some other things
-The capacity of Timer/Counter is based on the number of bits
they have.
Ex: Timer 8 bits  can be count from 0 to 255
Timer 16 bits  can be count from 0 to 65535
Timer 32 bits  can be count from 0 to 4294967296
-Timer/Counter have two modes: Count Up/ Count Down
- Timer needs a clock source, for example of the clock source
of 10KHz is input to a timer then one increment will take
100uS (micro second). This clock source can be obtained
from the MCU clock.
3

 2011 – Vo Tuong Quan

TIMER - COUNTER
Prescaler
The function of prescaler is to divide the CPU clock to obtain a
smaller frequency. Some typicle prescaler division factors:
256 128 64 32 16 8 4 2 1 (Prescaler by-passed)
What is watchdog timer?
A timer that monitors how long it takes the MCU to complete a
scan. Watchdog timers output an error message if the MCU
scan takes too long.

4
 2011 – Vo Tuong Quan

TIMER - COUNTER
Example: Using Timer of pic18f4520
TIMER0 control rsegister
Name
T0CON
Initial
Value

TMR0ON

T08BIT

T0CS

T0SE

PSA

PS2

PS1

PS0

1

1

1

1

1

1

1

1

BIT7 - TMR0ON: Timer0 On, set this to 1 to start the timer.
BIT6 - T08BIT: =1 for 8 bit mode and =0 for 16 bit mode.
BIT5 - T0CS: Timer0 clock source. =1 for T0CLK pin input i.e.
counter mode. Set to 0 for internal instruction clock.
BIT4 - T0SE: Used in counter mode only. Please see
datasheet for details.
BIT3 - PSA: Prescaler Assignment. Set this to 0 to assign
prescaler or 1 to by pass it.
BIT2 to BIT0 - PS2 to PS0: Prescaler Division factor select 5
 2011 – Vo Tuong Quan

TIMER - COUNTER
PS2

PS1
...
MICROCONTROLLERS
CHAPTER 3
TIMERS – COUNTERS MODULES
Dr. Vo Tuong Quan
HCMUT - 2011
timers -counter - Trang 2
Để xem tài liệu đầy đủ. Xin vui lòng
timers -counter - Người đăng: Trần Văn Nam
5 Tài liệu rất hay! Được đăng lên bởi - 1 giờ trước Đúng là cái mình đang tìm. Rất hay và bổ ích. Cảm ơn bạn!
19 Vietnamese
timers -counter 9 10 448