CSE466-03au Lab Assignment 4
This is a 3 part lab. In it, you will:
- Experiment with a
Triangle-wave Pulse Width Modulator, and control the brightness of a
LED.
- Construct a PWM
sine-wave generator.
- Play a tune
through a piezoelectric transducer.
In this lab you will learn the following:
- how to program a timer pulse-width modulator
output
- how to calculate and implement a basic low-pass
filter
- how to construct a table-driven sine generator
- how to calculate frequencies and
phase-increments of musical scales
Steps
Part 1
- Sample code is provided as PWM-demo.c. Compile this file and
load it. You need to connect a (green) LED to pin PD5 (pin 19) thru a
330 ohm current-limiting resistor to ground.
- The LED should fade up and back down. Observe
the PD5 output with your oscilloscope. Determine the PWM
frequency.
- Using the equation from Monday’s lecture:
·
Choosing the -3 dB point at 4 kHz, and using the relation:
·
RC = 1/(2 · pi ·f)
·
we get R = 4 k, if C is chosen as 0.01 uF:
·
R = 4.0 k
·
C = 0.01
uF
uF = microfarads .000001 farad
Now calculate R
with C = .22uF and f = 0.25
of your measured PWM frequency. Build the circuit, using the
nearest standard
value R that you can find. Record your calculations for turn-in. The
LED should
remain connected directly to PD5.
- Connect your oscilloscope probes to the PD5 pin
and to the output of the RC filter. Describe what you see for turn-in.
- Experiment with other values for R (2R, 4R),
and the effect on the output. Describe for turn-in the value that
produces the cleanest output, and calculate the -3 dB point for
your optimized filter.
- Demonstrate your optimized circuit to a TA.
End of part 1
Part 2
Construct a new
program based on
PWM-demo.c, with the following
characteristics:
- Instead of a calculated triangle wave, the
output comes from a 256 word sine table, containing one full cycle of a
sine wave, 10 bits accuracy.
- The table is accesses by means of a phase
accumulator, which is incremented each sample by a phase increment
value. See
Wednesday’s lecture.
- phase_index = modL(previous_phase
+ increment)
- increment = (TableLength x DesiredFrequency)/
SampleRate
- Your program should output a sine wave from 10
Hz to 95 Hz, with the value displayed on your hex display (in decimal)
and stepping up or down by 5 Hz at a rate of 0.25 steps/sec (4 sec. /
step)., controlled
by up/down and start/stop buttons. The frequency should wrap at the
extremes.
- Observe the output with your oscilloscope. Your
low-pass filter may need to be adjusted for smooth performance.
- Demonstrate your sine-wave generator to a TA.
- Turn in a hard copy of your code.
End of part 2
Part 3
- Connect a piezo
transducer between PD5 and ground, polarity doesn’t matter. Run
your code from Part 1 and listen to the result.
- Modify a copy of your code from part 2 to
output frequencies in the range of 2500 Hz. and listen to the result.
- Construct a new program based on score.c, with the following
characteristics:
·
Timer0 controls the tempo and the length of each tone.
·
Timer1 with PWM gives the frequency.
·
The program plays the three songs, selected by a button
·
One button selects which song (displayed)
·
One button is start/stop
·
The output is a pulse wave to the transducer, not a sine
- Read the comments in score.c for hints.
- Demonstrate your tune player to a TA.
- Turn in a hard copy of your code.
Deliverables
For all files turned in, the comments at the top
of the file
should contain:
- Both partners' full name, login and student
number.
- The lab number and the part of the lab (e.g.
Lab 4, part2 for the sine-wave generator).
- Any extra calculations or data that we've asked
for.
Part 1:
- Demonstrate your circuit to a TA. You can
either do this during this lab, or during the first 1/2 hour of the
next lab.
- Turn in the requested calculations and
descriptions.
Part 2:
- Demonstrate your generator to a TA. You can
either do this during this lab, or during the first 1/2 hour of the
next lab.
- Turn in hardcopy of your commented C code.
Part 3:
- Demonstrate your tune player to a TA. You
can either do this during this lab, or during the first 1/2 hour of the
next lab.
- Turn in hardcopy of your commented C code.
End