Chapter 2

Analog & Digital Electronics

Diodes, transistors, op-amps, and logic gates.

Analog & Digital Electronics

Analog and digital electronics form the foundation of all modern electronic systems. Understanding both domains and how they interface is crucial for designing sophisticated electronic circuits that process signals, perform computations, and enable communication.

Semiconductor Physics Fundamentals

Band Theory

The energy band structure of semiconductors determines their electrical properties:

E(k)=E0+2k22mE(k) = E_0 + \frac{\hbar^2 k^2}{2m^*}

Where mm^* is the effective mass of carriers and kk is the wave vector.

Band Gap Energy

Eg=EcEvE_g = E_c - E_v

Where EcE_c is the conduction band energy and EvE_v is the valence band energy.

Intrinsic Carrier Concentration

ni=NcNveEg/2kTn_i = \sqrt{N_c N_v} e^{-E_g/2kT}

Where NcN_c and NvN_v are effective density of states in conduction and valence bands.

Doping and pn Junctions

Doping Concentrations

  • n-type: Donor concentration NDN_D >> nin_i
  • p-type: Acceptor concentration NAN_A >> nin_i

pn Junction Depletion Width

W=2ϵsq(1NA+1ND)VbiW = \sqrt{\frac{2\epsilon_s}{q}\left(\frac{1}{N_A} + \frac{1}{N_D}\right)V_{bi}}

Where VbiV_{bi} is the built-in potential:

Vbi=VTln(NANDni2)V_{bi} = V_T \ln\left(\frac{N_AN_D}{n_i^2}\right)

Shockley Diode Equation

I=Is(eqV/kT1)I = I_s\left(e^{qV/kT} - 1\right)

Where IsI_s is the reverse saturation current and VT=kT/qV_T = kT/q is the thermal voltage.

Diode Applications

Rectifier Circuits

Average DC voltage=1T0Tv(t)dt\text{Average DC voltage} = \frac{1}{T}\int_0^T v(t) dt

For half-wave rectifier: Vdc=VmπV_{dc} = \frac{V_m}{\pi}

For full-wave rectifier: Vdc=2VmπV_{dc} = \frac{2V_m}{\pi}

Zener Diodes

Regulation equation:VZ=VZ0+IZRZ\text{Regulation equation}: V_Z = V_{Z0} + I_Z R_Z

Diode Small-Signal Model

rd=VTIDr_d = \frac{V_T}{I_D}

For forward-biased diode.

Bipolar Junction Transistors (BJTs)

Current Relationships

IC=βIB,IE=IB+IC=IC(1+1β)I_C = \beta I_B, \quad I_E = I_B + I_C = I_C\left(1 + \frac{1}{\beta}\right)

Ebers-Moll Model

IC=IS(eVBE/VTeVBC/VT)ISβR(eVBC/VT1)I_C = I_{S}\left(e^{V_{BE}/V_T} - e^{V_{BC}/V_T}\right) - \frac{I_{S}}{\beta_R}\left(e^{V_{BC}/V_T} - 1\right) IE=IS(eVBE/VTeVBC/VT)+ISβF(eVBE/VT1)I_E = I_{S}\left(e^{V_{BE}/V_T} - e^{V_{BC}/V_T}\right) + \frac{I_{S}}{\beta_F}\left(e^{V_{BE}/V_T} - 1\right)

Transistor Configurations

Common Emitter (CE)

  • Current gain: β=IC/IB\beta = I_C/I_B
  • Input impedance: Moderate
  • Output impedance: High
  • Voltage gain: High

Common Base (CB)

  • Current gain: α=IC/IE\alpha = I_C/I_E
  • Input impedance: Low
  • Output impedance: High
  • Voltage gain: High

Common Collector (CC)

  • Current gain: β+1\beta + 1
  • Input impedance: High
  • Output impedance: Low
  • Voltage gain: ~1 (emitter follower)

Field-Effect Transistors (FETs)

MOSFET Operation

Threshold Voltage

Vth=VFB+2ϕF+2qϵsiNA(2ϕF)CoxV_{th} = V_{FB} + 2\phi_F + \frac{\sqrt{2q\epsilon_{si}N_A(2\phi_F)}}{C_{ox}}

Where ϕF\phi_F is the Fermi potential.

Drain Current (Saturation Region)

ID=μnCox2WL(VGSVth)2(1+λVDS)I_D = \frac{\mu_n C_{ox}}{2}\frac{W}{L}(V_{GS} - V_{th})^2(1 + \lambda V_{DS})

Where λ\lambda is the channel-length modulation parameter.

JFET Operation

ID=IDSS(1VGSVP)2I_D = I_{DSS}\left(1 - \frac{V_{GS}}{V_P}\right)^2

Where IDSSI_{DSS} is the saturation drain current and VPV_P is the pinch-off voltage.

Operational Amplifiers

Ideal Op-Amp Characteristics

  • Open-loop gain: AOLA_{OL} \rightarrow \infty
  • Input impedance: RinR_{in} \rightarrow \infty
  • Output impedance: Rout0R_{out} \rightarrow 0
  • Bandwidth: BWBW \rightarrow \infty
  • Slew rate: SRSR \rightarrow \infty

Negative Feedback Analysis

For a feedback amplifier:

Af=A1+AβA_f = \frac{A}{1 + A\beta}

Where AA is open-loop gain and β\beta is feedback factor.

Inverting Amplifier

Gain:Av=RfRin\text{Gain}: A_v = -\frac{R_f}{R_{in}} Input impedance:Rin\text{Input impedance}: R_{in}

Non-Inverting Amplifier

Gain:Av=1+RfR1\text{Gain}: A_v = 1 + \frac{R_f}{R_1} Input impedance:Rin (ideal case)\text{Input impedance}: R_{in} \rightarrow \infty \text{ (ideal case)}

Differential Amplifier

Vout=Ad(V1V2)+AcV1+V22V_{out} = A_d(V_1 - V_2) + A_c\frac{V_1 + V_2}{2}

Where AdA_d is differential gain and AcA_c is common-mode gain.

Common-Mode Rejection Ratio (CMRR)

CMRR=AdAc\text{CMRR} = \frac{A_d}{A_c}

Digital Logic Families

TTL (Transistor-Transistor Logic)

  • Power consumption: ~10 mW/gate
  • Propagation delay: ~10 ns
  • Noise margin: ~0.4 V
  • Fan-out: ~10 gates

CMOS (Complementary MOS)

  • Power consumption: < 1 µW/gate (static)
  • Propagation delay: ~100 ps - 10 ns
  • Noise margin: High
  • Fan-out: >50 gates

Logic Gate Analysis

Basic Gates Truth Tables

NAND Gate
Y=AB=Aˉ+BˉY = \overline{A \cdot B} = \bar{A} + \bar{B}
ABY
001
011
101
110
NOR Gate
Y=A+B=AˉBˉY = \overline{A + B} = \bar{A} \cdot \bar{B}

Propagation Delay

tpd=tPHL+tPLH2t_{pd} = \frac{t_{PHL} + t_{PLH}}{2}

Where tPHLt_{PHL} and tPLHt_{PLH} are propagation delays for high-to-low and low-to-high transitions.

Power-Delay Product (PDP)

PDP=Pavg×tpd\text{PDP} = P_{avg} \times t_{pd}

MOSFET Switching Characteristics

Delay time:td=0.69ReqCL\text{Delay time}: t_d = 0.69 R_{eq}C_L

Where ReqR_{eq} is equivalent resistance and CLC_L is load capacitance.

Logic Families Comparison

ParameterTTLCMOSECL
SpeedFastMediumVery Fast
PowerMediumLowHigh
Noise marginMediumHighLow
Fan-out1050+25
Supply voltage5V3-18V-5.2V

Analog Circuit Design

Amplifier Configurations

Common-Emitter Amplifier

Av=RCre+REA_v = -\frac{R_C}{r_e + R_E}

Where re=VT/IEr_e = V_T/I_E.

Common-Source Amplifier

Av=gmRDA_v = -g_m R_D

Where gmg_m is transconductance.

Frequency Response

Low-Frequency Response

fL=12πRCf_L = \frac{1}{2\pi R C}

High-Frequency Response (Miller Effect)

Cin=Cgs+Cgd(1+Av)C_{in} = C_{gs} + C_{gd}(1 + A_v)

Where AvA_v is voltage gain.

Operational Amplifier Circuits

Integrator

Vout(t)=1RC0tVin(τ)dτ+Vout(0)V_{out}(t) = -\frac{1}{RC}\int_0^t V_{in}(\tau) d\tau + V_{out}(0)

Differentiator

Vout(t)=RCdVin(t)dtV_{out}(t) = -RC\frac{dV_{in}(t)}{dt}

Active Filters

  • Sallen-Key topology for second-order filters
  • Unity gain bandwidth: GBP=AOL×fbGBP = A_{OL} \times f_b
  • Slew rate limitation: SR2πfVpeakSR \geq 2\pi f V_{peak}

Mixed-Signal Circuits

Sample-and-Hold Circuits

Aperture time:tap=tacq+thold\text{Aperture time}: t_{ap} = t_{acq} + t_{hold}

Analog-to-Digital Converters (ADC)

Resolution:n=log2(2n) bits\text{Resolution}: n = \log_2(2^n) \text{ bits} Quantization error:ΔV=Vref2n\text{Quantization error}: \Delta V = \frac{V_{ref}}{2^n}

Successive Approximation ADC (SAR)

Conversion time=n×clock period\text{Conversion time} = n \times \text{clock period}

Digital-to-Analog Converters (DAC)

Vout=Vref2ni=0n1bi2iV_{out} = \frac{V_{ref}}{2^n}\sum_{i=0}^{n-1} b_i 2^i

Noise Analysis

Thermal Noise (Johnson Noise)

Vn=4kTRΔfV_n = \sqrt{4kTR\Delta f}

Shot Noise

in=2qIΔfi_n = \sqrt{2qI\Delta f}

Flicker Noise (1/f Noise)

S(f)=KfγS(f) = \frac{K}{f^{\gamma}}

Where KK and γ\gamma are constants.


Real-World Application: Audio Amplifier Design

Designing an audio amplifier requires balancing power, efficiency, and distortion.

Audio Amplifier Analysis

# Audio amplifier design parameters
amp_params = {
    'power_output': 50,        # W (RMS output power)
    'efficiency_target': 0.7,   # 70% efficiency target (Class AB)
    'frequency_response': [20, 20000],  # Hz (20Hz to 20kHz)
    'total_harmonic_distortion': 0.1,  # % (at full power)
    'slew_rate': 20,          # V/μs (minimum required)
    'supply_voltage': 60,      # V (single supply rail)
    'speaker_impedance': 8     # Ohms (nominal)
}

# Calculate power requirements
output_current_rms = math.sqrt(amp_params['power_output'] / amp_params['speaker_impedance'])
output_current_peak = output_current_rms * math.sqrt(2)

supply_current = amp_params['power_output'] / (amp_params['efficiency_target'] * amp_params['supply_voltage'])
supply_power = amp_params['supply_voltage'] * supply_current
dissipated_power = supply_power - amp_params['power_output']

# Calculate required gain
input_sensitivity = 1.0  # V (for full output power)
required_gain = (output_current_rms * amp_params['speaker_impedance']) / input_sensitivity

# Calculate slew rate requirements
max_frequency = amp_params['frequency_response'][1]
max_amplitude = output_current_rms * amp_params['speaker_impedance']

# For sine wave: SR = 2πfV_peak
required_slew_rate = 2 * math.pi * max_frequency * max_amplitude / 1e6  # Convert to V/μs

# Calculate distortion requirements (THD specifications)
harmonic_distortion_limit = amp_params['total_harmonic_distortion'] / 100  # Convert to fraction
output_power_fundamental = amp_params['power_output'] * (1 - harmonic_distortion_limit)
output_power_harmonics = amp_params['power_output'] * harmonic_distortion_limit

# Efficiency calculations
theoretical_max_efficiency = 1 - (required_gain / (required_gain + 1)) * (1 - amp_params['efficiency_target'])
practical_efficiency = amp_params['efficiency_target']

print(f"Audio Amplifier Design Analysis:")
print(f"  Target power output: {amp_params['power_output']} W into {amp_params['speaker_impedance']} Ω")
print(f"  Required gain: {required_gain:.2f}x ({20*math.log10(required_gain):.1f} dB)")
print(f"  Peak output current: {output_current_peak:.2f} A")
print(f"  Supply voltage: {amp_params['supply_voltage']} V")
print(f"  Supply current: {supply_current:.2f} A")
print(f"  Required slew rate: {required_slew_rate:.2f} V/μs")
print(f"  Available slew rate: {amp_params['slew_rate']} V/μs")
print(f"  Power dissipation: {dissipated_power:.2f} W")
print(f"  Target efficiency: {amp_params['efficiency_target']*100:.1f}%")
print(f"  Harmonic distortion: {harmonic_distortion_limit*100:.2f}%")
print(f"  Frequency response: {amp_params['frequency_response'][0]}-{amp_params['frequency_response'][1]} Hz")

# Performance assessment
if required_slew_rate > amp_params['slew_rate']:
    performance_issue = "Slew rate limiting - may cause distortion at high frequencies"
elif dissipated_power > 30:
    performance_issue = "High power dissipation - may require significant heat sinking"
else:
    performance_issue = "Good performance parameters"

print(f"  Performance assessment: {performance_issue}")

# Efficiency evaluation
efficiency_ratio = practical_efficiency / 0.785  # Divide by max theoretical for Class A (78.5%)
if efficiency_ratio > 0.9:
    efficiency_class = "Class D or high-efficiency Class AB"
elif efficiency_ratio > 0.6:
    efficiency_class = "Standard Class AB"
else:
    efficiency_class = "Class A or low-efficiency design"

print(f"  Efficiency classification: {efficiency_class}")

# Thermal considerations
thermal_resistance_junction_case = 1.5  # °C/W (for power transistors)
thermal_resistance_case_sink = 0.5     # °C/W (with thermal compound)
thermal_resistance_sink_ambient = 4.0   # °C/W (heat sink rating)

total_thermal_resistance = thermal_resistance_junction_case + thermal_resistance_case_sink + thermal_resistance_sink_ambient
temperature_rise = total_thermal_resistance * dissipated_power
junction_temperature = 25 + temperature_rise  # Assuming 25°C ambient

if junction_temperature < 125:  # Safe limit for silicon
    thermal_rating = "Thermal design adequate"
else:
    thermal_rating = f"Thermal design insufficient - junction temperature {junction_temperature:.1f}°C too high"

print(f"  Thermal analysis: {thermal_rating}")

Thermal Management

Proper thermal design is critical for reliable operation of power amplifiers.


Your Challenge: Oscillator Circuit Design

Design a Wien bridge oscillator to generate a precise sinusoidal signal at a specific frequency.

Goal: Calculate component values and analyze the oscillator's performance parameters.

Oscillator Specifications

import math

# Wien bridge oscillator design parameters
oscillator_specs = {
    'target_frequency': 1000,    # Hz (1 kHz)
    'frequency_stability': 0.01,  # ±1% frequency stability
    'amplitude_output': 2.0,     # Volts peak (sine wave amplitude)
    'total_harmonic_distortion': 1.0,  # % (acceptable distortion level)
    'op_amp_supply': 12,         # V (dual supply ±6V)
    'feedback_ratio': 3,         # Required gain for oscillation
    'temperature_coeff': 100e-6  # 100 ppm/°C (resistor temperature coefficient)
}

# Wien bridge oscillator frequency calculation
# For Wien bridge: f = 1 / (2πRC) when R1=R2=R and C1=C2=C
# The bridge provides zero phase shift at frequency f

# Calculate R and C values for target frequency
# Choose standard values to achieve target frequency
R_value = 10000  # Try 10kΩ
C_value = 1 / (2 * math.pi * oscillator_params['target_frequency'] * R_value)  # Required capacitance

# Calculate actual frequency with chosen values
actual_frequency = 1 / (2 * math.pi * R_value * C_value)

# The Wien bridge requires gain of exactly 3 to maintain oscillation
# With non-ideal op-amp, we may need slightly more gain
required_gain = 3.0  # Exact requirement for Wien bridge
gain_tolerance = 0.05  # 5% tolerance in gain

# Calculate feedback resistors
# For gain = 1 + (Rf/R1), we need Rf/R1 = 2
R_feedback = 20000  # If R1 = 10kΩ, then Rf = 20kΩ for gain of 3
R_input = 10000     # Input resistor

# Calculate gain
actual_gain = 1 + (R_feedback / R_input)

# Stability analysis considering component variations
# With 1% resistors and 5% capacitors
freq_tolerance = 0.01 + 0.05  # Combined tolerance
min_frequency = actual_frequency * (1 - freq_tolerance)
max_frequency = actual_frequency * (1 + freq_tolerance)

# Calculate distortion contributors
# Non-linearity in gain control affects harmonic distortion
output_power = (oscillator_params['amplitude_output']**2) / 2  # For sine wave into 1Ω load
power_supply_rejection = 60  # dB (typical op-amp PSRR)

# Temperature effects on frequency
# For R: typically positive TC
# For C: depends on dielectric (ceramic caps often negative TC)
# Overall: aim for temperature-compensated design
temperature_freq_drift = oscillator_params['temperature_coeff'] * (max_frequency - min_frequency)  # Simplified model

# Calculate power consumption
quiescent_current_opamp = 0.002  # 2mA typical for precision op-amps
supply_voltage = oscillator_params['op_amp_supply']
power_consumption = 2 * supply_voltage * quiescent_current_opamp  # Dual supply

# Evaluate design performance against requirements
gain_error = abs(actual_gain - required_gain) / required_gain
freq_error = abs(actual_frequency - oscillator_params['target_frequency']) / oscillator_params['target_frequency']

Design a Wien bridge oscillator circuit and analyze its performance characteristics.

Hint:

  • Use the Wien bridge relationship f = 1/(2πRC) for frequency determination
  • Maintain gain of exactly 3 for stable oscillation
  • Consider amplitude stabilization to reduce distortion
  • Evaluate temperature and component tolerance effects
# TODO: Calculate oscillator design parameters
resistor_value = 0    # Ohms (value for R in Wien bridge)
capacitor_value = 0   # Farads (value for C in Wien bridge)
actual_frequency = 0  # Hz (calculated frequency with selected components)
feedback_resistor = 0  # Ohms (Rf for gain setting)
input_resistor = 0    # Ohms (R1 for gain setting)
amplitude_stability = 0  # 0-1 metric for amplitude stability
frequency_stability = 0  # 0-1 metric for frequency stability
power_consumption = 0    # Watts (total power consumption)

# Calculate component values for target frequency
R_target = 10e3  # Start with 10kΩ as standard value
C_target = 1 / (2 * math.pi * oscillator_specs['target_frequency'] * R_target)  # F

# Select closest standard capacitor value
# Standard capacitors: 1pF, 10pF, 100pF, 1nF, 10nF, 100nF, 1µF, 10µF, etc.
capacitor_values_std = [1e-12, 10e-12, 100e-12, 1e-9, 10e-9, 100e-9, 1e-6, 10e-6, 100e-6]
closest_cap = min(capacitor_values_std, key=lambda x: abs(x - C_target))

# Recalculate with standard value
actual_frequency = 1 / (2 * math.pi * R_target * closest_cap)

# For Wien bridge oscillator, gain must be exactly 3
# Using resistive feedback: gain = 1 + (Rf/R1)
R1_target = R_target  # Same as R in bridge for symmetry
Rf_target = (oscillator_specs['feedback_ratio'] - 1) * R1_target  # Required for gain of 3

# Select standard resistor values
resistor_values_std = [1000, 1500, 2200, 3300, 4700, 6800, 10000, 15000, 22000, 33000, 47000, 68000, 100000]
feedback_resistor = min(resistor_values_std, key=lambda x: abs(x - Rf_target))
input_resistor = min(resistor_values_std, key=lambda x: abs(x - R1_target))

# Calculate actual gain
actual_gain = 1 + (feedback_resistor / input_resistor)

# Calculate stability metrics
amplitude_stability = 1.0 / (1 + abs(actual_gain - oscillator_specs['feedback_ratio']))  # Higher gain error = lower stability
frequency_stability = 1.0 / (1 + abs(actual_frequency - oscillator_params['target_frequency']) / oscillator_params['target_frequency'])

# Calculate power consumption
# Assume op-amp draws quiescent current
opamp_quiescent_current = 0.004  # 4mA for a decent op-amp
power_consumption = 2 * oscillator_params['op_amp_supply'] * opamp_quiescent_current  # Dual supply

# Print results
print(f"Oscillator design results:")
print(f"  Calculated R value: {R_target/1e3:.1f} kΩ")
print(f"  Selected C value: {closest_cap*1e9:.2f} nF")
print(f"  Actual frequency: {actual_frequency:.2f} Hz")
print(f"  Target frequency: {oscillator_params['target_frequency']} Hz")
print(f"  Required gain: {oscillator_params['feedback_ratio']:.1f}")
print(f"  Actual gain: {actual_gain:.3f}")
print(f"  Feedback resistor: {feedback_resistor/1e3:.1f} kΩ")
print(f"  Input resistor: {input_resistor/1e3:.1f} kΩ")
print(f"  Amplitude stability: {amplitude_stability:.3f}")
print(f"  Frequency stability: {frequency_stability:.3f}")
print(f"  Power consumption: {power_consumption*1000:.2f} mW")

# Design assessment
if abs(actual_frequency - oscillator_params['target_frequency']) / oscillator_params['target_frequency'] < 0.05:
    frequency_accuracy = "Good - within 5% of target"
elif abs(actual_frequency - oscillator_params['target_frequency']) / oscillator_params['target_frequency'] < 0.1:
    frequency_accuracy = "Acceptable - within 10% of target"
else:
    frequency_accuracy = "Poor - significant deviation from target"

print(f"  Frequency accuracy: {frequency_accuracy}")

if abs(actual_gain - oscillator_params['feedback_ratio']) / oscillator_params['feedback_ratio'] < 0.05:
    gain_accuracy = "Good - gain within oscillation requirements"
elif abs(actual_gain - oscillator_params['feedback_ratio']) / oscillator_params['feedback_ratio'] < 0.1:
    gain_accuracy = "Marginal - gain near oscillation requirements"
else:
    gain_accuracy = "Poor - gain outside oscillation requirements"

print(f"  Gain accuracy: {gain_accuracy}")

# Recommended improvements
improvements = []
if actual_frequency != oscillator_params['target_frequency']:
    improvements.append(f"Tune R or C to achieve exact {oscillator_params['target_frequency']} Hz")
if actual_gain > oscillator_params['feedback_ratio'] * 1.1:
    improvements.append("Reduce gain to prevent excessive distortion")
elif actual_gain < oscillator_params['feedback_ratio'] * 0.95:
    improvements.append("Increase gain to ensure oscillation starts")
    
print(f"  Recommended improvements: {improvements}")

How would you modify your oscillator design to achieve better frequency stability over temperature variations?

ELI10 Explanation

Simple analogy for better understanding

Think of analog and digital electronics like the difference between a dimmer switch and a regular on/off light switch. An analog system is like a dimmer switch where you can adjust the brightness to any level in between - it's like a smooth slider with infinite positions. A digital system is like a simple on/off switch where the light is either fully on or fully off - there are no in-between states. In electronics, analog devices handle signals that can have infinite values (like how loud a sound is or how bright light is), while digital devices only handle signals with discrete values (like on/off or 0/1). Transistors are like electronically-controlled switches and amplifiers (they can amplify small signals like a microphone to make them loud like a speaker), diodes are like one-way valves that only let electricity flow in one direction, and operational amplifiers (op-amps) are like super-powered amplifiers that can perform mathematical operations on electrical signals. Logic gates are like simple decision-making blocks that perform logical operations (like 'if A is true AND B is true, then output is true'). It's like having a toolbox where analog components handle smooth, continuous signals while digital components handle binary on/off decisions and calculations.

Self-Examination

Q1.

What are the key differences between BJT and FET transistor operation?

Q2.

How do feedback circuits improve operational amplifier performance?

Q3.

What factors determine the switching speed of digital logic gates?