2

I'm trying to input the frequency of a 3.3V square wave on a GPIO pin as a program feedback parameter. The input frequency range would be 1000 to 100,000 Hz and data polling would happen at 30 Hz. Its important to minimize processor overhead.

We got the dedicated PWM pin on the GPIO working fine. Is there a similar dedicated frequency counting / timer GPIO pin that could do the low overhead counting?

Thanks Jim

goldilocks
  • 58,859
  • 17
  • 112
  • 227
Jim Sears
  • 21
  • 1
  • 1
  • 3

2 Answers2

6

There is no hardware support for frequency counting via the Pi gpios. You will have to monitor the gpios in software.

Given your upper end is 100kHz I suspect my pigpio library is most likely to give reliable results. pigpio works by sampling and doesn't have the significant overhead involved with interrupts at these frequencies.

Two frequency count methods are given in these examples.

joan
  • 71,024
  • 5
  • 73
  • 106
  • Thanks Steve. Too bad on the dedicated pin. I'm aiming to control the averaging window and measurement precision and counting over a period seems the best way if it is possible. Ill check out your library. ..And use an external chip if needed. -Jim – Jim Sears Dec 05 '14 at 01:46
  • 2
    Steve, your library is awesome! – Jim Sears Dec 08 '14 at 19:21
0

Pigpio is a good library to use up to 20 KHz but at 100KHz it's accuracy seems to be dropping to about 40% (according to our recent benchmark test on a RPi 3B). Still, it is the best one we know.