# Driving a DC Motor using PWM

Note: this page describes one of two ways of doing PWM. This way uses two PWM signals inverse to each other. The other way uses one PWM signal and a DC level. See Pulse_width_modulation

Before doing this exercise, read about Brushed DC Motors and Driving Using Pulse Width Modulation. In this exercise you will use a function generator to create the pulse width modulation (PWM) signal that controls the motor. This simulates a signal that could be generated by a microcontroller.

Make sure your 7.2V battery pack is charged. The steps below assume you are using this gearmotor, which has a 224:1 gearhead and a stall torque of 50 oz-in at 5V, with a stall current of 600 mA.

1. Use a function generator to create a 5 kHz square wave between 0V (GND) and 5V. Verify that you have done this by looking at the signal on an oscilloscope. (Note: In the figures below, I used a 20 kHz square wave, an unnecessarily high switching frequency for this exercise.) To learn how to do this with the function generator and oscilloscopes in the Mechatronics Lab, read the manuals on the Tektronix CFG253 Function Generator and Tektronix TDS220 Oscilloscope. Looking at the oscilloscope signal, vary the duty cycle (the percentage of time the signal is "high" each cycle) of the signal using the symmetry knob, say from 20% to 80%. Your oscilloscope should look something like the figures below.

2. Attach your battery pack to your breadboard. Use your 7805 1A 5V voltage regulator so that you have 5V and 7.2V (with respect to the ground pin of the voltage regulator) available for use. Verify using your multimeter or an oscilloscope. (In my case, I measured about 5.2V and 9.5V.) Make sure your function generator ground is connected to the ground pin of the voltage regulator. Note: Don't try to jam the 7805 leads into a protoboard, as they are too large. Solder 22 AWG solid wires to the leads instead.

3. Use a 74HC04 Hex Inverter/Buffer to get an inverted version of the function generator signal, in addition to the original signal. (Don't forget to power this chip!) Verify by looking at both the original signal and the inverted signal simultaneously on the oscilloscope. You should see something like below: