Skip to main content
Engineering LibreTexts

3.1: Introduction

  • Page ID
    25690
  • \( \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}}\)

    In this exercise we will be taking a look at using conditionals. These include the if/else construct and the switch/case construct. Conditionals are used to make a choice, that is, to split the program flow into various paths. The if/else works best with simple either/or choices while the switch/case is designed to deal with one (or possibly multiple) choice(s) from a list of fixed possibilities.

    The simplest conditional is the straight if(). Depending on whether or not the item(s) to be tested evaluate to true determines if subsequent action is taken. By grouping clauses with the logical operators || and &&, complex tests may be created. if() statements may be nested as well as include processing for the test failure by using the else clause. If you need to choose a single item from a list, for example when processing a menu selection, this may be achieved through nesting in the following fashion:

    if( choice == 1 )
    {
          /* do stuff for 1 */
    }
    else
    {
          if( choice == 2 )
          {
                /* do stuff for 2 */
          }
          else
          {
                if( choice == 3 )
                {
                      /* do stuff for 3 */
                }
                /* and so on */
          }
    }
    

    This arrangement is a bit cumbersome when choosing from a large list. Also, it is difficult to deal with a plural choice (e.g., picking items 1 and 3). For these situations the C language offers the switch/case construct. There is nothing a switch/case can do that you can’t recreate with nested if/else’s and additional code, but the former offers greater convenience as well as clearer and more compact code. The switch/case is used frequently, but ultimately, the if/else is more flexible because it is not limited to choosing from a list of numeric values. Ordinarily, numeric constants are not used in production code, as in the example above. Instead, #define’s are used for the constants in order to make the code more readable. A real-world switch/case version of the previous example might look like:

    #define WALK_DOG        1
    #define LET_OUT_CAT     2
    #define COMB_WOMBAT     3
    
    switch( choice )
    {
          case WALK_DOG:
                /* c’mon poochie... */
                break;
    
          case LET_OUT_CAT:
                /* there’s the door... */
                break;
    
          case COMB_WOMBAT:
                /* first the shampoo... */
                break;
    
          /* and so on */
    }
    

    In this exercise we’re going to make use of both constructs. The program will involve the calculation of DC bias parameters for simple transistor circuits. We shall give the user a choice of three different biasing arrangements (voltage divider, two-supply emitter, and collector feedback). The program will then ask for the appropriate component values and determine the quiescent collector current and collector-emitter voltage. It will also determine whether or not the circuit is in saturation. These values will be displayed to the user.

    One approach to this problem is to consider it as three little problems joined together. That is, consider what you need to do for one bias and then replicate it with appropriate changes for the other two. The three are then tied together with some simple menu processing. Here is a pseudo code:

    1. Give the user appropriate directions and a list of bias choices.

    2. Ask the user for their bias choice.

    3. Branch to the appropriate routine for the chosen bias. For each bias,

    a. Ask for the needed component values (resistors, power supply, beta).

    b. Compute Ic and Vce and determine if the circuit is in saturation.

    c. Display values to the user.

    The appropriate equations for each bias follow. All biases use the following: Vcc is the positive supply. Re is the emitter resistor while Rc is the collector resistor. beta is the current gain (hfe). The base-emitter (Vbe) may be assumed to be 0.7 volts. Note that if Ic-saturation is greater than Ic, then the actual Ic is equal to Ic-saturation and Vce will be 0.

    Voltage Divider: also requires R1, R2 (upper and lower divider resistors).

    Vth = Vcc*R2/(R1+R2)

    Rth = R1*R2/(R1+R2)

    Ic = (Vth-Vbe)/(Re+Rth/beta)

    Vce = Vcc-Ic*(Re+Rc)

    Ic-saturation = Vcc/(Rc+Re)

    Collector Feedback: also requires Rb (base resistor).

    Ic = (Vcc-Vbe)/(Re+Rc+Rb/beta)

    Vce = Vcc-Ic*(Re+Rc)

    Ic-saturation = Vcc/(Rc+Re)

    Two-supply Emitter: also requires Vee (negative emitter supply) and Rb (base resistor).

    Ic = (Vee-Vbe)/(Re+Rb/beta)

    Vce = Vee+Vcc-Ic*(Re+Rc)

    Ic-saturation = (Vee+Vcc)/(Rc+Re)

    where Vee is an absolute value in all cases.


    This page titled 3.1: Introduction 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.