Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Thread

Frequency counter

Frequency counter

2005-06-05 by lehighuboy

Does anyone have sample code that counts pulses for a fixed time 
duration (frequency counter)?

Thanks, Garrett

Re: Frequency counter

2005-06-10 by lehighuboy

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:
Show quoted textHide quoted text
> Does anyone have sample code that counts pulses for a fixed time 
> duration (frequency counter)?
> 
> Thanks, Garrett

RE: [lpc2000] Re: Frequency counter

2005-06-10 by Dan Beadle

If you can sample over 1 second, this is pretty simple.  Just set the
signal up on an interrupt (rising or falling edge).  Count the
interrupts over 1 second.  There will be a +/- 1 count jitter - which is
significant at low frequencies (you might read 0 or 2 hz for a 1 hz
signal).  At 60mhz speed, you can run 300 instructions between
interrupts at 200Khz - about 60 lines of c code.  

 

You can get fancier - for high frequencies you can estimate after
counting for .1 second - leaving some CPU for other tasks.

 

I have to reduce this to code in the next few weeks.


Dan

 

 

  _____  
Show quoted textHide quoted text
From: lpc2000@yahoogroups.com [mailto:lpc2000@yahoogroups.com] On Behalf
Of lehighuboy
Sent: Thursday, June 09, 2005 10:18 PM
To: lpc2000@yahoogroups.com
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

*	To visit your group on the web, go to:
	http://groups.yahoo.com/group/lpc2000/
	  
*	To unsubscribe from this group, send an email to:
	lpc2000-unsubscribe@yahoogroups.com
<mailto:lpc2000-unsubscribe@yahoogroups.com?subject=Unsubscribe> 
	  
*	Your use of Yahoo! Groups is subject to the Yahoo! Terms of
Service <http://docs.yahoo.com/info/terms/> . 



[Non-text portions of this message have been removed]

Re: [lpc2000] Re: Frequency counter

2005-06-10 by Martin Maurer

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 ----- 
Show quoted textHide quoted text
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
>
>
>
>
>
>
>
>

RE: [lpc2000] Re: Frequency counter

2005-06-10 by Dan Beadle

This method works very well for low frequencies, but it can have
substantial error at high frequency where multiple interrupts are
running. The interrupt latency will cause a slight delay in capturing
the time base.  If this is always the same, it washes out. But if
another - higher priority - task sometimes runs, there will be jitter in
the latency - causing jitter in the frequency measurement.

 

Using counters for high frequency works well, but with high load. Using
edge-edge timers works very well for low frequencies.

 

  _____  
Show quoted textHide quoted text
From: lpc2000@yahoogroups.com [mailto:lpc2000@yahoogroups.com] On Behalf
Of Martin Maurer
Sent: Thursday, June 09, 2005 10:29 PM
To: lpc2000@yahoogroups.com
Subject: 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 Links

*	To visit your group on the web, go to:
	http://groups.yahoo.com/group/lpc2000/
	  
*	To unsubscribe from this group, send an email to:
	lpc2000-unsubscribe@yahoogroups.com
<mailto:lpc2000-unsubscribe@yahoogroups.com?subject=Unsubscribe> 
	  
*	Your use of Yahoo! Groups is subject to the Yahoo! Terms of
Service <http://docs.yahoo.com/info/terms/> . 



[Non-text portions of this message have been removed]

Re: [lpc2000] Re: Frequency counter

2005-06-10 by Richard Duits

The short fragment of code below can be used to measure frequency on a 
capture pin. Initialize FIQ_R8 to the timer address and FIQ_R9 to -1 and 
enable the fast interrupt.

The frequency can be calculated with: (float)(PCLK * FIQ_R9) / 
(float)(FIQ_R11 - FIQ_R10)


void FastInterrupt(void)
  __attribute__((interrupt("FIQ"), naked));

void FastInterrupt(void)
{
  asm volatile("ldr\t"   "r12, [r8,0]");          /* Read Timer 
Interrupt Register */
  asm volatile("ldr\t"   "r13, [r8,40]");       /* Read Capture Register 
0 */
  asm volatile("str\t"   "r12, [r8,0]");          /* Clear Interrupt */
  asm volatile("adds\t"  "r9, r9, #1");         /* Increment edge counter */
  asm volatile("moveq\t" "r10, r13");         /* Remember 1st edge 
capture */
  asm volatile("mov\t"   "r11, r13");         /* Remember last edge 
capture */
  asm volatile("subs\t"  "pc, lr, #4");         /* return from interrupt
}



Richard.







lehighuboy wrote:
Show quoted textHide quoted text
> 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*
>
>     * To visit your group on the web, go to:
>       http://groups.yahoo.com/group/lpc2000/
>        
>     * To unsubscribe from this group, send an email to:
>       lpc2000-unsubscribe@yahoogroups.com
>       <mailto:lpc2000-unsubscribe@yahoogroups.com?subject=Unsubscribe>
>        
>     * Your use of Yahoo! Groups is subject to the Yahoo! Terms of
>       Service <http://docs.yahoo.com/info/terms/>.
>
>

SV: [lpc2000] Re: Frequency counter

2005-06-10 by Helge Fabricius-Hansen

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
Show quoted textHide quoted text
----- 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 Links

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.