Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!ncr-sd!mattc From: mattc@ncr-sd.SanDiego.NCR.COM (Matt Costello) Newsgroups: comp.unix.i386 Subject: Re: super-HZ timers on SysV/386? Message-ID: <2737@ncr-sd.SanDiego.NCR.COM> Date: 1 Jun 90 18:15:42 GMT References: <9655@ogicse.ogi.edu> Organization: NCR Corporation, Rancho Bernardo Lines: 44 [Originally cross-posted to comp.unix.wizards] In article <9655@ogicse.ogi.edu> apfiffer@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 (CSNET) +1 619 485 2926 uunet!ncrlnk!ncr-sd!mattc