Interrupt Frequency Calculator and Timer Offset Calculator

Tips, Tricks and methods for programming, learn ways of making your programming life easier, and share your knowledge with others.

Moderators: Benj, Mods

Post Reply
medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Interrupt Frequency Calculator and Timer Offset Calculator

Post 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 14417 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.
Attachments
Int time CalulatorV1.xls
(51.5 KiB) Downloaded 866 times
Martin

saschech@gmx.de
Posts: 714
Joined: Wed Jan 31, 2007 12:41 pm
Has thanked: 1 time
Been thanked: 26 times
Contact:

Re: Interrupt Frequency Calculator and Timer Offset Calculator

Post by saschech@gmx.de »

Hello medelec35

Why,your calculator stopp at 20 000 000MHZ?

Regards wolfgang

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Interrupt Frequency Calculator and Timer Offset Calculator

Post 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.
Attachments
Int time CalulatorV3.xls
(68 KiB) Downloaded 656 times
Last edited by medelec35 on Thu Aug 20, 2009 6:39 am, edited 2 times in total.
Martin

fresh
Posts: 47
Joined: Mon Jun 08, 2009 11:11 am
Contact:

Re: Interrupt Frequency Calculator and Timer Offset Calculator

Post by fresh »

Hello medelec35,
that's great thank you for release.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Interrupt Frequency Calculator and Timer Offset Calculator

Post by medelec35 »

you welcome. Hope it comes in handy. If chip frequency is 4 or 8Mhz, it will make timing more accurate.
Good luck.
Martin

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Interrupt Frequency Calculator and Timer Offset Calculator

Post 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 14403 times
Martin

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Interrupt Frequency Calculator and Timer Offset Calculator

Post 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 668 times
Attachments
Int time CalulatorV4.jpg
Int time CalulatorV4.jpg (73.34 KiB) Viewed 14091 times
Martin

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Interrupt Frequency Calculator and Timer Offset Calculat

Post 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
Attachments
Int time CalulatorV5.xls
(94 KiB) Downloaded 829 times
Martin

Post Reply