This tutorial continues from where PWM Tutorial 2 left off
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.
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. |
Before you Start: Confirm that your Pioneer board power jumper is set to 5V to ensure full 0-5V operation.
Duplicate the project from Part 2 into a new project in your workspace.
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.
PWM_1
In the Design Wide Resources > Pins window, connect the new output pin to a new, unused port.
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 |
Open main.c
and add two lines of code in the line before the outer for(;;)
loop:
Inside both of the second inner for()
loops, change the duty cycle passing in the value of ii to PWM_4
.
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?