Using CCP to measure Pulse Period and PWM
________________________Updated
04/03/2019 _________________________________
Purpose: The purpose of this lab is to learn how to use timer modules and utilize CCP to measure an incoming clock's frequency. This lab contains the following parts:
- TMR0
- CCP1 Module
Optional Parts Required:
- Scope
- Signal Generator (1KHz)
- PICKit3 and USB connector (1)
- Breadboard (minimum of 40 rows are required) (1)
- PIC18F45K20 chip (through-hole) (1)
- LEDs or LCD or Seven Segment
Useful Links:
Procedure:
Part I - Use TMR0 to generate a 1KHz clock.
Purpose: In this section you learn how to use TMR0 to generate a 1 KHz signal. Make sure the MAIN part of the program is very clear and simple. You need to use a scope to make sure the clock frequency is correct. You MUST use TMR0 module. Answer the following questions:
- What is the frequency of the internal clock? How do you know? Take a snapshot of Fosc or Fosc/4.
- Take a snapshot of the generated 1KHz clock. Use the measuring tool on the scope to calculate the signal frequency. Use the cursors on the scope to verify the period.
- What value did you load into the timer in order to generate the 1 KHz clock. Show your calculations.
- Using the loaded value in the TMR0 , what is the difference between the measured and calculated period?
- Which pin are you using to generate the clock signal?
Part II - Use CCP module to measure period of an incoming 1KHz+/-500 Hz.
Purpose: In this section you learn how to use the CCP module in capture mode. This assignment has two parts (the second part is extra credit)- review the slides and read the textbook (Chapter 9):
- PART II-1: Measure the frequency of the incoming signal from a signal generatorand and display it on your LCD or serial port.
- PART II-2: Connect a sensor to a rotating object (e.g., wheel of a bike) and display how fast the wheel turns. You can use a Hall Effect Switch , buy one of these, or simply make your own switch. Alternatively, you can design a simple device to measure reaction time: An LED is turned on at a random time and the user must press a button as soon as the LED is turned on. The LCD should show the elapse time in msec. You can also change this problem to such that you measure the timing between two consecutive PUSH actions using a single switch. (Extra Credit)
Submit the following:
- Complate report as before.
- Test results. How do you verify your measurements are correct. You must clearly explain and support your answers with test results.
Answer the following questions:
- Which pin are you using to receive the incoming signal?
- Take a snapshot of the incoming signal. You can use a signal generator or your clock signal from Part I of this exercise.
- How accurately can you determine the frequency of the incoming signal?
- What happens if the frequency of the signal changes?
ALL SECTIONS MUST BE DEMONSTRATED IN CLASS -