Timer 2 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:

Timer 2 Calculator

Post by medelec35 »

I prefer using timer 2 over other timers as it allows much more precise control.
That is because you have a Postscaler, Prescaler and a rollover value to deal with.
While having more options gives you much better flexibility, it's downfall is its more complicated to calculate correct values to give desired frequency.
For example, I'm after an interrupt hat gives me exactly 60Hz, how do I determine the correct Postscaler, Prescaler and Rollover values?
That is where the attached Excel sheet comes in extremely handy.
Just enter the oscillator frequency and required interrupt frequency and the Excel sheet gives all the answers!
Timer 2 Calculator.png
(85.74 KiB) Downloaded 1936 times
Timer 2 Flowcode.png
(37.22 KiB) Downloaded 1936 times
As you can see if maximum prescaler is only 16 then the nearest value to 60 will be 75Hz.
How about I would like to know all the whole frequency values?
Not a problem, excel sheet can do that as well:
Timer 2 Calculator whole freq.png
(135.29 KiB) Downloaded 1936 times
Hope this helps you as much as it has helped me.
The Excel sheet was modified with Libra Office, but I see no reason why it won't work with excel.
Note: After entering frequency you must select the drop-down and what maximum Prescaler you have, before results are shown.
Attachments
Timer 2 Calculator V2.xlsx
(2.1 MiB) Downloaded 361 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: Timer 2 Calculator

Post by medelec35 »

V2 shows a more instant values without having to select drop-down filter.
Timer 2_Calculator V2 Instant View.png
(43.93 KiB) Downloaded 1904 times
Also, selection bug fix.
Martin

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 460 times
Been thanked: 523 times
Contact:

Re: Timer 2 Calculator

Post by Steve001 »

Thanks Martin

Appears to work ok with Apache open office

Steve
Success always occurs in private and failure in full view.

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: Timer 2 Calculator

Post by medelec35 »

Just saved with microsoft office.
Libra Office version was not working with excel 365
Martin

Post Reply