View previous topic :: View next topic |
Author |
Message |
Bill_Smith
Joined: 06 Feb 2004 Posts: 26 Location: Curitiba, Brazil
|
Capture Mode On PIC18F452 |
Posted: Thu Dec 02, 2004 6:46 am |
|
|
I hadn�t had the pleasure of using the PIC18F452�s Capture module until now, so I scanned through the postings on CCP to see the types of issues that I would run into. Now I have a question. Is it possible to capture the pulse width of Timer1 without physically connecting Timer1�s output to the capture input pin? If this is possible, how does the Edge Detector get triggered? After reading through the Capture/Compare section of the PIC18F452 data sheet I came to the conclusion that it was not possible measure Timer1�s pulse width without connecting it up physically, however there are several code postings here that imply it is.
Sorry for appearing to be dumb, but can anyone help me?
Thank you. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu Dec 02, 2004 8:31 am |
|
|
Are you driving timer1 externally? |
|
|
Bill_Smith
Joined: 06 Feb 2004 Posts: 26 Location: Curitiba, Brazil
|
|
Posted: Thu Dec 02, 2004 8:45 am |
|
|
Hi Mark,
No, I was intending on setting Timer1 to use Fclk/4. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu Dec 02, 2004 9:01 am |
|
|
Then what are you trying to measure?? Timer1 with no prescaler increments at the same rate as an instruction cycle. It is the unit of measurement for the capture port? |
|
|
Bill_Smith
Joined: 06 Feb 2004 Posts: 26 Location: Curitiba, Brazil
|
|
Posted: Thu Dec 02, 2004 10:36 am |
|
|
Hi Mark,
I was just trying to see if I understood what I reading here in the Forum, and from the Microchip data sheet about using the Capture function. I thought there might be a simple way, using only software to setup Timer1 as a free running clock generator, and measure it�s pulse width by capturing the timer�s count on the rising and falling edges and subtracting. I thought that I might be able to do this without having to make a external connection between the Timer and the Capture registers on my target board.
After reading the PIC18F452 data sheet it seemed that I indeed needed to drive one of the I/O pins at Timer1�s rate and connect this output to the CCP1 input pin in order to play with the module. However, I found several code examples here on the Forum that appear to be saying that you can simply setup Timer1 to run off the Fclk/4, set the Timer1 prescaler to whatever, and then setup CCP1 to capture Timer1�s count on each rising edge, and CCP2 to capture Timer1�s count on each falling edge. Then you subtract CCP1 from CCP2 to calculate the pulse width.
I had not used the function before, so I was just checking to see if anyone on the Forum with experience might be able to clear up my confusion. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu Dec 02, 2004 12:42 pm |
|
|
Quote: | I found several code examples here on the Forum that appear to be saying that you can simply setup Timer1 to run off the Fclk/4, set the Timer1 prescaler to whatever, and then setup CCP1 to capture Timer1�s count on each rising edge, and CCP2 to capture Timer1�s count on each falling edge. Then you subtract CCP1 from CCP2 to calculate the pulse width.
|
This is true but you are not measuring timer1's pulse width but rather some external signal. The width of the pulse is in timer1 increments. It is pointless to actually measure the width of timer1, you already know that base on the clock and prescaler nor would it be possible to do with the ccp module.
Quote: | After reading the PIC18F452 data sheet it seemed that I indeed needed to drive one of the I/O pins at Timer1�s rate and connect this output to the CCP1 input pin in order to play with the module. |
No, just some square wave signal connected to one of the ccp pins. |
|
|
|