$30
ECE 206: PWM and Motor Speed Control
PWM (Pulse-width modulation) is a convenient way to
generate an approximate analog voltage from a digital
signal. In a PWM system, the pulse width (sometimes
called the “duty cycle”) of a constant (base) frequency
waveform is changed (“modulated”). The result is sent
through a low-pass filter, which removes the high base
frequency. This results in an analog voltage being
generated at the output of the low-pass filter. Notice that
the microcontroller only needs to generate digital signals
directly (e.g. 0 – 5 V), but the output of the filter is a
continuous analog voltage.
Prelab Deliverables:
• A PWM output from STEMTera is composed of a DC offset and sinusoidal waveforms at a base
frequency of 490 Hz. Determine the cutoff frequency of the low-pass filter given in the circuit
diagram below. Is the low-pass filter able to attenuate the sinusoidal waveforms (AC components)?
References:
• Arduino PWM https://www.arduino.cc/en/Reference/AnalogWrite
• Installing the encoder onto the motor https://www.sparkfun.com/products/16413
Challenges:
• Build a circuit which controls motor speed from the encoder knob (see circuit diagram below).
• Obtain output waveforms of a wheel encoder (not the same as knob encoder) at 3 different motor
speeds.
• Come up with an algorithm to calculate the RPM of a motor given output waveforms.
Both knob encoder and wheel encoder are important parts of a complete system. Imagine you are driving
a car. The knob encoder is like the gas pedal that controls how fast fuel flows into the engine of your car,
while wheel encoder is the speedometer that tells you how fast the car is travelling.
We recommend you divide the work into two parts:
First: Build the open loop motor control circuit with the knob encoder controlling motor speed. Display
the filtered PWM with one analog input pin of the STEMTera.
Then: Finish the rest of the circuit by adding wheel encoder and display the signal from the wheel encoder
on another analog input of the STEMTera.
Lab Description updated 07/11/2020
The motor encoder uses a hall-effect sensor. Magnetic poles in the disk that is mounted to your motor
spin over the sensor to actuate it. Turning the encoder slowly by hand and observing the signal on your
oscilloscope will allow you to count how many times the encoder actuates per revolution. You will need
this for your RPM calculations.
Code:
• Use a high baud rate when using Serial Plotter (baud rate = 500000 recommended).
• Because the linear region of K3703 MOSFET is small, analogWrite values should be at a range from
100 to 120. (There is a built-in function constrain that you can use).
Report Deliverables:
• Provide descriptions with accompanying diagrams of your circuits and experimental setup; include
annotated photographs of your experimental setups.
• Have your TA verify that the speed of the motor can be changed by a knob encoder (Part I).
• Include Serial Plot traces of the PWM signals (unfiltered and filtered) and output of the wheel
encoder (green) at three different motor speeds.
• Have your TA verify that output waveforms change as the speed of the motor changes (Part II).
• Write an algorithm that can calculate the RPM of a motor given output waveforms of the wheel
encoder.