For use with: Student’s laptop
and
Python 3 (ipykernel)

Complete this notebook before the practical session.

16A: Oscillator - Simulation#

⏳ Estimated total time: 80 min

Experiments for This Week:

  • Oscillator 16A: Before the Classroom Session - Background and Simulation

  • Oscillator 16B: Before the Classroom Session - Assembly and Tests

  • Oscillator 16C: During the Classroom Session - Light Sensor

Learning goal:

  • Understand how a Relaxation Oscillator works and how to tune it.

This is a challenging assignment. Please support your partner in solving problems.

BACKGROUND#

⏳ Estimated time: 20 min

Introduction#

Until now, we have explored circuits that process signals, such as filters and amplifiers. These circuits take an external signal as input, modify it, and provide a processed signal as output. This week, however, we shift focus to a circuit that generates a signal: the relaxation oscillator.

Oscillators play a crucial role in enhancing signal quality, particularly in sensor and signal applications. Sensor outputs are often weak and noisy, which can make data readouts unreliable. By incorporating an oscillator, the sensitivity to noise can be reduced, enabling more robust and accurate sensor data analysis.

What is an Oscillator?#

An oscillator is a circuit designed to generate a repetitive waveform. There are two primary types:

  1. Harmonic Oscillator

    • Produces a clean sine wave.

    • Utilizes an amplifier and a frequency-determining network.

    • When parameters are balanced, the circuit generates a stable sine wave.

  2. Relaxation Oscillator

    • Operates by continuously charging and discharging a capacitor.

    • Various implementations exist, typically charging/discharging between two thresholds (linear or non-linear, e.g., exponential).

    • The output waveform often appears as a distorted triangle.

Focus of This Assignment#

In this assignment, you will

  1. Build a Relaxation Oscillator Circuit: Using an integrator and comparator, you will build a device that exhibits a self-sustained oscillation.

  2. Build a Tunable Light Source: You will assemble an OPAMP-based current-controlled light source. This component is crucial for providing a stable and controllable input for your experiment.

  3. Build a Light Sensor: Combine the oscillator with a photodiode to control the frequency of oscillation with light intensity.

  4. Learn how to plan your workflow for a complex build: This assignment will guide you through a process of simulating, testing and tuning of a complex device.

Relaxation Oscillator - An Oscillator with an Integrator and a Comparator#


Relaxation Oscillator with a light sensor

In this experiment, we will use an OPAMP-based integrator to charge and discharge a capacitor (which is part of the integrator circuit). The cycle operates as follows:

  • The capacitor charges until it reaches one threshold of the comparator.

  • At this point, the comparator switches states, reversing the direction of the charging current.

  • The capacitor discharges until it reaches the other threshold.

  • The thresholds are determined by the feedback network of the comparator.

The comparator is configured such that a negative slope at the integrator’s output corresponds to a positive signal at the comparator’s output.


Oscillator circuit: Charge (left) and discharge (right) cycles

Key characteristics of the circuit#

  1. The voltage across the capacitor (output of the integrator) continuously cycles between two thresholds.

  2. The comparator output also oscillates between two levels (not necessarily matching the integrator’s thresholds).

  3. The charging speed of the capacitor depends on the integrator’s input signal from the photodiode (light intensity) and the capacitor’s properties.

  4. The discharging speed is determined by the current through diode D1 and Rc.

In this experiment, a photodiode is used to generate the charging current as a function of light intensity. To make the circuit dependent only on the photodiode’s intensity, a diode is added so that charging occurs solely via the photodiode.

Note: Swapping the polarity of the photodiode and diode D1 results in a 180-degree phase shift in the oscillation but does not affect the circuit’s functionality.

Summary#

  • Photodiode converts light to a photocurrent.

  • Integrator shapes (integrates) the signal from the photodiode.

  • Comparator acts as a decision-maker, switching based on the integrator’s output.

  • Diode D1 that the capacitor is charged only by the photocurrent.

  • Resistor Rc determines the capacitor’s discharging time.

Current-Controlled LED#

Testing measurement setups often requires a highly controllable input. For this experiment, we use a light source with tunable intensity: an OPAMP-based current-controlled LED driver.


OPAMP-based LED drivers: Current-controlled (left) and Voltage-controlled (right)

We have chosen a current-controlled design to provide precise intensity control for the LED. This design ensures stable and predictable behaviour, which is crucial for testing and debugging your circuit.

Light-Sensing Relaxation Oscillator#

Relaxation oscillator coupled with a photodiode operating in the photocoductive mode can act as a sensor and an analog computer converting light intensity into an oscillation frequency.

The key process to understanding this system is the charging and discharging of the capacitor, controlled by the photocurrent generated by a photodiode and the current through the feedback line.

Oscillation Principle#

ℹ️ Derivation

The oscillation frequency \(F\) is reciprocal of the time it takes for the capacitor to charge and discharge. The total oscillation period \(T\) is the sum of the charging time \(t_{\text{charge}}\) and discharging time \(t_{\text{discharge}}\):

  1. Charging Phase: During charging, the photocurrent (\(I_{\text{photo}}\)) charges the capacitor until it reaches the upper threshold voltage (\(U_{\text{high}} = \frac{R_a \cdot |Uout|}{R_b} \)) of the comparator. The time required is: $\( t_{\text{charge}} = C \frac{U_{\text{high}} - U_{\text{low}}}{I_{\text{photo}}} \)$

  2. Discharging Phase: During discharging, the net current (\(I_{\text{photo}} - I_{\text{d}}\)) discharges the capacitor to the lower threshold voltage (\(U_{\text{low}} = - \frac{R_a \cdot |Uout|}{R_b}\)). The time required is:

\[ t_{\text{discharge}} = C \frac{U_{\text{high}} - U_{\text{low}}}{I_{\text{d}} - I_{\text{photo}}} \]

Substituting into \(T\): $\( T = C \frac{U_{\text{high}} - U_{\text{low}}}{I_{\text{photo}}} + C \frac{U_{\text{high}} - U_{\text{low}}}{I_{\text{d}} - I_{\text{photo}}} \)$

The frequency becomes:

\[ F = \frac{I_{\text{photo}} \cdot (I_{\text{d}} - I_{\text{photo}})}{C \cdot (U_{\text{high}} - U_{\text{low}}) \cdot I_{\text{d}}} \]

and as a quadratic equation of the photocurrent:

\[ I_{\text{photo}}^2 - I_{\text{photo}}\cdot I_{\text{d}} + F \cdot (I_{\text{d}} \cdot C \cdot (U_{\text{high}} - U_{\text{low}})) = 0 \]

Light Intensity Relation#

ℹ️ Derivation

The light intensity \(L\) can be determined from the photocurrent \(I_{\text{photo}}\) using the responsivity \(R_{\lambda}\) of the photodiode: $\( L = \frac{I_{\text{photo}}}{R_{\lambda} \cdot A_{\text{diode}}} \)$

For the SFH 203 photodiode by Osram that we are using in our experiments:

  • \(R_{\lambda} \approx 0.62 \, \text{A/W}\) at 860 nm, which we will approximate as average and constant for the broad white light spectrum of a white 6500K LED. It turns out that this value is significantly lower for a blue LED, and for the light incident at angles higher than \(10^{\circ}\)

  • \(A_{\text{diode}} = 1 \, \text{mm}^2\).

Substituting \(I_{\text{photo}}\) and \(I_d = \frac{U_{out}}{R_c}\), and solving the quadratic equation with the condition \(I_{\text{photo}} < I_{\text{d}}\) yields a formula that gives us parameters for controlling the circuit and calibrating the sensor:

\[ L(F) = \frac{|U_{\text{out}}|}{2 \cdot R_{\lambda} \cdot A_{\text{diode}} \cdot R_c} \cdot \left(1 - \sqrt{1 - \frac{8 \cdot F \cdot C \cdot \frac{R_a}{R_b}}{|U_{\text{out}}| \cdot R_c}}\right) \]

or in a more concise form:

\[ L(F) = \frac{\left(I_{\text{d}} - \sqrt{I_{\text{d}}^2 - 4 \cdot F \cdot C \cdot (U_{\text{high}} - U_{\text{low}}) \cdot I_{\text{d}}}\right)}{2 \cdot R_{\lambda} \cdot A_{\text{diode}}} \]

ANTICIPATE#

⏳ Estimated time: 30 min

Anticipate 1: Planning#

In this assignment, you will be introduced to a workflow designed to prepare you for the complexity of the final assignment. Unlike previous tasks, you will now take on greater responsibility for planning, implementing, and testing individual building blocks of the oscillator— components you are already familiar with but will need to be integrated more thoughtfully before the classroom session.

Maintaining an overview#

  1. Start by thoroughly reviewing the outline of the assignment. This will help you understand the goals of this experiment and allow you to break the project down into manageable tasks.

  2. Optional: Set up an external Layout Table with your partner. This tool might help you:

    • Stay aligned with the outline and maintain an overview across the three parts of this assignment.

    • Record your questions, observations, progress, results, and circuit schematics.

      Pro Tip: As your circuit expands, having clear and updated schematics will become essential for troubleshooting and success.

      Find a proposed minimal template for a Layout Table on Brightspace

In the following part, Anticipate 2, we will highlight the end goal of this assignment to guide you through this experiment. In Anticipate 3, we will suggest a practical starting point for understanding how the circuit works.

This approach is designed to help you stay organized and confident as the complexity of the project increases. Remember, thoughtful preparation now will save you time and effort later!

Anticipate 2: Light Sensor#

Think how to operate your relaxation oscillator light sensor and how to extract information about the intensity of light detected by the photodiode.

The goal of this exercise is to get an overview of the programming task during the implementation part, so in the cell below, outline the essential conceptual (programming) steps for your final measurements to extract the light intensity from the measurement.

ℹ️ Hint

Note that for this task, it is not yet necessary to fully understand how the oscillator works, and you only need one new piece of information, which you might have already concluded from the Background section.

The frequency of the relaxation oscillator is a function of the photocurrent.

You might find it useful to review some of the previous assignments to brush up your knowledge on two further pieces of information:

  • Using a photodiode as a sensor

  • Measuring the frequency of an analog signal

Feel free to retrieve your previously written code that you used to analyze the frequency of a time-based signal and remind yourself of the essential steps that you are already familiar with.

ℹ️ The story of why we ask you for the outline of your code and not the code

We will rely only on the Alpaca kernel in this assignment, and it turns out that the limitations of the Micropython implementation in the Alpaca firmware and the limitations of our customizations in the basic PicoPi firmware prevent us from using the typical Python code that you had seen before.

Since some of the usual numpy modules are not implemented on Alpaca, we need new functions to be written from scratch.

This is not an unusual scenario in a research lab, so imagine that you are writing this outline or pseudocode for a colleague who knows and manages the Alpaca, and you are asking them to implement the code for you.

In short, this is an exercise in planning and communication!

### BEGIN SOLUTION="Outline your code or write the pseudocode you want to use"

## Hints: 
## 0. Set the LED brightness ... 
##         Manually or programatically?
## 1. Perform the measurement ...
##         Which signal? Where to measure? Which input?
## 2. Display the signal to ensure it is what's expected
## 3. Extract ...
## 4. ...        

# Remark: the actual code will be given out later

### END SOLUTION

Anticipate 3: Signals in the Circuit#


Light-controlled Relaxation Oscillator circuit. The photodiode (left) is illuminated with a light source.

Write down your conclusions from the following tasks:

  1. Examine the circuit above and predict the polarity of the voltages at the following nodes during the charging and discharging phases of the oscillator:

    1. Input and Output voltage of OA1: VinOA1 and VoutOA1

    2. Input and Output voltage of OA2: VinOA2 and Vout

    3. Voltage over the diode D1: VD1

    ℹ️ Hints
    • Review the diagram in the Background section illustrating the capacitor’s charge and discharge behavior.

    • Think about the time scales and the direction of current flow.


  2. Identify when the diode is conducting.

  3. Compare the durations of the capacitor’s charging and discharging phases.

In the next part, you will verify your predictions using LTSpice simulations and compare them with your experimental measurements.

### BEGIN SOLUTION=" which signals do you expect, how do the voltage and current change in time"
# 1

# charging: 
# discharging:

#2

#3

### END SOLUTION

SIMULATE#

⏳ Estimated time: 30 min

Simulating your oscillator in LTSpice will help you understand the action of the individual components and guide your decision to choose values of the resistors \(Ra, Rb, Rc\) and the capacitor \(C1\) much quicker and safer than by swapping them on your Alpaca during the practical. In fact, the process suggested here will also help you understand what output signals you should expect from your oscillator. You might be surprised how well this simulation agrees with the behavior of your circuit (also quantitatively!).

If you would like to practice building circuits in LTSpice, use the schematic below as a reference. Otherwise, download the circuit of the oscillator already implemented in LTSpice from Brightspace(‘week16’) and simulate the behavior of the oscillator.

       
    LTSpice implementation of a relaxation oscillator

Note that the action of the photodiode is simulated with a DC source, a noisy DC source and a resistor Rphoto.

Explore#

  1. Run the transient analysis and plot VoutOA1, VinOA2, Vout, VD1 with the default settings. Write down your observations.

    ℹ️ Hints
    • Display only one or only a few traces at a time for better readability, or focus on VoutOA1 and Vout for your further analysis.

    • Voltage source V3 regulates I(Rphoto) which corresponds to the photocurrent Iphoto in the real circuit.

    • Noisy DC source mimicks the photocurrent noise in the real circuit, and it is required to kick start the oscillation in the simulation.

  2. Remove all traces, and plot I(D1), I(C1), I(Rphoto), and VoutOA1 with the default settings. Write down your observations.

Again, remove all traces. Apply the following changes, run the simulations, and write down your observations for each measurement. Use the table from the template on Brightspace to organise your observations:

  • Display VoutOA1, Vout, and add I(C1) and I(D1) to easily identify the charging and discharging phase, and feel free to add or remove some other traces temporarily if you find it more insightful.

  • Remember to restore the default values before moving on to the next step

  1. Change the orientation/direction of V3 and D1.

  2. Change C1 from 470n to 220n.

  3. Change the value of V3 from 1V to 0.2V, and then to 2V.

  4. Change Rc from 10k to 50k and then to 100k.

  5. Change Rb from 5k to 10k.

  6. Short circuit the noisy DC source.

Conclude#

Your answers to the following questions will be checked by the TAs at the beginning of the classroom session.

  1. How does the orientation of V3 and D1 affect the operation of the oscillator, and what is the condition for their polarity with respect to each other?

When answering the following questions, keep in mind that your end goal is to extract the frequency of oscillation from the voltage measurement while illuminating the photodiode with light at a range of intensities, so effectively, to operate a light intensity sensor.

  1. How do values of C1, Rc and V3 affect the frequency of oscillation?

  2. How does the ratio Ra:Rb, and more precisely the value of Rb, affect the frequency and the amplitude of the signal at VoutOA1?

  3. Which point in the circuit: VoutOA1, VinOA2, Vout, VD1 is the most suitable for a measurement that can be used to digitally extract the oscillation frequency?

    • List some arguments for and against each point regarding the shape and the amplitude of the signal and the limitations of Fast Fourier Transform.

    It may seem that all of them should work, but only one will give us a reliable signal for FFT. Can you already understand why?

  4. What voltages are expected at the selected point, and how will you measure that signal?

  5. Did you notice that some combinations of settings suppress the oscillation? What conclusions for your implementation can you make from this observation?

## Conclusions from the simulation

1.

2.

...

Conclude & Discuss#

⏳ Estimated time: 10 min

To be checked off by the TA:

  1. Present your conclusions (1 to 6) from the Simulate: Conclude section.

### Notes