Mail Archives: djgpp/1999/04/20/18:46:53
Guillermo Rodriguez Garcia wrote:
> > Another option
> >would be to use the Pentium clock register, but that wouldn't
> >work on 486 and below...
>
> But the Pentium clock register depends on the processor clock rate,
> thus it is system-dependet, isn't it? I may be wrong; could you please
> ellaborate this a bit more?
Yes. But if you borrow a real-time timer for a little while at first,
you can run it against the clock counter and estimate the clock speed.
Then you can use that to calibrate your measurements/delays/whatever.
Pseudocode:
volatile int tick;
void int_handler(void) { tick++; }
void calibrate()
{
install_timer_interrupt(int_handler);
set_timer_frequency(arbitrary_freq);
tick = 0;
while (!tick) /* loop */ ;
start = rdtsc();
tick = 0;
while (!tick) /* loop */ ;
end = rdtsc();
clock_ticks_per_sec = (end - start) * arbitrary_freq;
}
--
Nate Eldredge
nate AT cartsys DOT com
- Raw text -