PIC Vietnam

PIC Vietnam (http://www.picvietnam.com/forum/index.php)
-   Cơ bản về vi điều khiển và PIC (http://www.picvietnam.com/forum/forumdisplay.php?f=8)
-   -   timer2 trong pic6f887a (http://www.picvietnam.com/forum/showthread.php?t=6410)

eros_89_a 25-05-2010 04:03 PM

timer2 trong pic6f887a
 
em mới tìm hiểu về pic .đọc đến chỗ timer2 nhưng không hỉu cơ chế hoạt động của nó .mong các anh giải thích dùm em .cám ơn các anh !

manhdktd 03-07-2010 11:16 AM

timer2 hoạt động không khác gì timer0(cũng chế độ 8 bít)
chú ý là timer2 còn được thiết lập cho chế độ PWM,compa,capture.
(bạn đã nắm bắt được timer0 thì timer2 cũng vậy thôi).
hy vọng giúp được bạn.

baquyen 03-07-2010 08:57 PM

Tớ copy một đoạn trong cuốn sách tiếng Anh nhé (phần PWM), lười dịch quá :)
setup_timer_2(mode, period, postscale)
initializes timer 2 where mode is
T2_DISABLED
T2_DIV_BY_1
T2_DIV_BY_4
T2_DIV_BY_16

period is an offset value between 0 and 255
before the timer resets postscale is a value between 0 and 16 to determine the times before an interrupt occurs
set_pwm1_duty(value)
this will write the 10 bit value to the PWM module
set_pwm2_duty(value)
If only 8 bits are sent, the 2 lsb’s will be ignored.
Note, value is in the range 0 to period
set_ccp1(CCP_PWM), set_ccp2(CCP_PWM)
this function will initialize the CCP in a PWM mode
Example:
setup_ccp1(CCP_PWM);//sets up for pwm
setup_timer_2(T2_DIV_BY_4, 140, 1);
//140 as offset, timer 4
set_pwm1_duty(70);
//50% duty cycle, i.e. half of 140


Múi giờ GMT. Hiện tại là 05:09 AM.

Tên diễn đàn: vBulletin Version 3.8.11
Được sáng lập bởi Đoàn Hiệp.
Copyright © PIC Vietnam