Saltar al contenido principal
LibreTexts Español

3.2: El Programa

  • Page ID
    83230
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    El programa se presenta en trozos, a continuación, en la secuencia que podrías escribirlo. Primero viene el esqueleto principal.

    #include <stdio.h>
    #include <math.h>
    
    #define VOLTAGE_DIVIDER       1
    #define EMITTER               2
    #define COLLECTOR_FEEDBACK    3
    #define VBE .7
    
    int main( void )
    {
          int choice;
    
          give_directions();
          choice = get_choice();
    
          switch( choice )
          {
                case VOLTAGE_DIVIDER:
                      voltage_divider();
                      break;
    
                case EMITTER:
                      emitter();
                      break;
    
                case COLLECTOR_FEEDBACK:
                      collector_feedback();
                      break;
    
                default:    /* tell user they’re not so bright... */
                      printf(“No such choice!\n”);
                      break;
          }
    }
    

    Las dos primeras funciones podrían verse así (no olvides agregar sus prototipos más tarde):

    void give_directions( void )
    {
          printf(“DC Bias Q Point calculator\n\n”);
          printf(“These are your bias choices:\n”);
          printf(“1. Voltage Divider\n”);
          printf(“2. Two Supply Emitter\n”);
          printf(“3. Collector Feedback\n”);
    }
    
    int get_choice( void )
    {
          int ch;
    
          printf(“Enter your choice number:”);
          scanf(“%d”, &ch);
          return( ch );
    }
    

    Ahora es el momento de escribir las funciones de sesgo. Así es como podría verse la función voltage_divider ():

    void voltage_divider( void )
    {
          double vcc, vth, r1, r2, rth, re, rc, beta, ic, icsat, vce;
    
          printf(“Enter collector supply in volts”);
          scanf(“%lf”, &vcc);
          printf(“Enter current gain (beta or hfe)”);
          scanf(“%lf”, &beta);
          printf(“Please enter all resistors in ohms\n”);
          printf(“Enter upper divider resistor”);
          scanf(“%lf”, &r1);
          printf(“Enter lower divider resistor”);
          scanf(“%lf”, &r2);
          printf(“Enter collector resistor”);
          scanf(“%lf”, &rc);
          printf(“Enter emitter resistor”);
          scanf(“%lf”, &re);
    
          vth = vcc*r2/(r1+r2);
          rth = r1*r2/(r1+r2);
          ic = (vth-VBE)/(re+rth/beta);
          icsat = vcc/(rc+re);
    
          if( ic >= icsat )
          {
                printf(“Circuit is in saturation!\n”);
                printf(“Ic = %lf amps and Vce = 0 volts\n”, icsat );
          }
          else
          {
                vce = vcc-ic*(re+rc);
                printf(“Ic = %lf amps and Vce = %lf volts\n”, ic, vce );
           }
    }
    

    Las otras dos funciones de sesgo serían similares a esta. Algunos puntos a tener en cuenta: Para obtener el valor absoluto, considere usar la función fabs () (punto flotante absoluto). Otro enfoque del programa sería hacer globales las variables vce, icsat e ic y mover la sección de impresión a main () porque la comparación final y la impresión serán idénticas en las tres funciones. (También es posible que las funciones devuelvan los valores a través de punteros, evitando la necesidad de globals).

    Completa las otras dos funciones de sesgo, construye y prueba el programa. Utilice los siguientes valores: Prueba #1, Bialización de dos emisores de suministro, Vcc = 20 V, Vee = −10 V, Rb = 2 k\(\Omega\), Re = 1 k\(\Omega\), Rc = 1.5 k\(\Omega\), beta = 100. Prueba #2, Sesgo de retroalimentación del colector, Vcc = 30 V, Rc = 10 k\(\Omega\), Re = 1 k\(\Omega\), Rb = 100 k\(\Omega\), beta = 100. Para evitar las advertencias del compilador, deberá colocar prototipos de funciones antes de main (). Podría colocarlos en un archivo de encabezado separado, pero hay muy pocos para molestarse. Para crear los prototipos, simplemente copie y pegue las declaraciones de función y agregue un punto y coma final. Por ejemplo:

    #define VBE .7
    
    void give_directions( void );
    int get_choice( void );
    /* and so forth */
    
    void main( void )
    {
          ...
    

    Sin los prototipos, el compilador no “sabrá” qué toman las funciones como argumentos ni qué tipo de variables devuelven (si las hay). Así, el compilador no puede hacer comprobaciones de tipo y te avisará sobre esto. Además, el compilador asumirá argumento por defecto y devolverá tipos de int, así que cuando el compilador vea el código de función, se quejará de que los tipos no coinciden con el valor predeterminado. Esto puede parecer un dolor al principio, pero es un mecanismo de verificación cruzada que puede prevenir muchos errores de software.


    This page titled 3.2: El Programa is shared under a CC BY-NC-SA 4.0 license and was authored, remixed, and/or curated by James M. Fiore via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.