home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- ** **
- ** COILS **
- ** C Language Version **
- ** **
- ** Translated and modified by Alan E. Carman, original BASIC program **
- ** by David E. Powell. Published in the November 1988 issue of **
- ** Radio-Electronics magazine. **
- ** **
- ******************************************************************************/
-
- /**** Version written on an Amiga-500 using
- the Lattice AmigaDOS C compiler V4.0 ****/
-
- /* modified for DOS and corrected 12-19-89 (using Mix C compiler) */
- /* by */
- /* Mendel Cooper */
- /* Baltimore, MD */
-
-
-
- #include <stdio.h>
- #include <stdlib.h> /* may change for your compiler */
-
- #define K 1473061.855 /* conductance of copper wire...mhos per sq in area */
- #define MAXTURNS 10000 /* maximum allowed turns */
- #define PI 3.1415927
-
- /* The following three #define statements are the only system specific
- definitions I know of in this program
- change them as necessary for your printer
- and computer */
-
- #define PRINTER "prn" /* file name for fprintf() to parallel printer */
- #define SCREEN "con" /* file name for fprintf() to screen */
- #define RESET "\x1b\x40" /* escape code for reset on MX-80 printer */
-
- void main()
- {
- register float Ltry;
- float a, atemp, btemp, c, ctemp, r, wire_area, diff1, diff2;
- float max_length=0, wire_size=0, form_dia=0, L=0, b=0, Lfinal=0, layers;
- double log(), pow();
- int min_n=1, max_n=MAXTURNS, n=0;
- int ntemp, laytemp;
- long int wire_len;
- char ch;
- FILE *fp;
-
- clrscrn(); /*clears screen - may be different on your compiler*/
-
- printf(" ****************************************************\n");
- printf(" ** Inductor Design Calculator **\n");
- printf(" ** [Circular air-core coils] **\n");
- printf(" ****************************************************\n");
-
- printf("\n\nEnter desired inductance in microhenries........ ");
- scanf("%f",&L);
-
- printf("\nEnter gauge, or diameter of wire in inches...... ");
- scanf("%f",&wire_size);
-
- printf("\nEnter diameter of coil form in inches........... ");
- scanf("%f",&form_dia);
-
- printf("\nEnter maximum length of coil in inches.......... ");
- scanf("%f",&max_length);
-
- if (wire_size >= 1)
- wire_size = .46/(pow(1.1229283027,wire_size + 3));
-
- do /*************** start of loop to calculate number of turns **********/
- {
- ntemp = (max_n - min_n) / 2 + min_n;
- laytemp = 1;
-
- while((btemp = ntemp * wire_size / laytemp) > max_length)
- laytemp++; /* calculates laytemp for current ntemp */
-
- ctemp = laytemp * wire_size;
- atemp = ctemp + form_dia;
-
- Ltry =(0.0175*atemp*atemp * ntemp*ntemp) / (3*atemp + 9*btemp + 10*ctemp);
- /* WAS ERRONEOUSLY 0.2*atemp*atemp... in old program */
-
- if ( Ltry < L )
- min_n = ntemp;
- if ( Ltry > L )
- max_n = ntemp;
-
- diff1 = Ltry - L; /******************/
- diff2 = Lfinal - L;
- if( (fabs (diff1) ) < (abs (diff2) ) ) /* this finds */
- {
- Lfinal = Ltry; /* the value */
- layers = laytemp;
- a = atemp; /* of Ltemp */
- b = btemp;
- c = ctemp; /* closest to L */
- n = ntemp;
- /******************/
- }
-
- if(n >= (MAXTURNS - 1))
- {
- printf("\n\nERROR....This value will exceed %d turns.\n",MAXTURNS);
- printf("Try a longer or larger coil form diameter.\n");
- exit(1);
- }
- }
- while((max_n - min_n) > 1); /********* end of number of turns loop ********/
-
- if((n <= 1) && (Lfinal < .000001) )
- {
- printf("\n\nERROR...Less than one turn needed for this value.\n");
- printf("Try a smaller coil form diameter.\n");
- exit(1);
- }
-
- wire_len = n * a * PI;
- wire_area = pow((wire_size / 2),2.0) * PI;
- r = 1 / (wire_area * K) * wire_len;
-
- printf("\nDo you want a hardcopy (Y/N) ? ");
-
- ch = getchar();
- if ((ch = getchar()) == 'y')
- {
- fp = fopen(PRINTER,"w");
- fprintf(fp,RESET);
- }
- else
- fp = fopen(SCREEN,"w");
-
- if(fp == NULL)
- {
- printf("Error opening file");
- exit(1);
- }
-
- /**************** outputs ******************/
-
- clrscrn();
-
- fprintf(fp,"Desired inductance............ %-10.6f uH\n",L);
- fprintf(fp,"Wire diameter................. %10.6f in.",wire_size);
- fprintf(fp," or %2.0f gauge.\n",
- fabs( (log(wire_size/.46))/(log(1.1229283027)) +3) );
- fprintf(fp,"Coil form diameter............ %10.6f in.\n",form_dia);
- fprintf(fp,"Maximum coil length........... %10.6f in.\n",max_length);
-
- fprintf(fp,"\nOverall coil diameter......... %10.6f in.",wire_size * layers *
- 2 + form_dia);
- fprintf(fp,"\nAverage coil diameter......... %10.6f in.",a);
- fprintf(fp,"\nRadial depth of coil.......... %10.6f in.",layers * wire_size);
- fprintf(fp,"\nLength of coil................ %10.6f in.",b);
- fprintf(fp,"\nCoil DC resistance............ %-3.2f ohms",r);
- fprintf(fp,"\nActual Inductance............. %-10.6f uH",Lfinal);
- fprintf(fp,"\nApproximate length of wire.... %ld ft. %ld in.",
- wire_len /12,wire_len % 12);
- fprintf(fp,"\nNumber of layers.............. %1.0f",layers);
- fprintf(fp,"\nTotal number of turns......... %d",n);
- fprintf(fp,"\nTurns per layer............... %1.2f\n\n\n\n",n/layers);
-
-
- if (ch == 'y')
- {
- fprintf(fp,"\n\n\n");
- fprintf(fp,"\n");
- fprintf(fp,RESET);
- }
-
- fclose(fp);
-
-
- }
-