-
Notifications
You must be signed in to change notification settings - Fork 0
/
gainmargin.c
34 lines (31 loc) · 966 Bytes
/
gainmargin.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
/* Compile with gcc -Wall -o gainmargin gainmargin.c -lm
From STMicroelectronics AN2867 Rev 20 p.13
Project Crew 2024 */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <fenv.h>
int main (int argc, char **argv)
{
unsetenv ("LC_ALL");
setlocale (LC_NUMERIC, ""); // This should give us digit grouping
if (argc == 5)
{
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)
);
return (0);
}
else
{
puts ("gainmargin is a critical gain margin calculator for crystal oscillators.");
puts ("output is gₘcrit in mA/V");
puts ("");
puts ("Usage: gainmargin shunt_pF load_pF ESR MHz");
puts ("Example: gainmargin 5.0 12.0 150.0 12.0");
puts ("Output should be: 0.98576mA/V");
}
}