11.4.2 A Solution

A solution is to compute the period between ticks, and use its reciprocal as the speed. This method is not suitable when there is sufficient encoding resolution because reciprocal is difficult to compute (compared to counting ticks), and the resolution of the period-oriented approach drops as speed increases. However, at lower speeds, this period-oriented method yields much better resolution than tick counting.

In our previous example, using the tick count method, 0.1r/s cannot be distinguished from 0.09r/s because both yields about 5 ticks per PID invocation. However, using the period measurement, 0.1r/s results in a period of 10ms, whereas 0.09r/s results in a period of 11.1ms. Even with a timing resolution of 1ms, we can still distinguish 0.09r/s from 0.1r/s.

Note that timing resolution can be improved by hardware peripherals. The ATMega128, for example, has an ``input capture'' device associated with timer 1. It can record the duration of a pulse at resolutions down to single clock periods.



Copyright © 2006-02-15 by Tak Auyeung