-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgainmargin.c
More file actions
64 lines (56 loc) · 1.57 KB
/
gainmargin.c
File metadata and controls
64 lines (56 loc) · 1.57 KB
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
/* Compile with gcc -Wall -o gainmargin gainmargin.c -lm
From STMicroelectronics AN2867 Rev 20 p.13
Project Crew 2024 */
#if defined (__WATCOMC__)
#define PROGNAME "gainmarg"
#elif defined (__GNUC__)
#define PROGNAME "gainmargin"
#endif
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#if defined (__GNUC__)
#include <locale.h>
#endif
#if defined (__DOS__)
#define SUBM "(m)"
#else
#define SUBM "ₘ" /* differences of the codepage */
#endif
int main (int argc, char **argv)
{
#if defined (__GNUC__)
unsetenv ("LC_ALL");
setlocale (LC_NUMERIC, ""); // This should give us digit grouping
#endif
if (argc == 5)
{
#if defined (__WATCOMC__)
printf ("%.5LfmA/V\n",
4e3 * atoll(argv[3]) *
pow(2 * M_PI * atoll(argv[4]) * 1e6, 2) *
pow((atoll(argv[1]) + atoll(argv[2])) * 1e-12, 2)
);
#elif defined (__GNUC__)
printf ("%'.5LfmA/V\n",
4e3 * atoll(argv[3]) *
powl(2 * M_PI * atoll(argv[4]) * 1e6, 2) *
powl((atoll(argv[1]) + atoll(argv[2])) * 1e-12, 2)
);
#endif
return (0);
}
else
{
puts ( \
"\n"
" "PROGNAME" is a critical gain margin calculator for crystal oscillators.\n"
" output is g"SUBM"crit in mA/V\n"
"\n"
" Usage: "PROGNAME" shunt_pF load_pF ESR MHz\n"
" Example: "PROGNAME" 5.0 12.0 150.0 12.0\n"
" Output should be: 0.98576mA/V\n"
);
return (EXIT_FAILURE);
}
}