tmr2 interrupt flowcode calculator!
-
- Posts: 438
- Joined: Mon Aug 29, 2011 12:26 am
- Location: arizona
- Has thanked: 175 times
- Been thanked: 173 times
- Contact:
tmr2 interrupt flowcode calculator!
if you want to quickly get all the prescaler,postscaler.rollover values of a desired tmr2 frequency or get all the frequencys and adjustment settings in a certain range around a desired frequency this is for you....i created this as a simulator flowchart to help pick those frequecies and settings easy, the first code block at the top of the flowchart you'll see these four lines of code in a block that you can modify
f_osc = 16000000
target = 1000
range = 0
display_delay = 2
f_osc--> type in the oscillator speed of the crystal or internal osc
target--> type in the target tmr2 frequency that your trying to hit
range--> type in the range around the desired tmr2 freq that you would like to hit, for instance if you type in 25, it will search for the target frequency and any frequency that within 25 numbers positive and 25 numbers negative of the target freq
1000 (1025 to 975)
also if you select "0" it gives you direct hits only, these are all long variables so you can use big numbers, if you exceed more than 254 readbacks it will say ">254" on the lower right side of the screen and only give you 254 readbacks
display_delay--> type in the second delay you want between the readback data numbers
here is a screen shot that tells you what your looking at[img] [/img]
tell me what you guys think?
f_osc = 16000000
target = 1000
range = 0
display_delay = 2
f_osc--> type in the oscillator speed of the crystal or internal osc
target--> type in the target tmr2 frequency that your trying to hit
range--> type in the range around the desired tmr2 freq that you would like to hit, for instance if you type in 25, it will search for the target frequency and any frequency that within 25 numbers positive and 25 numbers negative of the target freq
1000 (1025 to 975)
also if you select "0" it gives you direct hits only, these are all long variables so you can use big numbers, if you exceed more than 254 readbacks it will say ">254" on the lower right side of the screen and only give you 254 readbacks
display_delay--> type in the second delay you want between the readback data numbers
here is a screen shot that tells you what your looking at[img] [/img]
tell me what you guys think?
- Attachments
-
- flowcode_tmr2_calculator.fcf
- (35.32 KiB) Downloaded 499 times
-
- Posts: 438
- Joined: Mon Aug 29, 2011 12:26 am
- Location: arizona
- Has thanked: 175 times
- Been thanked: 173 times
- Contact:
Re: tmr2 interrupt flowcode calculator!
something important to note that i forgot to mention on the calculator, if your searching something like 10hz you can do
f_osc = 16000000
target = 10
range = 9
display_delay = 2
**BUT THE "RANGE" NUMBER HAS TO BE LOWER THAN THE "TARGET" NUMBER
OR IT WILL NOT RETURN ANYTHING*** example below is bad juju,
range cannot be equel to target or greater than target
f_osc = 16000000
target = 10
range = 10
display_delay = 2
i always try range = 0 to see if there is a direct hit first, then adjust the range to other values progressivly till you get what your looking for
f_osc = 16000000
target = 10
range = 9
display_delay = 2
**BUT THE "RANGE" NUMBER HAS TO BE LOWER THAN THE "TARGET" NUMBER
OR IT WILL NOT RETURN ANYTHING*** example below is bad juju,
range cannot be equel to target or greater than target
f_osc = 16000000
target = 10
range = 10
display_delay = 2
i always try range = 0 to see if there is a direct hit first, then adjust the range to other values progressivly till you get what your looking for
-
- Posts: 438
- Joined: Mon Aug 29, 2011 12:26 am
- Location: arizona
- Has thanked: 175 times
- Been thanked: 173 times
- Contact:
Re: tmr2 interrupt flowcode calculator!
on this one i think i have it all fixed right, i added the rollover value of 256(oops), and made the range and target both floating point variables, now if you select "0" it will give you only the exact matches +/- .1
i also fixed a couple of minor things, now you will get alot more returns but more focused if you set your range correctly,
another thing i did with this fcf is if the returned number of results are greater than 254 it will tell you "buffer overflow refine results" instead of showing the 254 results, reason why i chose this is the array buffers are overflowed and you would be veiwing only part of the info,
same rules apply with target and range--> range cannot be equel to or greater than target
for range and target you can type in whole numbers or floating numbers, it will return floats either way
this new fcf is alot better than the old one, thanks for checking it out
i also fixed a couple of minor things, now you will get alot more returns but more focused if you set your range correctly,
another thing i did with this fcf is if the returned number of results are greater than 254 it will tell you "buffer overflow refine results" instead of showing the 254 results, reason why i chose this is the array buffers are overflowed and you would be veiwing only part of the info,
same rules apply with target and range--> range cannot be equel to or greater than target
for range and target you can type in whole numbers or floating numbers, it will return floats either way
this new fcf is alot better than the old one, thanks for checking it out
- Attachments
-
- flowcode_tmr2_calculator_fix.fcf
- (37.24 KiB) Downloaded 519 times
-
- 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 interrupt flowcode calculator!
Thanks for posting Brandon.
What a great idea
I was going to do a similar thing with excel, and kept putting it off due to how involved it was going to be.
Glad you have done this, since I don't need to work it out myself
Martin
What a great idea
I was going to do a similar thing with excel, and kept putting it off due to how involved it was going to be.
Glad you have done this, since I don't need to work it out myself
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 interrupt flowcode calculator!
i was hoping you would like it and would use it to make future projects speaking calculators i have a 32 to 4 x 8bit converter somewhere on the forums as well...hopefully i put this in a place where other members can easily find it if they need toGlad you have done this, since I don't need to work it out myself
-
- Valued Contributor
- Posts: 2045
- Joined: Wed Aug 27, 2008 10:31 pm
- Location: Netherlands
- Has thanked: 553 times
- Been thanked: 1081 times
- Contact:
Re: tmr2 interrupt flowcode calculator!
May-be this could be moved/copied to the tips & tricks section??brandonb wrote:hopefully i put this in a place where other members can easily find it if they need to
“Integrity is doing the right thing, even when no one is watching.”
― C.S. Lewis
― C.S. Lewis
-
- 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 interrupt flowcode calculator!
Good idea!kersing wrote:
May-be this could be moved/copied to the tips & tricks section??
Sorted.
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 interrupt flowcode calculator!
i really should get more sleep lately, 5 hours a night just dont cut it i've been playing with it alot and tonight i ran into my first incorrect result with the last file with the settings osc 32000000 target 30 range .6 it returned 30.39hz with settings 64-16-1 which is way off, i traced it down to image below, rollover division math is 1-256 but i used a 8 bit array to store the number in so what i did is i would add 1 to the loop value of rollover from starting point zero, do the math on it, subtract a count and store it in a array, when i recall it i add one back to it for the display, i was thinking rollover 256 but i should have been thinking rollover array 255.... it tests out proper after fcf second fix update below (sorry, hopefully there are no more groggy minded errors)
- Attachments
-
- flowcode_tmr2_calculator_second_fix.fcf
- (37.23 KiB) Downloaded 452 times
-
- oops my bad.jpg (92.87 KiB) Viewed 13865 times
-
- 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 interrupt flowcode calculator!
Hi Brandon,
I have just made some minor modifications.
My favorite mod allows the best setting out of all the results to be always left on the display.
E.g if you want 70 as the target and results are:
70.303, 70.028, 69.754, 70.323 70.028, 69.735, 70.382, 70.067, 69.754
The Calculator will show 70.028: The other mod is to be able to enter in the first calculation box either 16 (prescaler1 to 16) or 64 (prescaler1 to 64)
some clever calculations you did within flowchart Brandon!
I will definitely use this instead on online calculators!
Martin
I have just made some minor modifications.
My favorite mod allows the best setting out of all the results to be always left on the display.
E.g if you want 70 as the target and results are:
70.303, 70.028, 69.754, 70.323 70.028, 69.735, 70.382, 70.067, 69.754
The Calculator will show 70.028: The other mod is to be able to enter in the first calculation box either 16 (prescaler1 to 16) or 64 (prescaler1 to 64)
some clever calculations you did within flowchart Brandon!
I will definitely use this instead on online calculators!
Martin
- Attachments
-
- flowcode_tmr2_calculator_second_fix with Rounding4.fcf
- (49.49 KiB) Downloaded 487 times
Martin
-
- Posts: 438
- Joined: Mon Aug 29, 2011 12:26 am
- Location: arizona
- Has thanked: 175 times
- Been thanked: 173 times
- Contact:
Re: tmr2 interrupt flowcode calculator!
thanks martin, its nice to be able to give something back to the community i like the new features! i think we are making this too easy for people in flowchart below i added generated c code for the t2con register and pr2(rollover), tell me what you think? i had issues trying to figure out the string magic you did?some clever calculations you did within flowchart Brandon!
I will definitely use this instead on online calculators!
dannyberry wanted to see what the binary for the t2con register reads as well, so heres a flowchart that shows that, (thanks enamul for showing how to show binary numbers http://www.matrixmultimedia.com/mmforum ... ers#p41438) *** i changed the flowcharts to give // decimal number for doing lookup tables and such ***
Last edited by brandonb on Mon Dec 03, 2012 2:25 am, edited 2 times in total.
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
- Contact:
Re: tmr2 interrupt flowcode calculator!
Thanks Bandonb for your nice efforts. It's really great effort.
-
- Posts: 29
- Joined: Tue Aug 30, 2011 9:20 pm
- Has thanked: 11 times
- Been thanked: 1 time
- Contact:
Re: tmr2 interrupt flowcode calculator!
Thanks Brandon...I have to give you a big thumbs up, especially since I was the picky one about adding the binary part.
That was quick.
Danny
That was quick.
Danny
-
- Posts: 438
- Joined: Mon Aug 29, 2011 12:26 am
- Location: arizona
- Has thanked: 175 times
- Been thanked: 173 times
- Contact:
Re: tmr2 interrupt flowcode calculator!
there are two different calculators below
------ AUTOMATIC FIND------------------- -------------------
in this one you set only the F_OSC and F_TARGET and it will give you back the results that matches or the closest to your target frequency, the f_range is automaticly adjusted with in the running program, adjusting it does nothing
f_osc--> running oscillator frequency
f_target--> frequency you want to find the closest or direct match for
----------LOOPING ------------------- -----------------------------------
this one is made for creating frequency generators, you set the number that you want to increment in and it will find the closest single match to the number you input then increment by the number you selected for the incrementor and continue to show you the closest results each time it runs, f_range is automaticly adjusted with in the running program
f_osc--> running oscillator frequency
f_increment_target--> put in the number you want to increment by
f_target--> in this mode you set it where you want to start incrementing from
for those familiar with the previous calculators, when automatic is enabled as is by default, the range is calculated by
dividing the target by 2 and giving that above the target and below the target giving a large area of search,
it writes to different arrays and after checking all 16384 combinations there will be a closest number >= target and a closest number<=target, these are checked to see which one is closer, those arrays are linked to the lcd to display the best choice values... the numbers to right of the comment lines "//" are the numbers i use to write code with
*** NOTE: these are set up to check 64:1 prescaler and will return them as best choice if one is avalible ***
"martin can you fix these fcf's to your preferances"
------ AUTOMATIC FIND------------------- -------------------
in this one you set only the F_OSC and F_TARGET and it will give you back the results that matches or the closest to your target frequency, the f_range is automaticly adjusted with in the running program, adjusting it does nothing
f_osc--> running oscillator frequency
f_target--> frequency you want to find the closest or direct match for
Code: Select all
//MODIFY ITEMS IN THIS BLOCK
f_osc = 16000000 //float variable for oscillator speed
f_target = 19 //float variable (target freq)
display_delay = 2 //byte (display pause in m/s)
//-------------------------------------------
this one is made for creating frequency generators, you set the number that you want to increment in and it will find the closest single match to the number you input then increment by the number you selected for the incrementor and continue to show you the closest results each time it runs, f_range is automaticly adjusted with in the running program
f_osc--> running oscillator frequency
f_increment_target--> put in the number you want to increment by
f_target--> in this mode you set it where you want to start incrementing from
Code: Select all
// *** MODIFY THESE ITEMS ***
f_osc = 16000000 //float variable (oscillator speed)
f_increment_target = 10 // increments by this number
f_target = 0 // where to start incrementing from
//------------------------------------------------
dividing the target by 2 and giving that above the target and below the target giving a large area of search,
it writes to different arrays and after checking all 16384 combinations there will be a closest number >= target and a closest number<=target, these are checked to see which one is closer, those arrays are linked to the lcd to display the best choice values... the numbers to right of the comment lines "//" are the numbers i use to write code with
*** NOTE: these are set up to check 64:1 prescaler and will return them as best choice if one is avalible ***
"martin can you fix these fcf's to your preferances"