-
Notifications
You must be signed in to change notification settings - Fork 0
/
seriesw.c
45 lines (41 loc) · 1.35 KB
/
seriesw.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
/* compile with "gcc -Wall -oseriesw seriesw.c -lm"
*
* Steps through possible pot settings and finds the wattage dissipated
* by the pot and a series resistor.
* - by The Lightning Stalker 2014
*/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char **argv)
{
float rres, pot, v, rpot, wres, wpot, wrpeak = 0, wppeak = 0;
if (argc == 4)
{
rres = atof(argv[1]);
pot = atof(argv[2]);
v = atof(argv[3]);
for (rpot = pot; rpot > -0.0001; rpot-=0.1)
{
wpot = pow (v / (rpot + rres), 2) * rpot;
wres = pow (v / (rpot + rres), 2) * rres;
if (wpot > wppeak) wppeak = wpot;
if (wres > wrpeak) wrpeak = wres;
printf("R2 = %1.4fΩ R1 = %1.4fW R2 = %1.4fW\n", rpot, wres, wpot);
}
puts("done.");
printf("R1 peaked at %1.4fW, R2 peaked at %1.4fW\n", wrpeak, wppeak);
}
else
{
puts("seriesw finds wattages dissipated by a pot and series resistor.\n");
puts("Usage: seriesw R1 R2 V");
puts("R1 = Fixed Resistor Value");
puts("R2 = Potentiometer Maximum Resistance");
puts("V = Appied Voltage");
puts("Example: seriesw 4.7 50 1.25");
puts("Output should end with: R1 peaked at 0.3324W, R2 peaked at 0.0831W");
return(1);
}
return(0);
}