tmr2 desired frequency?

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

tmr2 desired frequency?

Post by brandonb »

im trying to get a tmr2 to interrupt at 100,000 hz, i tryed different crystal values by through digikey catalog and found value of 12.8Mhz crystal using tmr2 with prescaler:1 postscaler:1 rollover:32, i can get 100,000 hz tmr2 interrupt frequency.... is there another way that i can do this? i commonly use 16Mhz internal osc, and the crystal values i use are 16.384, 20.48 because they give me even interrupt numbers....... :arrow: with 20.48Mhz i can get 10,000 Hz, was wondering if i could somehow change the rollover number in the tmr2 register to obtain 10 times the frequency :)

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: tmr2 desired frequency?

Post by Benj »

Hello,

There are some good timer calculators out there if you search Google for "PIC timer calculator". Some should allow you to enter the frequency you want and your clock speed and it will work out the rest.

You can change the Timer 2 rollover value by editing the rollover value in the interrupt properties. The value can be typed in directly to give you values that aren't available from the standard drop down selection.
Timer2.jpg
Timer2.jpg (23.76 KiB) Viewed 4062 times

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: tmr2 desired frequency?

Post by medelec35 »

Hi Brandon.

For faster interrupts you should be looking at higher speed oscillators.
If osc is low ( I believe for 100KHz int 16MHz is low), then more time will be spent on serving interrupt than running any of the main code.
So your hardware may not work as you intended,

If look at:
http://eng-serve.com/pic/pic_timer.html
You can see that if you move the sliders so Post and prescaller are both on 1:1
and PR2 (Rollover Value) is on 40 then interrupt frequency with osc set at 16MHz = 100000Hz
Int 100KHz.png
(142.9 KiB) Downloaded 2357 times
Martin
Martin

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: tmr2 desired frequency?

Post by brandonb »

You can change the Timer 2 rollover value by editing the rollover value in the interrupt propertie
oh my gosh i didnt realize i could do that (cool).....
( I believe for 100KHz int 16MHz is low), then more time will be spent on serving interrupt than running any of the main code.
So your hardware may not work as you intended,
on this particular project it only runs the tmr2 then for 500m/s then looks at counts and updates number with some math string manipulation, it works great at a 10k interrupt frequency, was wanting more resolution go the number is not rounding down as much, i beleive this will work.... that brings me to another problem, the timers dont appear to work right at that frequency with the 16f1938, i'll play around with the math and see whats up.. thanks ben and martin, you guys are awesome

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: tmr2 desired frequency?

Post by brandonb »

thanks for the very useful info.....and like i way saying there isnt much in the main macro, this works like a charm, with an update rate of x3 per second which is low with all the tmr2 interrupts occuring at the time lcd is updating reducing the measurements but the resolution is what i was looking for at 10u/s roughly... the only input is B0.... file is below, here is a video, nano scope commanding pulses and showing wave, board is something i created http://youtu.be/0CgrgkEEty4
Attachments
fuel injector pulsewidth meter 100khz v1.0.01.fcf
(40.73 KiB) Downloaded 266 times

Post Reply