Page 1 of 1
tmr2 desired frequency?
Posted: Tue May 29, 2012 9:56 am
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.......

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

Re: tmr2 desired frequency?
Posted: Tue May 29, 2012 11:23 am
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 (23.76 KiB) Viewed 4324 times
Re: tmr2 desired frequency?
Posted: Tue May 29, 2012 6:32 pm
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
Martin
Re: tmr2 desired frequency?
Posted: Tue May 29, 2012 7:45 pm
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
Re: tmr2 desired frequency?
Posted: Wed May 30, 2012 8:18 am
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