I'd want to use the RPi-pico to measure the ratio between two frequencies, one stable F0 = 10MHz, the other F1 about 14MHz, both externally fed to two GPIOs. 20 bit accuracy is fine. That could be e.g. counting over 21 bits how many F1 pulses there are over 220 pulses of F0.

Q0: Can one confirm the built-in Frequency Counter does the trick? I hope so based on

The frequency counter measures the frequency of internal and external clocks by counting the clock edges seen over a test interval. The interval is defined by counting cycles of clk_ref which must be driven either from XOSC or from a stable external source of known frequency.

Q1: How do I select the source of clk_ref to make it my F0 = 10MHz from a GPIO?

Q2: Does that impact other things, in particular USB?

Q3: Are my 10 MHz and 14 MHz frequencies within parameters, and where is that specified?

Q4: Anything wrong in my understanding (below) of what the hardware does?

The doc of FC0_INTERVAL (4 bits) states

The test interval is 0.98us * 2interval, but let’s call it 1us * 2interval
The default (of 8) gives a test interval of 250us

I'm reading this as: the measurement interval is  FC0_REF_KHZ * 2FC0_INTERVAL-10  periods of clk_ref, somewhat rounded (for values of FC0_INTERVAL less than 10, some low-order bits of FC0_REF_KHZ are likely ignored).

The register FC0_RESULT (30 bits) is count * 215-FC0_INTERVAL where count is how many periods of the source selected by FC0_SRC there has been over the test interval.

I hope that's consistent with table 217 and the code for frequency_count_khz.

2 Answers 2


Very interesting project. Q0: ? I guess so. Q1: Register is Clockbase + 0x30, see ch 2.15.7 Q2: Only Watchdog&Timers, see ch 2.15.1 Q3: 6..12MHZ, see ch Q4: I guess not. Just check. I hope my answers help.

  • Thank you for the feedback. FYI, since I asked the question, a colleague of mine did implement that frequency counter with external reference using a RPi-pico, albeit not using the buit-in frequency counter. Rather, we use two PWM in counter mode (prescaler set to 1 to count every edge, interrupt generated on overflow to extend the counter range). We get arbitrary accuracy, limited only by the measurement time, a ±1 count error on both the reference and the measured frequency, and of course the reference (GPS disciplined). It rocks!
    – fgrieu
    Commented Aug 31, 2022 at 16:14

I made an Arduino library for the RP2-pico that counts cycles on one pin using a second pin as a trigger. This isn't quite what you want - you'd need to divide down your reference oscillator by, e.g., 2^20, to get the suitable trigger pulses.


This uses the PWM hardware for counting. You could probably build exactly what you propose using two PWM counters, but you'd need to modify the PWM_IRQ_WRAP handler to differentiate between the wrapping of each counter.

  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Sep 19, 2022 at 16:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.