ECE 362 – Experiment 8 Rev 10/13 Bigger Bytes Lab Manual Solved

40.00 $

Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: . zip solution files instantly, after Payment


5/5 - (2 votes)

ECE 362 – Experiment 8 Rev 10/13 Bigger Bytes Lab Manual -1- © 2013 by D. G. Meyer
Experiment 8: Whatsamatta U Reaction Timer
Instructional Objectives:
· To illustrate how the TIM module can be used to implement a precision time base
· To illustrate how the SPI module can be used in conjunction with an external shift register to
expand I/O
Parts Required:
· 2 x 16 LCD and 16-pin single-row header (available from the Instrument Room, EE 168)
· GAL22V10 configured as an 8-bit shift register
· RED, YELLOW, and GREEN LEDs plus current limiting resistors (previous experiment)
· Breadboard and wire
· Read this document in its entirety
· Review the material on the TIM and SPI subsystems
· Solder the 16-pin single-row header to your LCD
· Complete the wiring outlined in the Hardware Overview
· Complete and test the LCD device driver “C” code
Midway through the football season, Coach Boris Badenov of Whatsamatta U had an idea. Determined to be as quick as possible to challenge the “bad calls” he’s sure will be made at the Battle for the Bit Bucket game with Boo-Hoo-U, he realized that a customized reaction timer could help him test and sharpen the swiftness of his protest skills. The interface, however, would have to be simple enough for a website contractor to use, which is why he has enlisted you (along with a bevy of benevolent boisterous Boilermakers) to construct a prototype for him. An illustration of the finish product is shown in Figure 1. Whatsamatta U Reaction Timer
Figure 1. Reaction Timer Control Panel and Display.
NOTE: “C” code for “main”
and the ISRs must be written
and debugged during your
scheduled lab period (LCD
device driver should be
written and tested as part of
your pre-lab preparation.)
ECE 362 – Experiment 8 Rev 10/13
Bigger Bytes Lab Manual -2- © 2013 by D. G. Meyer
Coach BB’s reaction timer will use the docking module pushbuttons as follows: the left pushbutton starts the reaction test which will display the message “Ready, Set…” on the first line of the LCD and initiate a random delay. When this delay expires, “Go Team!” will be printed to the second line of the LCD, the yellow LED will be illuminated (simulating that a “yellow flag” has been thrown by the referee) and the reaction timer will start. The right pushbutton stops the test, at which point the reaction time will be displayed on the first line of the LCD in the format “RT = NNN ms” and an appropriate message will be displayed on the second line. Also, the YELLOW LED should be turned off and, if the resulting reaction time was less than 250 milliseconds, the GREEN LED should be turned on. If the reaction time was greater than 1 second, the RED LED should be turned on. The left LED on the docking module
will be used to indicate the reaction time test is “stopped” (i.e., ready to start a new test), while the right LED will be used to indicate a reaction time test is “in progress”.
In addition to the reaction time, appropriate messages (i.e., messages you wouldn’t mind if your Mom saw) should be displayed on the second line of the LCD (e.g., “Ready to start!” upon reset, “Go Whatsamatta U” if a really fast reaction time is recorded, etc.). It should be noted that LCD messages should be limited to 16 characters due to the size of the screen. If, for some reason, the reaction time exceeds 999 milliseconds, an appropriate suggestion should be displayed on the second line of the LCD (e.g., “Get HKN coffee!!”).
Lucky for Coach BB, there are plenty of underpaid and overworked ECE 362 students armed with 9S12C32 microcontroller kits willing to work for the opportunity to buy full-price Bit Bucket game tickets. Time’s running out, though, so gather up your parts and get to work!
Figure 2. Coach Boris Badenov of Whatsamatta U and the Coveted Boiler Bit Bucket.
ECE 362 – Experiment 8 Rev 10/13
Bigger Bytes Lab Manual -3- © 2013 by D. G. Meyer
Hardware Overview
On the docking module, the left pushbutton will be used to initiate a reaction time test, while the right pushbutton will be used to stop the test in progress (and display the reaction time results).
The left LED will be used to indicate the reaction timer is stopped (ready to start a new test), while the right LED will be used to indicate a reaction time test is in progress.
A GREEN LED on PTT[5] will be used to indicate a reaction time less than 250 milliseconds, a
RED LED on PTT[6] will be used to indicate a reaction time greater than 999 milliseconds and a
YELLOW LED on PTT[7] will indicate the start of the reaction time test.
An external 8-bit shift register (GAL22V10, programmed using the ABEL code given in
problem 5 of the Module 2 homework) will be used to interface LCD to the microcontroller via
the SPI module (MOSI, port pin PM[4]; and SCK, port pin PM[5]). The LCD will be interfaced
as described to the microcontroller module as described in the table below:
Pin # LCD Pin Description Connected to
1 Vss (ground) Vss (ground)
2 Vcc (+5V) Vcc (+5V)
3 VEE (contrast adjust) Vss (ground)
4 R/S (register select) PTT[2]
5 R/W’ (LCD read/write) PTT[3]
6 LCD Clock PTT[4]
7 DB[0] (LS bit) Q[0]
8 DB[1] Q[1]
9 DB[2] Q[2]
10 DB[3] Q[3]
11 DB[4] Q[4]
12 DB[5] Q[5]
13 DB[6] Q[6]
14 DB[7] (MS bit) Q[7]
15 Not connected
16 Not connected
Some of the LCD pins require a bit more explanation:
Mnemonic Name Description
RS Register
This pin is logic 0 when sending an instruction
command over the data bus and logic 1 when
sending a character.
R/W’ Read/write This pin is logic 0 when writing to the LCD,
logic 1 when reading from it. For this lab, we
will only write to the LCD.
LCDCLK LCD clock This pin latches in the data on the data[7:0]
bus on the falling edge. Therefore, this line
should idle as logic 1.
NOTE: The LCD does not
come with pre-soldered
headers. You will need to
solder a 16-pin header to
the LCD so that you will be
able to plug it in to your
NOTE: DB[#] are the LCD data inputs and Q[#] are the
data outputs of the GAL22V10 shift register.
ECE 362 – Experiment 8 Rev 10/13
Bigger Bytes Lab Manual -4- © 2013 by D. G. Meyer
Software Overview
Timer Channel 7 will be used to provide periodic interrupts at precise 1.000 millisecond intervals
for the purpose of gauging the reaction time. The Timer Channel 7 interrupt service routine
should keep count of the elapsed time using the “react” variable provided in the skeleton file.
This variable should be kept in BCD format.
The RTI will be used to sample the pushbuttons on the docking board every 2.048 milliseconds
as well as increment the “random” counter. Data for the LCD display will be shifted out to an
external shift register (GAL22V10) and will be interfaced to the SPI module through Port M.
A key element will be providing a “random” delay between the instant the “start test” (left
pushbutton) is pressed and the “Go Whatsamatta U” message is displayed on the LCD.
Here, the “random” counter maintained by the RTI service routine will be used to trigger the
start of a reaction time test.
In order to help with LCD interfacing, the “skeletons” of several functions outlining a simple
device driver have been provided to you:
Function Operation Performed
shiftout Transmits the contents of A to a shift register using SPI
lcdwait Delays for 2 milliseconds
send_byte Writes contents of A to the LCD
send_i Sends instruction byte in A to LCD
linechg Move LCD cursor to the cursor position passed in A
print_c Print character passed in register A on LCD
pmsglcd Print to the LCD all characters passed by call until an
ASCII NULL character (decimal 0) is found.
You will be required to write all of these functions (or equivalent) to interface with the LCD.
Additionally, many of these routines depend on others (for instance, pmsglcd requires print_c
be written). You should build the driver from the ground up starting at shiftout and
designing toward pmsglcd. The pmsglcd routine should take in a string passed by call and
print every character to the LCD until it reads an ASCII NULL character (“0”). You should
make multiple calls to print_c to print each individual character to the LCD screen.
Before printing characters to the LCD, it must first be initialized by writing instruction bytes.
The relevant LCD instructions are given in the skeleton file and are replicated below:
Instruction Byte Operation Performed
LCDON $0F Turn on the LCD driver chip
LCDCLR $01 Clear the LCD
TWOLINE $38 Enable two line display mode
CURMOV $FE Cursor move command (requires second cursor
position byte)
ECE 362 – Experiment 8 Rev 10/13
Bigger Bytes Lab Manual -5- © 2013 by D. G. Meyer
To initialize the LCD, you must send the LCD commands in the following order. NOTE:
LCDCLK and R/W¢ are names of signals, not instructions. Also, keep in mind send_i is a
function that takes arguments passed by value in register A.
NOTE: The LCD initializations call functions that you must write. It is
recommended that you validate these functions before attempting initialization.
The function chgline moves the cursor on the LCD to the cursor position passed by value in
register A. To accomplish this, you must first send the CURMOV instruction, followed by a
second instruction byte telling the LCD which position you want the cursor to move. These
cursor position bytes are given in the table below.
Cursor Position
0 1 2 … 15 … 40
Line 1 $00 $01 $02 $0F $26
Line 2 $40 $41 $42 $4F $66
Line 3 $80 $81 $82 $8F $A6
Line 4 $C0 $C1 $C2 $CF $E6
This is the cursor position byte map for our LCD driver (Hitachi HD44780). The area shaded in
green corresponds to the valid cursor positions for our 2 x 16 character LCD. For example, the
first character of the first line corresponds to cursor position $80 and first character of the second
line corresponds to cursor position $C0. It should be noted that both of these cursor positions are
given as variables in your skeleton file (LINE1/LINE2).
Keep in mind that the LCD driver chip is designed to accommodate up to a 4×40 character
display (ours is only 2 x 16). This means that you will be able to write to cursor positions that
are not within the viewable area of your LCD.
LCDCLK = ‘1’
R/W’ = ‘0’
ECE 362 – Experiment 8 Rev 10/13
Bigger Bytes Lab Manual -6- © 2013 by D. G. Meyer
Step 1. Interfacing
Interface the LCD and LEDs to your microcontroller kit as described in the Hardware Overview
section. This will require programming your GAL22V10 to function as an 8-bit shift register, as
described in problem 5 of the Module 2 homework. Complete all the interface wiring on your
breadboard as part of your pre-lab preparation.
Step 2. Software
Prior to your scheduled lab period, write the LCD device driver routines and test them with the
interface circuitry completed for Step 1. Complete the remainder of the “C” skeleton file
provided on the course website during your scheduled lab period. Note that the “finished
product” should work in a “turn key” fashion, i.e., your application code should be stored in flash
memory and begin running upon power-on or reset. Demonstrate the completed reaction timer
system to your lab T.A.
Step 3. Submission
Submit your “.C” solution file on-line after demonstrating it to your lab T.A. (but before leaving
lab). Be sure identifying information (i.e., name, class number, and lab division) is included in
the files you submit – credit will not be awarded if identifying information is omitted.
Bonus Credit
The “stock” reaction timer described above has a “fixed” 250 ms threshold which it uses to
distinguish between “fast” and “slow” reaction times. A simple extension would be to “dial in”
the desired threshold using a potentiometer, and to display how much faster/slower the user was
relative to that threshold.
Use a potentiometer (referenced to 5 VDC) connected to PAD0 as the means for entering the
variable “slow/fast” threshold – a suitable range might be 0 to 500 ms. This value should be read
as part of the program initialization (after reset) and displayed on the the LCD before the first
reaction test is initiated: “Thresh = NNN ms”. Then, when a reaction test is run to
completion, the first line of the LCD should display the reaction time the same way as the
“stock” version, but the second line should display the difference between the measured reaction
time and the threshold: “100 ms slower” or “50 ms faster”.
ECE 362 – Experiment 8 Rev 10/13
Bigger Bytes Lab Manual -7- © 2013 by D. G. Meyer
Debugging Tips
When debugging the LCD circuit, you should use the oscilloscope logic analyzer if you’re trying
to watch more than two signals at a time (e.g. looking at all eight shift register outputs at one
time. The only difference in using this rather than using the A1/A2 analog oscilloscope probes is
that instead, you’ll be using the D0-D7 probes. If these probes aren’t immediately visible, please
check the bag on top of the oscilloscope.
D0 and D1 LA probes
First, you should attach a probe to each pin you want to measure. Next, you should press the
D0-D15 button in the lower right corner of the oscilloscope controls. This display allows you to
enable D0-D7 and D8-D15. Enable D0-D7 by pressing the “On” control for these probes (the
third button from the left below the display). You can also choose to disable the A1/A2 probes if
you want more display room for D0-D7.
To trigger on any of these ports, you can press the Edge button and select the D bit as your
trigger source (third button from the left below the display). You can select among the D bits
after you have pressed this button by turning the knob marked “Select” under the D0-D15
button. You may also choose whether to trigger on a rising or falling edge in the same menu.
The last thing to check is under the Mode/Coupling button menu. You’ll want to select
“Normal” trigger mode if you want a one-shot trigger. If you have a periodic waveform, select
“Auto” as your trigger mode. Leave the coupling as “DC” for non-periodic waveforms. The
rejection functions are situation-dependent and can be changed at will.
You may now run your code and the LA will trigger based on the settings you’ve entered.