Definition
Clock conversion is the calculation that turns a counter reading into a time: the number of counts is divided by the rate, in counts per second, at which the counter advances. The resolution is the smallest step of time the counter can show, which is the duration of one count. The accuracy is how close the reported time is to the true time. A counter can have fine resolution and poor accuracy, because accuracy also depends on how exactly that rate is known.
Where it fits
Main entry: Counter quantization (§11.35).
The entry on counter quantization explains the error that comes from reading time in whole counts. This entry adds the step that follows before a graph can show seconds: division by a rate. Let be the number of counts between two readings and the rate at which the counter advances, in counts per second. The reported time is seconds, and the resolution is seconds. The division brings in a second error. The rate used is the nominal rate, the rate that the specification of the counter’s clock states, and the real clock runs slightly faster or slower.
The rounding error stays below one count however long the interval is. The rate error grows in proportion to the length of the interval. A counter at 64,000,000 counts per second has a resolution of 15.625 nanoseconds (billionths of a second). If its clock runs 50 parts per million fast, meaning 50 extra counts in every 1,000,000, a true interval of 600 seconds is reported as 600.03 seconds. The error of 30 milliseconds is 1,920,000 times the resolution.
A third error comes from a stopped counter, because a counter measures time only while it runs. Armv7-M, a specification by the company Arm for the processors in microcontrollers §6.1 (small computers on one chip), defines a counter of processor clock cycles that “does not increment when the processor is halted in Debug state”, the state in which a debugging tool has stopped the processor.
Questions answered
How can exact cycle counts still give approximate microseconds?
Exact cycle counts give approximate microseconds because a count becomes a time only when it is divided by the rate of the clock, and that rate is known only approximately. A cycle counter is a hardware counter that goes up by one on every cycle of a clock signal, so the difference of two readings is an exact whole number of cycles. The time is , where is the count and is the rate of the clock in cycles per second. With cycles and cycles per second, is seconds, which is 2 microseconds (millionths of a second). But the in the division is the nominal rate that the specification of the clock states, and the real clock runs slightly faster or slower. If the nominal rate is 1000 cycles per second and the real rate is 1010, then 101 cycles are reported as seconds although only seconds passed. Every reported time is 1% too long.
Events that are not tied to the clock also do not fall exactly on cycle boundaries, so the reported interval between two such events is off by less than one cycle. A counter that stops, for example while a debugging tool has halted the processor, misses the time it spent stopped. More printed digits remove none of these errors. Too few digits add one more: a conversion that drops the fraction turns 100 cycles at 64 cycles per microsecond, exactly 1.5625 microseconds, into 1 microsecond.
Related entries: Clock source and drift (§6.18), DWT cycle counter (§6.20), Wall clock and clock synchronization (§9.36), Resolution versus precision versus accuracy (§11.34), RTC versus cycle counter (§6.19), Clock domain (§13.29), Quantization error in a measured interval (§18.1.3). Further reading: [81].