CSE466-03au Lab Assignment 4

This is a 3 part lab. In it, you will:

In this lab you will learn the following:

Steps

Part 1

  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.
  2. The LED should fade up and back down. Observe the PD5 output with your oscilloscope.  Determine the PWM frequency.
  3. 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.

  1. Connect your oscilloscope probes to the PD5 pin and to the output of the RC filter. Describe what you see for turn-in.
  2. 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.
  3. 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:

  1. 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.
  2. The table is accesses by means of a phase accumulator, which is incremented each sample by a phase increment value. See Wednesday’s lecture.
  3. phase_index = modL(previous_phase + increment)
  4. increment = (TableLength x DesiredFrequency)/ SampleRate
  5. 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.
  6. Observe the output with your oscilloscope. Your low-pass filter may need to be adjusted for smooth performance.
  7. Demonstrate your sine-wave generator to a TA.
  8. Turn in a hard copy of your code.

End of part 2

Part 3

  1. Connect a piezo transducer between PD5 and ground, polarity doesn’t matter. Run your code from Part 1 and listen to the result.
  2. Modify a copy of your code from part 2 to output frequencies in the range of 2500 Hz. and listen to the result.
  3. 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

  1. Read the comments in score.c for hints.
  2. Demonstrate your tune player to a TA.
  3. Turn in a hard copy of your code.

Deliverables

For all files turned in, the comments at the top of the file should contain:

Part 1:

  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.
  2. Turn in the requested calculations and descriptions.

Part 2:

  1. 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.
  2. Turn in hardcopy of your commented C code.

Part 3:

  1. 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.
  2. Turn in hardcopy of your commented C code.

End