Newsgroups: rec.radio.amateur.homebrew
From: [email protected] (John Woods)
Subject: Re: Winding Coils
Nntp-Posting-Host: kerplop.proteon.com
Organization: Proteon, Inc., Westborough, Ma.
Date: Thu, 27 Jul 1995 18:31:07 GMT

Ference Kish <[email protected]> writes:
>I'm using bakelite tubes for my formers and I mount those on a modified 
>hand-drill. This way I have made coils with resonably uniform and firm 
>windings. The lengths of my coils are always longer than twice their diameter.
>My real "problem" is not so much inaccuracy but the fact that the error is not
>constant. If I could find a relationship between inductance or physical 
>dimensions and error then I could derive some for of correction factor and 
>should then be able to "design" and wind the coils resonaby accurately.
>However, the range of errors is quite wide and that's what's bugging me.

Is the range of errors you see on attempts to reproduce exactly the same
coil, or on attempts to produce coils of different dimensions?  If the coils
are supposed to have the same dimensions but don't have the same inductance,
then there's obviously something non-repeatable in the way you're winding
them.  If you get repeatable results that just don't match the formula you're
using, try this:

/*
 * solenoid - program to calculate the inductance of a solenoidal coil of wire
 *
 * based on the Technical Correspondance article
 * "Accurate Single-Layer-Solenoid Inductance Calculations" by Hank Meyer,
 * W6GGV, from QST magazine April 1992 (pp 76-77) plus corrections not yet
 * published as of May.
 *
 * usage:
 *  with no arguments, prompts for number of turns, coil length,
 *	coil inner diameter ("mandrel diameter"), and wire size or gauge.
 *	Enter wire gauge as #16 (or =16) for 16 AWG; enter wire size in
 *	inches as a number, or mils by suffixing number with m.
 *  with 4 arguments:  number of turns, coil length, ID, wire size
 *	all specified as above.
 *  with something other than 0 or 4 arguments, displays a terse usage
 *	message.
 *
 * This program written by John Woods, [email protected], 19 May 1992.
 * All Rights Reversed (K).
 *
 * Requires strtol() and strtod() which are common pre-ANSI library
 * extensions, as well as being official ANSI functions.  This isn't
 * necessarily the best code in the world, but it works.
 */
#include <stdio.h>
#include <math.h>
#include <stdlib.h>	/* for definition of strtol(), strtod() */

double awg_to_diam[] = {	/* from ARRL Handbook 1992 pg. 35-6 */
	0,	/* AWG 0, not in table */
	.2893,	.2576,	.2294,	.2043,	.1819,	/*  1 - 5  */
	.1620,	.1443,	.1285,	.1144,	.1019,	/*  6 - 10 */
	.0907,	.0808,	.0720,	.0641,	.0571,	/* 11 - 15 */
	.0508,	.0453,	.0403,	.0359,	.0320,	/* 16 - 20 */
	.0285,	.0253,	.0226,	.0201,	.0179,	/* 21 - 25 */
	.0159,	.0142,	.0126,	.0113,	.0100,	/* 26 - 30 */
	.0089,	.0080,	.0071,	.0063,	.0056,	/* 31 - 35 */
	.0050,	.0045,	.0040,	.0035,	.0031,	/* 36 - 40 */
	.0028,	.0025,	.0022,	.0020,	.0018,	/* 41 - 45 */
	.0016					/* 46 */
};	

#define DEBUG(x)
/* #define DEBUG(x) x */

main(argc, argv)
char **argv;
{
	/* inputs */
	double N;	/* Number of turns */
	double b;	/* length of coil */
	double a;	/* coil radius (measured to center of wire) */
	double p;	/* coil pitch == b/N */
	double d;	/* wire diameter */
	int awg;	/* AWG of wire */
	char Nbuf[64], bbuf[64], abuf[64], dbuf[64], *av[5], **avp, *pt;
	/* important calculated results */
	double K;	/* Nagaoka's constant */
	double G;	/* a correction factor */
	double H;	/* another correction factor */
	/* helpful quantities */
	double ln_4_over_B, B;
	double a2_b2, ab_term;
	/* oh yeah, the answer */
	double inductance;

	/* Get inputs */
	if (argc != 1 && argc != 5) {
fprintf(stderr,"usage: solenoid number-of-turns length coil-inner-diam #awg-or-wire-diameter\n");
		exit(1);
	}
	if (argc == 1) {
		avp = av;
		printf("N (number of turns) ");
		if (fgets(Nbuf, 64, stdin) == NULL) exit(1);
		av[0] = Nbuf;
		printf("b (length, inches) ");
		if (fgets(bbuf, 64, stdin) == NULL) exit(1);
		av[1] = bbuf;
		printf("a (coil inner diameter) ");/* will correct later */
		if (fgets(abuf, 64, stdin) == NULL) exit(1);
		av[2] = abuf;
		printf("wire size (mils or #awg) ");
		if (fgets(dbuf, 64, stdin) == NULL) exit(1);
		av[3] = dbuf;
	} else
		avp = argv+1;
	N = strtod(avp[0], &pt);
	if (*pt && *pt != '\n') {
		fprintf(stderr,"bad format for N: %s\n", avp[0]);
		exit(1);
	}
	b = strtod(avp[1], &pt);
	if (*pt && *pt != '\n') {
		fprintf(stderr,"bad format for b: %s\n", avp[1]);
		exit(1);
	}
	a = strtod(avp[2], &pt) / 2;
	if (*pt && *pt != '\n') {
		fprintf(stderr,"bad format for a: %s\n", avp[2]);
		exit(1);
	}
	if (avp[3][0] == '#' || avp[3][0] == '=') {
		awg = (int)strtol(&avp[3][1], &pt, 10);
		if (*pt && *pt != '\n') {
			fprintf(stderr,"bad format for d: %s\n", avp[3]);
			exit(1);
		}
		if (awg < 1) {
			fprintf(stderr,"using awg 1\n");
			awg = 1;
		} else if (awg > 46) {
			fprintf(stderr,"using awg 46\n");
			awg = 46;
		}
		d = awg_to_diam[awg];
	} else {
		d = strtod(avp[3], &pt);
		if (*pt == 'm') {	/* mils */
			d /= 1000.;
		} else
		if (*pt && *pt != '\n') {
			fprintf(stderr,"bad format for d: %s\n", avp[3]);
			exit(1);
		}
	}
	/* a should really be mean coil radius, not mandrel radius */
	a += d/2;

	p = b/N;

	/* now we are ready to roll */
	G = 1.25 - log(2. * p / d);
	H = ((((-.83/N - 2.5)/N + 3.8)/N - 2.5)/N+1)*.336 + .004;
	DEBUG(	printf("G = %f\nH = %f\n", G, H); )
	/* short or long coil? */
	if (2*a/b > 1) {
		/* short */
		double B2, B4;
		B = b / (2 * a);
		ln_4_over_B = log(4. / B);
		DEBUG( printf("ln 4/B = %f\n", ln_4_over_B); )
		B2 = B*B;
		K = ((5./1021.*(ln_4_over_B-109./120.)*B2
			- 1/64.*(ln_4_over_B - 2./3.))*B2
			 + 1/8.*(ln_4_over_B + 1/8.))*B2
			  + ln_4_over_B - .5;
		K *= M_2_PI * B;	/*note: M_2_PI is 2/pi from <math.h>*/
	} else {
		ab_term = a/b;
		K = 1 - 8./3.*M_1_PI * ab_term;
		a2_b2 = ab_term * ab_term;
		K += ((((147./128.*a2_b2 - 35./64.)*a2_b2 + 5./16.)*a2_b2
				- .25)*a2_b2 + .5)*a2_b2;
	}
	DEBUG( printf("K = %f\n", K); )
	/* payoff time */
	inductance = 5.08 * M_PI*M_PI * a * K * N * N/ (b / (2*a))
		- 10.2 * M_PI * N * (G+H) * a;
	printf("inductance is %.4fnH\n", inductance);
}