-
Notifications
You must be signed in to change notification settings - Fork 0
/
iloc.c
65 lines (55 loc) · 1.48 KB
/
iloc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* Simple solenoidal air coil calculator
* compile with cc -Wall -o iloc iloc.c -lm
* 2021 The Lightning Stalker
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define u 1.2566370621219E-6 // µ - magnetic constant
double roundval(long double inval)
// round to 1 decimal place
{
int i;
i = (int)(inval * 10 + .5);
return (double)i / 10;
}
int main()
{
// variable declarations
long double L, D, A, TS, l, N, i;
/* L = target inductance
* D = diameter in mm
* A = area of cross section
* TS = turn spacing
* l = length of coil in mm
* N = turns count
* i = intermediate temp variable
*/
// boiler plate
puts("\n \
iloc is a coil calculator.\n \
iloc will find turns count and length of a coil given the target\n \
inductance, desired diameter, and turns spacing (pitch).\n \
\n");
// input section
printf("Enter target inductance (µH): ");
scanf("%Lf", &L);
printf("Enter desired coil diameter (mm): ");
scanf("%Lf", &D);
printf("Enter turn spacing (mm per turn): ");
scanf("%Lf", &TS);
// begin formulas
// first some unit conversion
L = L / 1000000; // H --> µH
D = D / 1000; // m --> mm
TS = TS / 1000; // m --> mm
// Meet the meat
A = M_PI * powl(D / 2, 2); // M_PI = Pi
i = L * (1 / u) / A;
N = i * TS;
l = roundval(N * TS * 1000);
i = roundval(N);
// end formulas
// output section
printf("\nThe coil shall be %.1Lf mm in length and have %.1Lf turns.\n\n", l, i);
}