Pages created and updated by Terry Sturtevant Date Posted: June 25, 2019

CP316: Microprocessor Systems and Interfacing

Pulse Width Modulation

Objectives

Since creating square waves and pulses is common in circuits, hardware timers make this easy. Once set up, they can run indefinitely without software intervention.

Equipment

Procedure

Timer features - Fast PWM mode - 8 bit, 9 bit or 10-bit

  1. Connect the Arduino board.
  2. Create a new sketch, and download the fast PWM sketch.
  3. Connect the oscilloscope to output pin 9.
    (This is because each timer has certain pins which it can control. Timer 1 can control pins 9 and 10. Unfortunately, none of the timers can directly control pin 13.)
  4. Run the program to see that the square wave appears on the scope.
  5. Comment out the delay instructions in the program and rerun it so you can see the maximum frequency that can be produced.
    Sketch the output, and note the oscilloscope settings.
    arduino blink output

  6. Press the Run/Stop button on the oscilloscope to freeze the image, and note how consistent the pulses are. Repeat this 5 or 6 times to find the maximum variation between pulses that you observe.
    Sketch the output, and note the oscilloscope settings.
    Demonstration - demonstrate the screen showing the variation.
    Because there is no operating system, your program is the only task running.

Arduino PWM features - analogWrite() function

Arduino PWM features - Servo library

Timer features - Phase correct PWM mode - 8 bit, 9 bit or 10-bit

  1. Connect the Arduino board.
  2. Create a new sketch, and download the phase correct PWM sketch.

Timer features - Phase and Freq. PWM mode

Creative Commons License

Information on this site which is produced by Terry Sturtevant is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 Canada License.

Resources

To view pdf documents, you can download Adobe Acrobat Reader .
get Acrobat Reader
If you need to update a browser, you might try Firefox which is Get Firefox!
Since this page uses cascading style sheets for its layout, it will look best with a browser which supports the specifications as fully as possible.

If you are looking for an office package, with a word processor, spreadsheet, etc., you might try LibreOffice which is Get LibreOffice!

Go to the main page for the Department of Physics and Computer Science.

Valid XHTML 1.1

Valid CSS!

WCAG
2.0
(Level AA)

Wilfrid Laurier University