|
|
View previous topic :: View next topic |
Author |
Message |
tcruise7771
Joined: 12 Apr 2013 Posts: 24
|
Frequency , Timer1 and Division question. |
Posted: Fri Jun 21, 2013 5:15 am |
|
|
Quick question I have a Frequency Counter , but i have no source to test its real maximum frequency limit. The highest i tested was 750kHz with step of 1Hz and it was pretty acurate like 0.02% or more ( i think it only depends on the crystal accuracy)
The frequency depends on :
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);
and i am using 20MHz crystal , PIC16F877A at 20MHz, t1_overflow for exactly 1 second and i use it to make32(msb,lsb). So the value would be as big as the counts the timer can distinguish for 1 second.
From what i thought i think the theoretical maximum frequency should be 20MHz or 5MHz. How fast setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1); works ? I know it counts zero crossings of the signal so if it does it one counting for 1 instruction that means 5MHz?
Also how will changing the div_by_1 change the maximum frequency and the resolution
I know Proteus is out of the picture but the simulation gave me even 180MHz and that is redicilous.
----
Edit: CCS tutorial says : the timer will increment every 0.2us which means 5MHz right ? |
|
|
mdemuth
Joined: 16 Apr 2007 Posts: 71 Location: Stuttgart, Germany
|
|
Posted: Fri Jun 21, 2013 5:57 am |
|
|
The internal frequency is just 1/4 of the crystal or oscillator frequency.
Maybe you could change your approach by comparing the oscillator frequency to the other frequency you want to measure.
Connect the oscillator out pin to counter1 input for a 20MHz reference.
Connect your signal to measure to a different counter input.
Poll for the rising edge of the measurement input, then set timer1=0 and start it.
After a number of overflows on the reference oscillator input (depending in the accuracy you want to get) you just wait for the next rising edge of the measurement input.
Now everything else is just math (beware of larger numbers and overflows!)
Divide the two counter values and multiply by result by the reference clock. |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Fri Jun 21, 2013 7:07 am |
|
|
Excuse me for being naive, but I want to be absolutely certain of the facts.
Quote: | Quick question I have a Frequency Counter , but i have no source to test its real maximum frequency limit. The highest i tested was 750kHz with step of 1Hz and it was pretty acurate like 0.02% or more ( i think it only depends on the crystal accuracy) | Do you mean that you're using your PIC as a frequency counter?
I'm assuming that you are connecting you're unknown source to the T1CKI as an input.
In which case I believe you should be able to measure up to the maximum clock rate the data sheet will allow.
As a simple test, you can connect OSC2/CLKOUT to T1CKI.
With an external clock you should measure Fosc/4
With a crystal you should measure Fosc.
This link may help
http://www.ccsinfo.com/forum/viewtopic.php?t=47375&start=0
Quote: | Also how will changing the div_by_1 change the maximum frequency and the resolution
| I doubt it will improve anything as you're throwing data away.
Mike |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Fri Jun 21, 2013 7:12 am |
|
|
The timer has nothing to do with the internal oscillator, when it is running off an external source. It is just a simple binary counter being clocked from that source.
The 'div', is a simple binary prescaler you can turn on. effects how many edges the timer has to see before counting.
It does not count 'zero crossings', it counts rising edges.
Data sheet is your friend. Look at the 'timer1 block diagram'.
See how you have a clock input (with optional oscillator gate), feeding into a multiplexer. Here you can select to feed this clock, _or_ FOSC/4, on to the next stage. Then you have the programmable 'pre-scale' divider. Then you have an option to 'synchronise' the clock to the edge of the internal oscillator - if you use this, then the speed would become limited by the internal oscillator. Then the output from all this just feeds into a counter.
You can use timer1, at 10MHz, while the CPU is running of just 32Khz if you want....
However 'remember' that the latencies inherent in reading the timer, rise as your CPU clock rate goes down. Running the timer 'asynchronous', it's maximum clock rate is 16.6Mhz, if fed with a square wave. If your waveform is asymmetric, the supported rate falls.
Best Wishes |
|
|
tcruise7771
Joined: 12 Apr 2013 Posts: 24
|
|
Posted: Fri Jun 21, 2013 8:52 am |
|
|
Guys guys, i said "i am using 20MHz crystal , PIC16F877A at 20MHz, t1_overflow for exactly 1 second and i use it to make32(msb,lsb). So the value would be as big as the counts the timer can distinguish for 1 second."
Again I am using external 20MHz crystal to run the PIC, so with DIV_1 i would get up to 20MHz ?
Edit: just seen seen the link Mike Walne gave, and my program is similar to the frequency example, So i guess the maximum frequency is 20MHz. |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Fri Jun 21, 2013 9:32 am |
|
|
tcruise7771 wrote: | Guys guys, i said"i am using 20MHz crystal , PIC16F877A at 20MHz, t1_overflow for exactly 1 second and i use it to make32(msb,lsb). So the value would be as big as the counts the timer can distinguish for 1 second. "
Again I am using external 20MHz crystal to run the PIC, , so with DIV_1 i would get up to 20MHz ?
Edit: just seen seen the link Mike Walne gave , and my program is similar to the frequency example, So i guess the maximum frequency is 20MHz |
No. I wasn't trying to be silly (or clever).
There are several ways round you could have been doing things.
With the best will in the world we sometimes get our lines crossed.
Bear in mind we all have different backgrounds and a range of cultures.
Many of us (myself included) are not software specialists.
The mximum frequency you can rely on is set out in the data sheet, as Ttelmah has outlined.
You have to be careful, pick out the correct section, and read the detail.
It can be a minefield, most of us have tripped up at some stage.
Mike |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|