Re: continued fraction program

Jun 21, 2009 1 Replies


Okay. I think I'm done playing, for now. There's a free continuous


>fraction program available. This program provides the convergents for
>the continuous fractions of a value (plus declining error terms) and
>includes a well-featured calculator (with variable assignment support
>and multi-statement capability (use a ; to separate statements or
>expressions, or just type them one line at a time) and displays
>floating point notation in either single or double precision (the
>calculator itself can be switched to either mode.) So it may have a
>variety of practical uses for folks in embedded work of one kind or
>another.

Neat, writing and giving away programs.



I just a minute ago finished a PowerBasic (Console Compiler) program that prowls my parts database looking for pairs of resistors that can hit a desired ratio (tolerance specified) and Thevenin range. It allows me to include 0603, 0805, or 1206 resistors in any combination.



It outputs a file that lists all the pairs, actual ratio, ratio error, and actual parallel (Thevenin) value, followed by a 1-line inventory report for each. The output file looks like...


RUGRAT Resistor ratio report 06-20-2009 17:35:18



Target ratio 2.500000 Accuracy limit 1.000 per cent Thevenin 500.000 to 2,000.000 Types : 0805


Ratio 2.517483 Error 0.699 pct Thevenin 511.730



132-5250 RES 0805 1.8K 5% DIGIKEY P1.8KACT-ND 0.01 4226 11671
132-4821 RES 0805 715R 1% DIGIKEY RHM715CCT-ND 0.02 196 11104

Ratio 2.481390 Error -0.744 pct Thevenin 574.483



132-5291 RES 0805 2K 1% DIGIKEY P2.00KCCT-ND 0.01 5348 11759
132-4871 RES 0805 1/8W 806R 1% KOA RK73H2A8060F 0.01 515 11777

Ratio 2.481390 Error -0.744 pct Thevenin 574.483



132-5291 RES 0805 2K 1% DIGIKEY P2.00KCCT-ND 0.01 5348 11759
132-4872 RES 0805 806R 0.1% MOUSER 71-TNPW0805806RBE 0.64 79 11597

Ratio 2.481390 Error -0.744 pct Thevenin 574.483



132-5292 RES 0805 2K 0.1% MOUSER 71-TNPW08052K00BE 0.64 81 11596
132-4871 RES 0805 1/8W 806R 1% KOA RK73H2A8060F 0.01 515 11777


etc, 32 solutions in this case, several perfect hits. The parts lines are long, so wrap when pasted to the newsgroup.



This is about 400 lines of code, took about 2 hours to do, although I'll probably spend another hour to check, beautify, and comment everything. The PBCC compiler allows real SLEEP commands, so I use them to keep the cpu from being hogged when nothing's going on.



I included a spiffy progress bar for when it's doing the file input and crunching, which turned out to be silly since it runs in about half a second. The search is a brute-force nested FOR loop.



This is free too, but it needs an input file that includes one line per resistor in stock, in our format, so some futzing would be needed for general use. Our material control system MAX makes this text file automatically every time it's run, so I used that instead of opening the binary record file.



Oh, it's packed with GOTOs.



John


Don't you need a lot of food for the GOATs?

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required