View previous topic :: View next topic |
Author |
Message |
NEWBOY
Joined: 19 Dec 2003 Posts: 9
|
Can i use 50mhz on Timer1? |
Posted: Wed Jan 21, 2004 12:42 pm |
|
|
Hi guys
Could someone please clear this up for me.
i am planning to use a 50mhz oscillator that has TTL output connected
to RA0 of a 18F452.
As i want to use the Timer/counter option to measure frequency connected to RC2 Capture.
Is 50mhz to high for the pic ?
Santana |
|
|
fpgeh
Joined: 07 Sep 2003 Posts: 19 Location: Vancouver, BC
|
|
Posted: Wed Jan 21, 2004 1:24 pm |
|
|
Look in the datasheet for the 18F452. Table 22-4 shows max. external freq. to be 40MHz. Since 1 instruction cycle = 4 clock cycles, it's really only operating at 10MIPS.
I can't tell what you are trying to do, but it is not possible to use a PIC to measure frequencies 5x that of the operating frequency. |
|
|
NEWBOY
Joined: 19 Dec 2003 Posts: 9
|
|
Posted: Wed Jan 21, 2004 2:32 pm |
|
|
Thanks for that i should have looked.
This is what i and trying to do. i am trying to frequency measurements in the range 1 - 5khz with 0.1hz accuracy which would then be displayed on my Lcd.
i have tried using the capture mode but the best resolution i get is 0.3hz even when using the x 4 PLL to make the pic run at 40mhz because .
FOSC/4 = 10,000,000 but i need the complete 40mhz
so i decided to change my measurement method
Rather than counting the number of pulses in a given time, now i
want to count a number of fixed known pulses (my clock) gated by my
input pulses(The frequency are to be measured). Now, if i gate ten input pulses, i will have ten times the accuracy of gating one pulse. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Wed Jan 21, 2004 2:50 pm |
|
|
You should be able to do that with the CCP module. Your problem is most likely with the prescaler that you setup for timer1. Setting a prescaler for this will lower the resolution since the timer now increments more slowly. |
|
|
Billy Ray Cirus Guest
|
Check the Microchip application notes |
Posted: Wed Jan 21, 2004 4:49 pm |
|
|
There is an app. note on this. 50MHz is possible, but with limited resolution.
Regards |
|
|
NEWBOY
Joined: 19 Dec 2003 Posts: 9
|
|
Posted: Fri Jan 23, 2004 3:13 pm |
|
|
Sorry Guys
i just didn't explain myself properly
i am trying to measure frequency with 0.1Hz accuracy for the range 1 -
5khz just like a frequency counter and display this on an Lcd.
i have done the calculations using a pic16f452 @ 40mhz and from the calcutions below the best i could get was 0.3Hz accuracy using the capture method.
Example for 1000Hz
OSC = 40,000,000
FOSC/4 = 10,000,000
Prescaler = 8
TMR1 Input = 125,000 Hz
Period = 0.001 Sec
16 Rising = 0.016 Sec ' 16 rising edges of RC.2
Capture = 20,000 ' This should be the highest capture count (0.016 x 125,000)
Now, calculating the frequency:
20,000,000 / 20,000 = 1000.0
Ok, well that's an even number, so it works out perfect. Let's try an odd one.
Res Freq = 1000.437 Hz
Period = 0.000999563 Sec
16 Rising = 0.015993011 ' 16 rising edges of RC.2
Capture = 19991 ' capture count = INT(0.015993011 x 125,000)
Calculating the frequency:
20,000,000 / 19991 = 1000.4
Hmmm, that one works too. Maybe the higher end of the range:
Res Freq = 2000.478 Hz ' Just pulling numbers out of the air
Period = 0.000499881 Sec
16 Rising = 0.007998088 ' 16 rising edges of RC.2
Capture = 9997 ' capture count = INT(0.007998088 x 125,000)
Calculating the frequency:
20,000,000 / 9997 = 2000.6
That one's off by 0.122 not too bad.
So i decided to do it another way by feedind an external very fast clock to RC0 say 40mhz or 50mhz and count the number of pulses thats gone through when i now feed a low frequency to RC2
from that i might be able to work out the frequency fead to RC2.
Santana |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Sat Jan 24, 2004 9:28 pm |
|
|
Yeah, like I said - it is probably your prescaler! Don't set a prescaler and you will have a 10Mhz clock instead of a 125KHz one. Now you might have to extend the ccp value by incrementing a var in the timer1 int. |
|
|
|