• 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: 為何PIC12F629 timer1誤差這麼大, 快吐血了!!!
#2
資深會員
資深會員


查看用戶資訊
您知道內部RC振盪本身的誤差有多少嗎?看了一下data sheet,就算是填入校正值到OSCCAL,也還有大約有2%的誤差。您的誤差還不到1%,真是可喜可賀!

跟timer1關係不大。

勸您快快回頭是岸,外接crystal,情況保證大幅改善。

發表於: 2005/9/9 20:31
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


為何PIC12F629 timer1誤差這麼大, 快吐血了!!!
#1
新會員
新會員


查看用戶資訊
大家好(我一點也不好):
我用了一顆PIC12F629做計時器, 使用內部OSC 4MHz, GPIO2接LED, 程式如下:
參考http://www.microchip.com.tw/modules/n ... e=flat&order=ASC&start=10
#include <pic.h>

// 每50ms(0.05s)計數一次 
// (4Mhz/4) [1*(50000)] = 50mS (內部振盪器:4MHz, Prescale:1)
#define TMR1H_VALUE 256-(unsigned char)((4000000/4 * 0.05)/256)-1
#define TMR1L_VALUE 256-(unsigned char)(4000000/4 * 0.05) % 256 

#define WARNNING_LED    GPIO2

//**********************************
//* Function Prototype Declaration
//**********************************
void interrupt isr_Sevr void );
void Initial_Timer1Int(void);

// ================================================================
// **** Establish PIC12F629 Configuration Word
// **** == Internal Oscillator No Clock Mode
// **** == Watch-Dog Timer Off
// **** == Power Up Timer Off
// **** == MCLR Enable External
// **** == Brown-Out Detect Enabled
// **** == Code Protect Off
// **** == Data EE Read Protect Off
//__CONFIG  (INTRC_OSC_NOCLKOUT & WDT_OFF & PWRTE_OFF & MCLRE_EXT & BODEN_ON & CP_OFF & CPD_OFF);

unsigned long _50ms 0;
unsigned long _1s 0;
unsigned long _1m 0;
//---------------------------------------------------------------------------


//*********************************
//* program main()
//*********************************
void main(void)
{
    
// 校正內部Oscillator 4Mhz    
    
OSCCAL _READ_OSCCAL_DATA();

    
// Initial GPIO
    
GPIO 0;        // Init GPIO
    
CMCON 0x07;    // Set GP<2:0>(CM<2:0>) to digital IO
    
TRISIO 0b00000011;    // Set GP<1:0> as input and GP<2> as output

    
Initial_Timer1Int();

    while (
1)
    {
        if (
_50ms >= 20)    // 1秒
        
{
            
_50ms 0;
            
_1s++;
        }
        if (
_1s>=60)        // 1分鐘
        
{
            
_1s 0;
            
_1m++;
            
WARNNING_LED = !WARNNING_LED;
        }
    }
}
//---------------------------------------------------------------------------


//***********************************************
//*          Interrupt Service Routine            *       
//***********************************************
void interrupt isr_Sevr void )
{
    
//GIE = 0;        // INTCON<7> Disables all interrupts
    
if (TMR1IF)        // PIR1<0>
    
{
        
TMR1H TMR1H_VALUE;
        
TMR1L TMR1L TMR1L_VALUE;
        
TMR1IF 0;
        
_50ms++;
    }
    
//GIE = 1;        // INTCON<7> Enables all unmasked interrupts
}
//---------------------------------------------------------------------------


//***********************************************
//*         Initial Timer1 Interrupt
//***********************************************
void Initial_Timer1Int(void)
{
    
TMR1H TMR1H_VALUE;
    
TMR1L TMR1L_VALUE;
    
// Enable Timer1
    
T1CON 0b00000001;    // Enable Timer1, Internal Clock(Fosc/4), LP Oscillator is Off, 
                        // 1:1 Prescale Value, Timer1 is On ignore !T1G
    
    
TMR1IE 1;        // PIE1<0> Enable Timer1 Interrupt
    
PEIE 1;        // INTCON<6> Enables all unmasked peripheral interrupts
    
GIE 1;        // INTCON<7> Enables all unmasked interrupts
    
TMR1IF 0;        // PIR1<0> TMR1 register overflowed (must be cleared in software)
}

為何1分鐘就會快個0.5秒, 真傷腦筋

發表於: 2005/9/9 19:46
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... ]

教育訓練中心

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