super-HZ timers on SysV/386?

Matt Costello mattc at ncr-sd.SanDiego.NCR.COM
Sat Jun 2 04:15:42 AEST 1990


[Originally cross-posted to comp.unix.wizards]

In article <9655 at ogicse.ogi.edu> apfiffer at admin.ogi.edu (Andy Pfiffer) writes:
>I have a dumb A/D converter plugged into a System V/386 system that requires
>some clever device-driver wizardry. (I love a challenge)
>
>It has no on-board interrupt or DMA capability.  I need to sample it,
>within +/- 10%, at constant, super-HZ (ie: higher than clock tick) intervals;
>8000 Hz would be ideal.

It sounds as if you are trying to sample speech.  If you write a 8 kHz
timing routine then it will get called every 125us.  Getting the sample within
+/-10 percent requires that samples be taken within 12 microseconds of the
expected time.  This is tricky enough in a timing loop, but with interrupt
latency there is no way you are going to do this in a Unix system.  Remember
that critical kernel sections of code do splhi() to disable
interrupts.  If serial characters can sometimes be lost because the tty
interrupt routine are not called in 2 milliseconds, there is no way you can
expect interrupt response within 12 microseconds.

To get your sample rate you are going to have to disable all interrupts
and go into a very tight polling loop.  Any skew in taking samples will
result in unexpected harmonics in the resultant data.  This will stop the
Unix system for 8 seconds, so you will need to advance the clock afterwards.
The safest way to do this is to increase the clock interrupt rate 10% until
the Unix clock catches up with real time.  This will keep all the system
timing routines happy at the expense of slight higher execution times
for running processes.

You would be better off by scrapping the existing A/D board and getting
one that has an interval timer and lots (> 8kB) of dual-ported RAM.  You
could then just have your process do a big read() (80kB for 10 seconds)
and then have a callout() routine copy data over every half second or so.

As an aside I did something similar back in 1979 on a PDP-11.  The
information supplied by Digital for the AD-11 claimed that a PDP could
not sample faster than 4 kHz in an interrupt driven routine; this on a
board that included an interval timer that could automatically take
samples every 'n' microseconds.  I actually used interrupts since I
was writing the data out to magnetic tape in real-time since I needed
to take sample speech for 30 minutes.
-- 
Matthew Costello       <matt.costello at SanDiego.NCR.COM>      (CSNET)
+1 619 485 2926        uunet!ncrlnk!ncr-sd!mattc



More information about the Comp.unix.i386 mailing list