[comp.windows.ms.programmer] Interrupts and high-resolution timing under Windows

oivindt@bio.uio.no (Oivind Toien) (05/06/91)

I need a high resolution timer function (at least 100Hz) that works
under win 3.0 to trigger an A/D conversion routine.

The resolution of the timer function in windows is usually to low (55
ms) to be used for timing an A/D conversion routine. In addition, the
priority of timer messages are quite low, so that samples could be
lost because of mouse events. It seems that the only way to go is to
use an interrupt routine (although the only thing I found in the
Petzold book about this is that you should stay with the timer
function :-( ).

I have two interrupt routines that runs fine under DOS (Turbo-pascal).
They both use the Setintvect function to attach Int $1C (the user
timer interrupt) to an interrupt routine. 

When running the same routine under TPW the debugger shows that the
address is set correctly to the interrupt routine. But the routine does
not seem to be activated. Has anyone has got this to work in either C
or TPW? (If interest i can mail the source that works under dos).

If someone have some example code they would be willing to share
it would be highly appreciated too.
--
Oivind Toien   <oivindt@ulrik.uio.no>
Div. of General Physiology, Dept. of Biology, Univ. of Oslo
P.O. Box 1051, N-0316 Oslo 3, NORWAY  
Phone+47-2-454732  Fax+47-2-454726

Thomas_Hornschuh@p1.f36.n245.z2.fidonet.org (Thomas Hornschuh) (05/09/91)

OT> I have two interrupt routines that runs fine under DOS (Turbo-pascal).
OT> They both use the Setintvect function to attach Int $1C (the user
OT> timer interrupt) to an interrupt routine.
OT> 
OT> When running the same routine under TPW the debugger shows that the
OT> address is set correctly to the interrupt routine. But the routine does
OT> not seem to be activated. Has anyone has got this to work in either C
OT> or TPW? (If interest i can mail the source that works under dos).
OT> 

You can use the timer interrupt in windows. But you must install a protected 
mode interrupt handle with the help of the DPMI (DOS Protected Mode Interface).
DPMI is invoked via INT 31H.
You must use the functions

Name                             IN                       OUT
Get Protected Mode Int Vect.    AX=0204H,BL=Int Number.   CX:DX =
                                                          Selector:Offset of
                                                          handler

Set  "          "   "    "      AX=0205H,BL=Int. Number
                                CX:DX= Selector:Offset
                                of new handler             Carry flag = TRUE
                                                           if error

Using this functions is equal to the DOS SetInt/GetInt functions.
Don't forget to chain with a JMP FAR to the old handler at the end of your
new handler. 

An alternative is, use your old code as a DOS TSR, load it before windows and 
use the DPMI functions to pass control and data between your windows app and 
the TSR. But this is more complicated and only usefull if your old code can't 
run in protected mode.

The full DPMI specification can ordered from Intel, Santa Clara.


+-----------+                         Thomas Hornschuh
|           |                     SoftStream Development
|   *       |           Obermarkstr. 72, D-4600 Dortmund 30, FRG
| *   *     |         Tel ++49-231-48 64 60  Fax ++49-231-48 85 98
|   *       |                        FidoNet 2:245/36.1
+-----------+ UseNet: Thomas_Hornschuh%p1.f36.n245.z2@hippo.dfv.rwth-aachen.de