## Reaction Time Tester.

Introduction.

For this exercise you will use the development board to build a human reaction time tester. The pushbuttons, LEDs, and the mcu will be used to see how fast you can push a button after a light flashes.

Procedure:

As in Lab 1, be sure you save the SREG when you enter the interrupt routine. In this lab, you will typically be polling a button and doing some arithmetic, so you must save SREG in a register when you enter the interrrupt routine, then restore it when you leave. The following code fragment shows how to do it.

```.def SavReg=r20  ;a place to store the SREG
.		 ;rest of the main routine
.
.
;timer overflow handler
Ovfl_intr:
in SavReg, SREG
; rest of the interrupt routine
out SREG, SavReg
reti
```

You will need to generate a time base for measuring reaction times. Most people have a reaction time in the range of 100 mSec to 200 mSec, but this can be quite variable, up to several hundred mSec. If you use the 0.5 mSec timebase from lab 1, you will have enough time resolution, but you will need a 16 bit interrupt counter.

Make sure that the switches and LEDs are connected as they were in Lab 1. When in doubt, ask an instructor. Remember that a switch which is pushed reads back a logic zero. To read, for example, switch6 use:
`sbic PIND, 6 `
to skip the next instruction if bit 6 of the PortD pins is clear.

Assignment

Produce a program which:

1. Upon a reset signal, flashs the LEDs at a few Hz and waits for a button press.
2. At the button press, turns the LEDs off for about 2 seconds. Figure out a way to make the waiting time variable, so that it is harder to predict.
3. Turns on the LEDs, 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 LEDs, then waits. 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 LEDs when ARESET is pushed.

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

Your written lab report should include:

• The scheme you used to detect the pushbutton state. (e.g. polling loop, interrupt)
• How you generated the time base you used.
• Other design aspects of the assignment.
• A heavily commented listing of your code.

Jan 1999 Cornell University