Datasheet

Table Of Contents
WARNING
It is assumed the source frequency the programmer provides is correct. If it is not then the frequency returned by
clock_get_hz will be inaccurate.
2.14.6.2. Using the frequency counter
To use the frequency counter, the programmer must:
Set the reference frequency: clk_ref
Set the mux position of the source they want to measure. See FC0_SRC
Wait for the DONE status bit in FC0_STATUS to be set
Read the result
The Pico SDK defines a frequency_count function which takes the source as an argument and returns the frequency in kHz:
Pico SDK: https://github.com/raspberrypi/pico-sdk/tree/pre_release/src/rp2_common/hardware_clocks/clocks.c Lines 210 - 237
210 uint32_t frequency_count_khz(uint src) {
211 fc_hw_t *fc = &clocks_hw->fc0;
212
213 // If frequency counter is running need to wait for it. It runs even if the source is
Ê NULL
214 while(fc->status & CLOCKS_FC0_STATUS_RUNNING_BITS) {
215 tight_loop_contents();
216 }
217
218 // Set reference freq
219 fc->ref_khz = clock_get_hz(clk_ref) / 1000;
220
221 // FIXME: Don't pick random interval. Use best interval
222 fc->interval = 10;
223
224 // No min or max
225 fc->min_khz = 0;
226 fc->max_khz = 0xffffffff;
227
228 // Set SRC which automatically starts the measurement
229 fc->src = src;
230
231 while(!(fc->status & CLOCKS_FC0_STATUS_DONE_BITS)) {
232 tight_loop_contents();
233 }
234
235 // Return the result
236 return fc->result >> CLOCKS_FC0_RESULT_KHZ_LSB;
237 }
There is also a wrapper function to change the unit to MHz`:
Pico SDK: https://github.com/raspberrypi/pico-sdk/tree/pre_release/src/rp2_common/hardware_clocks/include/hardware/clocks.h Lines 140 - 144
140 static inline float frequency_count_mhz(uint src) {
141 // FC result already in khz so only need to divide
142 // by 1000 to get mhz
143 return ((float) (frequency_count_khz(src))) / KHZ;
144 }
RP2040 Datasheet
2.14. Clocks 171