For use with: Student’s laptop
and Alpaca kernel
Complete this notebook before the practical session.
REQUIREMENT: Work together with your partner.
There will be enough time to complete this notebook during the classroom session if you and your partner could not meet to work together.
16B: Oscillator - Simple Relaxation Oscillator#
Learning goal:
Build a Simple Relaxation Oscillator
Perform Unit Tests on individual components of the Oscillator
Timing of this experiment:
5+30+30+5+5 = 75 min
This is a challenging assignment. Please support your partner in solving problems.
IMPLEMENT & INVESTIGATE - Part A: Simple Relaxation Oscillator#
⏳ Estimated total time: 75 min
Overview of the circuit#
⏳ Estimated time: 5 min
The challenge starts here. Drafting a blueprint is a good first step to get an overview of the implementation. This time we prepared it for you as an example and an inspiration.
Implementation blueprint: Light-sensing Relaxation Oscillator
Start the assembly of the oscillator from building and testing the Integrator. Plan the placement of its components on the white breadboard (also known as the “Sandbox”) to make adding and testing the Comparator unit, as well as the Feedback Line, a straightforward task in the later stages of your build. We suggest that you build the Illumination Station on a separate breadboard - the black mini breadboard to avoid a densely wired setup in the later stage of this assignment.
In PART A of the Implementation, the emphasis is placed on ensuring that each component of the Oscillator works as expected before it is integrated further into the larger, more complex assembly. This procedure is commonly called “unit testing”. The suggested workflow in this assignment includes planning, unit testing, and journaling, and it demonstrates a good practice.
Implement 1 - The Integrator#
⏳ Estimated time: 30 min
Building the integrator on your ALPACA is simple, but testing will require some additional components that won’t be a part of the final setup, so make a note of what has to stay, especially when removing the components of the test setup afterwards.
ℹ️ Hint
Layout Table
Make a table, a spreadsheet (or download a template from Brightspace) with for example, 11 rows (index 20 to 30) and 10 columns (a to j) - the addressing of the lower part of the Alpaca’s Sandbox. Use it to store the labels of your build layout,
like+12V,Vout,VoutOA1,VinOA2,Ra=3.3k,C=470nFetc.
It might happen that this part of your Alpaca’s sandbox has some loose connections. In that case, consider moving your layout to the higher rows or to an external mini breakout box.
Build the Integrator#
List of components for the Integrator:
OPAMP
Use the left hand side OPAMP (OA1 = CH1) for the Integrator.
Opamp pin layout
Capacitor, we suggest the 470 nF (blue one), but feel free to choose any other one.
ℹ️ Detailed schematic of the suggested Integrator placement
Test the Integrator#
If you would like to develop your own creative technique to test the integrator, feel free to go ahead on your own from now on and report your ideas and findings. The following procedure and the code are only a suggestion.
Perhaps you realised already that you will need to implement a temporary method for discharging the capacitor to test the Integrator before all parts of the oscillator are complete. For example, you could short the capacitor manually by using switch SW3 and monitor the output voltage of the Integrator.
Example: Integrator Test Procedure#
You could use the idea for a test setup shown in the image below.
Schematic for the Integrator test
List of components for Unit Testing of the Integrator:
Signal source - Option A 1. DAC A Output 2. Alpaca’s Potmeter (
J13) or a large resistor of your choiceR > 100k- Option B 1. +5V output of the Playground (headerJ8) 2. Alpaca’s Potmeter (J13) or a large resistor of your choiceR > 100kManual discharge method - Use the pins SW3-A and SW3-B at the ALPACA PLAYGROUND to connect the switch.
Output voltage monitoring on
VoutOA1- Live plot of measured signal - Cria’s voltmeter
ℹ️ Hints for Testing
Option A
Use the PicoPi’s DAC A output to set a DC Voltage and the PicoPi’s ADC input to record the signal using the liveplot. This is a more flexible, quantitative and tunable test method, but be careful here! The output signal of the Integrator is negative.
Use the Alpaca’s amplifier viaSIGNAL-pin of theADC0atJ40. Additionally, place a jumper onSIGNAL+andGNDofJ40.ℹ️ Detailed schematic of the suggested Integrator Test: Option A
Integrator Test Layout - Option A. Source: `DAC A`, Measure via `ADCO: SIGNAL-`
Option B
Use the Alpaca’s DC source via the Potmeter and the Cria’s Voltmeter to observe the action of the integrator. This qualitative option is quick to set up, but it might be too inaccurate depending on your choice of the resistor and the capacitor. This might be a trap! ;) If you decide to go for it, make double sure that you connected the Potmeter correctly.ℹ️ Detailed schematic of the suggested Integrator Test: Option B
Integrator Test Layout - Option B: Source: `J8: +5V`, Measure via `Voltmeter`
To test the Integrator, evaluate (qualitatively):
Do you observe the expected action of the integrator when you manually discharge the capacitor?
Make a note of how the charging/switching time is controlled by the value of
the Input signal
the Input Resistor
the Capacitor
Optional: Estimate the range of values of the charging/switching that is reasonable for the purpose of this Oscillator.
Remember that you could always simulate some ideas with LTSpice, but at this point a qualitative evaluation is sufficient. For a more realistic quantitative simulation, more information about the photocurrent from the illumination station would be required.
Make sure you keep track of what elements are staying in the breadboard and which elements are there only for the test. The code in the three (hidden) cells below should be familiar to you. Feel free to adapt it for your test.
# Initialize the connection with your Alpaca
%serialconnect to --port="COM4"
%plot --mode live
import time
import numpy as np
import matplotlib.pyplot as plt
from machine import ADC # type: ignore
from functiongenerator import FuncGen, DC, Sine # type: ignore
# Instantiate a measurement pin Ain0 for the output signal
adc0 = ADC(26)
# The other pin can be instantiated with the following line:
# adc1 = ADC(27)
# Define the sampling frequency and the duration of the experiment
DELAY_MS = 50
NUM_SAMPLES = 200
# Initialize the array for the acquired signal
output_signal = np.zeros(NUM_SAMPLES)
# Start the measurement
with FuncGen(DC(V=0.5)):
time.sleep_ms(100)
for ii in range(NUM_SAMPLES):
# Take a sample ever 20 ms (e.g. at 50 Hz)
sample = adc0.read_u16()
output_signal[ii] = sample
if (ii % 5) == 0 :
# Plot 1 in 5 samples to the live plotter (e.g. with a frequency of 10 Hz)
plt.liveplot(sample*3/2**16, labels = ['Output [V]'])
time.sleep_ms(DELAY_MS)
print('Acquisition done!')
# Plot the complete acquisition, without dropped datapoints like in the code above
output_signal = output_signal / 65535 * 3.0
plt.plot(output_signal)
plt.plot([0],[0]) # Lazy trick to get the X-axis in the plot
plt.ylabel('Output [V]')
plt.xlabel('Sample number')
### Notes: Integrator Test
Implement 2: The Comparator#
⏳ Estimated time: 30 min
Carefully remove the wiring of the temporary components used to test the Integrator and make sure that only the Integrator components are present in the Sandbox. If you followed the suggested layout, you should only have: the OPAMP, the Capacitor, +12V and -12V power supply wires in the Sandbox.
⚠️ WarningRemember to turn off the Alpaca’s +12V and -12V switches for safety during the (dis-)assembly.
Add the components of the Comparator with the chosen resistors. Do not connect Ra to the line with the Integrator’s output VoutOA1, and make sure to make a note of your temporary layout to maintain the overview of your growing circuit. It’s recommended to dedicate one row in the Sandbox for the node between VoutOA1 and Ra, but do not yet connect VouOA1 to this line. You will test the Comparator separately first with an external signal injected into the Comparator.
The test will not work if
Rais connected to the Integrator’s outputVoutOA1.
Build the Comparator#
List of components of the Comparator
The right-hand side of the OPAMP (OA2 = CH2) in the Sandbox
OPAMP pin layout
Resistors
RaandRbof your choiceℹ️ Hint
The ratio
Ra:Rb*12sets the Comparator’s switching threshold on the nodeVinOA2.
Is a very high threshold or a very low threshold preffered for your oscillator?
The answer to this question will determine the quality of the signal for your final measurement. The suggested values for the resistors are:Ra = 1k or 3.3kRb = 5k or 10k
If you are struggling to choose a set of resistors:RaandRb, have a look at the default choices in the LTSpice Simulation as the starting point, and test some choices in the simulation! You may also have a look into the setup of the testboard from week 14 for some ideas. The threshold in that case was approx. 4V, but is there anything that stops you from using a higher threshold here?
ℹ️ Detailed schematic of the suggested Comparator placement
In this example, we dedicate the line
22a:22efor the node between the Integrator and the Comparator, which are not yet connected.
Test the Comparator#
This time, it’s your task to define the PASS/FAIL condition.
Write down your observations and the conclusions from the test: PASS/FAIL?
Example: Comparator Test Procedure#
List of components for Unit Testing of the Comparator:
Signal source on
VinOA2- Option A: DAC A with the DAC Assistant - Option B: 1. Alpaca’s Potmeter (J13) Warning! Read the hints 2. +12V and -12V power supplyOutput voltage monitoring on
Vout- Live plot of the measured signal via amplifier/attenuator - Cria’s voltmeter
ℹ️ Hints for Testing
Option A
Use an already familiar method: Use PicoPi’s DAC A output and the DAC Assistant to generate a triangle wave with positive and negative voltages to mimic the real input of the oscillator on theVinOA2node.
Feel free to have a look into the LTSpice simulation for a visual proof that it is the case. Use the code below adapted from “13 C: Integrator and Comparator” to convert DAC A voltage to a required DAC Assistant output.
This is a more flexible, quantitative and tunable test method, but be careful here!
Use PicoPi’s 1:10 attenuated ADC0 SIGNAL+ input pin to record the
Voutsignal, and feel free to enable the offset potentiometerOFFSET0by placing a jumper onJ44 WITH OFFSET. A good start is always to use 1:10 attenuation first, and then think whether you gain any extra information by using the offset. You can plot the results with live plot making quick adjustments easier.Use PicoPi’s 1:2 attenuated (Jumper Positions:
J62:A,J63:Band,J64:B) ADC1 SIGNAL+ pin (J60) with DC Coupling (J61) to record the reference signal directly from DAC A. You might need to cleverly wire the DAC A to DAC Assistant IN via a line in the Sandbox to measure this signal.
⚠️ Warning:
In the test code below,DAC Ais unlocked to output4V, so measureDAC Anecessarily with attenuation 1:2!
The signal measured fromDAC AwithADC1is converted to the value expected at DAC Assistant’sJ15:OUTwith the formula:
J15:OUT= 5* (DAC A- 2.048)
which is equivalent to measuringDAC Assistant OUT.
Alpaca configuration for the Comparator test
⚠️ Warning: Option B
Use the Alpaca’s DC +12V and -12V sources via Potmeter and the PicoPi’s Voltmeter to observe the action of the integrator. This qualitative option is quick to set up, but there is a great risk of burning your Alpaca if you make a mistake in your wiring. If you decide to go for it, make double sure that you connected the Potmeter correctly. Use the following layout.J14has three pins:
Connect
J14 left pinto+12VConnect
J14 right pinto-12VConnect
J14 center pintoRa(i.e. line 22d in the Sandbox)
# Initialize the connection with your Alpaca
%serialconnect to --port="COM4"
# Import required libaries, define functions and initialize the measurement pins
import time
import numpy as np
import matplotlib.pyplot as plt
from machine import ADC # type: ignore
from functiongenerator import FuncGen, DC, Triangle, Sine, Square # type: ignore
def convert_DAC_voltage(assistant_v_out):
"""Converts OUT to +IN at DAC ASSISTANT
Finds the correct DAC voltage to get a specific output at the DAC ASSISTANT
"""
assistant_v_in = assistant_v_out / 5 + 2.048
return assistant_v_in
def convert_samples_to_volts(samples, gain=1):
"""Converts integer values to volts
Converts the measurements from the analog input of the ALPACA
into volts. Has an optional parameter `gain` which when set
to the gain of the AMP0/1 will automatically correct for
the applied gain.
"""
return samples / 65536 * 3.0 / gain
# Instantiate a measurement pin Ain0 for the output signal
adc0 = ADC(26)
adc1 = ADC(27)
# This cell can be used for testing the Comparator with OPTION A
# Settings
V_MAX = 10
V_MIN = -10
NUM_SAMPLES = 500
DELAY_MS = 2
Ra = 3.3
Rb = 5
output_signal = np.zeros(NUM_SAMPLES)
input_signal = np.zeros(NUM_SAMPLES)
assert NUM_SAMPLES < 3000, "Error: can't take that many samples!"
with FuncGen(Triangle(
Vmin=convert_DAC_voltage(V_MIN),
Vmax=convert_DAC_voltage(V_MAX),
freq=2, unsafe=1)):
#time.sleep_ms(100)
for i in range(NUM_SAMPLES):
v_out = adc0.read_u16()
output_signal[i] = v_out
v_in = adc1.read_u16()
input_signal[i] = v_in
time.sleep_ms(DELAY_MS)
print('Acquisiton done!')
plt.plot(convert_samples_to_volts(output_signal, gain=0.1), color='r', label='Vout (Comparator Output)')
plt.plot((convert_samples_to_volts(input_signal, gain=0.5)-2.048)*5, color='b', label='Vin (DAC A converted to DAC Assistant OUT)')
#plt.axhline(y=Ra/Rb*10.8, color='g', linestyle='--', label='Expected Switching level')
plt.ylabel("Voltage [V]")
plt.xlabel("Sample number")
plt.grid()
plt.legend()
### Notes: Comparator Test
Implement 3: Simple Relaxation Oscillator#
⏳ Estimated time: 5 min
Barebone Oscillator#
Carefully remove the temporary Comparator test wires and prepare your circuit for the next step.
If you followed the suggested layout, connect the Integrator’s output to the Comparator’s input, using a wire between 22d and 26d, and add a label VoutOA1 in your layout table at these two positions. This setup is a barebone Oscillator that will stay unmodified.

Barebone Oscillator
Double-check your layout and fill the missing node labels into your layout table for future reference. This way, you will be able to confidently return to the default setup or simply pick up just where you paused and focus on the tasks of the IMPLEMENT: Light Sensor.
ℹ️ Detailed schematic of the suggested Barebone Oscillator
Feedback line#
At this point, you are only one step away from building a simple oscillating circuit. Add a feedback line with a Resistor Rc between the output of the Comparator and the input of the Integrator.

Simple Relaxation Oscillator
Option A:
Add a large resistor,
Rc = 100k, orRc = 220kor evenRc = 470k, betweenVoutOA2andVinOA1.
Option B:
Use Alpaca’s Potmeter
J13:centerandJ13:rightpin, to make use of a variable resistor (Rmax = 100k) and connect it betweenVoutOA2andVinOA1.
Test the Simple Relaxation Oscillator#
Measure VoutOA1 with Cria’s Voltmeter, and enjoy the light show!
🏆 Challenge
Try to formulate an explanation:
Why does this circuit oscillate without an external signal source at
VinOA1?Would this circuit still oscillate if the diode
D1was added to the feedback line beforeRf?
Keep your setup for the demonstration during classroom session.
Feel free to make a video recording of your working setup, just in case something goes wrong later. Make sure then to also capture your Alpaca’s number plate in the video for reference.
### Notes: Simple Relaxation Oscillator
Conclude and Discuss#
⏳ Estimated time: 5 min
To be checked off by the TA:
Demonstrate your success and present a functioning Simple Relaxation Oscillator
### Notes: Conclusions





