PWM Tutorial 3 – Using Low-Pass Filters with PWM Signals

This tutorial continues from where PWM Tutorial 2 left off

Introduction

The purpose of this tutorial is to walk you through the steps of using a low-pass filter with a PWM output in order to generate an analog signal.

Resources

Critical Information and Concepts

Concept Importance
a. What does a low-pass filter do to a signal? Needed in order to understand how the filter in the schematic below works.
b. Why might you want to use a low-pass filter on a PWM square wave? Needed in order to understand the purpose of the circuit below.

Steps

Before you Start: Confirm that your Pioneer board power jumper is set to 5V to ensure full 0-5V operation.

  1. Duplicate the project from Part 2 into a new project in your workspace.

    1. Right click on the breathing LED project and select “Save As…”
    2. Rename the project to something descriptive like “PWMAnalog”. When it asks if you would like to rename the internal files as well, accept.
    3. Add the “PWMAnalog” project back to your workspace
      1. Right click on the workspace and select “add existing project”
      2. Select the “PWMAnalog” project
    4. Activate the new “PWMAnalog” project by right clicking on it and selecting “Set as Active Project”
  2. Open up the Top Design. Copy the PWM_1 block along with its clock and digital output, and paste back in once, next to or below the PWM_2 and PWM_3 blocks, to create a PWM_4 block.

    1. Keep the clock frequency the same as PWM_1
  3. In the Design Wide Resources > Pins window, connect the new output pin to a new, unused port.

  4. Add the following circuit to your breadboard and connect to the selected port on your Pioneer board.

    Example of low-pass filtering a PWM signal to output an analog signal
    Example of low-pass filtering a PWM signal to output an analog signal

  5. Open main.c and add two lines of code in the line before the outer for(;;) loop:

    1. One to initialize the new PWM subsystem
    2. One to start the new PWM subsystem
  6. Inside both of the second inner for() loops, change the duty cycle passing in the value of ii to PWM_4.

  7. Compile and build your code to see what happens when you measure the Vout signal with an oscilloscope.

Food for thought: Try changing the base PWM frequency to see what the output looks like when the signal is 10x faster or 10x slower. How does the selection of the R and C values impact your measurements?