0

I use hardware timers

  bitTimer = timerBegin(0, 2, true);
  timerAttachInterrupt(bitTimer, &timerESP, true);
  timerAlarmWrite(bitTimer, halfBit, true);
  timerAlarmEnable(bitTimer);

My board uses a 40 MHz 10ppm crystal, I want to improve the accuracy of the timer. From the documentation I understood that the 40 MHz crystal does not affect the timers. But I saw that you can use the ability to connect an external 32 kHz crystal. But I can't find information about what exactly affects the accuracy of the hardware timer. Please tell me. Is it true that using an external 32 kHz crystal with an error of 0.2 ppm will increase the accuracy of the timers?

5
  • Where do you get the idea of "error of 0.2 ppm"? The 40MHz is the main crystal, and the 10ppm means that the frequency will drift at an aging rate of 10ppm/year for the first year (so the freq could varies between 39,999,600Hz to 40,000,400Hz, i.e. +/-400Hz). you are setting up a timer0 running at 20MHz as indicated by your code timerBegin(0, 2, true) so the 32.768kHz RTC crystal is irrelevant for your application if you are expecting a timer running at 20MHz.
    – hcheung
    Commented Jul 9 at 10:12
  • @hcheung Got it, thanks for the clarification. So, in order to improve the timer's performance with less error, I need to change the 40MHz crystal, for example, to 40MHz 0.2ppm?
    – EndyVelvet
    Commented Jul 9 at 16:07
  • There is no such crystal exists with 0.2ppm, where do you get the idea? and what exactly is the application that you need such an stability? 40MHz with 0.2ppm means frequency delta of +/- 8Hz, or a timer resolution of 0.00001 nano seconds(1.000e-14)...
    – hcheung
    Commented Jul 9 at 23:01
  • @hcheung Crystals with such frequency exist with different accuracy ±0.02ppm,±0.05ppm, ±0.1ppm, ±0.2ppm,±0.5ppm. Such crystals are used where counting accuracy is needed. For example, in cinema equipment. Some manufacturers have crystals with an accuracy of 0.2ppm
    – EndyVelvet
    Commented Jul 10 at 9:50
  • I believe what you described is something like oven-control crystal oscillator(OCXO) or temperature-control crystal oscillator (TCXO), they are entire oscillator module, the crystal is still have the same aging ppm, but it provides the calibration and stability circuit to make sure the frequency, once calibrated, will not fluctuated or change by external factor such as temperature. GPS could also be a timer clock source for higher accuracy if you need a high accurate 1s timing.
    – hcheung
    Commented Jul 12 at 7:44

0

Browse other questions tagged or ask your own question.