EE 476: Laboratory 2

Reaction Time Tester.

Introduction.

For this exercise you will use the 80196KB to build a human reaction time tester. Some simple circuitry and the microcontroller will be used to see how fast you can push a button after a light flashes.


Procedure:

You will need to be able to time various events and detect pushbutton presses. You will need to make a copy of the setup.inc file, modify it to allow an HSO interrupt (int03),and include it in this program. Do not modify c:\mcs96\ecm96\setup.inc, modify your own copy. The include is shown below as "keybd2.inc" but you will have change this to match the name of your file.

There are various ways of generating a time base using the processor. A handy scheme for this lab is to use the HSO.0 output to generate a 500Hz square-wave which you should connect to the T2CLK pin. Timer2, when enabled to use this input, will count at 1KHz, generating a 1 MSec time base. A millsecond time base is approximately the right timescale for human interaction. Typical human reaction times vary from around 80 MSec to about 400 MSec.

The code shown below will set up the HSO to generate a 500 Hz signal. The code reads Timer1 and calls the interrupt subroutine only once. After that, the interrupt routine itself generates the next cycle of the square wave and sets up the next interrupt.


$include(a:keybd2.inc)
;
	rseg at 20H

period:	dsw	1		;the audio period for HSO
cleart:	dsw	1		;time to set HSO low
temp_t:	dsw	1		;temp time for HSO start
;
	cseg at 2080H
;
init:	ld	sp, 	#100h	;setup the stack pointer
;HSO CAM constants and setup
	ldb	ioc2, 	#80H	;clear HSO CAM
	ldb	int_mask, #08H	;setup HSO int mask
	ld	period, #1500D	; 500 Hz (x2=1KHz for t2)
	ld	cleart, #750D	; 50% duty cycle

;call interrupt routine to force first cycle
;for input to timer 2
	ei			;enable interrupts
	ld	temp_t, timer1	;get current time
	call	int03		;the hso interrupt
;
;timer 2 input source setup
	ldb	ioc0,	#0	;timer2 input from T2CLK
;

;---- The rest of your code goes here ----

;hso interrupt
int03:	pusha
	add	temp_t, period	  ;start one cycle from now
	ldb	hso_command, #30H ; hso.0 set & interrupt
	ld 	hso_time, temp_t  ; hso time
	skip	r0		  ;wait 3 cycles (for hso load)
	skip	r0		  ;wait 3 cycles
	ldb	hso_command, #0H  	 ; hso.0 clear at 
	add	hso_time, temp_t, cleart ;clear time
	popa
return:	ret
;	
end

You will need to connect one input port bit (perhaps port0.0) to a pushbutton. Place a 47k resistor pack and a pushbutton on the prototype board and wire it as shown to the left. The end of the resistor pack with the dot is common. The other leads are each connected to the common by a 47k resistor.

Eight of the LEDs on the prototype board are wired to Port1. You will control the LED bar through Port1.

The prototype board connectors should not be connected or disconnected. Get help from an instructor if you need to do change connectors. The pinout of the prototype board connectors is available in the lab and here.


Assignment

Produce a program which:

  1. Waits for the button to be released, then Flashs the LED bar at a few Hz and waits for a button press.
  2. At the button press, turns the LED bar off for about 2 seconds.
  3. Turns on the whole LED bar, starts a timer and waits for a button press. (your code should detect the cheating condition of a pressed button at t=0 and respond by returning to the flashing LEDs.
  4. At the button press, computes the time between LED illumination and the button press, displays the number of millseconds in binary on the LED bar, waits a couple of seconds, then waits for a button press, followed by a button release. If your reaction time is longer than 255 Msec, then scale the value by two before displaying it on the LED bar. Displayed time should be accurate to 1 mSec (unless you scaled the time by 2.
  5. Returns to the flashing LED bar.

For extra credit:
Use all 10 LEDs on the bar and display the time in BCD. This should work as long as the reaction time is less than 300 mSec. Eight LEDs are driven by port1. The other two are HSO0.0 and port2.5.

You will demonstrate the working reaction time tester to the TA in the lab.

Your written lab report should include:


Copyright Statement