Response Devices and Timing

Psychological experiments need different types of input devices. The PXL programs currently support up to three different ways for response collection:

  1. Input from the keyboard. This is the default if speed is not important or if many different input signals are required.
  2. Input from a switchboard that is connected to a parallel input port. On IBM PC compatible machines the parallel printer connector may be used to connect up to five digital input lines to the computer. The game port also contains 4 digital input switches. This type of input is very fast and allows for precise response timing.
  3. Input from a mouse pointer and its buttons. Mouse devices usually have two or three buttons that may be used as response switches in a way comparable to special switchboards.

Insert Table scode here.

Selection of one of these input devices is done by setting the experimental variable switchtype to a numerical code that describes the device. Table scode contains the currently valid code values. The default is switchtype 0 which enables keyboard input. Code values from 1 to 19 are reserved for switchboard devices. Values from 1 to 5 are reserved for switchboards connected to the game port connector. Values from 11 to 16 are used by switches connected to one of the parallel printer connectors.

It must be clear, however, that not every PXL program allows input from every arbitrary device. There may be programs that definitely require a certain device in order to work properly. Suppose you want to measure response times. Using the keyboard as a response device will be a bad idea in this case, since there will be a considerable delay between the subject's response and the software interrupt that is needed to detect it. Thus a program to measure response time may require a switchboard. In this case the program will check the current value of switchtype before it starts. If the switchtype value is not appropriate, the program will issue a fatal error message and stop execution.

Thus switchtype has two functions: it tells PXL programs about the type of response device available, and it allows the user to select one device if several are available and the program is able to use different devices. Most programs are able to use any of the three devices possible. In these cases the variable switchtype may be used to tell the respective program which type of switch should be used. Note that the command line option -t n may also be used to set the default input device. This mechanism is described in Chapter run. As described in Chapter exvars an assignment in a program's parameter file overrides the defaults. In some cases it is not sufficient to set the input device. It may also be necessary to tell a program the exact input codes in order to decide what are correct and false responses. An example is the program rtm. Figure sboard gives the input codes for the switches of switch boards. The input codes for keyboard input are the corresponding ASCII values or the keyboard scan codes.

Keyboard Input

Each computer has a keyboard that may be used as a response device. For many experiments a keyboard is sufficient or even necessary. One major problem with keyboard input is that the system's keyboard software usually is not very useful for running experiments. PXL provides some but not too much help for MS-DOS users. PXL programs intercept the keyboard interrupt service in order to get the interrupt time as early as possible and they provide a real BREAK key, that even works if the program runs in a dead loop not doing any system call. Thus a PXL program may be stopped any time by pressing the CTRL-C key combination. Such a break closes all open files and restores the original system status. The break mechanism works on MS-DOS systems but only as long as the keyboard buffer is not filled by other nonsense input.

If the keyboard is used as a response device one may want to disable the keyboard break mechanism in order to prevent the subject from being able to kill the program. This is possible by setting

   keybreak = OFF
in the parameter file. By default the experimental variable keybreak is ON.

Insert Figure gswitch here.



Switchboards on IBM PC/AT compatibles may be connected to the parallel printer port or the game port. The printer port provides 5 handshake input lines that may be used to connect up to 5 digital switches to the computer. Figure prswitch shows a simple passive network to connect 5 switches to the IBM PC parallel input connector. Figure gswitch shows how to connect 4 digital switches to the game port connector.

Insert Figure prswitch here.

Note from Table scode that the switchtype codes for switches do not stand for the number of switches but for the configuration. Thus number 4 is a switchboard with four switches in a single row, while number 5 stand for 4 switches in a square. Figure sboard shows the suggested configurations for switch boards and the corresponding numbering schema.

Insert Figure sboard here.

Installation and Configuration

There are several ways to configure the switchboard software to specific devices connected to non-standard ports. The parameter switchport may be used to tell a PXL program that the switchboard is not connected to the printer port of LPT1 but to a different port number. Possible values for switchport are 2 (LPT2) and 3 (LPT3). All other values default to the standard configuration.

PXL uses several ports and masks to access the switchboards. All of these may also be redefined for adapting the software to non-standard devices. The parameters are collected in the integer array switchmask. It is possible to install a special switch board for response collection provided the mechanism for reading the board's bit pattern is compatible with PXL's own mechanism to read parallel input switches. The general schema is to have an 8-bit parallel input port to read from. The switch port is read by the instruction:

Reading the port until there are at least two identical inputs is some save guarding against mechanical switch vibrations, although this is not perfect. SWITCHPORT is the port address of the input port and SWITCHSLCT is a pattern mask for selecting only special bits of the input pattern.

The input port may also be initialized. This is simply done by writing an initialization pattern SWITCHINIT to the control port address SWITCHCTRL:

Since the input bit polarity of any input port strongly depends on the port hardware a mask is applied to each input pattern such that pressing a switch always results in a logical 1 for the respective bit while a logical 0 always represents an open switch. Thus the hardware port pattern pis modified by the expression
before it is handed over to the calling program.

Response switches usually have special patterns which are related to special meanings for experimental programs. An example is a program for adjusting some stimulus intensity. Such a program needs at least 3 keys: one for up, one for down, and one to indicate that the adjustment is finished. These keys are selected by binary patterns which are used to mask off certain bits of the input ports.

All the parameters for an input switch board are stored in the array switchmask. The list of definitions in Table swmask shows the meaning of the different entries of switchmask. The array switchmask may be redefined in parameter files. The following example defines the patterns for an 8-bit parallel input port at port address 0x104(= 260) with initialization port address at 0x107 (=263):

   switchmask = [260,263,155,255,255,255,255,85,170,12,3,48,192,1]
Note that the parameter switchtype is not affected by changing switchmask. In fact, the default values of switchmask are those belonging to the built in mask values for switchtype. One may change only selected entries of switchmask by inserting only those entries which have to be changed. All the entries which are not to be changed have to be set to -1.

Insert Table swmask here.

Mouse Input

Mouse devices may be convenient for experiments since they have simple buttons that make them saver than keyboards. However, they suffer from the same timing problems as keyboards. The PXL software automatically detects the number of buttons and uses the buttons in the same way as switchboards are used. Note that mouse usage requires that a mouse device driver is installed. Mouse drivers are able to generate interrupts and some PXL programs are able to use interrupt driven response keys. Usually these have to activated by a flag and are not used by default. In order to get stable timing with mouse buttons one has to make sure that no mouse movements occur while the programs is waiting for a response. Thus either the mouse is fixed or the mouse ball should be removed.

Voice Key

Some programs support voice key input via a microphone connected to a Sound Blaster board. This device is still in an experimental phase.

Response Event Numbers

All response events are numbered. The switch numbering is bitwise and it is defined by the entries of the array switchnumbers. The default for switchnumbers depends on the device type. For game port switches the default is
   switchnumbers = [0, 0, 0, 0, 1, 2, 3, 4]
Note that bits 0 to 3 are not used with game port switches since the single switches are connected to bits 4 to 7 of the game input port. For printer port switches the default is
   switchnumbers = [0, 0, 0, 1, 2, 3, 4, 5]
The array switchnumbers may also be redefined in a parameter file.

Mouse event numbers are switchnumbers = [1, 2, 3] depending on the number of buttons available. The event numbers for keyboard input are identical to the key's scan code combined with the extended ASCII code for the respective key. The test program event.exe may be used to find out the event numbers of any response device.

Frequently Used Events: "yes", "no", and "stop"

Many experiments use yes/no responses. In this case the parameters yeskey, nokey, and stopkey offer a simple way to define which switch number corresponds to the respective response. Simply define the parameter value to be the switch number of the corresponding response event. The default values for these keys in case of keyboard input are
   yeskey = 19200           /* 0x4B00, cursor left */
   nokey = 19712            /* 0x4D00, cursor right */
   stopkey = 20224          /* 0x4F00, END */
These correspond to the left and right arrow key and the END-key. The test program event.exe (Chap. demos) returns the switch number of any response event.


The PXL programs use milliseconds as their unit for timing parameters. The time is derived from the hardware and software timer available in IBM PC/AT computers. Precision of timing is around 1 millisecond on these systems. The IBM PC timing software is extremely hardware dependent and works only on true "compatibles". The system time on these machines is derived from a hardware counter whose input frequency is 1.19318 MHz. This frequency is constant across all IBM PC compatible computers and independent of system bus timing and of processor clock speed. The PXL timing software is optimized for speed by using only integer arithmetic. No hardware floating point processor is used by the timing functions. One consequence of this is that timing is not correct across midnight. Thus it is better not to run experiments that try to measure the time between two events such that the system time crosses midnight in between the two events. If this seems to be an absolute necessity for someone, a simple solution is to use a wrong time of day value. Simply set the time of day such that the midnight overflow does not happen during the experimental run. Section ttcheck describes the test program ttcheck which may be used to test the proper working of PXL's basic timing functions.

Back to table of contents

Author: Hans Irtel