View previous topic :: View next topic |
Author |
Message |
MAKInnovation
Joined: 16 Nov 2010 Posts: 61
|
0 to 100Hz reading |
Posted: Thu Jan 12, 2012 12:35 am |
|
|
Need a simple code to read input frequency of 0 to 100Hz
Ash |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jan 12, 2012 12:39 am |
|
|
Use the forum's search page to search for:
also search for
Quote: |
PicBasic Count Command
|
In the last case, set the search page to: Search for All Terms
Links to forum search page:
http://www.ccsinfo.com/forum/search.php |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Thu Jan 12, 2012 7:13 am |
|
|
You need to think carefully about reading near 0Hz. To read 1Hz will usually take a full second. Reading 0.1Hz will take 10 seconds. 0Hz will literally take forever. What resolution do you need and how long can you wait? _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Thu Jan 12, 2012 7:34 am |
|
|
for low frequencies - you are better off using the frequency of interest
as a PERIOD GATE, applied to a (16 bit TMR1) timer that is counting the PICS ( crystal - 16 mhz - prescaled to 1 usec ?) clock - and doing the math to calculate the frequency .
then you can have a frequency measurement of each complete cycle of the unknown. |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Thu Jan 12, 2012 11:02 am |
|
|
Even with a period gate, reading a 0.1Hz signal will still take 10 seconds. You need to time from + edge to + edge or - edge to - edge, unless you KNOW it is a 50% duty cycle in which case it is still 5 seconds.
To accurately display 0Hz with 0.1 resolution you need to look for 10 seconds and see no more than one countable edge to be sure. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Thu Jan 12, 2012 1:32 pm |
|
|
If the waveform you want to count is close to 50% duty cycle - you can edge trigger on a b port change - to count a HALF cycle too i suppose.
Then - another - but dicer way that can be used.
Add a 74HC4046 - and a VCO output divider - divide by 8 or 16 - and do a PLL lock to the 4046 oscillator out incoming. YES there will be PLL lock time - but if the signal is not whipping about TOO fast in the freq/time domain -
- this can cut down the read gate time too - and possibly be of some help. |
|
|
MAKInnovation
Joined: 16 Nov 2010 Posts: 61
|
|
Posted: Thu Jan 12, 2012 11:37 pm |
|
|
Can i use a Frequency to Voltage converter like LM331 or LM2907 and then read converter output value with uController ADC |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19487
|
|
Posted: Fri Jan 13, 2012 3:06 am |
|
|
Not with any sort of resolution.
You need to specify rather better what you actually need.
Resolution?.
Accuracy?.
What is the real range, does it genuinely go to '0'?.
How fast should the update be?.
Zero, really is the problem area. Normally the approach is to accept anything under some specific rate as 'zero', and write the code to avoid things like maths overflows when this is reached. You can speed up responsiveness, with tricks, like phase locking a higher frequency onto the signal to be measured, but all fail when you get to '0'.
Best Wishes |
|
|
MAKInnovation
Joined: 16 Nov 2010 Posts: 61
|
|
Posted: Fri Jan 13, 2012 4:14 am |
|
|
Thanks Brother;
Yes the frequency could be zero
Resolution is not really important, it could be 1hz, 2hz.... or 1hz or 3hz...
But measurement must be accurate.
Regards;
Ash |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Fri Jan 13, 2012 7:12 am |
|
|
What is the source of the signal? Is it some sort of spinning wheel with a notch or magnet on it? Could it have several notches or magnets, giving a higher frequency to measure?
Having the uP measure a PLL locked to a multiple of the signal makes life easier for the uP, but doesn't actually help the system any. This is because the PLL can't track the input if there are no input edges for it to respond to. You have moved the problem from the uP to the PLL but it is the same problem.
Now if you have an analog sine wave input instead of a square wave there is lots of information in a fraction of a cycle. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Fri Jan 13, 2012 7:21 am |
|
|
A while back I had a project with a spinning disk whose speed had to be reported in part for feedback to the motor driving it.
One magnet and hall sensor would not give the required update rate at low speeds. We could use multiple magnets, but could not guarantee they would be evenly spaced around the wheel, so reading from one magnet to the next would give reported speed jitter.
So I had 4 magnets with one sensor and had to keep 4 distinct times, magnet A to magnet A, magnet B to magnet B, etc. I reported speed 4 times per revolution with no jitter. But I still could not report anything until the first rotation was complete. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
MAKInnovation
Joined: 16 Nov 2010 Posts: 61
|
|
|
|