Change CONFIG_MSEC_PER_TICK to CONFIG_USEC_PER_TICK. This gives more options for system timers in general, but more importantly, let's us realize higher resolution for the case of CONFIG_SCHED_TICKLESS=y -- of course, at the risk of some new interger overvflow problems
This commit is contained in:
parent
ed3f7857e2
commit
baf2c2098e
@ -2220,23 +2220,23 @@ The system can be re-made subsequently by just typing <code>make</code>.
|
||||
|
||||
<p><b>System Timer</b>
|
||||
In most implementations, system time is provided by a timer interrupt.
|
||||
That timer interrupt runs at rate determined by <code>CONFIG_MSEC_PER_TICKS</code> (default 10 or 100Hz).
|
||||
The timer generates an interrupt each <code>CONFIG_MSEC_PER_TICKS</code> milliseconds and increments a counter called <code>g_system_timer</code>.
|
||||
<code>g_system_timer</code> then provides a time-base for calculating <i>up-time</i> and elapsed time intervals in units of <code>CONFIG_MSEC_PER_TICKS</code>.
|
||||
That timer interrupt runs at rate determined by <code>CONFIG_USEC_PER_TICKS</code> (default 10000 microseconds or 100Hz. If <code>CONFIG_SCHED_TICKLESS</code> is selected, the default is 100 microseconds).
|
||||
The timer generates an interrupt each <code>CONFIG_USEC_PER_TICKS</code> microseconds and increments a counter called <code>g_system_timer</code>.
|
||||
<code>g_system_timer</code> then provides a time-base for calculating <i>up-time</i> and elapsed time intervals in units of <code>CONFIG_USEC_PER_TICKS</code>.
|
||||
The range of <code>g_system_timer</code> is, by default, 32-bits.
|
||||
However, if the MCU supports type <code>long long</code> and <code>CONFIG_SYSTEM_TIME16</code> is selected,
|
||||
a 64-bit system timer will be supported instead.
|
||||
</p>
|
||||
<p><b>System Timer Accuracy</b>
|
||||
On many system, the exact timer interval specified by <code>CONFIG_MSEC_PER_TICKS</code> cannot be achieved due to limitations in frequencies or in dividers.
|
||||
As a result, the time interval specified by <code>CONFIG_MSEC_PER_TICKS</code> may only be approximate and there may be small errors in the apparent <i>up-time</i> time.
|
||||
On many system, the exact timer interval specified by <code>CONFIG_USEC_PER_TICKS</code> cannot be achieved due to limitations in frequencies or in dividers.
|
||||
As a result, the time interval specified by <code>CONFIG_USEC_PER_TICKS</code> may only be approximate and there may be small errors in the apparent <i>up-time</i> time.
|
||||
These small errors, however, will accumulate over time and after a long period of time may have an unacceptably large error in the apparent <i>up-time</i> of the MCU.
|
||||
</p>
|
||||
If the timer tick period generated by the hardware is not exactly <code>CONFIG_MSEC_PER_TICKS</code> <i>and</i> if there you require accurate up-time for the MCU, then there are measures that you can take:
|
||||
If the timer tick period generated by the hardware is not exactly <code>CONFIG_USEC_PER_TICKS</code> <i>and</i> if there you require accurate up-time for the MCU, then there are measures that you can take:
|
||||
</p>
|
||||
<ul>
|
||||
<li>
|
||||
Perhaps you can adjust <code>CONFIG_MSEC_PER_TICKS</code> to a different value so that an exactly <code>CONFIG_MSEC_PER_TICKS</code> can be accomplished.
|
||||
Perhaps you can adjust <code>CONFIG_USEC_PER_TICKS</code> to a different value so that an exactly <code>CONFIG_USEC_PER_TICKS</code> can be realized.
|
||||
</li>
|
||||
<li>
|
||||
Or you can use a technique known as <i>Delta-Sigma Modulation</i>. (Suggested by Uros Platise). Consider the example below.
|
||||
@ -2247,7 +2247,7 @@ The system can be re-made subsequently by just typing <code>make</code>.
|
||||
Consider this case: The system timer is a count-up timer driven at 32.768KHz.
|
||||
There are dividers that can be used, but a divider of one yields the highest accuracy.
|
||||
This counter counts up until the count equals a match value, then a timer interrupt is generated.
|
||||
The desire frequency is 100Hz (<code>CONFIG_MSEC_PER_TICKS</code> is 10).
|
||||
The desire frequency is 100Hz (<code>CONFIG_USEC_PER_TICKS</code> is 10000).
|
||||
</p>
|
||||
<p>
|
||||
This exact frequency of 100Hz cannot be obtained in this case.
|
||||
|
Loading…
Reference in New Issue
Block a user