Advertisement
LightningStalker

Potentiometer and series resistor wattage finder

Sep 3rd, 2014
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.31 KB | None | 0 0
  1. /* compile with "gcc -Wall -oseriesw seriesw.c -lm"
  2.  *
  3.  * Steps through possible pot settings and finds the wattage dissipated
  4.  * by the pot and a series resistor.
  5.  * - by The Lightning Stalker 2014
  6.  */
  7.  
  8. #include <math.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11.  
  12. int main (int argc, char **argv)
  13. {
  14.     float rres, pot, v, rpot, wres, wpot, wrpeak = 0, wppeak = 0;
  15.    
  16.     if (argc == 4)
  17.     {
  18.         rres = atof(argv[1]);
  19.         pot = atof(argv[2]);
  20.         v = atof(argv[3]);
  21.         for (rpot = pot; rpot > -1; rpot--)
  22.         {
  23.             wpot = pow (v / (rpot + rres), 2) * rpot;
  24.             wres = pow (v / (rpot + rres), 2) * rres;
  25.             if (wpot > wppeak) wppeak = wpot;
  26.             if (wres > wrpeak) wrpeak = wres;
  27.             printf("R2 = %1.4fΩ R1 = %1.4fW R2 = %1.4fW\n", rpot, wres, wpot);
  28.         }
  29.         puts("done.");
  30.         printf("R1 peaked at %1.4fW, R2 peaked at %1.4fW\n", wrpeak, wppeak);
  31.     }
  32.     else
  33.     {
  34.         puts("seriesr finds wattages dissipated by a pot and series resistor.\n");
  35.         puts("Usage: seriesr R1 R2 V");
  36.         puts("R1 = Fixed Resistor Value");
  37.         puts("R2 = Potentiometer Maximum Resistance");
  38.         puts("V  = Appied Voltage");
  39.         puts("Example: seriesr 4.7 50 1.25");
  40.         return(1);
  41.     }
  42.    
  43.     return(0);
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement