This document contains code for a web application that allows users to generate and view circles based on radius, color, and fill criteria. It includes code to:
1) Create a web page form to accept circle criteria input from users.
2) Connect to a SQLite database to query for and retrieve circle objects matching the given criteria.
3) Draw the matching circles on an image using PIL and display the image on a results page.
14. #curs.execute("create table circles (x integer, y integer, r
integer, color text, fill integer)")
#circlist = []
#for i in range(0,100) :
#circlist.append((random.randint(0,600),
random.randint(0,400), random.randint(5,50),
random.choice(["red","blue","green","yellow","orange","purple"
,"pink","black"]), random.randint(0,1)))
#curs.executemany("insert into circles (x,y,r,color,fill) values
(?,?,?,?,?)", circlist)
#db.commit()
data = curs.execute("select * from circles where r > 25 or fill
== 1 order by r desc")
for item in data :
print("x =", item[0], "y =", item[1], "r =", item[2], "color
=", item[3], "fill =", item[4])
db.close()
showcircles(1).py
#!/usr/local/bin/python3
import tkinter
import tkinter.messagebox
import math
import sqlite3
import random
15. random.seed()
def createdb() :
db = sqlite3.connect("circles.db")
curs = db.cursor()
curs.execute("create table if not exists circles (x integer, y
integer, r integer, color text, fill integer)")
circlist = []
for i in range(0,100) :
circlist.append((random.randint(0,600),
random.randint(0,400), random.randint(5,50),
random.choice(["red","blue","green","yellow","orange","purple"
,"pink","black"]), random.randint(0,1)))
curs.executemany("insert into circles (x,y,r,color,fill)
values (?,?,?,?,?)", circlist)
db.commit()
db.close()
def selectdb() :
db = sqlite3.connect("circles.db")
curs = db.cursor()
query = "select * from circles where r >= " +
str(radius.get())
if color.get() != "none" :
query += " and color == '" + color.get() + "'"
if checkfill.get() != -1 :
21. Michael Lay
G00129687
Lab 2
Grantham University
Introduction
The purpose of this lab exercise is to build a half wave rectifier
and a full wave rectifier in MULTISIM and on a breadboard.
The various output voltage are to be measured. The myDAQ is
to be used for data acquisition from the breadboard to the
MULTISIM software. The calculate values are to be compared
with the measured values to check for consistency.
Equipment/components used
Materials:
1. Simulated Parts (Multisim):
1. 10:1 center-tapped transformer
22. 1. Two diodes 1N4001
1. Two 2.2 kΩ resistors
1. One 100 μF, 50 V electrolytic capacitor
1. One fuse (any rating is fine since it is for simulation only)
1. Hardware Parts (In the Toolbox):
1. Two diodes 1N4001
1. Two 2.2 kΩ resistors
1. One 100 μF, 50 V electrolytic capacitor
1. Virtual Instruments (Multisim):
1. Function Generator (Multisim)
1. Function Generator (NI Elvisms Instrument Launcher)
1. Arbitrary Waveform Generator (NI Elvismx Instrument
Launcher)
1. Tektronix oscilloscope (Multisim)
1. Oscilloscope (NI Elvismx Instrument Launcher)
1. Hardware Equipment:
1. Breadboard
1. NI myDAQ Instrument Device
1. Screw Driver
1. Screw Terminal connector
1. Jumper wires
Problem statement
The circuits shown in the figure below both for the half-wave
rectifier and a full wave rectifier are to be constructed in
MULTISIM and on a breadboard.
Theoretical solution
For the half wave rectifier the calculations are done as follows:
Without filter capacitor
The input voltage is 30V rms. The transformer has a turn-ratio
of 10:1
The secondary RMS voltage is: 30V/10=3VRMS
The peak secondary voltage is equal to 3*sqrt(2)= 4.2426V
The peak load voltage is equal to 4.2426-0.7V=3.5426
23. The RMS load voltage is equal to
The average DC voltage is equal to
The peak to peak ripple voltage is equal to: 3.5426-0=3.5426V
The ripple frequency is equal to the source frequency=60Hz
Half wave rectifier with the filter capacitor:
The filter capacitor is equal to 100uF:
The ripple voltage is equal to
FULL wave rectifier calculations:
The source voltage is equal to 30V rms. The turns-ratio of the
transformer is 10:1
The secondary voltage is equal to 30V/(10*2)=1.5V
The peak secondary voltage is equal to 1.5*sqrt(2)= 2.1213V
The peak load voltage is equal to 2.1213-0.7=1.4213V
The RMS load voltage is equal to 1.4213/sqrt(2)=1.005V
The average DC load voltage is equal to: 0.637*1.4213=
0.9054V
The peak to peak ripple voltage is equal to 1.4213V-
0V=1.4213V
With the filter capacitor
The ripple frequency is equal to 2*F=1*60Hz=120Hz
The peak to peak ripple voltage is equal to
Experimental procedure
Circuit design
The half wave rectifier is constructed as shown in the figure
below:
The full-wave rectifier circuit is constructed as shown below:
Execution/results
Half wave rectifier MULTISIM measurements
1. RMS secondary voltage
24. 1. RMS load voltage
1. Peak to peak ripple voltage
1. Ripple frequency
1. Peak to peak ripple voltage with the filter capacitor
1. Ripple frequency
Half wave rectifier myDAQ measurements
1. Load voltage measurement
1. Secondary voltage measurement
1. Load voltage measurement with the filter capacitor
Full wave rectifier MULTISIM measurements
1. RMS load voltage
1. Peak to peak ripple voltage
1. Ripple frequency
1. Peak to peak voltage with filter capacitor
1. Ripple frequency
Full wave rectifier myDAQ measurements
1. Load voltage without the filter capacitor
1. Load voltage with the filter capacitor
Analysis
25. The measured and the calculated values were summarized in the
tables below:
1. Half –wave rectifier
Parameter
Calculated value
Multisim value
NI myDAQ value
RMS load voltage
1.7713V
1.4V
1.756V
RMS secondary voltage
3V
3V
3V
Ripple voltage
3.5426V
3.68V
3.682V
Ripple frequency
60Hz
60Hz
60Hz
Ripple voltage with capacitor
267mV
217mV
216.85mV
Ripple frequency with capacitor
60Hz
60Hz
60Hz
26. 1. Full wave rectifier values
Parameter
Calculated value
Multisim value
NI myDAQ value
RMS load voltage
1.005V
561mV
1.046V
RMS secondary voltage
1.5V
1.5V
1.5V
Ripple voltage
1.4213V
1.6V
1.594V
Ripple frequency
120Hz
120Hz
120Hz
Ripple voltage with capacitor
53.8mV
40.7mV
40.45mV
Ripple frequency with capacitor
120Hz
120Hz
120Hz
Review questions
Part 1
1. What is the purpose of having a half-wave rectifier in the
27. circuit?
It converts the positive going cycles of an alternating AC
voltage into a pulsating DC voltage.
1. Describe the procedure in this lab to arrive at the final design
of both the hardware portion and the software portion to achieve
the design objectives?
The connections on the breadboard and in the MULTISIM
software were done as per the connection diagram.
1. Discuss the impact of having the capacitor on the output
voltage and the effect of additional load on the ripple voltage.
The function of the capacitor is to reduce the ripples in the
output voltage and make it more like a DC voltage.
Part 2
1. What is the purpose of having a full-wave rectifier in the
circuit?
A full-wave rectifier converts the alternating AC voltage into a
pulsating DC voltage. It conducts for both the positive going
cycle and the negative going cycle.
1. Describe the procedure in this lab to arrive at the final design
of both the hardware portion and the software portion to achieve
the design objectives?
The connections on the breadboard and in the MULTISIM
software were done as per the connection diagram.
1. Discuss the impact of having the capacitor on the output
voltage and the effect of additional load on the ripple voltage.
The function of the capacitor is to reduce the ripples in the
output voltage and make it more like a DC voltage.
1. How is the output of the full-wave rectifier different from
half-wave rectifier?
The output voltage of a full wave rectifier is more linear than
the output voltage of a half wave rectifier.
Conclusion
28. This lab exercise was a good insight in the study and design of a
half wave rectifier and a full wave rectifier. The measured
values and the calculated values were very close to each other
and thus the lab exercise was a success.
Electronics I and Lab
Bridge Rectifier
Introduction:
Week 3 lab is based on the previous lab from week 2 on half-
wave and full-wave rectifiers and taking that knowledge to
build a bridge rectifier.
Materials and Equipment:
Materials:
· Simulated Parts (Multisim):
. A 30/3 Vrms center-tapped transformer
. Two diodes 1N4001
. Two 2.2 kΩ resistors
. One 100 μF, 50 V electrolytic capacitor (any voltage rating is
fine since is simulation only)
. One fuse (any rating is fine since is simulation only)
Equipment:
· Virtual Instruments (Multisim):
. Tektronix Oscilloscope
. Agilent Multimeter
. Agilent Function generator
Procedure:
*** This lab has to be implemented only in software (running
simulations on Multisim)***
1. Construct the bridge rectifier circuit shown in Figure 1.
Notice that no terminal of the transformer secondary is at
ground potential (some simulation software will not run if it is
not connected to the ground, check yours). The input voltage to
the bridge, VSEC, is not referenced to ground. Make sure to
include resistor tolerance of 5%.
2. Use a function generator to provide VAC and run the
29. simulation.
3. Use a multimeter to measure VSEC (rms) and then use the
oscilloscope to measure the peak output voltage (VLOAD)
without a filter capacitor. Tabulate all data gathered.
Figure 1
4. Connect the 100 μF capacitor in parallel with the load
resistor. Measure VLOAD, the peak-to-peak ripple voltage
VRIPPLE, and the ripple frequency. Tabulate all data gathered
and compare the results with and without the filter capacitor.
Without the capacitor
With the capacitor
Output load voltage VLOAD
Peak-to-peak ripple voltage VRIPPLE
Ripple frequency
5. Choose a diode among the four connected to the bridge and
open it. Simulate an open diode in the bridge and explain what
happens to the output voltage, the ripple voltage and the ripple
frequency?
6. Investigate the effect of the load resistor on the ripple
voltage by connecting a second 2.2 kΩ, 5% tolerance, and load
resistor in parallel with RL and C1 in the full-wave circuit of
Figure 3. Measure the ripple voltage. Captures a screenshot.
Review questions:
1. Compare a bridge rectifier circuit with full-wave rectifier
center-tapped circuit which you did in Lab 2. Which circuit has
the higher output voltage?
2. Explain how you could measure the ripple frequency to
determine if a diode were open in a bridge rectifier circuit.
30. 3. What is the maximum dc voltage you could expect to obtain
from a transformer with a 3 Vrms secondary using a bridge
circuit with a filter capacitor?
Deliverables:
1. Measure the voltage VSEC and the output load voltage,
VLOAD without a filter capacitor. Capture the screenshots of
your measurements.
2. Measure the output load voltage, VLOAD, with the capacitor
and the peak-to-peak ripple voltage, VRIPPLE, in the output.
Capture the screenshots of your measurements. Also, measure
the ripple frequency. Table with all the data gathered for the
circuit with and without the capacitor.
3. Follow the template “Lab Report Template” to compile the
report and make sure to check the report against the grading
rubric below. The template can be found in the “Tools and
Templates” link in the navigation center.
4. Make sure to include the table, calculations, screenshots of
the measurements and the answer to the questions. Save the
document as Lab2YourGID.docx (ex: Lab3G00000000.docx).
Grading Criteria
Points
Construct bridge rectifier circuit in Multisim without a
capacitor
15
Measurement of VSEC and VLOAD voltages with screenshots
10
Construct bridge rectifier circuit in Multisim with a capacitor
10
Measurement of VSEC, VLOAD and VRIPPLE voltages with
screenshots
15
Simulation with an open diode and measurement with
screenshots
20
Including 5% tolerances in the measurements
10