tmr2 desired frequency?
Moderator: Benj
-
- Posts: 438
- Joined: Mon Aug 29, 2011 12:26 am
- Location: arizona
- Has thanked: 175 times
- Been thanked: 173 times
- Contact:
tmr2 desired frequency?
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
- 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?
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- 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?
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
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
Martin
-
- 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?
oh my gosh i didnt realize i could do that (cool).....You can change the Timer 2 rollover value by editing the rollover value in the interrupt propertie
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( 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,
-
- 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?
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