`millis()` runs faster on a 200MHz RP2040

I am noticing that on a RP2040 running at 200MHz, millis() is returning values that change faster then the wall clock. From some searches, I am finding that this might be normal since the Arduino core cannot compensate for that.

However, my search results are also saying that it is possible to tell the core or the compiler about the clock rate and it will compensate. Alternatively, use a library that can handle the overclocked speed.

What is the recommended way to deal with this?

Every board type has at least one F_CPU value defined and displayed in the compile options. Pick the appropriate one for your clock speed.

-DF_CPU=200000000L is already being set on the compile command line and I still get the "sped up" millis().

So, I am thinking that the clock runs fine but for some reason, it jumps 22s ahead while running some code in the setup() function. After that, it seems consistently off by the same 22s.

So it's not in fact running faster. Your code (which you haven't shown) is experiencing a one time 22 second jump.

Good luck figuring it out.

How much time has passed between those “22 second jumps”?

Do you mean 22 ms? Is it the time since the sketch actually started and you reported the first millis?
Since you have not posted the code we can't test. Good luck.

post a short demo code which shows the effect you are seeing. Just a short example. Complete and compilable.

Also, which core and which version are you using?

Thank you all for your help! I figured out my issues and it had nothing to do with the RP not measuring time correctly.

@voidtrance - you rattled the cage, care to share your findings?

a7

In my sketch, the first thing that happens is that the rp asks for the current time. My RP does not have WIFI so I can't use anything over the networks.

After that the sketch does a calibration cycle of an external of some external HW. Then, the main UI is display, where the time is shown.

What I was seeing is that the time shown in the main UI was not synched to the time on my wall clock. My assumption was that there is something odd since the RP was running at 200Mhz when the default rate is ~125MHz.

It turns out that some time had passed between the RP booting and the clock starting to when I input the time. Since my sketch was not compensating for that, there was a time discrepancy.