
Lab 8
The MC68HC11 Timer
Before the Lab
The main timer of the MC68HC11 can be used to generate an interrupt when a
certain amount of time elapses. It can be used to generate a pulse or a square
wave with a specified duration. The timer can also be used to measure the
duration of a pulse or count external pulses.
The MC68HC11 timer
is based on a free running 16-bit counter. Three independent input-capture
functions are used to automatically record the time when a selected transition
is detected at a respective timer input pin. Five output-compare functions are
included for generating output signals or for timing software delays. Each of
the three input-capture functions has its own 16-bit time capture latch and each
of the five output-compare functions has its own 16-bit compare registers. All
timer functions have their own interrupt controls and separate interrupt
vectors. You will need to refer to the description of the HC11-VDK's vector
table handed to you earlier to see how to set your program to handle the
different interrupts. Control bits permit software to control the edge(s) that
trigger input-capture functions and the automatic actions that result from
output-compare functions.
To use an
input-capture function to detect a specific edge on a timer input pin you need
to set the control bits (EDGxB,
EDGxA) in
the control register TCTL2 according to the table given in the reference manual
page 10-17 of the MC68HC11
Reference Manual.
The ICxF
status bits in the
TFLG1
register are automatically set to one each time a selected edge is detected at
the corresponding input-capture pin. Writing clears these status pins to the
TFLG1
register with a one in the corresponding data bit position. When the
ICxI
bit in the
TMSK1
register is zero, the corresponding input-capture interrupt is inhibited. When
this bit is set to one, the corresponding input-capture interrupt is enabled and
a hardware interrupt request is generated whenever the corresponding
ICxF
bit is set to one.
To program the
automatic pin action to occur for an output-compare function you need to set the
control bits (OMx,
OLx) in the
control register
TCTL1
according to the table given in the reference manual page 10-31. The
OCxF
status bits in the
TFLG1
register are automatically set to one each time the corresponding output-compare
register matches the free running timer. Writing clears these status pins to the
TFLG1
register with a one in the corresponding data position. When the
OCxI
bit in the
TMSK1
register is zero, the corresponding output compare interrupt is inhibited. When
this bit is set to one, the corresponding output-compare interrupt is enabled
and a hardware interrupt request is generated whenever the corresponding
OCxF
bit is set to one.
More
information on the timer is available in the
MC68HC11 Reference
Manual. Read with care through chapter 10 in this
manual, especially sections 10.3 and 10.4. This device has some subtleties that will trip you up if you are not thoroughly familiar with its operation.
You need to write the following programs:
-
A program that will generate a square wave from pin 5 of port
A. The wave should have a variable duty cycle. You will have to specify the width of the high and the low portion of the waveform. You need to set the timer to generate an interrupt when the specified time elapses and to set your
ISR to reload the timer with the required duration. Your program should be initialized to be able to take over the timer interrupt. Don't forget to clear the
0C3F in the ISR.
-
A program that will rotate a single lit LED from right to left. Use the timer to accurately control the time an LED will be kept lit (e.g. 500
ms). When the light reaches the boundary of the 8 LEDs just make the sequence wrap around. You might need to refer to your code in
Lab 6.
-
A program that will generate a
sine wave with a specified frequency on one of port C's
pins.
-
A program that will measure the period of a signal from a function generator
and continuously display it on the screen (for
that you will need to use the monitor subroutine called
_out2bdsp
at location
$ffcc). To do this you will connect the i/p signal to pin 2 of port
A.
You will need to set up an ISR that will be called whenever a leading (or trailing) edge is detected. Each time the
ISR is called it reads the content of the
input-capture latch. By computing the difference between two edges, the
period of a pulse can easily be determined.
In the Lab
Before you run any of your programs, a word about connections. These exercises will require access to the header pins on the
HC11-VDK board. DO NOT, UNDER ANY CIRCUMSTANCES, USE THE GORILLA CLIPS TO ATTACH TO THE HEADERS.
ATTACH ALL CONNECTIONS VIA WIRE-WRAP. Your
T.A. will show you how. Once you are through making your measurements, REMOVE THE WRAPS from the
board. Loose wires could accidentally short out. Wire is cheap. IC's are not.
- Load and run your first program. Observe the output on an oscilloscope. Is it what you expected? Note the different durations carefully. Can you see any deviation from what you expected? Why? (Or why not?) What are the limits of your program? What are the limits of the high and low portions of your signal? Why?
- Load and run program two. Ensure that the timing is as designed.
- Load and run program three. What is the smallest and largest signal frequency that you can generate? Where are the limitations coming from?
- Load and run program four. You need to explain to your T.A. the meaning of your results.
After the Lab
Clean up your programs to hand in to the TA. Answer all the questions appearing above. Calculate the longest period that you can measure with the last program.
| EE-218 Homepage |
Syllabus
| Schedule | Lab News | Faculty |
Contact
Information | Lab Info | Project
|
Department of Electrical Engineering and Computer Science
Box 1824 Station B
Nashville, TN 37235
Phone: 322-2771
Fax: 343-6702
|
Search |
Site Index
| People Finder
| Phone
Directory | VUnet |
VUmail |
VU Library | Help
|
Last Updated:
Saturday, March 05, 2005
Juan J. Rodriguez-Moscoso
Copyright © 2003
Vanderbilt University
|