You are misled by the name Timer. It is actually not a Timer. It is only a counter. If you use the "Timer" to count the cycles of a known frequency, you can derive the time interval indirectly and accurately. In your case, you use the "Timer" is counting the SMCLK, and you assume that SMCLK has a frequency of 1000000 Hz. This assumption is incorrect and you could be off by as much as 20%. You can improve the accuracy somewhat (to ~3%) by using the so-call factory calibrate DCO settings. Beyond that, you need to install the 32768 Hz Crystal and get more accurate result.
↧