• AVR Freaks

Hot!How can I calculate the accurancy of time measurement ?

Author
irmak
Starting Member
  • Total Posts : 49
  • Reward points : 0
  • Joined: 2019/07/05 23:50:12
  • Location: 0
  • Status: offline
2019/10/27 01:36:00 (permalink)
0

How can I calculate the accurancy of time measurement ?

Dear Forum Members
 
I use PIC16f1789
I use 4 MHz external Cyristal 
 
I set Timer0 period to 200uS
 
I measure the time difference between an alarm LED blink and alarm reset button push.
How can I calculate the accurancy of my results ?
 
===============
 
 
#1

8 Replies Related Threads

    crosland
    Super Member
    • Total Posts : 1692
    • Reward points : 0
    • Joined: 2005/05/10 10:55:05
    • Location: Warks, UK
    • Status: offline
    Re: How can I calculate the accurancy of time measurement ? 2019/10/27 01:43:08 (permalink)
    +1 (1)
    Too little information.
     
    What's the purpose of the timer?
     
    How are you measuring the time difference?
     
    What do you mean by "accuracy"?
     
    Show your code...
     
    The crystal with have an accuracy specification. Calculate from that. That's why we use crystals when we want accuracy.
    #2
    irmak
    Starting Member
    • Total Posts : 49
    • Reward points : 0
    • Joined: 2019/07/05 23:50:12
    • Location: 0
    • Status: offline
    Re: How can I calculate the accurancy of time measurement ? 2019/10/27 02:01:43 (permalink)
    0
    Dear Crosland
     
    My code is too long to put in forum.
     
    I use an oem cyristal without a datasheet. 
     
    If the exteranl oscilator have accurate to around 20 ppm how doe this effect timer0 calculations ?
    #3
    ric
    Super Member
    • Total Posts : 24540
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: How can I calculate the accurancy of time measurement ? 2019/10/27 03:29:09 (permalink)
    +1 (1)
    irmak
    I set Timer0 period to 200uS

    How?
    Using MCC?
    On most PIC16F PICs, Timer 0 is NOT the best one for periodic measurements.
     

    I measure the time difference between an alarm LED blink and alarm reset button push.

    How are you doing this?
    I suspect the technique is more important than the accuracy of your crystal.
     
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #4
    irmak
    Starting Member
    • Total Posts : 49
    • Reward points : 0
    • Joined: 2019/07/05 23:50:12
    • Location: 0
    • Status: offline
    Re: How can I calculate the accurancy of time measurement ? 2019/10/27 03:41:34 (permalink)
    0
    Dear Ric
     
    My timer settings are below.
    I have used a web based timer wizard.
    Do you have any sugession alternate to timer0 ?
     
     
    -----TIMER0---
    void timer0_pasif(void);
    void __interrupt() KESME(void);
    void timer0_register_ayarla(void)
    {

    T0CS = 0; 
    T0SE = 0; 
    PSA = 0; 
    PS2 = 0;
    PS1 = 0;
    PS0 = 1;

    //
    TMR0 = 206;
    }
    void timer0_aktif(void)
    {
    GIE=1;
    T0IE=1;
    }
    void timer0_pasif(void)
    {
    GIE=0;
    T0IE=0;
    }
    void __interrupt() KESME(void)
    {
    if (T0IF==1)
    {
    genel_zaman=genel_zaman+200; //
    TMR0=206; //TMR0 preload degeri // reset the timer preset count
    T0IF=0;
    }
    }
     
    ------------------------------------------------------
     
     
    #5
    ric
    Super Member
    • Total Posts : 24540
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: How can I calculate the accurancy of time measurement ? 2019/10/27 03:48:41 (permalink)
    +2 (2)
    Use TMR2. It has a PR2 register which does the preload automatically for you, perfectly accurately
    Doing it in software is not good, as you are not allowing for the overhead of the interrupt service entry.
    (There are better ways do do it in software than you have done, but still not as accurate as getting TMR2 to do it in hardware.)

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #6
    irmak
    Starting Member
    • Total Posts : 49
    • Reward points : 0
    • Joined: 2019/07/05 23:50:12
    • Location: 0
    • Status: offline
    Re: How can I calculate the accurancy of time measurement ? 2019/10/27 04:08:24 (permalink)
    0
    Dear Ric Many Thanks
     
    http://ww1.microchip.com/downloads/en/devicedoc/31013a.pdf
     
    Timer (TMR2) and Period (PR2) Registers The TMR2 register is readable and writable, and is cleared on all device resets. Timer2 increments from 00h until it matches PR2 and then resets to 00h on the next increment cycle. PR2 is a readable and writable register. TMR2 is cleared when a WDT, POR, MCLR, or a BOR reset occurs, while the PR2 register is set. Timer2 can be shut off (disabled from incrementing) by clearing the TMR2ON control bit (T2CON<2>). This minimizes the power consumption of the module
     
    http://ww1.microchip.com/downloads/en/DeviceDoc/31011a.pdf
     
    11.5 Using Timer0 with an External Clock 
    11.5.1 External Clock Synchronization
    11.5.2 TMR0 Increment Delay
    #7
    ric
    Super Member
    • Total Posts : 24540
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: How can I calculate the accurancy of time measurement ? 2019/10/27 04:14:36 (permalink)
    0
    I'm not sure why you quoted parts of the datasheet.
    Did you have another question?
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #8
    irmak
    Starting Member
    • Total Posts : 49
    • Reward points : 0
    • Joined: 2019/07/05 23:50:12
    • Location: 0
    • Status: offline
    Re: How can I calculate the accurancy of time measurement ? 2019/10/27 04:22:37 (permalink)
    0
    Dear RIC
     
    First of all many thanks for your effort.
     
    When I ask a question in the form, if any one give final answer I put related documents and detailed description to support others who may encounter the same problem.
     
    I found it usefull...
    #9
    Jump to:
    © 2019 APG vNext Commercial Version 4.5