View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Feb 13, 2008 12:44 am |
|
|
His question is really, can he use the Timer1 oscillator with an external
crystal in the CCP capture mode ? I tried experimenting with this a
few days or weeks ago, while reading one of his previous threads, and
I couldn't make it work. It would not capture. Switching to an internal
clock for Timer1 caused it to capture.
The 16F917 data sheet says this:
Quote: | Timer1 must be running in Timer mode or Synchronized
Counter mode for the CCP module to use the capture
feature. In Asynchronous Counter mode, the capture
operation may not work. |
Well, an external 32.768 KHz crystal oscillator (driving Timer1)
is certainly an asynchronous source. It's not synchronous to
the internal 8 MHz oscillator in the PIC. |
|
|
RLScott
Joined: 10 Jul 2007 Posts: 465
|
|
Posted: Wed Feb 13, 2008 7:33 am |
|
|
Then here is what he can do. Forget about input capture mode. Use the frequency to be measured to generate an interrupt, either on RB0 or on some other interrupt-on-change input. Then in the ISR, read Timer 1. This will be just as good as input capture since 32kHz gives 30 microseconds between ticks. Therefore the interrupt latency is less than one tick.
Robert Scott
Real-Time Specialties |
|
|
deepakomanna
Joined: 06 Mar 2007 Posts: 92 Location: Pune,India
|
how to measure frequency |
Posted: Thu Feb 14, 2008 8:10 am |
|
|
RLScott wrote: | Then here is what he can do. Forget about input capture mode. Use the frequency to be measured to generate an interrupt, either on RB0 or on some other interrupt-on-change input. Then in the ISR, read Timer 1. This will be just as good as input capture since 32kHz gives 30 microseconds between ticks. Therefore the interrupt latency is less than one tick.
Robert Scott
Real-Time Specialties |
In my application all seg0 to seg14 are used for LCD segment only RC5 & RE3 are remainng & Only for RB0 to RB7 are used for IOC,then how could i calculate frquency by using external source for timer1 at RA7/RA6. _________________ Thank You,
With Best Regards,
Deepak. |
|
|
RLScott
Joined: 10 Jul 2007 Posts: 465
|
Re: how to measure frequency |
Posted: Thu Feb 14, 2008 9:19 am |
|
|
Since you have not told us which PIC you are using, I have no idea what functions are on RC5, RE3, RA7 and RA6. But if one of these is an input capture pin, perhaps the input capture interrupt will work even if the loading of the PR register does not. In that case you can use the interrupt to read Timer 1 yourself. If this interrupt does not work when Timer 1 is asynchronous, then you are out of luck.
Robert Scott
Real-Time Specialties |
|
|
Kenny
Joined: 07 Sep 2003 Posts: 173 Location: Australia
|
|
Posted: Fri Feb 15, 2008 5:43 pm |
|
|
Options are limited. I too experimented with the capture (on a different pic) and got some odd results.
Could just use timer 1 as a counter for the input signal on the T1CKI pin (RC5 if it's the 16F917), and count for one second.
The count is the frequency in Hz if the counter was cleared first.
Use
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);
Another timer, timer 0 or timer 2, could be used for timing the one second. Timer 2 is convenient for this purpose.
eg with
setup_timer_2(T2_DIV_BY_16,249,10);
the timer 2 interrupt will occur every 20mS. In the timer 2 interrupt service routine count the interrupts,
and when 50 have occurred get the count from timer 1. Set a flag for main() to display the count.
Accuracy would be 1Hz at the 10 Hz end of the input range, and within the accuracy limits of the internal 8MHz RC oscillator higher up the range. |
|
|
|