EE 476: Laboratory 3
Cricket-call generator.
Introduction.
You will construct a cricket-call generator which will produce audio output
of a simplified cricket call. A cricket call may be very complex, but we will
limit ourselves to the following form.
- A call is made up by repeating indefinitely a chirp and a silent period.
If the duration of the silence is zero, the call is refered to as a trill.
- A chirp is made up of a certain number of syllables with specific duration
and repitition interval.
- A syllable is made up of a squarewave burst at a certain frequency.
The image below summerizes the definition ( from bionb
420).
Procedure:
You will need the 8515 header file
for CodevisionC. You will probably want to review the code examples given in
the CodevisionC Tutorial.
You will use PortB of the mcu to read four switches. One bit of another port,
perhaps bit 6 (which happens to be adjacent on the connector to ground), will
be used to drive an earphone.
You will need to figure out how to generate a variety of time delays and durations.
I suggest one of the following, but you may use any scheme you want.
Scheme 1
- Timer 0 described in the first lab will be modified to produce one interrupt
per 1/2 cycle of the desired syllable burst frequency. Be sure to use a pre-scaler
value which maximizes the frequency accuracy. The interrupt routine should
toggle the audio output bit. The output bit can drive the earphone directly,
but is somewhat loaded by the earphone.
- Use timer1a to determine when a new chirp should begin. Timer1a can be set
up to clear itself on a compare-match. This function makes a handy time reset.
- Use timer1b to determine times at which an audio burst should stop and start.
Timer1b will always be set up so that the compare-match function is triggered
when the audio should start or stop. This means that the timer1b compare-match
ISR will need to compute the next relevant time and reload the 1b compare
register.
Scheme 2:
- Timer 0 is used to schedule all intervals on the millSecond scale, as outlined
in the second example in the Program
Organization document.
- Timer 1a is used to generate the high speed interrupts necessary for the
squarewave frequency.
Assignment
- Write a C program which implements a cricket-call generator with the following
specifcations:
- Buttons 0-3, when individually pushed, produce four different calls,
according to the table below. Once started, the call repeats indefinitely,
until the next button push. All times are in milliSeconds. Frequencies
are in Hz.
parameter |
chirp+ silence duration |
number of syllables |
syllable
duration
|
syllable
repeat
interval
|
burst
frequency |
call 0 |
20 |
1 |
10 |
--- |
4500 |
call 1 |
250 |
4 |
18 |
30 |
5000 |
call 2 |
1500 |
50 |
8 |
20 |
6000 |
call 3 |
1000 |
5 |
30 |
50 |
3000 |
- Output from one bit of a port will be a squarewave connected to a speaker.
- Demo this program to a staff member. Show that all specifications are met
by verifying times and frequencies with an oscilloscope. Frequency accuracy
should be +/-1%. Duration accuracy should be +/-1 mSec.
- Your written lab report should include:
- The scheme you used to detect the pushbutton state. (e.g. polling loop,
interrupt)
- How you generated the freqencies and an estimate of how accurate they
are.
- How you generated the various time intervals required by this project.
- Other design aspects of the assignment (e.g. did you use table lookup
for the frequencies or did you hardcode them).
- A heavily commented listing of your code.
Copyright Cornell University December 2000