• slider image 442
  • slider image 483
  • slider image 484
  • slider image 485
  • slider image 486
  • slider image 487
  • slider image 488
  • slider image 491
:::


Browsing this Thread:   1 Anonymous Users






Re: 請問使用Timer2來做Delay Time的問題
#3
新會員
新會員


查看用戶資訊
Dear yiming:

感謝你的詳解~

發表於: 2007/7/3 17:35
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問使用Timer2來做Delay Time的問題
#2
資深會員
資深會員


查看用戶資訊
拿timer2來做delay真的有點怪怪的...一般timer2都是使用pwm.

其實你如果只想把timer2拿來做delay根本不用設定那麼多...
void Delay_Timer2(void){
tmr2=0;
if(tmr2 > delayX) T2CONbits.TMR2ON=0;
}

16MHZ 一個指令週期就是0.25us
delay_time = 0.25 us* delayX
delayX=100;
delay_timer=0.25us*100=250us

其實你的程式1000us會變成100us 的原因是因為你使用後除器(除10),後除器是給中斷使用的,你的用法後除器是失效的.
所以是(4/16M)*4*100=100 us.

一般delay會用timer0來做,或者算指令時間...
例:使用4MHZ,一個指令週期1us
delay1ms:
movlw .250
movwf lop1
loop1:
clrwdt ;1
decfsz lop1,f ;1
goto loop1 ;2
retlw .o

發表於: 2007/6/30 1:58
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


請問使用Timer2來做Delay Time的問題
#1
新會員
新會員


查看用戶資訊
Dear 各位高手:

使用Fosc 16MHZ,依計算DELAY TIME應該為1m sec
(4/16M)*4*10*100=1m sec
但我用示撥器看ㄉ結果卻為100u sec
請各位高手幫我看看何處有問題ㄋ?感謝!!!

程式如下:
#include <p18f452.h>
#include <timers.h>
void Delay_Timer2(void);
void main()
{
ADCON1=0b00000110;
T2CON =0b01001001;
PR2=99;
TRISD=0x00;
PORTD=0x01;
while(1)
{
PORTDbits.RD0=~PORTDbits.RD0;
Delay_Timer2();
}

}

void Delay_Timer2(void)
{
TMR2=0;
T2CONbits.TMR2ON=1;
while(TMR2<PR2);
{
}
T2CONbits.TMR2ON=0;
}

發表於: 2007/6/26 16:14
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------