The author describes an algorithm that allows high-precision measurement using microcontrollers. The precision of measurements using any digital computer is limited by the finite clock frequencies present in the system. The proposed algorithm overcomes this limitation by dynamically adjusting the measurement time as a function of the required precision and the clock frequency present in the system. Speed and phase measurements are described to illustrate the algorithm. The examples considered have been implemented in electricity generating equipment.