Project HighPrecisionTimer
Version v1.2
Date 19th July 1999
Copyright, Authors Tom Peiffer <peiffer@rhrk.uni-kl.de>
NPS <kvk@estpak.ee>
Alex Abreu <simonet@bhnet.com.br>
Gordon Bamber <gbamber@mistral.co.uk>
Project type Delphi 4 Component
Filename HighPrecisionTimer v1.2.zip
Description Invisible component that makes very high time measures possible, depending on the speed of your CPU.
Files in zip-archiv HighPrecisionTimer.pas
HighPrecisionTimer.dcr
hpThread.pas
Back.gif
Green.gif
Demo.zip

Copyright - InstallationGeneral information - Usage - Properties - Methods - Events  

Copyright

This component is completely copyright by the authors listed above. However, you are absolutely allowed to make changes to the source, but you have to leave the names of the authors in the source files. Just add your name to the list.

Installation

Delphi 4: Unzip the files HighPrecisionTimer.pas, HighPrecisionTimer.dcr and hpThread.pas in your component directory. Go to menu Components and choose "Install component". Select the HighPrecisionTimer.pas file and click on OK. The component is placed in the "System" pallette. There are no other files needed than those contained in the zip file.

General Information

  1. When setting Enabled to true, the thread starts automatically and the trigger is only called after the second elaps of TimePeriod seconds. Because of internal calls in the thread, the time of the first trigger is normally a little bit bigger than it should be.
  2. You can use the StartTimer, StopTimer and GetElapsedSeconds to make exact time measuring of your code. This is much more accurate than the normal usage of the component by writing some code in the event since no second thread needs to be started. In the thread itself, many calls are made in regular intervals, which all take some time. On my system for example (AMD K6-200 MHz)I get a maximum time resolution by using the Event OnHighPrecisionTime of about only 0.00013 seconds = 7700 Hz, which is far away from the theoretical 200 MHz of my system. But anyway, this timer is much more precise than the normal Delphi timer, which has a maximum resolution of 7,7 Hz (on a Win95 machine), resp. 100 Hz (on a Win NT machine).
    The faster your CPU, the better is your time resolution! You can use the demo program to determine the maximum time resolution of your machine.
  3. I have tried the test program on my Win95 system and the program failed completely. I have no idea why. Any comments about this problem would be appreciated by mailing to Tom Peiffer.

Usage

Just drop the component on your form. Assign values to either the property Frequency or TimePeriod. Place your code to the OnHighPrecisionTimer Event.

Properties

Property About: string ;
Shows a box about the authors.

Property ProcessorSpeed:Double ;
A read-only property showing the speed of your CPU.

Property HasTimeStamp:Boolean ;
Indicates if your processor is able to read time stamps. All Pentiums and AMD-K6 should be able to do so.

property Frequency : extended ;
Put in the number of Hz that you want to make time triggers. This value is equal to the inverse of TimePeriod.

property TimePeriod : extended ;
Put in the number of seconds between two time triggers. This value is equal to the inverse of Frequency.

property ThreadPriority : TTHreadPriority ;
Select the ThreadPriority used for make the measures. tpLower is a good choice.

property Enabled : boolean ;
If true, then the OnhighPrecisionTimer event is triggered.

property Version : string ;
Shows the version of the component.

Methods

Procedure ShowAbout;
Shows a box whith the authors.

Procedure RefreshTimeStamp;
Refreshed the timestamp of your CPU.

Function GetTimeStamp:TLargeInteger ;
Read the timestamp of your CPU, if supported.

Function SupportsTimeStamp:Boolean;
See HasTimeStamp property.

Procedure StartTimer;
Starts the internal timer.

Procedure StopTimer;
Stops the internal timer.

Function GetElapsedTicks:Comp;
Gives you the number of ticks since the procedure StartTimer has been called.

Function GetTicksPerSecond(ITERATIONS:Word):Comp;
For example on a 200MHz computer, 200.000.000 ticks are counted per second.

function GetExactCpuSpeed:Double;
Read the exact MHz of your CPU.

Function GetElapsedSeconds:Double;
Gives you the number of seconds since the procedure StartTimer has been called.

Function GetCPUSpeed:Comp;
See GetExactCpuSpeed.

Events

property OnHighPrecisionTimer : TOnHPTimer ;
This event is triggered when the time indicated in TimePeriod has elapsed. As parameters, you get the elapsed seconds since you've set enabled to true, the DeltaSeconds between this and the last measure an the total number of calls since enabled=true.

© 1999. Authors: Tom Peiffer,NPS,  Alex Abreu,  Gordon Bamber