+ Reply to Thread
Results 1 to 4 of 4
Thread: Finding Fractional calculator

 13th December 2017, 23:52 #1
Finding Fractional calculator
Hi,
I've got a problem to find a way to create numerator and denominator for my calculation
Here is the formula: (used by analog devices ADF435x software (windows))
(INT+(FRAC/MOD)x(PFD/DIV))=RF
I just calculate some variables but cannot find FRAC variable (see picture)
I found all my variables are OK but I found 6,25 for MOD !!! WOW not 125 as Analog give me
so.... I found some C code to calculate the FRAC and MOD, but how to calculate these numbers with PBP ? (FRAC & MOD knowing I found 6.25 for MOD)
seems they use C code with integer (math.round) ?
thanks for help !
regards

 15th December 2017, 01:52 #2
Re: Finding Fractional calculator
First, I know with SELECT CASE you want to start with your smallest possibility with "IF VAR < VAL THEN" type statements. You have largest listed first. If your code executes in order, then you will be changing your OutputDividerBox.Text value with each successive IF... clause.
Secondly, to work with decimals in PBP, multiply it by 10 or 100 up front, then divide the result back down by the same 10 or 100 at the end. Example:
7.5 X 22 = (75 X 22) / 10
That would allow you to work with decimals in PBP. Of course, you need a filter to tell you if that's needed (perhaps IF MOD != 0 THEN). I'm sure there are other aspect that need attention, but these were the obvious things I could contribute towards.

 15th December 2017, 19:49 #3
Re: Finding Fractional calculator
Thank you, that's what I've done now... Many select case and if then else... seem's to work now but not tried everything... looking for bugs.... Running...
Regards

 16th December 2017, 10:38 #4
Re: Finding Fractional calculator
math.round is only used there because the result will be copied to an integer.
The calculation is done with floats though (at least I assume because you didn’t show variable declarations).
If it weren’t for that, the result would always be rounded down. You can simulate that by rounding up if the decimal part is greater than 0.5.
Similar Threads

fractional code
By luisfe in forum mel PIC BASIC ProReplies: 2Last Post:  27th November 2015, 14:57 
range finding HELP
By longpole001 in forum GeneralReplies: 7Last Post:  3rd August 2014, 15:42 
need help finding a PIC
By asdhillon86 in forum GeneralReplies: 1Last Post:  10th January 2011, 00:49 
Help finding Alarm System Example
By bbawkon in forum GeneralReplies: 1Last Post:  20th September 2008, 05:39 
Lost in finding a example
By F1CHF in forum mel PIC BASIC ProReplies: 2Last Post:  18th January 2007, 23:20
Bookmarks