from IPython.core.display import HTML
def set_width(width):
display(HTML(f"""<style>
.container {{ width:{width}% !important;
min-width:800px !important; margin: 0 auto}}
.jp-Cell {{ width:{width}% !important;
min-width:800px !important; margin: 0 auto}} </style>"""))
# Set container width to X% of the fullscreen
set_width(50)
11B: Diode rectifier#
Learning goal: Explain and understand fundamental properties of diode circuits
Structure of an experiment:
Background+Anticipate+ Simulate: per person; 45 min.
Implement + Investigate: with your partner (group of 2); 40 min.
Compare + Conclude: with a group of 4 (per table); 10 min
Extra information or hints is given in boxes denoted by: ℹ️
Help fixing progrems is given in boxed denoted by: 🔥
Materials used:
ALPACA
A diode
A capacitor of 47 \(\mu\)F
A resistor of 1k \(\Omega\)
A red LED
Background: LED and rectifier#
⏳ Estimated time: 5 min
During this exercise you will explore the functioning of a diode in different circuits. For this purpose, you will mostly be using a specific type of diode called a Light Emitting Diode (LED). An LED functions just like any other diode, with the added functionality of creating light when a current flows through it. The ALPACA has many LEDs already available on board, and you’ll use these in circuits. A difference between a LED and other diodes is the voltage drop - LED’s is higher at around 2V (depending on a LED type and manufacturer).
You already know that a capacitor has a frequency dependent impedance. It ‘blocks’ low frequency signals. When combining a clipper with a capacitor, you can make use of the frequency dependent impedance, and build a rectifier. In this experiment we will look at a half-wave rectifier, which makes a DC signal from AC input.
Anticipate: LEDs and a Rectifier#
A) Predict the blinking behavior of the LED in the circuit below with an input (at DAC A) of a square wave with a \(V_{min}\) of 0 and \(V_{max}\) of 1 V. Explain which of the following answers is correct:
no led will turn on
only led A will blink
only led C will blink
both leds blink at the same time
the leds blink alternatingly (either one on at any point in time)
B) Do the same prediction but with with a different input signal: \(V_{min}\) of -10 V and \(V_{max}\) of 10 V.
C) What will be the output voltage, Vout0 ?

For the exercise C you might want to read the rectifier book section (see scheme on BrightSpace)
### TO DO ="your prediction + reasoning"
Note: In a half wave rectifier only half of the sine wave passes through a diode, charging the capacitor. In the rest of the remaining period the capacitor will discharge, leading to the characteristic output signal.
Simulate: half-wave rectifiers in LTSpice#
⏳ Estimated time: 15 min
Put the above rectifier circuit (C) in LTSpice. Insert your screendumps of the LTSpice circuit+simulated signals.
from ipywidgets import FileUpload
from IPython.display import Image
upload=FileUpload()
upload
import os
file_name="LTS05e_third_sim_diode_rectifier.jpg"
if upload.value!={}:
with open(file_name,"wb") as f:
try: f.write(upload.data[-1]) # python 3.7 Kernel code, not working on Vocareum
except: f.write(upload.value[-1]["content"]) # python 3.8 Kernel code, not working on Vocareum
Image(filename=file_name, width="50%")
The following movie gives more info for the simulation.
%python
# diode rectifier 1b
from IPython.lib.display import YouTubeVideo
YouTubeVideo('Pcwxl9ofFHE', width = 600, height = 450)
Implement & investigate 1: directionality and polarity of LEDs#
⏳ Estimated time: 25 min
1a Implement the circuit#
You can use the LEDs that are present on the Alpaca to test the directionality and the polarity. Implement the circuit below.
ℹ️ Hints schematic
In order to test this circuit you will write some Python code. Part of it is al ready written, but you will have to complete it. The code can be found in the cells below.
The code must be able to make a square wave ranging from 0 to 3 V. For the frequency, we will select a frequency at which we can easily see the changes in the LEDs by eye, say 1 Hz. You can do this using the function generator and the DAC A output. You must be able to set a certain frequency for this square wave.
Do not yet perform a measurement using the analog in pins during this first part of the exercise.
Part of the code is already written for you in the cells below. Comments with instructions are given at the places where you should complete it.
ℹ️ To refresh your memory, the syntax for the function generator was:
from functiongenerator import FuncGen, Square with FuncGen(Square(Vpp=X, offset=Y, freq=Z)): # Do stuff here
%serialconnect to --port="COM3"
#ADD COM PORT ABOVE, e.g. --port="COM3"
import time
from functiongenerator import FuncGen, Square # type: ignore
'''
Fill in a desired frequency and a duration
'''
FREQ = None # Frequency of the measurement, in Hz
DURATION = None # Duration of the measurement, in seconds
'''
Add the correct Vpp, offset, and frequency
'''
with FuncGen(Square(Vpp=None, offset=None, freq=None)):
'''
Think of how we can have the square wave be on for the time specified by DURATION.
'''
pass
ℹ️ Hints Thinking of what to put inside the
withstatement? Remember that thewithfunction stops whenever the code inside thewith(so whatever is indented) is finished.
1b describe the LED blinking pattern#
Describe the blinking patterns of the LEDs (are they alternating or do they blink simultaneously)? Is this what you expect, note that the orientation of both LEDs is the same (unlike the above prediction)?
# Describe the blinking patterns of the LEDs(are they alternating or do they blink simultaneously)? Is this what you expected?
# write your answer here
### TO DO="Describe the blinking patterns of the LEDs. Did you expect this pattern?"
📝 Todo:
You are going add a slight change to the circuit now. Implement the circuit below. Note that you only have to switch the wires on LED3-A and LED3-C in order to build the new circuit.
You can use the same code you wrote in the previous exercise. Keep the frequency at 1 Hz.
1c blinking for different LED orientations compared#
A) Check you prediction for two LEDs with opposite orientation (exercise 1A)
B) Observe how the blinking pattern changed compared to the previous exercise.
C) Explain the difference between the blinking patterns of exercise 1 & 2?
### TO DO="explain the differences between blinking in 1a and 1b "
ℹ️ Hints Did you expect both LEDs to blink in an alternating fashion? Why did that not happen?
1d signal through DAC assistant#
Let’s change the circuit a slight bit again . Instead of using the output from the DAC A pin directly, we pass it through the DAC Assistant on the ALPACA.
Wire the signal of pin DAC A to the +IN port of the DAC assistant (right top of the ALPACA board, see image below). The output signal is now generated at the pin called OUT. Also see the circuit below.
Note that for this part of the exercise both USB cables must be connected. Turn the two switches for the +12V >ON and -12V >ON supplies on, their indicator LEDS will glow now.
ℹ️ Hints The ALPACA manual states that the the DAC assistant converts an input from 0 to 4.096 V, to an output voltage range of -10.24 to +10.24 V
Because you’re using the DAC assistant on the ALPACA, the square wave you create using the function generator will be turned into a square wave of the same frequency, but with a voltage from -10 to +10 V. You can see that your voltage range changed by using the voltmeter on the Cria, but avoid connecting your signal to any of the input pins of the Pico, this voltage range is harmful for your it!
Observe the blinking pattern of the LED by running the code you wrote previously. What happened, and can you explain why this happened?
### TO DO="describe and explain the blinking"
1e frequency of the LED#
Increase the frequency in the code. Determine the highest frequency at which you can still observe the blinking of the LEDs. Why can you no longer seperate the blinking of the LEDs at high frequencies?
### TO DO="for which frequency you cannot see blinking anymore, and why?"
Implement & investigate 2: half-wave rectifier#
2a. build the setup#
⏳ Estimated time: 15 min
Now we are going to build the last circuit for this exercise.
Unplug your ALPACA. (Always recommended when rebuilding)
For this purpose, do not use one of the LEDs on the ALPACA, but take the red LED that was supplied to you together with the capacitors and resistors.
Note that you’ll no longer be needing the DAC Assistant
Build the circuit below using the breadboard on the ALPACA.
ℹ️ Hints Detailed fritzing
2b. do the measurement#
The code for this exercise is already written for you, it generates a sine wave. Execute it by running the cell below. Both the input and output signal of the circuit will be measured.
ℹ️ Hints Remember that the long leg of the capacitor and the LED correspond to the positive side (anode).
%serialconnect to --port="COM3"
#ADD COM PORT ABOVE, e.g. --port="COM3"
import time
import numpy as np
from machine import ADC # type: ignore
from functiongenerator import FuncGen, Sine # type: ignore
NUM_SAMPLES = 100
DELAY_MS = 1
adc0 = ADC(26)
adc1 = ADC(27)
input_signal = np.zeros(NUM_SAMPLES)
output_signal = np.zeros(NUM_SAMPLES)
with FuncGen(Sine(Vpp=3, offset=1.5, freq=20)):
time.sleep(0.5)
for ii in range(NUM_SAMPLES):
input_signal[ii] = adc0.read_u16()
output_signal[ii] = adc1.read_u16()
time.sleep_ms(DELAY_MS)
input_signal = input_signal / 65535 * 3.3
output_signal = output_signal / 65535 * 3.3
import matplotlib.pyplot as plt
plt.plot(input_signal, label='Input signal')
plt.plot(output_signal, label='Output signal')
# plt.plot(output_signal + 0.7, label='Output signal + 0.7 V')
plt.ylabel('signal [V]')
plt.xlabel('Measurement number')
plt.legend()
🔥
If the values of the input/output signal are lower than you expect, please check that there are no jumpers on AMPLIFIER DIRECT TO NANO (slot on the right of the Cria-Pico Pi converter)
You might have noticed that the output is lower than you might expect. That has to do with us using LEDs instead of simple diodes. LEDs have a higher voltage drop.
2c explain plus test the dependency on the capacitor value#
A) Explain the shape of the output signal
B) Test what will happen with the ripple voltage if you increase the capacitance of the capacitor
### TO DO="Explain the shape of the output signal, how does this depend on the capacitance value?"
Compare and conclude#
⏳ Estimated time: 10 min
Wait till all (4) group members finish their observation
Compare your results with your other group members.
If your results agree, and are in line with all predictions, then talk to a TA and get checked off
Otherwise, so if your results do not agree, or your results are not in line with your predictions, then first discuss amongst your group before getting a TA.
to be checked off by a TA:
explain why this rectifier is a half-wave rectifier?
For the half-wave rectifier, discuss the effect of a (bigger) capacitor.
exit card:
Write a brief abstract on what you learned (conclusion, useful graph),
Which troubleshooting skills do you want to remember for next sessions,
Which code do you copy for use in next sessions,
How do you think this notebook could be improved
#11B diode rectifier
### TO DO ="1. explanation why this rectifier is a half-wave one"
### TO DO="2. Explain the effect of a larger capacitor"
### TO DO="3a. abstract"
### TO DO="3b. troubleshooting"
### TO DO="3c. code"
### TO DO="4. what changes would you suggest?"
%rebootdevice
%disconnect
Recording: https://www.youtube.com/watch?v=YevPm66rgGg