Using an Apple II Microcomputer for Real-Time Control in a Behavioral Laboratory
Total Page:16
File Type:pdf, Size:1020Kb
Behavior Research Methods & Instrumentation 1983, Vol. 15(2),158-166 SESSION IV TECHNICAL ISSUES IN SYSTEM DESIGN STUDENT COMPETITION AWARD Using an Apple II microcomputer for real-time control in a behavioral laboratory WINFORD A. GORDON, DON FOREE, and DAVIn A. ECKERMAN University ofNorth Carolina, ChapelHill, North Carolina 27154 This report describes the hardware and software developed to implement an Apple II (48 KB) as a real-time control device for operant experiments. The hardware has a straightforward design, so that it is readily understandable and can be built by individuals with only minimal experience in the use of integrated circuits and other electronic components. The software routines listed below represent an approach to controlling and handling the data generated by an operant experiment. Using these routines, we are able to record each response and experi mental event, the time of the occurrence, and the conditions at that time. The advent of microprocessor systems has made THE INTERFACE EXPANSION real-time computer control broadly available. Yet, lack ing the electronic skills needed to interface a micro The first element in the system is the AIO serial processor with laboratory equipment, many researchers parallel interface card, which has two 8-bit parallel are reluctant to implement a computer control system. ports and two serial ports. Since we do not use the Commercially produced hardware and software systems serial ports in this application, the expansion circuit are available, but the cost of these systems is often could be adapted to any device that provides two prohibitive. We have developed a control system that is 8-bit parallel ports. The AIO card is inserted into one of straightforward and inexpensive. It is our hope that the main board slots in the Apple II to provide input this description will help others who lack extensive and output (I/O) lines. We use one of the ports for experience in programming or circuit design to imple output and the other for input. Each port is represented ment microprocessor control of laboratory experiments. in the Apple as a single memory location and can be Our laboratory is equipped with an Apple II micro accessed by using a PEEK or POKE from APPLESOFT processor configured with 48-KB memory, an AIO BASIC, by using a free union variant record in PASCAL, serial-parallel interface card (SSM Microproducts, Inc.), or by using the load or store command in an assembly a Mountain Hardware Apple clock, and a single disk language routine. drive. The sections below describe the hardware expan With this card, additional interfacing logic is required sion we built for the AIO parallel interface and our in order to control more than eight devices. The first software approach. system described below is a simple, inexpensive circuit that expands the output of the interface to as many as 48 separate devices. It is not uncommon for laboratory studies to require such an array ofoutputs. Our operant This system was developed and documented as part of the studies of stimulus control, for example, require at least dissertation research of Winford A. Gordon. The work was partially supported by Public Health Service Grant MH-14269, 36 output lines to operate the 12 stimulus lamps in the awarded to the experimental psychology program of the Uni three in-line projectors that display the training and test versity of North Carolina. There was also support from the stimuli. We also need output lines to present reinforce Smith Research Fund of the University of North Carolina and ment and operate the chamber houselight. The circuit from a Sigma Xi grant in aid of research. Reprints of this described here meets these specific needs: It operates paper and program listings can be obtained by writing David A. Eckerman, Department of Psychology, UNC-Chapel Hill, all 36 stimulus lamps, although only one at any time, Chapel Hill, North Carolina 27154. and it operates the houselight and hopper at any time. 158 Copyright 1983 Psychonomic Society, Inc. REAL-TIME CONTROL 159 Our circuit recognizes logical combinations of the Table 2 8 bits in the interface port. Bits 0-3 are combined to Output Code for the Apple II AID Card in Slot 4 Output Port 49312 ($COAO) specify a value between 1 and 16. Since we have only = 12 stimulus lamps in each projector, we use only values CXJTPUT GlUJP 1-12. The value in interface port Bits 0-3 determines CXJTPUT # I. B C which of the 12 lamps in the projector is potentially 0 16 ($10) 32($20) 48($30) enabled. Bits 4 and 5 produce four mutually exclusive 1 17($11) 33 ($21) 49($31) 2 18($12) 34($22) 50 ($32) states: OFF, ENABLE PROJECTOR A, ENABLE 3 19($13) 35($23) 51 ($33) PROJECTOR B, or ENABLE PROJECTOR C. Thus, 4 20($14) 36 ($24) 52 ($34) these 2 bits turn on the selected lamp in the selected 5 21 ($15) 37 ($25) 53 ($35) 6 22($16) 38($26) 54($36) projector. Bits 6 and 7 are operated independently to 7 23 ($17) 39($27) 55 ($37) control the houselight and the reinforcement hopper, C 24 ($18) 40 ($28) 56($38) respectively. Table 1 shows how these 8 bits from the 9 25 ($19) 41 ($29) 57 ($39) AIO card are combined to provide the number of out 10 26 ($IA) 42 ($2A) 58 ($3A) 11 27 ($IP) 43 ($2Bl 59 ($38) puts we use. 12 28 ($IC) 44($2C) GO($3C) As an example of how these combinations work, consider that placing the value 19 in the output port Note- To use either of the independent lines, add 64 ($40) for turns on Lamp 3 in Projector A, whereas placing the Line 7 or 128 ($80) for Line 8 to the values listed above. value 35 in this location turns on Lamp 3 in Projector B. The binary representation of these values reveals that the lowest 4 bits (Bits 0-3), which select the lamp, are and out of the AIO card are passed through standard equivalent, but Bits 4 and 5, which select the projector, optoisolators (Radio Shack 76-1628) to protect the differ. In binary notation, these values are 000100 II Apple from any circuit overloads. The light-emitting vs.00100011. diode (LED) in the optoisolators is driven by the 5-V Table 2 lists the code that would be used to produce signal from the Apple, and the phototransitors switch the various outputs of our interface system. Decimal a 5-V signal generated by an external power supply. values are listed, with their hexadecimal equivalents. The second power source is needed if the Apple is to be These values would be given in a table for the table completely isolated and protected from circuit over lookup, as described in the software section. loads; it also avoids potential problems with power The interface hardware can be described as having demands on the Apple power supply. three stages (see Figure I). Stage 1 involves optoisolation Stage 2 in the circuit contains the logic needed to of the computer from the interface. The eight lines in create the additional output lines. All signals in this stage are standard 5-V transistor-transitor logic (TTL) signals. The outputs of Optoisolators 0-3 are passed into Table I Logical Combinations of Eight Lines to Yield 38 Outputs a 4-line-to-16-line decoder (LS74154). The decoder ---~-_. provides 16 discrete outputs: one output is grounded, AIO ooTPUT or "pulled low," for each of the possible configurations LINE # LINE # o --) of Bits 0-3. These outputs are inverted (LS7404), so 1 --) LINES 0-3 aHlINE that the grounded output becomes a 5-V signal, and o ---) 2 ---) L(X;ICALLY 'TO QlliATE passed into Stage 3 of the circuit. The outputs ofOpto 3 --) 12 LINES FOR 'IllE isolators 4 and 5 are logically combined with inverters 1 ---) 4 ---) STHlJLUS LAMPS llJ 5 ---) THE 'IllREE IIDJECTORS and a set of two-leg AND gates (LS7408). A different 2 ---) 6 ---) THIS IS DONE WITH gate produces a 5-V output for each of three conditions 7 ---) A 4-'I\f-16 LINE of Optoisolators 4 and 5: on/off, off/on, and on/on. The 3 ---) 8 ---) DEaIDER IC C(XIlBINED 9 ---) VlITH AN INVERTER outputs of Optoisolators 6 and 7 are passed directly to 10 ---) Stage 3. 11 ---) Stage 3 consists of 17 additional optoisolators. The input to these optoisolators is the 5-V TTL signal gen 12 ---) A LINFS 5 ~ID 6 4 ---) CO/EINE '10 ENABLE erated in Stage 2. The output is a 12-V signal that 13 --) B a'IE OF WE 'llIREE operates NPN power transistors (Radio Shack 76-2042). 5 ---) PRCDECTORS The power transistors switch the 28 V needed to operate 14 --) C the laboratory equipment we use. In our application, 6 ---) 15 ---) WRNS 01 'IllE HOOSE the equipment consists of small incandescent bulbs and LICHT relay coils. Figure 2 details the circuit between the transistors, relays, and bulbs. The maximum power 7 ---) 16 ---) RAISES WE rcco HOPPER demand placed on our 28-V power supply never exceeds 1.5 A. 160 GORDON, FOREE, AND ECKERMAN n IGll 11 III ~ Itit I 74154 II 7404 I.I 7 ""I IJ I J I J W c.,~ L!~ ", I II r v1 n II II 1" 7404 1 L 7404 1 I ~I I~ \J _ .J A. pp~ ., ..0 i' AIO ILt=vLj" POR " 1 1& - - - - - '2 API'lE " GNO bfi ,A -R~~RI GND = + +5V = V 470 = RI 4700 = R2 IOK=R3 (RESISTANCE IN OHMS) Figure 1.