--------------Boundary-00=_5A3ESKVBR9PLPIHYPDRR Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Okay, that was fairly simple. I guess I'm not as washed up w.r.t.=20 C-programming as I thought I was :-) I've attached a new file called rdiv.c . Add/remove resistors for what y= ou=20 have and run it. For 1/7 (IIRC that's what you asked for, type in the va= lue=20 "0.1429" for the ratio, and try 2% accuracy ... you'll get some possible=20 combinations. For exact multiples, use 0% for accuracy. Thanks for the exercise -- it was a refreshing break from all the other c= rap I=20 have to do here. :-) Cheers, -Neil. On Sunday 10 August 2003 00:46, Picdude scribbled: > Attached. If you can't open .tgz, I can send a zip instead. > > There were supposed to be 2 data files of resistance values (with 1 per > line) -- the intention was that the primary is the resistors I actually > have, and the secondary is what I can get. But IIRC, I never finished > implementing the secondary-resistors file. > > The tolerance you specify is the tolerance to the stated value, and doe= s > not take the resistors' tolerances into account. > > Excuse the coding inefficiency -- it had been a while since I programme= d > anything serious in C. :-) > > I'm actually looking at the code now, so give me a couple minutes and I= 'll > see if I can convert it easily. > > Cheers, > -Neil. > > On Sunday 10 August 2003 00:08, Ken Pergola scribbled: > > Hi Neil, > > > > Thanks. If you don't mind sending it I'd appreciate it greatly. Right= now > > I'm just playing with this in Excel. > > > > Thanks kindly, > > > > Ken Pergola > > > > > > -----Original Message----- > > From: pic microcontroller discussion list > > [mailto:PICLIST@MITVMA.MIT.EDU]On Behalf Of Picdude > > Sent: Sunday, August 10, 2003 1:06 AM > > To: PICLIST@MITVMA.MIT.EDU > > Subject: Re: [EE]: 1% resistors - How to find exact integer multiples= of > > each other > > > > > > I wrote a C program some months ago that asks for a resulting resista= nce, > > then it chooses 2 resistors from a list of standard values and calcul= ates > > how > > it could come up with the resulting resistance either in parallel or > > series. It outputs many possible combinations within a tolerance that= you > > also enter. > > And it sorts in by how close it gets. > > > > With a few minutes of work, you could adapt it for voltage dividers q= uite > > easily. Let me know if you want it, and I'll forward it. > > > > Cheers, > > -Neil. > > > > On Saturday 09 August 2003 21:47, Ken Pergola scribbled: > > > Sorry guys -- I made a mistake in the text -- I meant 12.0 K ohms f= or > > > the upper leg instead of 6.0 K ohms. Sorry for the confusion and br= ain > > > lapse. Corrected text below. > > > > > > Regards, > > > > > > Ken Pergola > > > > > > > > > > > > > > > > > > > > > > > > > > > Hi, > > > > > > Kind of a strange question but very basic: > > > > > > Without pulling out the calculator or spreadsheet and doing it > > > manually, what is the quickest way to come up with resistors that a= re > > > exact > > > > *integer* > > > > > multiples of each other (from the 1% standard value list)? > > > > > > Let me elaborate: In other words, say I want to make a 'divide by 4= ' > > > voltage divider using 1% resistors and *only* two resistors (no > > > building > > > > of > > > > > new resistance values allowed). > > > > > > For example, let me pick 2.00 K ohms as the bottom leg of the volta= ge > > > divider. That means I need 12.00 K ohms as the upper leg of the > > > voltage divider. Well, 12.00 K ohms is not a standard value, so I n= eed > > > to try again: So I'll try the next standard value for the bottom le= g -- > > > 2.05 K ohms (standard value). This would require 12.3 K ohms as the= top > > > resistor which is not a standard value. Try again...ad nauseam... > > > > > > Some values are exact integer multiples of each other -- what's the > > > quickest and easiest way to identify them? > > > Does anyone have something in their 'toolbox' they'd like to share? > > > > > > Does anyone know of any existing chart, software, or Excel spreadsh= eet > > > > that > > > > > already exists to do this. I realize this is simple math and I coul= d go > > > > off > > > > > and do this myself, but it would be nice having something that alre= ady > > > exists. I'm sure a lot of people have had a need for this at one ti= me > > > or another. > > > > > > Thanks very much. > > > > > > Best regards, > > > > > > Ken Pergola -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads --------------Boundary-00=_5A3ESKVBR9PLPIHYPDRR Content-Type: text/x-csrc; charset="iso-8859-1"; name="rdiv.c" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="rdiv.c" #include #include #include #include #include #include float rreq, areq; double rmin, rmax; FILE *frespri, *fressec; int num_res, i, j; char sres[51]; double r; char res[1000][50]; // Array of resistors available double accuracy; struct resultnode { double accuracy; char r1[51]; char r2[51]; double rnet; char format; }; struct resultnode results[500]; //Overkill, I know int num_results; char r1[51], r2[51]; double rnet; char format; int anotherpass; char c; double divcalc(double, double); main(int argc, char *argv[]) { printf("\n***************************\n"); printf("RESISTOR-DIVIDER CALCULATOR\n"); printf("***************************\n\n"); while ((c=getopt(argc, argv, "h")) != -1) { if (c=='h') { printf("Usage: rcalc [-h]\n"); printf("Prompts:\n"); printf(" Required ratio -- the voltage-divider ratio you're trying to achieve\n"); printf(" Accuracy -- error allowance (over stated value)\n"); printf("Note: rdiv does not calculate for tolerance of available resistors.\n"); printf("Additional files:\n"); printf(" rdiv_primary.dat -- list of common/easily-available resistors\n"); exit (0); } } // Get list of primary resistors... printf("Loading primary resistor values..."); if ((frespri=fopen("rdiv_primary.dat","r"))==NULL) { printf("\n ERROR: Could not load primary resistors data.\n"); exit(1); } else { // Build list of resistors... num_res = 0; while (!feof(frespri)) { if (fgets(sres,50,frespri) != NULL) { sres[strlen(sres)-1] = '\0'; strcpy(res[num_res],sres); num_res++; } } fclose(frespri); printf("done (%d).\n\n", num_res); } // Print back all values in table to check... //for (i=0; i%s<\n", res[i]); // Get requirements... printf("Enter required voltage-divider ratio (< 1) ... "); scanf("%f", &rreq); printf("Enter accuracy (%) ... "); scanf("%f", &areq); // Initial calculations... rmin = (double)rreq*(100-(double)areq)/100; rmax = (double)rreq*(100+(double)areq)/100; printf("\nTarget ratio = %.4f ohms\n",rreq); printf("Accuracy = %.2f\%\n", areq); printf("Acceptable range = %.4f to %.4f \n\n", rmin, rmax); // Test all pairs ... printf("Calculating..."); num_results = 0; for (i=0; i= rmin && r <=rmax) { accuracy = 100*fabs((r-rreq)/rreq); results[num_results].accuracy = accuracy; results[num_results].rnet = r; results[num_results].format = 'P'; strcpy(results[num_results].r1, res[i]); strcpy(results[num_results].r2, res[j]); num_results++; //printf("Voltage-divider: %s || %s = %.4f (%.2f\%)\n", res[i], res[j], r, accuracy); } } } printf("done.\n"); // Sort results here by resulting accuracy... printf("Sorting..."); if (num_results >1) { anotherpass = 1; while (anotherpass) { anotherpass=0; for (i=0; i results[i+1].accuracy) { // Swap nodes... accuracy = results[i].accuracy; rnet = results[i].rnet; format = results[i].format; strcpy(r1, results[i].r1); strcpy(r2, results[i].r2); results[i].accuracy = results[i+1].accuracy; results[i].rnet = results[i+1].rnet; results[i].format = results[i+1].format; strcpy(results[i].r1, results[i+1].r1); strcpy(results[i].r2, results[i+1].r2); results[i+1].accuracy = accuracy; results[i+1].rnet = rnet; results[i+1].format = format; strcpy(results[i+1].r1, r1); strcpy(results[i+1].r2, r2); anotherpass=1; // Gotta run thru again. } } } } printf("done.\n"); // Display results... if (num_results==0) printf("No solutions found.\n"); else { printf("Solutions...\n"); for (i=0; i< num_results; i++) { printf(" V-Divider: %s || %s = %.4f (%.2f\%)\n", results[i].r1, results[i].r2, results[i].rnet, results[i].accuracy); } } // TODO: Read extended resistors file here... printf("\n\n"); } double divcalc(double a, double b) { double c; c=(a/(a+b)); return c; } --------------Boundary-00=_5A3ESKVBR9PLPIHYPDRR Content-Type: text/plain; charset="iso-8859-1"; name="rdiv_primary.dat" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="rdiv_primary.dat" 10 22 47 100 120 150 180 220 270 330 390 470 560 680 820 1000 1200 1500 1800 2200 2700 3300 3900 4700 5600 6800 8200 10000 12000 15000 18000 22000 27000 33000 39000 47000 56000 68000 82000 100000 120000 150000 180000 220000 270000 330000 390000 470000 560000 680000 820000 1000000 1200000 1500000 1800000 2200000 2700000 3300000 3900000 4700000 5600000 6800000 8200000 10000000 12000000 15000000 18000000 22000000 27000000 33000000 39000000 47000000 56000000 68000000 82000000 100000000 -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads --------------Boundary-00=_5A3ESKVBR9PLPIHYPDRR--