I don't know if this has been done before, but here's a little tool I've been working on to help run an interrupt at some target rate based on the CPU clock. It uses Dr. Dnar's speed test code to establish the rate at which the calculator is running, then uses this to determine the CPU divisor and counter values which produce a "derived clock" most closely matching the desired rate. This means that the timer rate is optimal for the calculator executing the program, not just for the developer's calculator. This might be useful if your program needs something to run at the same rate across calculators. The code isn't really ready to be used in a program as-is (it was coded for display purposes), but it shouldn't be hard to get it there.

Download Link

Example of how it works:

Here, the actual speed produced by these values is 14.919E6/52/13 = 22069.53Hz, which is about 0.09% off from desired 22050Hz. For the most part, the target rate seems to be matchable with less than 1% error, so the speed differences across calculators should be negligible. However, be aware that the lowest frequency that can be produced off the CPU clock is CPUSpeed/128/255, so if you need anything less than that, you'll need to use the other timers.

Also, there's a couple of things I was uncertain about when making this, which may lead to larger errors than indicated by the program. If anybody could help clarify these points, that'd be awesome! Smile
1.) I'm not sure that the CPU speed is 100% accurate. There are three different CPU speed test programs that I'm aware of, and it appears they all produce different output. Jim e made one here (can't find a working download link on the web), thepenguin77 made one here, and Dr. Dnar's is what I modified to make this. Has anybody verified which of these methods actually produces the most accurate output? Dr. Dnar's and Jim e's vary by about 3%, which makes a huge difference.
2.) I don't fully understand how counter looping is handled. Valid counter values for the interrupt range from 0-255, but should a value of 255 be treated as if it divides by 255 or 256? Basically, is there an overhead of 1 count when it wraps around?
This is kind of cool. I wish I understand more of the usefulness, but I'm sure some asm programmer will find use with this Smile
Oh neat! I totally missed this! Razz Great work; I'm sure that I can find an application for it somewhere. Thanks! Smile

The highest number you can store in an 8-bit register is 255. There are 256 digits though, because 0 counts as a digit. Razz
My speed test does not synchronize with the crystal, so duration of the first loop is variable. You see, the crystal ticks on its own and doesn't reset its oscillation phase just because you start a timer.
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum