Yahoo Groups archive

Lpc2000

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

Message

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:

> 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/>.
>
>

Attachments

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.