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

CP316: Microprocessor Systems and Interfacing

Timers and Counters

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

Arduino timer "poll overflow flag" program

  1. Connect the Arduino board.
  2. Create a new sketch, and download the timer poll overflow flag sketch.
  3. Connect the oscilloscope to output pin 13.
    (This is because each timer has certain pins which it can control. Timer 1 can control pins 9 and 10. 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. Arduino timer "poll compare flag" program

    1. Connect the Arduino board.
    2. Create a new sketch, and download the timer poll compare flag sketch.
    3. Connect the oscilloscope to output pin 13.
      (This is because each timer has certain pins which it can control. Timer 1 can control pins 9 and 10. 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.

    Timer parameters -normal vs. CTC mode

    Normal; rolls over at TOP; OCR doesn't matter
    CTC; rolls over at OCR

    Multiple timers; adapt for Timer 2

    Adapt the code to use Timer 2 instead; demonstrate this during this lab or the next one.

    Timer parameters -prescaler

    Timer parameters -MAX value

    Timer features - counter

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