Hi,
I would say that counting pulses during 1 - 10 seconds will give you the
most accurate frequency.
Using a capture input set to either pos or neg edge.
Problem with measuring the pulsewidth is that you will not get a resolution
of 1 Hz at 200KHz.
The difference between 200000 and 200001 Hz is just about 0.000025 us.
//Helge
-----Ursprungligt meddelande-----
Från: lpc2000@yahoogroups.com [mailto:lpc2000@yahoogroups.com] För Martin
Maurer
Skickat: den 10 juni 2005 07:29
Till: lpc2000@yahoogroups.com
Ämne: Re: [lpc2000] Re: Frequency counter
Hello,
i don't know if there is any hardware support for this ?
Here are two not elegant solutions, but give you perhaps an idea !
Easiest way without hardware support: Measure the time between line going
low->high and second low->high.
WaitForPinLow();
WaitForPinHigh();
for(t1 = 0; t1 < BigTimeoutValue; t1++)
{
WaitForPinLow();
}
for(t2 = 0; t2 < BigTimeoutValue; t2++)
{
WaitForPinHigh();
}
According to values t1 and t2 (in sum) you can get the frequency.
BUT: This is very compiler dependant, if it does any optimization, values
can change !
Better use one of the timers: Start a timer with high frequency, read it out
the first time low->high and read it out the second time low->high. Then you
can calculate the frequency.
Regards,
Martin
----- Original Message -----
From: "lehighuboy" <garrett.j.young@...>
To: <lpc2000@yahoogroups.com>
Sent: Friday, June 10, 2005 7:18 AM
Subject: [lpc2000] Re: Frequency counter
>I need to read the frequency of a 50% duty cycle waveform from 0 to
> 200kHz (+/- 1Hz) using the LPC2129. Any suggestions?
>
> Thanks, Garrett
>
> --- In lpc2000@yahoogroups.com, "lehighuboy" <garrett.j.young@g...>
> wrote:
>> Does anyone have sample code that counts pulses for a fixed time
>> duration (frequency counter)?
>>
>> Thanks, Garrett
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>
Yahoo! Groups LinksMessage
SV: [lpc2000] Re: Frequency counter
2005-06-10 by Helge Fabricius-Hansen
Attachments
- No local attachments were found for this message.