3

I'm trying to port some old Pascal code that I was handed, whose purpose is to control a digital I/O card, and I've run into a snag involving a wait function. Whenever sending a signal the programmer would do something like this

[Set the port status]
LoopDelay([a long integer])
[Set the next port status]
LoopDelay([next long integer])  
etc.

LoopDelay looks like this:

procedure loopdelay(looping:longint);
var
  counter,count : longint;
begin
  for counter:=1 to looping do
    inc(count);
end {loopdelay};

It looks to me like he did some math based on the processor speed and calculated how many times he would have to iterate through a loop to wait a certain amount of time. How can I figure out how long the wait is?

Additional information: The processor is a late 80s/early 90s 486 (according to wikipedia at between 20 and 66 MHz). The computer runs either DOS or an early Windows, and the code was compiled with Turbo Pascal 7. The two constants being passed to loopdelay are 1266 and 6328.

I should be visiting the machine soon, so hopefully I'll be able to find out the exact processor then. Ideally I would like a formula into which I can plug the clock speed.

Rohit Gupta
  • 4,022
  • 20
  • 31
  • 41
  • 3
    I don't think you can't. Moreover, such values were usually more a guestimate than a cold calculation. Usually in such cases you try to guess the magnitude from the problem description, and then simply test. But in newer software on preemptive systems, better use sleep() or something like it. Or you face the same issues as TP did, overflow from DIY delay code on fast processors – Marco van de Voort Mar 26 '14 at 19:50
  • Are you still supporting the original digital IO card? You might check it's documentation to see the delays are defined there. – EricM Apr 04 '14 at 18:51
  • It shouldn't be more than a few ms, [a 50 MHz 80486 executes around 40 million instructions per second](http://en.wikipedia.org/wiki/Intel_80486). – Sertac Akyuz Nov 23 '14 at 16:17

2 Answers2

0

With the actual pascal implementations you can use the delay procedure, no delay loop necessary. But how long should the delay be? I can think of four ways to get this information.

  1. Eventually you can find the documentation of the card or the parts thereon where the necessary delays are listed.

  2. You can find an old PC and measure a delay loop with a very large count.

  3. You disassemble the loopdelay procedure, look for an 486 manual and and calculate the time that the loop takes by hand.

  4. Try and error and add a good safety margin.

Kitana
  • 187
  • 10
0

Loop delays were something I encountered a few times in the past. They looked like bad programming practice. I rewrote one as an interrupt routine using the old DOS terminate and stay resident, or pug into the event loop triggered by a real time clock read and compare. This is probably something where you could improve the code.

kd4ttc
  • 1,075
  • 1
  • 10
  • 28