1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Arduino Uno timing accuracy?

Discussion in 'Arduino' started by MikeMl, Jul 20, 2015.

  1. MikeMl

    MikeMl Well-Known Member Most Helpful Member

    Joined:
    Mar 17, 2009
    Messages:
    11,045
    Likes:
    541
    Location:
    AZ 86334
    I have a periodic stream of pulses roughly 10ms between rising edges. I want to measure the period of the pulses. I am willing to take data for up to 10s (average of ~1000 periods) before computing the answer. What absolute accuracy can I expect considering the untrimmed 16MHz resonator and the millis() function in the Uno?
     
  2. Tony Stewart

    Tony Stewart Well-Known Member Most Helpful Member

    Joined:
    Aug 31, 2012
    Messages:
    3,151
    Likes:
    281
    Location:
    Richmond Hill , ON Canada near Toronto
    Using FreqMeasure your count of CPU cycles is expected to be 16k and over 1k samples is expect to be 16M. THe resolution is now greater than the Xtal accuracy of < 50 ppm which can be tuned or replaced with a 1ppm TCXO to determine your accuracy.
     
  3. DerStrom8

    DerStrom8 Super Moderator Most Helpful Member

    Joined:
    Aug 9, 2010
    Messages:
    5,484
    Likes:
    503
    Location:
    Vermont (GMT-5:00)
    The Arduino does very poorly at measuring time, at least in my experience. The libraries are very bulky and waste a lot of time that is not taken into account. The millis() function alone is horrifically inaccurate. I would recommend either writing your own libraries and take the instruction timing into account (nearly impossible to do with C++), or use a bare micro (AVR, PIC) running Assembly (for most efficient code).
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,798
    Likes:
    134
    Location:
    morristown,tn

    Millis is not that bad
    With a little testing you could hit time almost on the head. The ardunio's I have got crystals and playing with some code for time it was as good as my alarm clock it lost a sec or two a day.
     
  6. analog1

    analog1 Member

    Joined:
    Jul 22, 2015
    Messages:
    32
    Likes:
    1
    Well you need a frequency counter with start stop lucky i have one. but you could detect a level rise with a gate and a level stop with a gate now to get to the count you need registers quite a few 10ms is long time
     

Share This Page