home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / JSAGE / ZSUS / PROGPACK / CVIDLIB.LBR / POWER.CQ / POWER.C
Text File  |  2000-06-30  |  3KB  |  119 lines

  1. #define FLOAT        /* Must use floating point routines in clib */      
  2. #define ZCPR3        /* Must use ZCPR3           "      "   "  */
  3. #include <stdio.h>
  4.  
  5. /* A cheaters way of doing floating point input */
  6. #define finput    atof((ptr=gets(temp,28)))
  7.  
  8. extern float atof();
  9. extern char *gets();
  10.  
  11. x_vc()
  12. {
  13.     float Vsec,Vrect,Iout,Rs,C;
  14.     float Vpeak,Vc,Vripple,PIV,Isurge,PDavg;
  15.     char temp[30],*ptr;
  16.  
  17.     Cmode=1;
  18.     cls();
  19.     printf("Enter in the following values:\n");
  20.     printf("Vsec,rms =");
  21.     Vsec=finput;
  22.     printf("Vrect    =");
  23.     Vrect=finput;
  24.     printf("Iout     =");
  25.     Iout=finput;
  26.     printf("Rsec cir =");
  27.     Rs=finput;
  28.     printf("Cfarads  =");
  29.     C=finput;
  30.  
  31.     Vpeak   = (Vsec * 1.414) - Vrect;
  32.     Vripple = (.0833 * Iout) / C;
  33.     Vc      = Vpeak - Vripple;
  34.     PIV     = 1.414 * Vsec;
  35.     Isurge  = Vpeak / Rs;
  36.     PDavg   = (((C * Vripple / .00119) + Iout) * Vrect ) / 13.96;
  37.  
  38.     printf("\nThe following are the calculated values\n");
  39.     printf("Vpeak   = %.2f\tVripple = %.2f\tVc      = %.2f\n",Vpeak,Vripple,Vc);
  40.     printf("PIV     = %.2f\tIsurge  = %.2f\tPDavg   = %.2f\n",PIV,Isurge,PDavg);
  41.     wait();
  42. }
  43.  
  44. vc_x()
  45. {
  46.     float Vc,Vripple,Vrect,Iout,Rs;
  47.     float Vpeak,Vsec,C,Isurge,PDavg,PIV;
  48.     char temp[30],*ptr;
  49.  
  50.     Cmode=1;
  51.     cls();
  52.     printf("Enter in the following values:\n");
  53.     printf("Vc       =");
  54.     Vc=finput;
  55.     printf("Vripple  =");
  56.     Vripple=finput;
  57.     printf("Vrect    =");
  58.     Vrect=finput;
  59.     printf("Iout     =");
  60.     Iout=finput;
  61.     printf("Rsec cir =");
  62.     Rs=finput;
  63.  
  64.     Vpeak  = Vc + Vripple;
  65.     Vsec   = (Vpeak+Vrect) / 1.414;
  66.     C      = (.0833 / Vripple) * Iout;
  67.     Isurge = Vpeak / Rs;
  68.     PDavg  = (((C * Vripple / .00119) + Iout) * Vrect) / 13.96;
  69.  
  70.     printf("The following are the calculated values:\n");
  71.     printf("Vpeak  %.2f\tVsec   %.2f\tC      %.6f\n",Vpeak,Vsec,C);
  72.     printf("Isurge %.2f\tPDavg  %.2f\n",Isurge,PDavg);
  73.     wait();
  74. }
  75.  
  76. wait()
  77. {
  78.     inchar("Press a key to go return to the menu : :\b\b");
  79. }
  80.  
  81. main()
  82. {
  83.     char choice;
  84.  
  85.     zsysinit();
  86.     while(TRUE)
  87.     {
  88.     cls();
  89.     stndout();
  90.     puts("\t\t+-------------------------------------+\n");
  91.     puts("\t\t|       POWER SUPPLY CALCULATOR       |\n");
  92.     puts("\t\t+-------------------------------------+\n");
  93.     puts("\t\t|                                     |\n");
  94.     puts("\t\t| 1. Xformer to Vc                    |\n");
  95.     puts("\t\t|                                     |\n");
  96.     puts("\t\t| 2. Vc to Xformer                    |\n");
  97.     puts("\t\t|                                     |\n");
  98.     puts("\t\t| 3. Exit                             |\n");
  99.     puts("\t\t|                                     |\n");
  100.     puts("\t\t+-------------------------------------+\n");
  101.     puts("\t\t                 : :\b\b");
  102.     stndend();
  103.     Cmode=0;
  104.     switch((choice=getchar()))
  105.     {
  106.         case '1' : x_vc();
  107.                break;
  108.  
  109.         case '2' : vc_x();
  110.                break;
  111.  
  112.         case '3' : exit();
  113.  
  114.         default  : putchar('\07');
  115.                break;
  116.     }
  117.     }
  118. }
  119.