Pages created and updated by Terry Sturtevant Date Posted: May 12, 2017

CP316: Microprocessor Systems and Interfacing

Timers and Counters

Objectives

Microcontroller timers can typically operate as a timer or a counter. A timer outputs a signal after a specified interval of time. A counter counts the number of pulses (by counting rising or falling edges) for a particular input signal. The timing signal will be monitored using an oscilloscope driven from Port C.

Equipment

Procedure

  1. Modify one of your LED programs from the last lab (new project) to turn the left LED on/off every second, i.e. on for one second, off for one second. Structure the program so that you have one subroutine that measures 1/100 of a second based on timer0. You should have another subroutine that calls the .01 second routine the appropriate number of times to get the required timing.

  2. Check GROUND and VDD pins on the header to make absolutely sure you understand the header pin numbering. Verify your timing for the previous program using the oscilloscope.

    Demonstration - demonstrate and explain the operation of your program.

  3. If you wanted to change the timing of the above program to turn the left LED on/off every two seconds, there are three different ways to change the timing.
    • You could change the counting routine that calls the timing routine.
    • You could change the timing routine to run twice as long.
    • You could reconfigure the timer to run twice as slow

    Implement the three techniques. Note the changes that have to be made to the base program in your lab notebook. Verify the timing for each implementation using the oscilloscope. Comment on the respective accuracy of each technique.

    Demonstration - demonstrate the operation of all three techniques.

  4. With respect to the previous question, if you simultaneously maxed out all three parameters and assuming that you did not change the structure of your program by adding additional loops, at what interval would the LED flash? Clearly show the maximum for each of the parameters and how it contributes to your calculation.

    Demonstration - explain the your calculation.

  5. Using the PIC18F452 datasheet or your text, review the block diagrams for the four timers.
    • Which of the timers allow input from a pin for use as a counter?
    • For each of these counters, which pin is used for input and where is it located on the PIC18F452 Block Diagram ?
      NOTE: references in the text or in the Timer3 section of datasheet to pin T13CKI should be replaced with T1CKI.
    • For each of these input pins, what is the associated port pin (from block diagram)?
    • How are these port pins used in the QwikFlash system (from schematic)?
    • Can we use any of these port pins as input to a counter?

    Demonstration - explain your investigation.

  6. Modify your program from question 1 of this lab (new project) to turn the left LED on/off every 1.5 seconds based on timer1. Verify your timing using the oscilloscope.

    Demonstration - demonstrate and explain the operation of your program.

  7. Although RC0, RC3, and RC5 are connected as inputs to the DAC, the DAC does not drive any of these pins. These pins can be used by expansion circuitry and, at worst, the only consequence would be erratic output voltages appearing on the DAC outputs.
    • Use the DAC datasheet, MAX522, to determine the function of the CS pin on the DAC.
    • Use the DAC datasheet, to determine the electrical specifications for the CS pin on the DAC.
    • Use the QwikFlash board test program (the QFPV.asm project from last week's lab) and an oscilloscope to verify your results.


  8. Setup the signal generator to produce a 0-5V square wave and verify the signal using the scope.
    Demonstration - explain your investigation of the DAC, demonstrate your 0-5V signal, and demonstrate location of pin1 on the header.

    You may not proceed to next task until the lab supervisor gives his OK.



  9. Write a program to demonstrate the use of timer1 as a counter. Use the information from the previous steps to provide a suitable input signal without harming the DAC.
    Demonstration - demonstrate and explain the operation of your program.

  10. Make a macro to initiallize timer 1 and add it to your include file. How much flexability can you put into the macro compared to doing all of the configuration in your main program? Adjust your main program accordingly.
    Demonstration - demonstrate the revised code in operation.
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