Page 1 of 1

Interrupt Frequency Calculator and Timer Offset Calculator

Posted: Sat Aug 15, 2009 6:08 pm
by medelec35
This is for people who using timer0 would like microcontrollers to interrupt at different frequency to those available.

E.g your microcontroller speed is 4MHz and you required an interrupt frequency of 1000Hz. You look at properties of interrupt to discover you only can have an interrupt at 976.53Hz with prescaler set at 1:4 or and interrupt at 1953.125Hz.
With attached calculator,It will show how to get that desired interrupt frequency to set at 1000Hz.
It won't work on all cases. This is because timer offsets can only have a whole number between 0 and 255 and the calculation result could be 120.53 for instance, and you can only enter 120 or 121 for offset. For that reason I have also included in the calculator offset if not a whole number and frequency of interrupt generated with the calculated offset since there are times these won't match 100%.
Hope this would come in useful. I created calculator for my new project, but I'd thought I'd share it.
Int Freq Cal.jpg
Int Freq Cal.jpg (78.3 KiB) Viewed 15229 times
Note: May sound obvious. But two points.
1) Calculator created in excel 2007, so if opened on a version prior to 2007, then colours will vary form attactached image.

2) All text within light grey areas are user inputs. All text within purple areas are calculated results.

Re: Interrupt Frequency Calculator and Timer Offset Calculator

Posted: Tue Aug 18, 2009 4:06 am
by saschech@gmx.de
Hello medelec35

Why,your calculator stopp at 20 000 000MHZ?

Regards wolfgang

Re: Interrupt Frequency Calculator and Timer Offset Calculator

Posted: Tue Aug 18, 2009 5:43 am
by medelec35
I use a data list validation base on values in Flowcode. That stops as 20MHz
My intention was to use any values but that did not happen.
Try this one, any Frequency can be entered.

Re: Interrupt Frequency Calculator and Timer Offset Calculator

Posted: Tue Aug 18, 2009 8:35 am
by fresh
Hello medelec35,
that's great thank you for release.

Re: Interrupt Frequency Calculator and Timer Offset Calculator

Posted: Tue Aug 18, 2009 8:53 am
by medelec35
you welcome. Hope it comes in handy. If chip frequency is 4 or 8Mhz, it will make timing more accurate.
Good luck.

Re: Interrupt Frequency Calculator and Timer Offset Calculator

Posted: Thu Aug 20, 2009 6:38 am
by medelec35
V3. Added Useful list of Interrupt frequencies produced for all Timer offset values from 0 - 255 at the set prescaler rate.
I cal V3.jpg
I cal V3.jpg (110.31 KiB) Viewed 15215 times

Re: Interrupt Frequency Calculator and Timer Offset Calculator

Posted: Wed Oct 21, 2009 11:09 pm
by medelec35
V4.
Added extra columns to calculate variable value required in interrupt macro for a given time delay. Untested. Comments for improvements or usability are welcome. Perhaps comments on the maths please, i.e. how accurate calculations are.
Thanks.
Int time CalulatorV4.xls
(101.5 KiB) Downloaded 776 times

Re: Interrupt Frequency Calculator and Timer Offset Calculat

Posted: Sun Nov 08, 2009 4:12 pm
by medelec35
V5
Some minor cosmetic improvements.
Improve accuracy on updating timer values, thanks to sean for saying about += instead of just =.
Calculator on the right loads with same Osc Freq and Prescaler as entered on the left, so less data to enter.
Notice you can use calculator if require;
A interrupt frequency e.g 80Hz
or
A specific time delay using interrupts eg 300 seconds.
Also if require a particular delay, then delay given for all timer offsets (0-255)
Timer0 calculator.png
(133.06 KiB) Downloaded 5662 times