Possible accuracy issues in clock timer

I would not call it a workaround. This type of programming is used in e.g. C language to create artificial multithreading. The clock error will be imperceptible here and certainly will not worsen with each tick.

1 Like

Hi Paryk_F:
Your solution is simple. I modified your code to also count the number of beats and display it when stop is paused. I also display total elapsed time from start to finish. I also increased the max number of beats to 240 from 160. For bpm of 60, the # of beats was exactly equal to the time elapsed over a 6 minute interval. When I increased the bpm to 240. and ran for 385 seconds total. I counted only 1517 beats instead of expected 1540. Is this expected? My modified code is attached if you want to try it.

Hi Anke:
You are using a precise timer extension. Is there an aia file for that? How is it different from the built in timer?

Thanks to both of you for awesome help.metronom (1).aia (7.4 KB)

Has the screen been turned off for a while during these 385 seconds? The screen must be on when the metronome is working.

No. The screen was always on. I had set it to turn off after 10 min. which is the maximum on my phone. I also made sure this was the only application that was running (as far as I could tell). I have a Samsung Galaxy S8.
Maybe you can try my code on your phone and see if you replicate similar results?

thanks.

In fact, that solution was not exact. Here is a solution that uses a counter to correct the time.
metronom2 (2).aia (7.5 KB)
Also test with a real stopwatch

I stopped the clock 1 second too fast, but you can see that it is exactly right now. So I still say the extension is not needed;).

This should not happen with my app.
Here is the result:

Blocks

Hi Patryk_F

Your modified code seems to work. I ran for 569s and I got a beat count of 2277 at 240 bpm.
It is off by 1 but that is good enough for my purposes. I understand the logic of your code but I recall reading somewhere in these forums that timer interval <10ms can be inaccurate. You have set it to 1ms.
Is that ok? Is the issue fixed.

Hi Anke:
Based on this code, the built-in timer seems to be accurate enough. You have created your extension of a precise timer. How is it different and how does it work?

As always, thanks to both of you for helping me debug the metronome.

An error by 1 measure may be due to something else. I don't know if you tested in the original code or modified it. In general, there are no delays in this solution, because it is corrected on an ongoing basis using a numerator. As for the clock speed, I don't think 1ms has any negative effects. You can try to set 10ms and see if this affects the accuracy. But in my opinion 1ms is ok.

It doesn't matter whether you set the TimerInterval 1, 10 or 25 (ms). The timer needs some time to start / react (I think at least 25 ms, depending on the device).

I think I am set for now with solution that Patryk_F provided. It seems adequate for my needs. Thanks to both Patryk_F and Anke for all the helpful suggestions (especially Anke for the loop playback idea).

Anke: I am curious how your timer extension is different from Patryk_F's implementation?

Chandra