This tutorial continues from where PWM Tutorial 1 left off
Introduction
The purpose of this tutorial is to apply the “breathing” PWM approach toward a motor driven by an H-Bridge
Steps
- Duplicate the project from PWM Tutorial 1 into a new project in the same workspace.
- Right click on the Breathing LED project and select “Save as…”
- Rename the project to something descriptive like “H-Bridge”. When it asks if you would like to rename the internal files as well, accept.
- Add the breathing LED project back to your workspace
- Right click on the workspace and select “Add existing project”
- Select the Breathing LED project
- Activate the new “H-Bridge” project by right clicking on it and selecting “Set as Active Project”
- Open up the Top Design. Copy the clock, PWM, and digital output and paste the blocks back in twice, next to or below the first, to create
PWM_2
and PWM_3
blocks
- Change the clock frequencies going into the new blocks to 256 kHz.
- In the Design Wide Resources > Pins window, connect the two new output pins to new, unused ports.
- Remove the switches and other components that will not be used in this assignment (motor, resistors) from your H-Bridge circuit.
- Connect two jumper wires from those new ports to the two forward/backward inputs of your H-Bridge circuit from ICC3.
- Open
main.c
and add four lines of code in the line before the outer for(;;)
loop: two to initialize and two to start the two new PWM subsystems.
- In the first of the two, inner
for()
loops, add code that:
- Sets the compare value of
PWM_2
to the value of ii
.
- Sets the compare value of
PWM_3
to zero.
- In the second of the two, inner
for()
loops, add code that:
- Sets the compare value of
PWM_2
to zero.
- Sets the compare value of
PWM_3
to the value of ii
.
- Compile and build your code to see what happens. Then, modify your code so that the motor “breathes” both forward and backward, going from a small pwm value to a large and back down in both directions.
Continue on to PWM Tutorial 3 – Using Low-Pass Filters with PWM Signals