-
Notifications
You must be signed in to change notification settings - Fork 1
Poor accuracy on timer interrupt frequency or interval. #4
Comments
You can't use inaccurate To make some sense, you have to, at least, use accurate enough Check ISR_16_Timers_Array_Complex on RaspberryPi Pico and/or use ISR_16_Timers_Array_Complex example for better way to measure the accuracy without |
Well, I have a scope, so I'll check it that way. I haven't found mills() to be inaccurate though. |
By the way, the code in the loop doesn't measure the period. That's measured in the interrupt. The loop just prints out a snapshot of the most recent period. |
Okay, I just checked it with a scope. It's off by 2%. I have the interrupt at 20 kHz, and I toggle an output pin every time through. One cycle of that output pin takes 102 us. It should be 100 us. Here's the modified code with the scope trigger.
|
I checked it at some other frequencies. At 50 kHz, I get 42 us instead of 40, so it's off by 2 us. |
Hi @pixpop OK, the issue is convincing now. I'll have a look soon when having time. Can you help try using the previous cores, such as v2.7.2, and v3.0.0 to see if the issue caused by the library or the cores. Thanks, |
The bug still shows as closed. Can you reopen it? |
Can you also try RPI_PICO_TimerInterrupt library, especially have a look at Enable fixed timing between timer calls (vs fixed time btw. end of timer call and next call as implemented) #3 to see if related. The previous problem caused by weird syntax introduced by RPi-Pico SDK, possibly confusing the Arduino MBED core people ???
|
Can you try to modify
to
and see if better |
The real code of |
Re: line 134. Should it be -1 or -2 ? |
After replacing with (-1, not -2)
The result running your first code is better
|
It's good. It's possibly a little off at 50 kHz. Hard to be sure. Scope says it's 39.8 us instead of 40. |
It's hard to measure it accurately enough on my scope at 50 kHz. It might be okay. |
Try using the RPI_PICO_TimerInterrupt library to see your scope is OK. The timing was checked and OK. I'll investigate this issue later. If we can't fix it, I have to rewrite the library using SDK directly, not relying on the hidden |
I have a frequency counter that's very accurate. Let me check with that. Of course, I don't know how accurate the Arduino clock is to start with ;-( |
Hi @pixpop The new MBED_RPI_PICO_TimerInterrupt v1.2.0 has just been published. Your contribution is noted in Contributions and Thanks Releases v1.2.0
|
### Releases v1.3.0 1. Fix `poor-timer-accuracy` bug. Check [Poor accuracy on timer interrupt frequency or interval. #4](khoih-prog/MBED_RPI_PICO_TimerInterrupt#4)
### Releases v1.3.0 1. Fix `poor-timer-accuracy` bug. Check [Poor accuracy on timer interrupt frequency or interval. #4](khoih-prog/MBED_RPI_PICO_TimerInterrupt#4)
Hi @pixpop Your contribution has been spread to the newly published MBED_RP2040_Slow_PWM v1.3.0. Your contribution is also noted in Contributions and Thanks Releases v1.3.0
|
Describe the bug
Timer interrupts at a lower frequency than expected.
Arduino IDE 1.8.19
Arduino MBED nano 3.3.0
MBED_RPI_PICO_TimerInterrupt 1.1.2
Hardware: Arduino nano rp2040
Steps to Reproduce
I set a frequency of 20 kHz, and then count 20k interrupts. I check mills() before and after. The delta comes out to 1020 ms where it should be 1000. So it's off by 2%.
Expected behavior
I expected it to take 1000 ms to count 20000 interrupts at 20000 Hz
Actual behavior
It took 1020 ms, so it's off by 2%. I see the same error if I program it by interval or by frequency.
Test code:
Sample printout:
The text was updated successfully, but these errors were encountered: